/* Health AI Assistant — minimal Swiss/Linear style */
:root {
  --bg: #fafafa;
  --bg-alt: #f3f4f6;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0f;
    --bg-alt: #1a1a1a;
    --surface: #1f1f1f;
    --border: #2e2e2e;
    --text: #f3f4f6;
    --text-muted: #9ca3af;
  }
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100dvh; }

/* Layout */
.app { display: flex; height: 100dvh; }
.sidebar { width: 260px; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; flex-shrink: 0; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* Sidebar */
.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.sidebar-header h1 { font-size: 14px; font-weight: 600; }
.sidebar-nav { padding: 8px; flex: 1; overflow-y: auto; }
.nav-btn { display: block; width: 100%; padding: 8px 12px; border: none; background: none; text-align: left; font-size: 13px; border-radius: var(--radius); cursor: pointer; color: var(--text-muted); transition: all .15s; }
.nav-btn:hover { background: var(--bg-alt); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }
.new-chat-btn { margin: 8px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 13px; cursor: pointer; text-align: center; color: var(--text); font-weight: 500; }
.new-chat-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Topbar */
.topbar { height: 52px; border-bottom: 1px solid var(--border); padding: 0 20px; display: flex; align-items: center; justify-content: space-between; background: var(--surface); }
.topbar-title { font-size: 14px; font-weight: 500; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-btn { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 12px; cursor: pointer; color: var(--text-muted); }
.topbar-btn:hover { border-color: var(--accent); color: var(--accent); }
.topbar-btn.danger { color: var(--danger); border-color: var(--danger); }

/* Chat */
.chat-area { flex: 1; overflow-y: auto; padding: 20px; }
.message { max-width: 720px; margin: 0 auto 16px; padding: 12px 16px; border-radius: var(--radius); }
.message.user { background: var(--accent); color: #fff; margin-left: auto; max-width: 600px; }
.message.assistant { background: var(--surface); border: 1px solid var(--border); }
.message pre { background: var(--bg-alt); padding: 12px; border-radius: 6px; overflow-x: auto; font-family: var(--mono); font-size: 13px; margin: 8px 0; }
.message code { font-family: var(--mono); font-size: 13px; background: var(--bg-alt); padding: 2px 6px; border-radius: 4px; }

/* Input */
.chat-input-area { padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface); }
.chat-input-wrap { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; }
.chat-input { flex: 1; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; font-family: var(--font); background: var(--bg); color: var(--text); resize: none; outline: none; min-height: 44px; max-height: 200px; }
.chat-input:focus { border-color: var(--accent); }
.send-btn { padding: 12px 20px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Login */
.login-view { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; }
.login-card h2 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; margin-bottom: 6px; color: var(--text-muted); }
.form-group input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; background: var(--bg); color: var(--text); outline: none; }
.form-group input:focus { border-color: var(--accent); }
.login-btn { width: 100%; padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: 14px; font-weight: 500; cursor: pointer; margin-top: 8px; }
.login-btn:disabled { opacity: .5; }
.login-error { color: var(--danger); font-size: 12px; margin-top: 8px; }

/* Admin */
.admin-view { padding: 24px; max-width: 1000px; margin: 0 auto; overflow-y: auto; flex: 1; }
.admin-view h2 { font-size: 18px; margin-bottom: 16px; }
.admin-section { margin-bottom: 32px; }
.admin-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text-muted); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-muted); }
td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 500; }
.badge-admin { background: #dbeafe; color: #1d4ed8; }
.badge-user { background: #dcfce7; color: #166534; }
.badge-disabled { background: #fee2e2; color: #991b1b; }

/* Token usage */
.usage-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.usage-stat { text-align: center; }
.usage-stat .value { font-size: 24px; font-weight: 700; font-family: var(--mono); }
.usage-stat .label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.quota-bar { height: 6px; background: var(--bg-alt); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.quota-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.quota-bar-fill.warning { background: var(--warning); }
.quota-bar-fill.danger { background: var(--danger); }

/* Lang toggle */
.lang-btn { padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 11px; cursor: pointer; background: var(--surface); color: var(--text-muted); }
.lang-btn:hover { border-color: var(--accent); }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .chat-input-wrap { flex-direction: column; }
  .send-btn { width: 100%; }
}

/* Typing indicator */
.typing { display: flex; gap: 4px; padding: 12px 16px; }
.typing span { width: 8px; height: 8px; background: var(--text-muted); border-radius: 50%; animation: bounce .6s infinite alternate; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { to { opacity: .3; transform: translateY(-4px); } }

/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; padding: 12px 20px; background: var(--text); color: var(--bg); border-radius: var(--radius); font-size: 13px; z-index: 9999; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } }

/* Sidebar sections */
.sidebar-label { padding: 8px 16px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.session-btn { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; width: 100%; padding: 8px 12px; border: none; background: none; text-align: left; font-size: 13px; border-radius: var(--radius); cursor: pointer; color: var(--text-muted); font-family: var(--font); }
.session-btn:hover { background: var(--bg-alt); color: var(--text); }
.session-btn.active { background: var(--bg-alt); color: var(--accent); }
.session-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.session-date { font-size: 10px; font-family: var(--mono); color: var(--text-muted); flex-shrink: 0; }
.session-empty { padding: 8px 16px; font-size: 12px; color: var(--text-muted); }
.usage-panel { padding: 8px 12px; border-top: 1px solid var(--border); }
.usage-panel .sidebar-label { padding: 0 4px 6px; }

/* Tools used tag */
.tools-tag { font-size: 11px; color: var(--text-muted); margin-top: 8px; font-family: var(--mono); }

/* Bar chart (7-day usage) */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 90px; padding: 4px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar-col .bar { width: 100%; max-width: 32px; background: var(--accent); border-radius: 2px 2px 0 0; }
.bar-value { font-size: 9px; font-family: var(--mono); color: var(--text-muted); margin-bottom: 2px; white-space: nowrap; }
.bar-label { font-size: 9px; font-family: var(--mono); color: var(--text-muted); margin-top: 4px; white-space: nowrap; }

/* Numeric cells */
td.num { font-family: var(--mono); font-size: 12px; }
.pct-label { font-size: 10px; font-family: var(--mono); color: var(--text-muted); }
.quota-bar-fill.ok { background: var(--success); }

/* Period toggle */
.period-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.period-btn { padding: 6px 14px; border: none; background: var(--surface); font-size: 12px; cursor: pointer; color: var(--text-muted); font-family: var(--font); }
.period-btn + .period-btn { border-left: 1px solid var(--border); }
.period-btn.active { background: var(--accent); color: #fff; }

/* Row action buttons */
.row-actions { white-space: nowrap; }
.mini-btn { padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); font-size: 11px; cursor: pointer; color: var(--text-muted); margin-right: 4px; font-family: var(--font); }
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.mini-btn.danger { color: var(--danger); }
.mini-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.mini-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Modal dialogs */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; max-height: 90dvh; overflow-y: auto; }
.modal h3 { font-size: 15px; margin-bottom: 16px; }
.modal select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; background: var(--bg); color: var(--text); outline: none; font-family: var(--font); }
.modal select:focus { border-color: var(--accent); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.check-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; cursor: pointer; color: var(--text); }
.check-row .num { font-family: var(--mono); }
.check-row input { accent-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog-primary { padding: 8px 16px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer; font-family: var(--font); }
.dialog-primary:hover { background: var(--accent-hover); }
.dialog-primary:disabled { opacity: .5; cursor: not-allowed; }
.dialog-error { color: var(--danger); font-size: 12px; margin-top: 8px; min-height: 16px; }

/* Per-user model selector */
.model-row { display: flex; align-items: center; gap: 8px; padding: 0 0 6px; font-size: 12px; color: var(--text-muted); }
.model-row select { font-size: 12px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 5px; background: var(--bg); color: var(--text); }
.model-row select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Welcome + example chips + catalog */
.welcome { text-align: center; padding: 48px 20px; max-width: 640px; margin: 0 auto; }
.example-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { font-size: 12.5px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 16px; background: var(--bg); color: var(--text); cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.mono { font-family: var(--mono, ui-monospace, monospace); }
