:root {
  --bg: #0f1115; --bg-2: #151821; --bg-3: #1b1f2a; --bg-4: #232838;
  --fg: #e6e8ee; --fg-2: #a7adbd; --fg-3: #6e7488;
  --line: #262b38; --line-2: #333a4d;
  --accent: #6d8cff; --accent-2: #4f6ee0;
  --ok: #35c08a; --warn: #e8b84b; --err: #f0605f;
  --radius: 10px; --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, "Helvetica Neue", Arial, sans-serif;
}
html[data-theme="light"] {
  --bg: #f6f7f9; --bg-2: #ffffff; --bg-3: #f0f2f6; --bg-4: #e4e8ef;
  --fg: #16181d; --fg-2: #4d5566; --fg-3: #808898;
  --line: #e0e4ec; --line-2: #cfd5e1;
  --accent: #3358e0; --accent-2: #24429e;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.55 var(--sans); -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; }
.login-card {
  width: 340px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 32px 28px; text-align: center;
}
.login-mark { font-size: 34px; color: var(--accent); }
.login-card h1 { font-size: 20px; margin: 8px 0 2px; }
.login-card input {
  width: 100%; margin: 18px 0 12px; padding: 11px 12px;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: var(--radius);
}
.muted { color: var(--fg-3); font-size: 13px; margin: 0; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
.app.with-drawer { grid-template-columns: 260px 1fr 440px; }

.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.brand {
  display: flex; align-items: center; gap: 9px; padding: 14px 14px 10px;
  font-weight: 600; letter-spacing: .2px; border-bottom: 1px solid var(--line);
}
.brand .mark { color: var(--accent); font-size: 17px; }
.brand .icon-btn { margin-left: auto; }

.side-section { padding: 10px 8px; border-bottom: 1px solid var(--line); min-height: 0; display: flex; flex-direction: column; }
.side-section.grow { flex: 1; border-bottom: none; }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 6px 8px; color: var(--fg-3); font-size: 11px;
  text-transform: uppercase; letter-spacing: .08em;
}
.list { display: flex; flex-direction: column; gap: 2px; }
.list.scroll { overflow-y: auto; min-height: 0; }
.item {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px;
  border-radius: 8px; cursor: pointer; color: var(--fg-2);
  border: 1px solid transparent; font-size: 13px;
}
.item:hover { background: var(--bg-3); color: var(--fg); }
.item.active { background: var(--bg-4); color: var(--fg); border-color: var(--line-2); }
.item .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.item .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.item .mini { color: var(--fg-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.item .row-btn { opacity: 0; color: var(--fg-3); background: none; border: none; cursor: pointer; padding: 0 3px; }
.item:hover .row-btn { opacity: 1; }
.item .row-btn:hover { color: var(--err); }

.side-foot { display: flex; gap: 4px; padding: 8px; border-top: 1px solid var(--line); }
.side-foot form { margin: 0; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 11px 18px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.chat-title { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
#thread-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }
.chat-actions { margin-left: auto; display: flex; gap: 6px; }
.pill {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--bg-4); color: var(--fg-2); font-weight: 500; white-space: nowrap;
}
.badge {
  display: inline-block; min-width: 17px; padding: 0 5px; margin-left: 4px;
  border-radius: 9px; background: var(--bg-4); color: var(--fg-2);
  font-size: 11px; text-align: center; font-variant-numeric: tabular-nums;
}

.messages { flex: 1; overflow-y: auto; padding: 22px 0 12px; }
.msg { max-width: 900px; margin: 0 auto 22px; padding: 0 22px; }
.msg-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
  font-size: 11px; color: var(--fg-3); text-transform: uppercase; letter-spacing: .07em;
}
.msg-head .who { font-weight: 700; letter-spacing: .1em; }
.msg.user .who { color: var(--accent); }
.msg.assistant .who { color: var(--ok); }
.msg-body { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.msg.user .msg-body { background: var(--bg-3); }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 { margin: 18px 0 8px; line-height: 1.3; }
.msg-body h1 { font-size: 20px; } .msg-body h2 { font-size: 17px; } .msg-body h3 { font-size: 15px; }
.msg-body p { margin: 9px 0; }
.msg-body ul, .msg-body ol { margin: 9px 0; padding-left: 22px; }
.msg-body li { margin: 3px 0; }
.msg-body code { font-family: var(--mono); font-size: 12.5px; background: var(--bg-4); padding: 1px 5px; border-radius: 5px; }
.msg-body pre { background: var(--bg-4); border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; overflow-x: auto; }
.msg-body pre code { background: none; padding: 0; font-size: 12.5px; }
.msg-body table { border-collapse: collapse; width: 100%; margin: 12px 0; display: block; overflow-x: auto; }
.msg-body th, .msg-body td { border: 1px solid var(--line-2); padding: 6px 9px; text-align: left; vertical-align: top; font-size: 13px; }
.msg-body th { background: var(--bg-4); font-weight: 600; }
.msg-body blockquote { margin: 10px 0; padding: 2px 14px; border-left: 3px solid var(--line-2); color: var(--fg-2); }
.msg-body img { max-width: 100%; border-radius: 8px; }
.msg-foot {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 7px;
  font-size: 11px; color: var(--fg-3); font-variant-numeric: tabular-nums;
}
.msg-foot b { color: var(--fg-2); font-weight: 600; }
.msg-imgs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.msg-imgs img { max-height: 190px; border-radius: 8px; border: 1px solid var(--line-2); }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

details.thoughts { margin-bottom: 10px; border: 1px dashed var(--line-2); border-radius: 9px; padding: 6px 11px; }
details.thoughts summary { cursor: pointer; color: var(--fg-3); font-size: 12px; }
details.thoughts .body { color: var(--fg-2); font-size: 13px; white-space: pre-wrap; margin-top: 8px; }

.ctx-report { margin-bottom: 10px; }
.ctx-report summary { cursor: pointer; color: var(--fg-3); font-size: 11.5px; }
.ctx-report table { margin: 8px 0 0; font-size: 12px; }

.empty { color: var(--fg-3); text-align: center; padding: 60px 20px; }
.empty h2 { color: var(--fg-2); font-size: 16px; font-weight: 600; }
.empty ul { display: inline-block; text-align: left; max-width: 460px; font-size: 13px; }

/* ---------- composer ---------- */
.composer { border-top: 1px solid var(--line); background: var(--bg-2); padding: 10px 18px 14px; }
.composer.dragover { outline: 2px dashed var(--accent); outline-offset: -6px; }
.composer-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 9px; }
.ctl { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--fg-3); }
.ctl select {
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 7px;
  padding: 4px 7px; font-size: 12px; max-width: 210px;
}
.temp-ctl input[type=range] { width: 110px; accent-color: var(--accent); }
.temp-ctl output {
  font-family: var(--mono); font-size: 12px; color: var(--fg);
  min-width: 34px; text-align: right; font-variant-numeric: tabular-nums;
}
.temp-presets { display: flex; gap: 3px; }
.chipbtn {
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--fg-3);
  border-radius: 6px; padding: 1px 6px; font-size: 11px; cursor: pointer;
}
.chipbtn:hover { color: var(--fg); border-color: var(--accent); }
.spacer { flex: 1; }
.ctx-hint { font-size: 11.5px; color: var(--fg-3); font-variant-numeric: tabular-nums; }

.composer-input { display: flex; gap: 9px; align-items: flex-end; }
.composer-input textarea {
  flex: 1; resize: none; max-height: 320px; padding: 11px 13px;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 11px;
  outline: none; line-height: 1.5;
}
.composer-input textarea:focus { border-color: var(--accent); }
.composer-buttons { display: flex; align-items: center; gap: 6px; }

.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px;
  background: var(--bg-4); border: 1px solid var(--line-2); border-radius: 20px; font-size: 12px;
}
.chip img { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; }
.chip button { background: none; border: none; color: var(--fg-3); cursor: pointer; padding: 0; }
.chip button:hover { color: var(--err); }

/* ---------- drawer ---------- */
.drawer { background: var(--bg-2); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 3px; flex-wrap: wrap; }
.tab {
  background: none; border: 1px solid transparent; color: var(--fg-3);
  padding: 4px 9px; border-radius: 7px; cursor: pointer; font-size: 12px;
}
.tab:hover { color: var(--fg); }
.tab.active { background: var(--bg-4); color: var(--fg); border-color: var(--line-2); }
.drawer-head .icon-btn { margin-left: auto; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.field { margin-bottom: 13px; }
.field label { display: block; font-size: 11px; color: var(--fg-3); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .06em; }
.field input[type=text], .field input[type=number], .field input[type=password], .field textarea, .field select {
  width: 100%; padding: 8px 10px; background: var(--bg-3);
  border: 1px solid var(--line-2); border-radius: 8px; outline: none;
}
.field textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field .hint { font-size: 11.5px; color: var(--fg-3); margin-top: 4px; }
.row { display: flex; gap: 9px; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--fg-2); margin-bottom: 11px; }

.card { border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; margin-bottom: 9px; background: var(--bg-3); }
.card h4 { margin: 0 0 5px; font-size: 13px; display: flex; align-items: center; gap: 7px; }
.card .meta { font-size: 11.5px; color: var(--fg-3); font-variant-numeric: tabular-nums; }
.card .acts { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }

h3.sec { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--fg-3); margin: 18px 0 9px; }
h3.sec:first-child { margin-top: 0; }

table.grid { width: 100%; border-collapse: collapse; font-size: 12px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; }
table.grid th { color: var(--fg-3); font-weight: 500; font-size: 11px; text-transform: uppercase; }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }

/* ---------- buttons ---------- */
.btn {
  padding: 8px 15px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--bg-3); cursor: pointer; font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.wide { width: 100%; }
.btn.small, .ghost.small { padding: 4px 9px; font-size: 12px; }
.ghost {
  background: none; border: 1px solid var(--line-2); color: var(--fg-2);
  padding: 5px 10px; border-radius: 8px; cursor: pointer; font-size: 12.5px;
}
.ghost:hover { color: var(--fg); border-color: var(--accent); }
.ghost.danger:hover { color: var(--err); border-color: var(--err); }
.icon-btn {
  background: none; border: none; color: var(--fg-3); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 3px 6px; border-radius: 6px;
}
.icon-btn:hover { color: var(--fg); background: var(--bg-3); }
.hidden { display: none !important; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 14px;
  padding: 20px; width: min(660px, 100%); max-height: 85vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.alert { padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alert.error { background: rgba(240,96,95,.13); color: var(--err); border: 1px solid rgba(240,96,95,.3); }
.alert.ok { background: rgba(53,192,138,.12); color: var(--ok); border: 1px solid rgba(53,192,138,.3); }
.alert.warn { background: rgba(232,184,75,.12); color: var(--warn); border: 1px solid rgba(232,184,75,.3); }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--bg-4); border: 1px solid var(--line-2); border-radius: 9px;
  padding: 9px 13px; font-size: 13px; max-width: 380px; animation: fade .2s ease;
}
.toast.err { border-color: var(--err); color: var(--err); }
.toast.ok { border-color: var(--ok); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.cursor::after {
  content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 1100px) {
  .app, .app.with-drawer { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; width: 260px; height: 100%; transform: translateX(-100%); transition: .2s; }
  .sidebar.open { transform: none; }
  .drawer { position: fixed; right: 0; top: 0; width: min(440px, 100%); height: 100%; z-index: 40; }
}
