:root {
  --bg: #0b1020;
  --bg-soft: #111829;
  --panel: #151d31;
  --panel-2: #1b2438;
  --border: #263049;
  --text: #e6ebf5;
  --muted: #8c9ab5;
  --accent: #6366f1;
  --accent-soft: #312e81;
  --ok: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, #1e2a52 0%, transparent 55%), var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1 1 auto; min-height: 0; }

/* ---------------------------------------------------------------- login */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}

.logo {
  font-size: 42px;
  line-height: 1;
  color: var(--accent);
  margin-bottom: 10px;
}
.logo.small { font-size: 20px; margin: 0; }

.login h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.02em; }
.login form { display: grid; gap: 10px; margin: 22px 0 14px; text-align: left; }
.recaptcha { display: flex; justify-content: center; margin: 2px 0; }
.login label { font-size: 13px; color: var(--muted); }
.login input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14px;
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

/* ---------------------------------------------------------------- shell */
.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 16px;
  background: rgba(17, 24, 41, .82);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  letter-spacing: -.01em;
  padding: 2px 2px 6px;
}

.badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 999px;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  font-weight: 600;
}

.dropzone {
  display: grid;
  gap: 3px;
  padding: 14px;
  border: 1px dashed #33405f;
  border-radius: 10px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  margin-bottom: 10px;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: rgba(99, 102, 241, .08); }
.dropzone span { color: var(--text); }
.dropzone small { color: var(--muted); }

.file-list, .tool-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 13px;
}
.file-item:hover { background: var(--panel-2); }
.file-item a { color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item a:hover { color: var(--accent); }
.file-item .size { margin-left: auto; color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.file-item button {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 14px; line-height: 1; padding: 2px 4px; border-radius: 6px;
}
.file-item button:hover { color: var(--error); background: rgba(248, 113, 113, .1); }

.tool-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 13px;
}
.tool-item:hover { background: var(--panel-2); }
.tool-item.clickable { cursor: pointer; }
.tool-item.clickable:hover { box-shadow: inset 0 0 0 1px var(--border); }
.tool-item .tool-name { font-weight: 550; }
.tool-item .tool-desc { grid-column: 1 / -1; color: var(--muted); font-size: 11.8px; line-height: 1.4; }
.tool-state {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 6px; border-radius: 999px; align-self: start;
}
.tool-state.available { color: var(--ok); background: rgba(52, 211, 153, .1); border: 1px solid rgba(52, 211, 153, .25); }
.tool-state.planned { color: var(--muted); background: rgba(140, 154, 181, .08); border: 1px solid var(--border); }

.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-top: 1px solid var(--border); padding-top: 12px; margin-top: auto;
}
.panel-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 8px;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
  cursor: pointer;
}
.panel-toggle:hover { color: var(--text); }
.panel-toggle .chevron { font-size: 10px; transition: transform .15s ease; }
.panel-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }

.new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.new-chat:hover { border-color: var(--accent); background: rgba(99, 102, 241, .1); color: #c7d2fe; }
.new-chat .plus { font-size: 15px; line-height: 1; color: var(--accent); }
.account { display: flex; align-items: center; gap: 8px; min-width: 0; }
.avatar-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }
#user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ composer */
.icon-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { color: var(--accent); border-color: var(--accent); background: rgba(99, 102, 241, .1); }
.composer.dragover { border-radius: 14px; background: rgba(99, 102, 241, .08); }
.composer-hint { text-align: center; margin: 0 0 14px; }
.chip a { color: inherit; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip a:hover { text-decoration: underline; }
.chip-dl { font-size: 12px; opacity: .75; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 8px; }

/* ---------------------------------------------------------------- main */
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 16, 32, .7);
  backdrop-filter: blur(8px);
}
.selects { display: flex; gap: 8px; flex-wrap: wrap; }
.topbar-right { margin-left: auto; }

select {
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  max-width: 260px;
}
select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.status { font-size: 12.5px; color: var(--muted); }
.status.error { color: var(--error); }

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 26px 22px 10px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.empty-state { margin: auto; text-align: center; max-width: 460px; padding: 30px; }
.empty-state h3 { margin: 0 0 6px; font-size: 19px; }

.msg { display: flex; gap: 12px; max-width: 900px; width: 100%; margin: 0 auto; }
.msg .avatar {
  flex: 0 0 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--panel-2); color: var(--muted);
}
.msg.user .avatar { background: var(--accent-soft); color: #c7d2fe; }
.msg .bubble { min-width: 0; flex: 1 1 auto; }
.msg .role { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; letter-spacing: .02em; }
.msg .content { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .content pre {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 9px;
  padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 13px; white-space: pre;
}
.msg .content code { font-family: var(--mono); font-size: 13px; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
.msg .content pre code { background: none; padding: 0; }
.msg .thinking { color: var(--muted); font-style: italic; font-size: 13px; white-space: pre-wrap; margin-bottom: 6px; }
.msg .copy { margin-top: 6px; border: none; background: none; color: var(--muted); font-size: 11.5px; cursor: pointer; padding: 0; }
.msg .copy:hover { color: var(--accent); }

.composer-wrap {
  max-width: 940px;
  width: 100%;
  margin: 0 auto;
  padding: 10px 22px 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  border: 1px solid #3b3a8f;
  color: #c7d2fe;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  border: none;
  background: none;
  color: #c7d2fe;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 999px;
}
.chip button:hover { color: #fff; background: rgba(255, 255, 255, .1); }

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  width: 100%;
  margin: 0;
  padding: 8px 0 20px;
}
.composer textarea {
  flex: 1 1 auto;
  resize: none;
  max-height: 220px;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
  text-decoration: none; transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.google { width: 100%; margin: 6px 0 4px; }
.btn.small-btn { padding: 5px 10px; font-size: 12.5px; }

.error { color: var(--error); font-size: 13px; }
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); z-index: 10;
}
.toast.error { border-color: rgba(248, 113, 113, .5); color: var(--error); }

/* ------------------------------------------------------------- attachments */
.file-item.attached { background: rgba(99, 102, 241, .12); }
.file-item button.attach,
.file-item button.preview,
.file-item button.ask { font-size: 12px; font-weight: 600; }
.file-item button.attach:hover,
.file-item button.preview:hover,
.file-item button.ask:hover { color: var(--accent); background: rgba(99, 102, 241, .12); }
.attached-note { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.attached-note.error { color: var(--error); }
.linklike {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}

dialog.preview {
  width: min(900px, 92vw);
  max-height: 82vh;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
dialog.preview::backdrop { background: rgba(0, 0, 0, .6); }
dialog.preview header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
dialog.preview header button {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
dialog.preview pre {
  margin: 0;
  padding: 16px;
  max-height: 66vh;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 12.5px;
}

/* ------------------------------------------------------------------ voice */
dialog.voice { width: min(720px, 94vw); }
.voice-body { display: grid; gap: 16px; padding: 14px 16px 18px; max-height: 72vh; overflow: auto; }
.voice-block h4 { margin: 0 0 6px; font-size: 13px; }
.voice-block textarea,
.voice-block input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.voice-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.voice-lang { width: 180px; }
.voice-out {
  margin: 10px 0 0;
  padding: 10px;
  min-height: 42px;
  max-height: 170px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
}
.voice-row audio { height: 36px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .sidebar { display: none; }
}

.mode-group { display: flex; flex-wrap: wrap; gap: 10px 14px; font-size: 12.5px; }
.mode-group label { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); cursor: pointer; }
.mode-group input { accent-color: var(--accent); }

/* Document dialog download link (dark background) */
#doc-link a {
  color: #ffffff;
  text-decoration: underline;
  text-underline-offset: 2px;
}
#doc-link a:hover { color: #c7d2fe; }
