:root {
  --bg: #f6f7f9; --panel: #ffffff; --side: #eef0f3; --text: #1d2330; --muted: #6b7280;
  --border: #e3e6eb; --accent: #0f766e; --accent-2: #115e59; --user: #e6f4f2; --danger: #b42318;
  --code: #f1f3f6; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --panel: #1b1f26; --side: #111418; --text: #e6e8eb; --muted: #9aa3ae;
    --border: #2a3039; --accent: #2bb3a3; --accent-2: #1f8f83; --user: #1d3330; --danger: #f97066;
    --code: #232831;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.55 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; border-color: transparent; }
button:disabled { opacity: .5; cursor: default; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card p.sub { margin: 0 0 20px; color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; background: var(--side); padding: 4px; border-radius: 10px; }
.tabs button { flex: 1; border: none; background: transparent; }
.tabs button.active { background: var(--panel); font-weight: 600; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.field input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 16px; color: var(--muted); font-size: 14px; }
.auth-card button.primary { width: 100%; padding: 10px; }
.error { color: var(--danger); min-height: 20px; font-size: 14px; margin-top: 10px; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.sidebar { background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.side-top { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.brand .dot.ok { background: #22c55e; } .brand .dot.warn { background: #f59e0b; } .brand .dot.err { background: var(--danger); }
.status { font-size: 12px; color: var(--muted); }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.conv { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.conv:hover { background: var(--panel); }
.conv.active { background: var(--panel); box-shadow: inset 3px 0 0 var(--accent); }
.conv .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conv .acts { display: none; }
.conv:hover .acts, .conv.active .acts { display: flex; }
.conv .acts button { padding: 2px 6px; font-size: 12px; border: none; background: transparent; color: var(--muted); }
.side-bottom { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; font-size: 14px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: none; padding: 10px 14px; border-bottom: 1px solid var(--border); align-items: center; gap: 10px; }
.messages { flex: 1; overflow-y: auto; padding: 24px 16px; }
.inner { max-width: 860px; margin: 0 auto; }
.msg { margin-bottom: 18px; display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 100%; padding: 10px 14px; border-radius: var(--radius); overflow-x: auto; }
.msg.user .bubble { background: var(--user); max-width: 80%; white-space: pre-wrap; }
.msg.assistant .bubble { background: transparent; padding-left: 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.bubble th { background: var(--code); }
.bubble pre { background: var(--code); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.bubble code { background: var(--code); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.bubble pre code { padding: 0; background: none; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 14px 0 6px; line-height: 1.3; }
.bubble p { margin: 6px 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.empty { text-align: center; color: var(--muted); padding-top: 12vh; }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.quick button { font-size: 14px; }

.composer { border-top: 1px solid var(--border); padding: 12px 16px 16px; background: var(--bg); }
.docs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 13px; }
.chip a { color: var(--text); text-decoration: none; }
.chip button { border: none; background: transparent; padding: 0 4px; color: var(--muted); }
.box { display: flex; gap: 8px; align-items: flex-end; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 8px; }
.box.drag { border-color: var(--accent); border-style: dashed; }
.box textarea { flex: 1; resize: none; border: none; background: transparent; max-height: 200px; min-height: 24px; padding: 6px; }
.box textarea:focus { outline: none; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: center; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .topbar { display: flex; }
  .msg.user .bubble { max-width: 90%; }
}
