:root {
  --bg: #0f1117;
  --sidebar: #171a21;
  --panel: #1c1f28;
  --panel-2: #232733;
  --line: #2b3040;
  --text: #ececf1;
  --muted: #9aa1b1;
  --accent: #E8811A;
  --accent-ink: #ffb469;
  --user-bubble: #2a2f3c;
  --danger: #f0603a;
  --green: #34c48a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }
#app { height: 100%; }
.hidden { display: none !important; }

/* ---------- Auth screens ---------- */
.auth-wrap {
  height: 100%; display: grid; place-items: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 32px;
}
.auth-logo {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent);
  display: grid; place-items: center; margin-bottom: 18px; font-weight: 700; color: #1a1205; font-size: 20px;
}
.auth-card h1 { font-size: 21px; margin: 0 0 4px; }
.auth-card p.sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 11px 12px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 9px; color: var(--text); font-size: 14px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; padding: 12px; background: var(--accent); color: #1a1205;
  border: none; border-radius: 9px; font-weight: 600; font-size: 14.5px; margin-top: 6px;
}
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.auth-err { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 16px; }

/* ---------- App shell ---------- */
.shell { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 264px; flex: none; background: var(--sidebar);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.side-top { padding: 12px; }
.new-chat {
  width: 100%; display: flex; align-items: center; gap: 9px; padding: 11px 12px;
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-size: 14px; font-weight: 500;
}
.new-chat:hover { background: var(--panel); }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.chat-list-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 12px 8px 6px; }
.chat-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px;
  color: var(--text); font-size: 13.5px; cursor: pointer; margin-bottom: 2px;
  white-space: nowrap; overflow: hidden;
}
.chat-item:hover { background: var(--panel); }
.chat-item.active { background: var(--panel-2); }
.chat-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chat-item .del { opacity: 0; border: none; background: transparent; color: var(--muted); padding: 2px; border-radius: 5px; flex: none; }
.chat-item:hover .del { opacity: 1; }
.chat-item .del:hover { color: var(--danger); }
.side-foot { border-top: 1px solid var(--line); padding: 10px; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 9px; }
.user-row:hover { background: var(--panel); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #1a1205; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.user-meta { flex: 1; min-width: 0; }
.user-meta .name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.user-meta .role { font-size: 11px; color: var(--muted); }
.icon-btn { border: none; background: transparent; color: var(--muted); padding: 6px; border-radius: 7px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ---------- Chat main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main-head { height: 52px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid var(--line); gap: 10px; position: sticky; top: 0; z-index: 20; background: var(--bg); flex: none; }
.main-head .brand { font-weight: 600; }
.thread { flex: 1; overflow-y: auto; }
.thread-inner { max-width: 760px; margin: 0 auto; padding: 28px 20px 40px; }
.msg { display: flex; gap: 14px; margin-bottom: 26px; }
.msg .who { width: 30px; height: 30px; border-radius: 7px; flex: none; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.msg.user .who { background: var(--user-bubble); color: var(--text); }
.msg.assistant .who { background: var(--accent); color: #1a1205; }
.msg .body { flex: 1; min-width: 0; padding-top: 4px; }
.msg .body .content { font-size: 15px; line-height: 1.65; white-space: pre-wrap; word-wrap: break-word; }
.msg .sources { margin-top: 10px; font-size: 12px; color: var(--muted); }
.msg .sources b { color: var(--accent-ink); font-weight: 600; }
.cursor::after { content: "▋"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.empty-hero { max-width: 620px; margin: 12vh auto 0; text-align: center; padding: 0 20px; }
.empty-hero .logo { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); color: #1a1205; display: grid; place-items: center; font-weight: 700; font-size: 24px; margin: 0 auto 20px; }
.empty-hero h2 { font-size: 24px; margin: 0 0 8px; }
.empty-hero p { color: var(--muted); font-size: 15px; line-height: 1.6; margin: 0; }
.suggest { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 26px; }
.suggest button { padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 13.5px; }
.suggest button:hover { border-color: var(--accent); }

.composer { padding: 12px 20px 22px; }
.composer-inner { max-width: 760px; margin: 0 auto; }
.input-box { display: flex; align-items: flex-end; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 16px; }
.input-box:focus-within { border-color: var(--accent); }
.input-box textarea { flex: 1; background: transparent; border: none; outline: none; resize: none; color: var(--text); font-size: 15px; line-height: 1.5; max-height: 200px; padding: 8px 0; }
.send { width: 38px; height: 38px; border-radius: 10px; border: none; background: var(--accent); color: #1a1205; display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .35; cursor: not-allowed; }
.composer-hint { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 9px; }

/* ---------- Admin ---------- */
.modal-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { width: 100%; max-width: 720px; max-height: 85vh; overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; margin: 0; flex: 1; }
.tabs { display: flex; gap: 6px; padding: 12px 20px 0; }
.tab { padding: 8px 14px; border: none; background: transparent; color: var(--muted); font-size: 14px; border-radius: 8px; }
.tab.active { background: var(--panel-2); color: var(--text); }
.modal-body { padding: 16px 20px 22px; overflow-y: auto; }
.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.row-form .field { margin: 0; flex: 1; min-width: 130px; }
.row-form .btn-primary { width: auto; margin: 0; padding: 11px 16px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .primary { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .secondary { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: var(--panel-2); color: var(--muted); }
.pill.admin { background: rgba(232,129,26,.15); color: var(--accent-ink); }
.pill.ready { background: rgba(52,196,138,.15); color: var(--green); }
.pill.processing { background: rgba(232,129,26,.15); color: var(--accent-ink); }
.pill.error { background: rgba(240,96,58,.15); color: var(--danger); }
.btn-danger { border: 1px solid var(--line); background: transparent; color: var(--danger); padding: 7px 11px; border-radius: 8px; font-size: 12.5px; }
.btn-danger:hover { background: rgba(240,96,58,.1); }
.btn-ghost { border: 1px solid var(--line); background: transparent; color: var(--text); padding: 7px 11px; border-radius: 8px; font-size: 12.5px; }
.btn-ghost:hover { background: var(--panel-2); }
.drop-zone { border: 1.5px dashed var(--line); border-radius: 12px; padding: 26px; text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 18px; }
.drop-zone:hover, .drop-zone.over { border-color: var(--accent); color: var(--text); }
.mini-err { color: var(--danger); font-size: 13px; min-height: 16px; margin-top: 4px; }
.spinner { width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .sidebar { position: absolute; z-index: 40; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: none; }
