:root {
  --bg: #070708;
  --sidebar: #0b0b0d;
  --panel: #111214;
  --card: #1a1b1f;
  --chip: #1f2024;
  --border: #2a2b31;
  --text: #f4f4f5;
  --muted: #9a9aa3;
  --accent: #ff7a1a;
  --accent-2: #ff8d3d;
  --danger: #f43f5e;
  --ok: #22c55e;
  --shadow: 0 12px 40px rgba(0,0,0,.35);
  --radius: 18px;
  --sidebar-w: 268px;
  --font: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
}
[data-theme="light"] {
  --bg: #f3f4f6;
  --sidebar: #ffffff;
  --panel: #ffffff;
  --card: #f8fafc;
  --chip: #eef2f6;
  --border: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --shadow: 0 10px 30px rgba(15,23,42,.08);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar-backdrop { display: none; }
.icon-btn.sidebar-close { display: none; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 6px 8px 18px; }
.brand img { width: 48px; height: 40px; object-fit: contain; }
.brand h1 { font-size: 16px; line-height: 1.25; margin: 0; font-weight: 700; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; color: var(--muted);
  text-decoration: none; border: 0; background: transparent; width: 100%; text-align: left; cursor: pointer;
}
.nav-item.active, .nav-item:hover { background: var(--chip); color: var(--text); }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: #8b8b93; }
.history { flex: 1; overflow: auto; margin-top: 12px; padding-right: 2px; }
.history a {
  display: block; padding: 8px 10px; border-radius: 10px; color: var(--muted);
  text-decoration: none; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history a:hover, .history a.active { background: var(--chip); color: var(--text); }
.sidebar-foot { padding-top: 10px; border-top: 1px solid var(--border); }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px 8px; gap: 12px;
}
.top-left, .top-right { display: flex; align-items: center; gap: 10px; }
.icon-btn, .ghost-select {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; min-height: 36px; padding: 0 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
.icon-btn { width: 36px; justify-content: center; padding: 0; }
.icon-btn.wide { width: auto; padding: 0 12px; }
.conv-meta { color: var(--muted); font-size: 13px; }
.conv-meta b { color: var(--text); font-weight: 600; display: block; }
.chat-wrap { flex: 1; display: flex; flex-direction: column; padding: 8px 22px 18px; }
.chat-panel {
  flex: 1; background: var(--panel); border: 1px solid var(--border);
  border-radius: 28px; display: flex; flex-direction: column; min-height: 420px;
  overflow: hidden;
}
.messages { flex: 1; overflow: auto; padding: 36px 8% 20px; }
.empty {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--muted);
}
.empty h2 { color: var(--text); font-size: 34px; margin: 0 0 8px; font-weight: 650; letter-spacing: -.02em; }
.msg { max-width: 820px; margin: 0 auto 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble {
  background: var(--card); border: 1px solid var(--border); border-radius: 18px;
  padding: 14px 16px; line-height: 1.65; white-space: pre-wrap;
}
.msg.user .bubble { background: #232429; max-width: min(680px, 92%); }
[data-theme="light"] .msg.user .bubble { background: #e8eef6; }
.who { font-size: 12px; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; }
.msg-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; opacity: .7; }
.msg-actions button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 4px; }
.sources { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.source {
  font-size: 12px; background: #16171b; border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; color: #d6d6db; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
a.source.file { color: #ffd7b0; border-color: #ff7a1a66; }
a.source.file:hover { background: #2a1c10; }
[data-theme="light"] .source { background: #fff; color: #334155; }
.msg.thinking .bubble.think { color: var(--muted); border-style: dashed; }
.think-dots::after {
  content: '';
  display: inline-block;
  width: 1.2em;
  animation: thinkDots 1.2s steps(4, end) infinite;
}
@keyframes thinkDots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}
.refs { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--border); }
.refs-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.refs .ref {
  display: block;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  padding: 3px 0;
  word-break: break-all;
}
.refs .ref:hover { color: var(--text); }
.suggests { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 14px 0; }
.suggest {
  background: var(--chip); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 14px; text-align: left; cursor: pointer; color: var(--text); min-height: 74px;
}
.suggest:hover { border-color: #3f4048; }
.composer-row { display: flex; align-items: center; gap: 10px; }
.composer {
  display: flex; align-items: center; gap: 8px; background: var(--card);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 8px 6px 14px;
  flex: 1;
}
.composer input {
  flex: 1; border: 0; background: transparent; outline: none; min-height: 42px; color: var(--text);
}
.send, .mic {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
}
.mic { background: transparent; color: var(--muted); }
.mic.listening { background: #3f1d20; color: #fda4af; animation: micPulse 1s ease-in-out infinite; }
.mic.busy { opacity: .6; pointer-events: none; }
@keyframes micPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
.send { background: #2a2b31; color: #fff; }
.send:not(:disabled) { background: var(--accent); }
.send:disabled { opacity: .45; cursor: default; }
.disclaimer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 10px; }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(460px, 100%); background: #141416; border: 1px solid var(--border);
  border-radius: 28px; padding: 28px 28px 24px; box-shadow: var(--shadow);
}
[data-theme="light"] .auth-card { background: #fff; }
.auth-card h2 { text-align: center; margin: 8px 0 4px; }
.auth-card .sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.auth-card .emblem { display: block; margin: 10px auto 18px; width: 96px; height: auto; object-fit: contain; }
label { display: block; font-size: 13px; margin: 12px 0 6px; }
.field { width: 100%; background: #0e0e10; border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; }
.password-wrap { position: relative; }
.password-wrap .field { padding-right: 48px; }
.password-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }
.forgot { margin: 8px 0 0; text-align: right; font-size: 13px; }
.forgot a { color: var(--muted); text-decoration: none; }
.forgot a:hover { color: var(--text); }
[data-theme="light"] .field { background: #f8fafc; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn {
  width: 100%; border: 0; border-radius: 999px; padding: 12px 16px; cursor: pointer;
  background: var(--accent); color: #111; font-weight: 700; margin-top: 16px;
}
.btn.secondary { background: #232428; color: var(--text); margin-top: 10px; font-weight: 600; }
[data-theme="light"] .btn.secondary { background: #e4e4e7; }
.alert { background: #3f1d20; color: #fecdd3; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.ok { background: #14532d; color: #bbf7d0; padding: 10px 12px; border-radius: 10px; }
.links { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.links a { color: var(--muted); }
.back { background: none; border: 0; color: var(--muted); cursor: pointer; margin-bottom: 4px; }
.admin { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.admin nav { background: var(--sidebar); border-right: 1px solid var(--border); padding: 18px 12px; }
.admin main { padding: 24px; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 16px; overflow: hidden; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px; vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 16px; }
.stat b { display: block; font-size: 28px; margin-top: 6px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--chip); }
.badge.pending { background: #3b2a12; color: #fdba74; }
.badge.active { background: #14532d; color: #86efac; }
.badge.locked { background: #3f1d20; color: #fda4af; }
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; place-items: center; padding: 20px; z-index: 20;
}
.modal.open { display: grid; }
.modal .box { width: min(560px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 22px; }
.hamburger { display: none; }
@media (max-width: 960px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .admin { grid-template-columns: 1fr; }
  .desktop-only { display: none !important; }
  .hamburger { display: inline-flex; }
  .icon-btn.sidebar-close { display: inline-flex; margin-left: auto; flex-shrink: 0; }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.52);
    z-index: 40;
  }
  body.menu-open { overflow: hidden; }
  body.menu-open .sidebar-backdrop { display: block; }
  .sidebar {
    display: flex;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100dvh;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: none;
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 12px 0 40px rgba(0,0,0,.45);
  }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 8;
    padding: 10px 12px 8px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--bg);
  }
  .chat-wrap {
    padding: 0 12px max(12px, env(safe-area-inset-bottom));
  }
  .chat-panel {
    border-radius: 18px;
    min-height: 0;
  }
  .messages { padding: 20px 14px; }
  .empty h2 { font-size: 22px; }
  .suggests {
    display: flex;
    grid-template-columns: none;
    gap: 8px;
    margin: 10px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .suggests::-webkit-scrollbar { display: none; }
  .suggest {
    flex: 0 0 auto;
    min-height: 0;
    max-width: 78vw;
    padding: 10px 14px;
    border-radius: 999px;
    font-size: 13px;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .composer { padding: 4px 6px 4px 12px; }
  .disclaimer { margin-top: 8px; font-size: 11px; }
}
@media (max-width: 640px) {
  .row2 { grid-template-columns: 1fr; }
  .empty h2 { font-size: 22px; }
  .empty p { font-size: 14px; padding: 0 12px; }
  .conv-meta span { display: none; }
}
