:root {
  --navy: #0d1b2a;
  --bg: #eef3f8;
  --bg-elev: #ffffff;
  --sidebar: #0d1b2a;
  --line: #d5e0ea;
  --text: #1c2e3d;
  --muted: #5d7386;
  --accent: #00cb98;
  --accent-2: #20e0c9;
  --user: #e4f7f2;
  --danger: #c94c4c;
  --shadow: 0 16px 40px rgba(13, 27, 42, .08);
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden;
}
body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
  background:
    radial-gradient(900px 480px at 100% 0%, rgba(0, 203, 152, .10), transparent 50%),
    radial-gradient(700px 400px at 0% 100%, rgba(32, 120, 180, .08), transparent 55%),
    var(--bg);
}

.app {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--sidebar);
  border-right: 1px solid #16324a;
  padding: 22px 16px 16px;
  min-width: 0;
  color: #eef5fa;
  --text: #eef5fa;
  --muted: #8aa3b7;
  --line: #1e3a52;
}

.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 18px; flex-shrink: 0; }
.logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  flex-shrink: 0;
}
.brand-name { font-weight: 800; letter-spacing: .4px; font-size: 20px; color: #eef5fa; }
.brand-name span { color: var(--accent); }
.brand-sub { color: #8aa3b7; font-size: 12px; margin-top: 1px; letter-spacing: .08em; text-transform: uppercase; }

.logo-badge {
  width: 128px;
  height: 128px;
  border-radius: 22px;
  background: #fff;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(13, 27, 42, .10);
}
.logo-badge img { width: 112px; height: 112px; object-fit: contain; }

.new-chat {
  width: 100%;
  border: 1px solid #1e3a52;
  background: #132536;
  color: #eef5fa;
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  flex-shrink: 0;
}
.new-chat:hover { border-color: var(--accent); color: var(--accent); }

.conv-search {
  width: 100%;
  margin-top: 12px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid #1e3a52;
  background: #132536;
  color: #eef5fa;
  font: inherit;
}

.conv-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin: 22px 8px 8px;
}
.conv-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}
.group-label {
  color: var(--muted);
  font-size: 11px;
  margin: 14px 8px 6px;
}
.conv {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 8px;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.conv:hover, .conv.active { background: #16324a; }
.conv .title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: inherit;
  font-size: 14px;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.conv .ops { display: none; gap: 2px; flex-shrink: 0; }
.conv:hover .ops { display: flex; }
@media (hover: none) {
  .conv.active .ops { display: flex; }
}
.ghost {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 12px;
}
.ghost:hover { color: var(--text); background: #e4edf4; }
.sidebar .ghost:hover { background: #1a3144; color: #eef5fa; }
.ghost.danger:hover { color: var(--danger); }

.sidebar-foot {
  color: var(--muted);
  font-size: 11px;
  padding: 8px 8px 4px;
}

.settings-btn {
  width: 100%;
  margin-top: 12px;
  border: 1px solid #1e3a52;
  background: transparent;
  color: #8aa3b7;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  text-align: left;
  flex-shrink: 0;
}
.settings-btn:hover { color: #eef5fa; border-color: var(--accent); }

.setup-note {
  margin-top: 18px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}
.setup-note:hover { border-color: var(--accent); }

.icon-btn.shown { display: inline-flex; align-items: center; justify-content: center; }

.settings-shell {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(920px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 32px));
  color: var(--text);
}
.settings-shell::backdrop { background: rgba(13, 27, 42, .45); }
.settings-win {
  display: flex;
  flex-direction: column;
  height: min(720px, calc(100vh - 32px));
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  color: var(--text);
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.settings-head h2 { margin: 0; font-size: 18px; }
.settings-body { display: grid; grid-template-columns: 220px 1fr; min-height: 0; flex: 1; }
.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 12px;
  border-right: 1px solid var(--line);
  background: #f4f8fb;
  overflow: auto;
}
.settings-nav input {
  margin: 0 0 10px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  font: inherit;
}
.set-nav {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
}
.set-nav:hover { background: #e7eef4; }
.set-nav.active { background: #d9f5ed; color: #0d1b2a; }
.settings-main { overflow: auto; padding: 8px 28px 28px; }
.set-panel { display: none; }
.set-panel.active { display: block; }
.set-panel h3 { margin: 18px 0 14px; font-size: 22px; }
.set-lead { color: var(--muted); margin: 0 0 16px; }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.set-row.stack { align-items: flex-start; flex-direction: column; gap: 12px; }
.set-row strong { display: block; margin-bottom: 4px; }
.set-row p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; max-width: 420px; }
.set-row em { display: block; margin-top: 8px; font-style: normal; font-size: 13px; color: #b5811a; }
.set-row code { color: var(--accent); }
.set-value { color: var(--muted); white-space: nowrap; font-size: 14px; }
.set-key { display: flex; gap: 8px; width: 100%; max-width: 520px; }
.set-key input {
  flex: 1;
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  font: inherit;
}
.set-key .primary, .modal-actions .primary {
  border: 0;
  background: var(--accent);
  color: #04241d;
  font-weight: 800;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font: inherit;
}
.set-models { list-style: none; margin: 0; padding: 0; }
.set-models li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.set-models b { color: var(--text); font-weight: 600; }

@media (max-width: 720px) {
  .settings-body { grid-template-columns: 1fr; }
  .settings-nav {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .settings-nav input { width: 100%; }
  .set-row { flex-direction: column; align-items: flex-start; }
}

.main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: transparent;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.72);
  flex-shrink: 0;
}
.top-title { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  display: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
}
.model-wrap { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.test-ai-btn { font-size: 12px; padding: 6px 10px; white-space: nowrap; }
.model-wrap select {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  max-width: 260px;
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.main.empty .stage { justify-content: center; }
.main.empty .thread { display: none; }
.main.active .welcome { display: none; }
.main.active .powered { display: none; }

.welcome {
  text-align: center;
  padding: 12px 24px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.welcome h1 { margin: 0; font-size: 42px; letter-spacing: .4px; color: #0d1b2a; }
.welcome-q { margin: 10px 0 0; color: var(--muted); font-size: 18px; }

.thread {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 28px 20px 12px;
}
.thread-inner { max-width: 820px; margin: 0 auto; }
.msg { margin: 0 0 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: 78%;
  background: var(--user);
  border: 1px solid #b7e8d8;
  border-radius: 16px 16px 6px 16px;
  padding: 12px 16px;
  white-space: pre-wrap;
  line-height: 1.55;
}
.msg.assistant .who {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  margin-bottom: 8px;
}
.msg.assistant .bubble {
  background: #ffffff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 4px 16px 16px 16px;
  padding: 16px 18px 12px;
  line-height: 1.65;
  overflow-x: auto;
}
.msg .actions { display: flex; gap: 8px; margin-top: 8px; }

.md h1, .md h2, .md h3 { line-height: 1.25; margin: 1.1em 0 .4em; }
.md h1 { font-size: 1.4em; }
.md h2 { font-size: 1.2em; }
.md p { margin: .7em 0; }
.md ul, .md ol { margin: .5em 0 .8em 1.2em; }
.md a { color: var(--accent); }
.md pre {
  position: relative;
  background: #f4f7fb;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 36px 14px 14px;
  overflow: auto;
  margin: 12px 0;
}
.md code { font-family: Consolas, "Cascadia Code", monospace; font-size: 13px; }
.md p code, .md li code {
  background: #e8eef4;
  padding: 1px 6px;
  border-radius: 6px;
}
.md table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.md th { background: #eef4f8; }
.md blockquote {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 11px;
}

.composer-dock {
  width: min(820px, calc(100% - 32px));
  margin: 0 auto 18px;
  flex-shrink: 0;
}
.stream-progress {
  padding: 0 22px 10px;
  background: rgba(255, 255, 255, .82);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  transition: opacity .25s ease, max-height .25s ease;
  max-height: 44px;
  overflow: hidden;
}
.stream-progress[hidden] { display: none !important; }
.stream-progress.is-idle .stream-progress-track { display: none; }
.stream-progress.is-idle .stream-progress-comment { margin-top: 0; }
.stream-progress-track {
  height: 3px;
  margin-top: 10px;
  border-radius: 999px;
  background: #d5e0ea;
  overflow: hidden;
}
.stream-progress-bar {
  height: 100%;
  width: 34%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  animation: stream-indeterminate 1.1s ease-in-out infinite;
}
.stream-progress-comment {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
}
.think-inline span {
  color: var(--muted);
  font-size: 13px;
}
@keyframes stream-indeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
@media (prefers-reduced-motion: reduce) {
  .stream-progress-bar { animation: none; width: 100%; opacity: .65; }
}
.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.icon-attach {
  border: 0;
  background: #e8eef4;
  color: #0d1b2a;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
}
.attach-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 4px 8px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 12px;
}
.chip img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.drop-mask {
  position: fixed;
  inset: 0;
  background: rgba(13, 27, 42, .55);
  color: #fff;
  display: none;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  z-index: 40;
  pointer-events: none;
}
.drop-mask:not([hidden]) {
  display: grid;
}
.msg .thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg .thumbs img { max-width: 180px; max-height: 140px; border-radius: 10px; border: 1px solid var(--line); }
.vision { color: var(--accent); font-size: 11px; margin-left: 6px; }
textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
  max-height: 180px;
  min-height: 28px;
}
.send, .stop {
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.send { background: var(--accent); color: #04241d; }
.send:disabled { opacity: .45; cursor: default; }
.stop { background: #f3e8ea; color: #8a2f2f; }
.powered { text-align: center; color: var(--muted); font-size: 11px; margin: 10px 0 0; letter-spacing: .04em; }

.error-card {
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid #f0c9c9;
  background: #fff6f6;
  border-radius: 12px;
  color: #7a2e2e;
}
.error-card button {
  margin-top: 10px;
  border: 0;
  background: var(--accent);
  color: #04241d;
  font-weight: 800;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

.modal {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  color: var(--text);
  padding: 0;
  width: min(420px, 92vw);
}
.modal::backdrop { background: rgba(0, 0, 0, .55); }
.modal form { padding: 20px; }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { color: var(--muted); }
.modal input {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  font: inherit;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions button {
  border: 1px solid var(--line);
  background: #f4f8fb;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}
.modal-actions .danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 20;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    z-index: 30;
    transform: translateX(-105%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .welcome h1 { font-size: 32px; }
  .model-wrap span { display: none; }
  .msg.user .bubble { max-width: 92%; }
}
