*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--t2); }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

:root {
  --bg-0: #0d0d0d;
  --bg-1: #141414;
  --bg-2: #1c1c1c;
  --bg-3: #252525;
  --border: #2a2a2a;
  --t0: #e8e8e8;
  --t1: #888;
  --t2: #555;
  --accent: #4f8ef7;
  --accent-h: #6ba3ff;
  --accent-d: rgba(79,142,247,0.1);
  --green: #34c759;
  --yellow: #ff9f0a;
  --red: #ff453a;
  --r: 6px;
  --bar: 52px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
body { background: var(--bg-0); color: var(--t0); overflow: hidden; }

#app { display: flex; flex-direction: column; height: 100vh; }

#topbar {
  height: var(--bar);
  min-height: var(--bar);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  gap: 12px;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: var(--t0);
}

.topbar-brand-icon {
    height: 28px;
    width: auto;
}
.topbar-right { display: flex; align-items: center; gap: 4px; }

.logo-img {
    position: fixed;
    bottom: 24px;
    left: 24px;
    height: 80px;
    width: auto;
    opacity: 1;
    pointer-events: none;
    z-index: 0;
}

@media (max-width: 768px) {
    .logo-img { display: none; }
}

.topbar-right button {
  display: flex; align-items: center; gap: 5px;
  background: none; border: 1px solid var(--border); color: var(--t1);
  padding: 5px 10px; border-radius: var(--r); font-size: 12px;
  cursor: pointer; transition: all 0.12s; white-space: nowrap;
}
.topbar-right button:hover { background: var(--bg-3); color: var(--t0); border-color: var(--accent); }
.topbar-right button:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }
#settings-btn { padding: 5px 7px; }

.model-status { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.model-status.checking   .status-dot { background: var(--yellow); animation: pulse 1.5s infinite; }
.model-status.ready      .status-dot { background: var(--green); }
.model-status.unavailable .status-dot { background: var(--red); }
.model-status.downloading .status-dot { background: var(--accent); animation: pulse 1s infinite; }
.model-status.ready       .status-text { color: var(--green); }
.model-status.unavailable .status-text { color: var(--red); }
.model-status.downloading .status-text { color: var(--accent); }
.model-status.checking    .status-text { color: var(--yellow); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#welcome-screen { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.welcome-content { text-align: center; max-width: 460px; }
.welcome-icon { margin-bottom: 18px; }
.welcome-icon img { height: 40px; width: auto; }
.welcome-content h1 { font-size: 24px; font-weight: 600; margin-bottom: 6px; letter-spacing: -0.3px; }
.welcome-content > p { color: var(--t1); font-size: 13px; margin-bottom: 22px; }
.welcome-chips { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }
.chip {
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--t1); padding: 7px 13px; border-radius: 4px;
  cursor: pointer; font-size: 12px; transition: all 0.12s;
}
.chip:hover { background: var(--bg-3); color: var(--t0); border-color: var(--accent); }

#messages-container { flex: 1; overflow-y: auto; padding: 20px 0; }

#messages { max-width: 700px; margin: 0 auto; padding: 0 24px; display: flex; flex-direction: column; gap: 18px; }

.message { display: flex; gap: 11px; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from{opacity:0;transform:translateY(5px)} to{opacity:1;transform:none} }

.message-avatar {
  width: 26px; height: 26px; border-radius: 4px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; margin-top: 2px;
}
.message.user .message-avatar { background: var(--accent); color: #fff; }
.message.ai   .message-avatar { background: #185FA5; border: none; padding: 3px; }
.message.ai   .message-avatar img { width: 100%; height: 100%; object-fit: contain; filter: brightness(0) invert(1); }

.message-body { flex: 1; min-width: 0; }
.message-name { font-size: 11px; font-weight: 600; color: var(--t2); margin-bottom: 4px; }

.message-text { font-size: 14px; line-height: 1.7; color: var(--t0); word-break: break-word; }
.message-text p { margin-bottom: 7px; }
.message-text p:last-child { margin-bottom: 0; }
.message-text h1,.message-text h2,.message-text h3 { font-weight: 600; margin: 12px 0 5px; }
.message-text h1 { font-size: 17px; }
.message-text h2 { font-size: 15px; }
.message-text h3 { font-size: 14px; }
.message-text ul,.message-text ol { padding-left: 18px; margin-bottom: 7px; }
.message-text li { margin-bottom: 2px; }
.message-text blockquote { border-left: 2px solid var(--accent); padding-left: 10px; color: var(--t1); margin: 7px 0; }
.message-text hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.message-text a { color: var(--accent); text-decoration: underline; }
.message-text code { background: var(--bg-2); border: 1px solid var(--border); border-radius: 3px; padding: 1px 4px; font-family: 'SF Mono','Consolas',monospace; font-size: 12px; }
.message-text pre { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r); padding: 12px; overflow-x: auto; margin: 7px 0; }
.message-text pre code { background: none; border: none; padding: 0; }

.message-attachments { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 7px; }
.attachment-thumb { width: 72px; height: 72px; border-radius: var(--r); overflow: hidden; border: 1px solid var(--border); background: var(--bg-2); }
.attachment-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attachment-file { display: flex; align-items: center; gap: 5px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r); padding: 6px 10px; font-size: 12px; color: var(--t1); }

.dino-typing {
    display: inline-block;
    width: 18px;
    height: auto;
    margin-left: 6px;
    vertical-align: middle;
    filter: brightness(0) invert(0.6);
    animation: dino-hop 0.35s steps(1) infinite;
    transform-origin: bottom center;
}

@keyframes dino-hop {
    0%   { transform: translateY(0); }
    50%  { transform: translateY(-4px); }
    100% { transform: translateY(0); }
}

#attachments-preview { max-width: 700px; width: 100%; margin: 0 auto; padding: 7px 24px 0; display: flex; flex-wrap: wrap; gap: 7px; }
.preview-item { position: relative; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.preview-item img { width: 56px; height: 56px; object-fit: cover; display: block; }
.preview-item-file { display: flex; align-items: center; gap: 5px; padding: 7px 10px; font-size: 12px; color: var(--t1); height: 36px; }
.preview-remove { position: absolute; top: 3px; right: 3px; width: 16px; height: 16px; background: rgba(0,0,0,.75); border: none; border-radius: 3px; color: #fff; cursor: pointer; font-size: 11px; display: flex; align-items: center; justify-content: center; }

#input-area { padding: 10px 24px 14px; max-width: 700px; width: 100%; margin: 0 auto; }

#input-box {
  display: flex; align-items: flex-end; gap: 7px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 9px 11px; transition: border-color 0.12s;
}
#input-box:focus-within { border-color: var(--accent); }

#attach-btn, #send-btn {
  background: none; border: none; cursor: pointer; color: var(--t2);
  padding: 3px; border-radius: 4px; display: flex; align-items: center;
  transition: all 0.12s; flex-shrink: 0;
}
#attach-btn:hover { color: var(--t1); background: var(--bg-3); }
#send-btn:not(:disabled) { color: var(--accent); }
#send-btn:not(:disabled):hover { color: var(--accent-h); background: var(--accent-d); }
#send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

#message-input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--t0); font-size: 14px; font-family: inherit;
  resize: none; max-height: 200px; line-height: 1.5;
}
#message-input::placeholder { color: var(--t2); }

.input-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; gap: 8px; }
.input-disclaimer { font-size: 11px; color: var(--t2); white-space: nowrap; }
.footer-credit { flex-shrink: 0; }
.footer-credit a { color: var(--t2); text-decoration: none; transition: color 0.12s; }
.footer-credit a:hover { color: var(--accent); }

.dino-runner {
  width: 0; height: 22px; flex-shrink: 0; overflow: hidden;
  transition: width 0.18s ease; position: relative; display: flex; align-items: center;
}
.dino-runner.running { width: 30px; }
.dino {
  position: absolute; left: 0; width: 14px; height: auto;
  animation: dino-bounce 0.3s steps(1) infinite, dino-move 0.9s ease-in-out infinite alternate;
  animation-play-state: paused; opacity: 0; transition: opacity 0.12s;
}
.dino-runner.running .dino { animation-play-state: running; opacity: 1; }
@keyframes dino-bounce { 0%{transform:translateY(0)} 50%{transform:translateY(-3px)} }
@keyframes dino-move { 0%{left:0} 100%{left:13px} }

.panel { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; justify-content: flex-end; z-index: 200; backdrop-filter: blur(2px); }
.panel-content {
  width: 340px; max-width: 100%; background: var(--bg-1); border-left: 1px solid var(--border);
  height: 100%; overflow-y: auto; padding: 22px; display: flex; flex-direction: column;
  gap: 18px; animation: slideIn 0.18s ease;
}
@keyframes slideIn { from{transform:translateX(30px);opacity:0} to{transform:none;opacity:1} }

.panel-header { display: flex; align-items: center; justify-content: space-between; }
.panel-header h2 { font-size: 15px; font-weight: 600; }
.icon-btn { background: none; border: none; color: var(--t1); cursor: pointer; padding: 3px; border-radius: 4px; display: flex; transition: color 0.12s; }
.icon-btn:hover { color: var(--t0); }

.settings-group { display: flex; flex-direction: column; gap: 5px; }
.settings-label { font-size: 11px; color: var(--t2); font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }
.settings-input, .settings-textarea {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r);
  color: var(--t0); font-size: 13px; font-family: inherit;
  padding: 8px 10px; outline: none; transition: border-color 0.12s; resize: vertical;
}
.settings-input:focus, .settings-textarea:focus { border-color: var(--accent); }
.settings-hint { font-size: 11px; color: var(--t2); }
.settings-actions { display: flex; gap: 7px; }
.settings-divider { border-top: 1px solid var(--border); }
.storage-info { font-size: 12px; color: var(--t1); background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r); padding: 7px 10px; }

.btn-primary { background: var(--accent); color: #fff; border: none; padding: 9px 18px; border-radius: var(--r); font-size: 13px; font-weight: 500; cursor: pointer; transition: background 0.12s; }
.btn-primary:hover { background: var(--accent-h); }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--t1); padding: 9px 18px; border-radius: var(--r); font-size: 13px; cursor: pointer; transition: all 0.12s; }
.btn-outline:hover { border-color: var(--accent); color: var(--t0); }
.btn-secondary { display: inline-block; margin-top: 7px; color: var(--accent); text-decoration: none; font-size: 12px; }
.btn-danger { background: none; border: 1px solid var(--red); color: var(--red); padding: 8px 14px; border-radius: var(--r); font-size: 12px; cursor: pointer; transition: all 0.12s; }
.btn-danger:hover { background: rgba(255,69,58,.08); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 300; backdrop-filter: blur(3px); }
.modal-content { background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--r); padding: 28px; max-width: 380px; width: 90%; text-align: center; }
.modal-icon { color: var(--accent); margin-bottom: 12px; }
.modal-content h2 { font-size: 16px; margin-bottom: 7px; }
.modal-content > p { color: var(--t1); font-size: 13px; margin-bottom: 16px; }

.progress-bar { background: var(--bg-2); border-radius: 3px; height: 4px; overflow: hidden; margin-bottom: 7px; }
.progress-fill { height: 100%; background: var(--accent); transition: width .25s; width: 0%; }
#progress-text { font-size: 12px; color: var(--t1); }

.setup-note { font-size: 11px; color: var(--t2); margin-top: 9px; }
.setup-section-label { font-size: 11px; color: var(--t2); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 9px; }
#setup-error-msg { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.setup-error-actions { display: flex; flex-direction: column; gap: 7px; align-items: center; }

.lang-grid { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.lang-check {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 7px 12px; font-size: 13px; color: var(--t1);
  cursor: pointer; transition: all 0.12s;
}
.lang-check:has(input:checked) { border-color: var(--accent); color: var(--accent); background: var(--accent-d); }
.lang-check input { accent-color: var(--accent); cursor: pointer; }

.compat-box { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.compat-title { font-size: 11px; color: var(--t2); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 2px; }
.compat-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--t1); }
.compat-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--t2); }
.compat-ok   { background: var(--green); }
.compat-fail { background: var(--red); }
.compat-warn { background: var(--yellow); }

.specs-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r); padding: 9px 11px; font-size: 12px; }
.specs-key { color: var(--t2); white-space: nowrap; }
.specs-val { color: var(--t1); word-break: break-word; }

.chrome-links { display: flex; flex-direction: column; gap: 5px; }
.chrome-link-btn {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r);
  color: var(--t1); font-size: 11px; font-family: 'SF Mono','Consolas',monospace;
  padding: 7px 10px; cursor: pointer; text-align: left; transition: all 0.12s; word-break: break-all;
}
.chrome-link-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-d); }

.msg-copy {
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: 1px solid var(--border); border-radius: var(--r);
  color: var(--t2); font-size: 11px; padding: 3px 8px; cursor: pointer;
  margin-top: 7px; transition: all 0.12s; opacity: 0;
}
.message.ai:hover .msg-copy { opacity: 1; }
.msg-copy:hover { color: var(--t0); border-color: var(--t1); }

.code-block { margin: 8px 0; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.code-header { display: flex; align-items: center; justify-content: space-between; background: var(--bg-3); padding: 5px 10px; }
.code-lang { font-size: 11px; color: var(--t2); font-family: 'SF Mono','Consolas',monospace; text-transform: uppercase; letter-spacing: .4px; }
.code-copy { background: none; border: 1px solid var(--border); color: var(--t2); font-size: 11px; padding: 2px 8px; border-radius: 3px; cursor: pointer; transition: all 0.12s; }
.code-copy:hover { color: var(--t0); border-color: var(--t1); }
.code-block pre { margin: 0; border: none; border-radius: 0; background: var(--bg-2); padding: 12px; }


.history-dropdown {
  position: absolute;
  top: calc(var(--bar) + 4px);
  right: 16px;
  width: 280px;
  max-height: 420px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.history-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--t1); }
#history-list { overflow-y: auto; max-height: 360px; padding: 4px; }
.history-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--r); cursor: pointer; transition: background 0.12s; }
.history-item:hover { background: var(--bg-3); }
.history-item.active { background: var(--bg-2); }
.history-title { flex: 1; font-size: 13px; color: var(--t1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item.active .history-title { color: var(--t0); }
.history-del { background: none; border: none; color: var(--t2); cursor: pointer; padding: 2px; border-radius: 3px; display: flex; transition: color 0.12s; flex-shrink: 0; }
.history-del:hover { color: var(--red); }
.history-empty { font-size: 13px; color: var(--t2); text-align: center; padding: 20px; }

.analyzing-label {
    font-size: 13px;
    color: var(--t1);
    font-style: italic;
    margin-right: 4px;
}

/* pdf reading toast */

.pdf-toast {
    position: fixed;
    bottom: 32px;
    right: 32px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 12px 18px;
    font-size: 13px;
    color: var(--t1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
    z-index: 500;
    animation: toastIn 0.2s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}

.pdf-toast-dino {
    width: 22px;
    height: auto;
    filter: brightness(0) invert(0.6);
    animation: dino-hop 0.3s steps(1) infinite;
}

.hidden { display: none !important; }

@media (max-width: 600px) {
  #messages, #attachments-preview { padding-left: 14px; padding-right: 14px; }
  #input-area { padding: 8px 14px 12px; }
}
