:root {
  --bg:#080b12; --surface:#101521; --surface2:#171e2d; --surface3:#1d2535;
  --line:rgba(255,255,255,.08); --line-strong:rgba(255,255,255,.13);
  --text:#edf2ff; --muted:#8d98ab; --accent:#7157e8; --accent-hover:#846cff;
  --danger:#e55266; --green:#4ed39c;
  font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  font-feature-settings:"cv01","ss03";
}
* { box-sizing:border-box; }
*[hidden] { display:none !important; }
html,body { margin:0; min-height:100%; background:var(--bg); color:var(--text); }
button,input,textarea { font:inherit; }
a { color:#b9a8ff; text-decoration:none; }
button { cursor:pointer; }
button:disabled { cursor:not-allowed; opacity:.55; }
:focus-visible { outline:2px solid #917cff; outline-offset:2px; }

.brand-mark { display:grid; place-items:center; width:58px; height:58px; border-radius:18px; background:linear-gradient(135deg,#9f7aea,#5b34d6); font-weight:800; font-size:28px; box-shadow:0 14px 40px #6f45ff44; }
.brand-mark.small { width:34px; height:34px; border-radius:10px; font-size:16px; }
.brand-row { display:flex; align-items:center; gap:11px; min-height:44px; }
.eyebrow { font-size:11px; letter-spacing:.17em; color:#9e8cff; font-weight:600; }
.muted { color:var(--muted); }

.primary,.secondary,.danger,.ghost { border:0; border-radius:10px; padding:10px 16px; min-height:44px; color:#fff; }
.primary { background:linear-gradient(135deg,var(--accent),#5b34d6); font-weight:600; }
.primary:hover { background:linear-gradient(135deg,var(--accent-hover),#6841df); }
.secondary { background:rgba(255,255,255,.04); border:1px solid var(--line); }
.danger { background:#4b1f2a; border:1px solid #7d3041; }
.ghost { background:transparent; color:var(--muted); }
.wide { width:100%; }

/* Login */
.login-shell { min-height:100vh; display:grid; place-items:center; padding:24px; background:radial-gradient(circle at 50% 20%,#39216f55,transparent 35%); }
.login-card { width:min(420px,100%); background:#101521e8; border:1px solid var(--line); border-radius:24px; padding:38px; box-shadow:0 30px 90px #0008; }
.login-card h1 { font-size:32px; letter-spacing:-.7px; margin:20px 0 6px; }
.stack { display:grid; gap:18px; margin-top:28px; }
label { display:grid; gap:8px; color:#c9d0df; font-size:14px; }
input,textarea { border:1px solid var(--line); background:#0b0f18; color:var(--text); border-radius:12px; padding:13px; outline:none; }
input:focus,textarea:focus { border-color:#8056ff; box-shadow:0 0 0 3px #8056ff22; }
.alert { padding:12px; border-radius:10px; margin-top:18px; }
.alert.error { background:#4b1f2a; color:#ffc2ca; }

/* Chat shell */
.app-shell { display:grid; grid-template-columns:280px minmax(0,1fr); height:100vh; height:100dvh; overflow:hidden; }
.sidebar { min-height:0; background:#0c1019; border-right:1px solid var(--line); padding:18px; display:flex; flex-direction:column; gap:16px; }
.sidebar-header { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.sidebar-close { display:none; width:40px; height:40px; border:0; border-radius:9px; background:transparent; color:#aeb7c6; font-size:25px; }
.sidebar-close:hover { background:rgba(255,255,255,.05); color:#fff; }
.conversation-list { min-height:0; flex:1; display:grid; align-content:start; gap:4px; overflow-y:auto; overscroll-behavior:contain; padding-right:2px; }
.conversation-row { display:grid; grid-template-columns:minmax(0,1fr) 34px; align-items:center; border-radius:8px; }
.conversation-row:hover,.conversation-row.active { background:rgba(255,255,255,.055); }
.conversation-item { min-width:0; border-radius:8px; padding:10px 9px; color:#b8c0cf; background:transparent; border:0; text-align:left; width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.conversation-row.active .conversation-item { color:#fff; }
.conversation-delete { width:30px; height:30px; border:0; border-radius:7px; background:transparent; color:#697486; opacity:0; font-size:20px; line-height:1; }
.conversation-row:hover .conversation-delete,.conversation-delete:focus-visible { opacity:1; }
.conversation-delete:hover { color:#ff9daa; background:#4b1f2a; }
.sidebar-footer { display:grid; gap:10px; border-top:1px solid var(--line); padding-top:14px; }
.sidebar-nav-link { min-height:52px; display:flex; align-items:center; gap:12px; padding:8px 10px; border:1px solid transparent; border-radius:10px; color:#d9dfeb; }
.sidebar-nav-link:hover { background:rgba(255,255,255,.04); border-color:var(--line); }
.sidebar-nav-link > span:first-child { width:28px; height:28px; display:grid; place-items:center; border-radius:8px; background:var(--surface2); }
.sidebar-nav-link span:last-child { min-width:0; display:grid; gap:2px; }
.sidebar-nav-link strong { font-size:13px; font-weight:600; }
.sidebar-nav-link small { font-size:11px; color:var(--muted); }
.logout-button { text-align:left; padding-left:10px; }
.sidebar-backdrop { display:none; }

.chat-main { min-width:0; min-height:0; position:relative; display:grid; grid-template-rows:auto minmax(0,1fr) auto; background:radial-gradient(circle at 50% -10%,#1a1732,transparent 32%); }
.topbar { min-width:0; height:68px; border-bottom:1px solid var(--line); display:flex; align-items:center; gap:14px; padding:0 22px; background:#080b12e8; backdrop-filter:blur(12px); z-index:2; }
.chat-heading { min-width:0; display:grid; gap:3px; }
.chat-heading strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.topbar small,.admin-header small { display:block; color:var(--muted); font-size:12px; }
.icon-button { display:none; width:42px; height:42px; background:transparent; border:0; border-radius:10px; color:#fff; font-size:21px; }
.icon-button:hover { background:rgba(255,255,255,.05); }
.topbar-actions { margin-left:auto; display:flex; align-items:center; gap:9px; }
.status-pill { border:1px solid var(--line); background:rgba(255,255,255,.025); padding:7px 11px; border-radius:999px; color:var(--muted); font-size:12px; white-space:nowrap; }
.topbar-action { min-height:38px; display:flex; align-items:center; gap:7px; padding:7px 11px; border:1px solid var(--line); border-radius:9px; color:#dce2ef; font-size:13px; font-weight:500; }
.topbar-action:hover { background:rgba(255,255,255,.055); border-color:var(--line-strong); }

.messages { min-height:0; overflow-y:auto; overflow-x:hidden; overscroll-behavior:contain; scrollbar-gutter:stable; scroll-behavior:smooth; padding:30px max(24px,calc((100% - 880px)/2)) 24px; }
.empty-state { text-align:center; min-height:75%; display:grid; place-content:center; justify-items:center; color:var(--muted); }
.empty-state h1 { color:var(--text); font-size:32px; letter-spacing:-.7px; margin:22px 0 5px; }
.empty-state p { margin:0; }
.message { display:grid; grid-template-columns:34px minmax(0,1fr); gap:13px; margin:0 0 30px; }
.message-avatar { width:34px; height:34px; border-radius:10px; display:grid; place-items:center; background:var(--surface2); font-size:11px; font-weight:700; }
.message.assistant .message-avatar { background:linear-gradient(135deg,#8056ff,#5b34d6); }
.message-box { min-width:0; }
.message-meta { font-size:11px; color:var(--muted); margin-bottom:6px; }
.message-content { max-width:100%; line-height:1.68; overflow-wrap:anywhere; color:#e6ebf5; }
.message.user .message-content { white-space:pre-wrap; font-weight:500; color:#f2f5fb; }
.answer-content > :first-child,.thinking-content > :first-child { margin-top:0; }
.answer-content > :last-child,.thinking-content > :last-child { margin-bottom:0; }
.answer-content p,.thinking-content p { margin:0 0 14px; }
.answer-content h2,.answer-content h3,.answer-content h4,.answer-content h5 { color:#f7f8fb; line-height:1.28; margin:24px 0 10px; letter-spacing:-.02em; }
.answer-content h2 { font-size:23px; }
.answer-content h3 { font-size:19px; }
.answer-content h4,.answer-content h5 { font-size:16px; }
.answer-content ul,.answer-content ol,.thinking-content ul,.thinking-content ol { margin:8px 0 16px; padding-left:24px; }
.answer-content li,.thinking-content li { margin:5px 0; padding-left:3px; }
.answer-content blockquote,.thinking-content blockquote { margin:14px 0; padding:8px 14px; border-left:3px solid #7157e8; color:#b8c1d1; background:rgba(113,87,232,.07); border-radius:0 8px 8px 0; }
.answer-content hr { border:0; border-top:1px solid var(--line); margin:22px 0; }
.answer-content code:not(pre code),.thinking-content code:not(pre code) { font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace; font-size:.9em; background:rgba(255,255,255,.065); border:1px solid var(--line); border-radius:5px; padding:2px 5px; color:#d9ccff; }
.answer-content a,.thinking-content a { color:#a995ff; text-decoration:underline; text-underline-offset:3px; }

.thinking-panel { margin:1px 0 14px; border:1px solid var(--line); border-radius:10px; background:rgba(255,255,255,.018); overflow:hidden; }
.thinking-panel summary { min-height:40px; display:flex; align-items:center; gap:9px; padding:8px 12px; color:#9ca6b7; cursor:pointer; font-size:13px; user-select:none; list-style:none; }
.thinking-panel summary::-webkit-details-marker { display:none; }
.thinking-panel summary::after { content:'›'; margin-left:auto; transform:rotate(90deg); transition:transform .15s ease; color:#697486; }
.thinking-panel[open] summary::after { transform:rotate(-90deg); }
.thinking-panel summary:hover { color:#c6cdda; background:rgba(255,255,255,.025); }
.thinking-dot { width:8px; height:8px; border-radius:50%; background:#697486; box-shadow:0 0 0 3px rgba(105,116,134,.12); }
.thinking-dot.active { background:#9b85ff; animation:thinkingPulse 1.4s ease-in-out infinite; }
@keyframes thinkingPulse { 50% { opacity:.45; transform:scale(.8); } }
.thinking-content { max-height:360px; overflow:auto; border-top:1px solid var(--line); padding:13px 14px; color:#9ca6b7; font-size:13px; line-height:1.58; background:#090d15; }
.stream-status { color:#7d8798; font-size:13px; padding:1px 2px; }

.code-block { margin:14px 0 18px; overflow:hidden; border:1px solid var(--line); border-radius:10px; background:#090c13; }
.code-toolbar { min-height:36px; display:flex; align-items:center; justify-content:space-between; padding:6px 10px; border-bottom:1px solid var(--line); background:rgba(255,255,255,.025); color:#778295; font:12px ui-monospace,SFMono-Regular,Menlo,monospace; }
.copy-code { border:0; border-radius:6px; background:transparent; color:#9ca6b7; padding:4px 7px; font-size:11px; }
.copy-code:hover { color:#fff; background:rgba(255,255,255,.06); }
.code-block pre { margin:0; padding:15px; overflow:auto; color:#d8def0; font:13px/1.6 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace; tab-size:2; }
.markdown-table-wrap { max-width:100%; overflow:auto; margin:14px 0 18px; border:1px solid var(--line); border-radius:9px; }
.markdown-table-wrap table { width:100%; border-collapse:collapse; font-size:13px; }
.markdown-table-wrap th,.markdown-table-wrap td { padding:9px 11px; border-bottom:1px solid var(--line); border-right:1px solid var(--line); text-align:left; white-space:nowrap; }
.markdown-table-wrap th { color:#cdd4e1; background:rgba(255,255,255,.035); }
.generation-notice { margin-top:10px; color:#9ca6b7; font-size:12px; }
.generation-notice.error { color:#ff9daa; }

.scroll-bottom { position:absolute; right:max(24px,calc((100% - 880px)/2)); bottom:106px; z-index:3; width:38px; height:38px; border-radius:50%; border:1px solid var(--line-strong); background:#171e2ded; color:#dce2ef; box-shadow:0 8px 30px #0008; }
.scroll-bottom:hover { background:#222b3d; }
.composer-wrap { padding:10px max(24px,calc((100% - 880px)/2)) 18px; text-align:center; background:linear-gradient(180deg,transparent,#080b12 22%); }
.composer { border:1px solid var(--line-strong); border-radius:17px; background:#111723; padding:7px; display:flex; align-items:flex-end; gap:6px; box-shadow:0 12px 50px #0005; }
.composer:focus-within { border-color:#6650d7; box-shadow:0 0 0 3px rgba(113,87,232,.11),0 12px 50px #0005; }
.composer textarea { resize:none; max-height:180px; min-height:46px; flex:1; border:0; background:transparent; padding:12px; line-height:1.45; }
.composer textarea:focus { box-shadow:none; }
.send-button,.stop-button { width:44px; height:44px; flex:0 0 44px; border-radius:12px; border:0; color:#fff; font-size:20px; }
.send-button { background:var(--accent); }
.send-button:hover { background:var(--accent-hover); }
.stop-button { background:#e7eaf0; color:#1a1d24; font-size:13px; }
.composer-wrap > small { display:block; color:#687386; margin-top:8px; font-size:11px; }

/* Admin */
.admin-shell { min-height:100vh; }
.admin-header { height:72px; border-bottom:1px solid var(--line); display:flex; align-items:center; justify-content:space-between; gap:24px; padding:0 max(24px,calc((100% - 1180px)/2)); background:#0b0f18; }
.admin-nav { margin-left:auto; display:flex; align-items:center; gap:8px; }
.admin-nav-link { min-height:40px; display:inline-flex; align-items:center; justify-content:center; gap:7px; padding:0 13px; border:1px solid transparent; border-radius:9px; color:#aeb8ca; font-size:13px; font-weight:650; text-decoration:none; white-space:nowrap; }
.admin-nav-link:hover { color:#fff; background:rgba(255,255,255,.05); }
.admin-nav-link:focus-visible { outline:2px solid #9c8cff; outline-offset:2px; }
.admin-nav-primary { color:#f2f4fb; border-color:var(--line-strong); background:var(--surface2); }
.admin-nav-primary:hover { border-color:rgba(156,140,255,.4); background:#20283a; }
.admin-nav-label-short { display:none; }
.admin-main { min-width:0; width:100%; max-width:1180px; margin:auto; padding:28px 24px 60px; display:grid; gap:22px; }
.admin-main > * { min-width:0; }
.metric-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:14px; }
.metric,.panel { background:var(--surface); border:1px solid var(--line); border-radius:16px; }
.panel { min-width:0; }
.metric { padding:20px; display:grid; gap:8px; }
.metric span { color:var(--muted); font-size:12px; }
.metric strong { font-size:21px; }
.panel { padding:22px; }
.panel-head { display:flex; align-items:center; justify-content:space-between; gap:20px; }
.panel h2 { margin:2px 0 0; }
.actions { display:flex; gap:8px; flex-wrap:wrap; }
.status-box { background:#090d15; border:1px solid var(--line); border-radius:12px; padding:14px; color:#a9f2d3; overflow:auto; min-height:70px; }
.table-wrap { min-width:0; max-width:100%; overflow:auto; margin-top:18px; }
.table-wrap table { border-collapse:collapse; width:100%; font-size:13px; }
.table-wrap th,.table-wrap td { text-align:left; padding:12px; border-bottom:1px solid var(--line); white-space:nowrap; }
.table-wrap th { color:var(--muted); font-weight:600; }
.secret-reveal { background:#11271f; border:1px solid #285944; padding:14px; border-radius:12px; margin-top:16px; overflow-wrap:anywhere; }
.hidden { display:none; }

@media (max-width:760px) {
  .app-shell { grid-template-columns:1fr; }
  .sidebar { position:fixed; inset:0 auto 0 0; width:min(84vw,330px); z-index:20; padding:16px; transform:translateX(-105%); transition:transform .2s ease; box-shadow:none; }
  .sidebar.open { transform:translateX(0); box-shadow:24px 0 80px #000c; }
  .sidebar-close { display:grid; place-items:center; }
  .sidebar-backdrop { display:block; position:fixed; inset:0; z-index:19; border:0; background:#0009; }
  .icon-button { display:grid; place-items:center; flex:0 0 42px; }
  .topbar { height:64px; padding:0 11px; gap:8px; }
  .topbar-action { width:40px; height:40px; justify-content:center; padding:0; }
  .topbar-action-label { display:none; }
  .status-pill { padding:6px 9px; }
  .messages { padding:20px 13px 18px; scrollbar-gutter:auto; }
  .message { grid-template-columns:30px minmax(0,1fr); gap:10px; margin-bottom:25px; }
  .message-avatar { width:30px; height:30px; border-radius:9px; font-size:10px; }
  .message-content { font-size:15px; }
  .thinking-content { max-height:280px; }
  .composer-wrap { padding:8px 10px 12px; }
  .composer-wrap > small { display:none; }
  .scroll-bottom { right:15px; bottom:84px; }
  .empty-state h1 { font-size:27px; }
  .metric-grid { grid-template-columns:1fr 1fr; }
  .panel-head { align-items:flex-start; flex-direction:column; }
  .admin-header { height:64px; padding:0 14px; gap:10px; }
  .admin-nav { gap:5px; }
  .admin-nav-link { min-height:40px; padding:0 10px; }
  .admin-main { padding:18px 14px; }
  .login-card { padding:28px; }
}

@media (max-width:520px) {
  .admin-header .brand-row small { display:none; }
  .admin-nav-label-long { display:none; }
  .admin-nav-label-short { display:inline; }
}

@media (max-width:430px) {
  .status-pill { display:none; }
  .metric-grid { grid-template-columns:1fr; }
  .login-shell { padding:14px; }
}
