*{box-sizing:border-box}
html,body{height:100%}

:root{
  --bg:#0f172a;
  --fg:#e2e8f0;
  --panel:#0b1020;
  --border:#1f2937;
  --muted:#94a3b8;
  --title:#f8fafc;
  --input-bg:#0f172a;
  --input-border:#334155;
  --link:#93c5fd;
  --primary:#2563eb;
  --primary-hover:#1d4ed8;
}

html[data-theme='light']{
  --bg:#f8fafc;
  --fg:#0f172a;
  --panel:#ffffff;
  --border:#e2e8f0;
  --muted:#475569;
  --title:#0f172a;
  --input-bg:#ffffff;
  --input-border:#cbd5e1;
  --link:#1d4ed8;
  --primary:#2563eb;
  --primary-hover:#1d4ed8;
}
/* Prevent page scrolling; only #chat should scroll */
html,body{overflow:hidden}
body{margin:0;font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif;background:var(--bg);color:var(--fg)}
#app{width:100%;max-width:none;margin:0;padding:16px;min-height:100%;height:100%;display:flex;flex-direction:column}
header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
header h1{margin:0;font-size:20px;color:var(--title)}
.pill{padding:4px 8px;border-radius:999px;font-size:12px;margin-left:6px}
.pill.offline{background:#334155;color:#94a3b8}
.pill.online{background:#065f46;color:#d1fae5}
.pill.muted{background:#1f2937;color:#9ca3af}
main{background:var(--panel);border:1px solid var(--border);border-radius:12px;overflow:hidden;display:flex;flex-direction:column;flex:1;min-height:0}
#chat{flex:1;min-height:0;overflow:auto;padding:16px}
.msg{display:flex;margin:10px 0}
.msg.user{justify-content:flex-end}
.msg.assistant{justify-content:flex-start}
.bubble{max-width:75%;padding:12px 14px;border-radius:14px;line-height:1.4}
.msg.user .bubble{background:#1e3a8a;color:#e0e7ff;border-top-right-radius:4px}
.msg.assistant .bubble{background:#111827;color:#e5e7eb;border-top-left-radius:4px;border:1px solid #1f2937}

html[data-theme='light'] .msg.user .bubble{
  background:#dbeafe;
  color:#0f172a;
  border:1px solid #bfdbfe;
}

html[data-theme='light'] .msg.assistant .bubble{
  background:#f1f5f9;
  color:#0f172a;
  border:1px solid #e2e8f0;
}
#composer{display:flex;gap:8px;align-items:center;padding:12px;border-top:1px solid var(--border);background:var(--panel)}
#composer input[type=text]{flex:1;padding:10px 12px;border-radius:10px;border:1px solid var(--input-border);background:var(--input-bg);color:var(--fg)}
#composer select{padding:10px 12px;border-radius:10px;border:1px solid var(--input-border);background:var(--input-bg);color:var(--fg)}
#composer button{background:var(--primary);border:none;color:#fff;padding:10px 14px;border-radius:10px;cursor:pointer}
#composer button:hover{background:var(--primary-hover)}
.checkbox{display:flex;align-items:center;gap:6px;color:var(--link)}
/* Ensure hidden overrides #processing display */
.hidden{display:none}
#processing.hidden{display:none}
#send.hidden{display:none}
#processing{display:flex;align-items:center;gap:8px}
.spinner{width:16px;height:16px;border:2px solid #334155;border-top-color:#93c5fd;border-radius:50%;animation:spin 1s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* Bottom status toolbar */
.bottom-status{padding:10px 12px;border-top:1px solid var(--border);background:var(--panel);color:var(--muted);font-size:12px}

/* Markdown styles */
.bubble h1,.bubble h2,.bubble h3{margin:6px 0}
.bubble pre{background:#0a0f1f;border:1px solid #1f2937;padding:10px;border-radius:8px;overflow:auto}
.bubble code{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}
.bubble-footer{display:flex;align-items:center;gap:8px;margin-top:8px;font-size:12px;color:#9ca3af}
.bubble-footer .actions{display:flex;gap:6px}
.bubble-footer .icon-btn{display:none;background:transparent;border:none;color:#9ca3af;cursor:pointer;padding:2px 6px;border-radius:6px}
.bubble:hover .bubble-footer .icon-btn{display:inline-block}
.bubble-footer .icon-btn:hover{background:#0a0f1f;color:#cbd5e1}
.bubble-footer .icon-btn.active{color:#f59e0b}
.bubble-footer .rt{margin-left:auto;color:#94a3b8}
.bubble table{width:100%;border-collapse:collapse;margin:8px 0;background:#0b1020;border:1px solid #1f2937}
.bubble th,.bubble td{border:1px solid #1f2937;padding:8px;text-align:left}
.bubble th{background:#0f172a;color:#cbd5e1}
.bubble tr:nth-child(even){background:#0d1326}

html[data-theme='light'] .bubble pre{background:#f8fafc;border:1px solid #e2e8f0}
html[data-theme='light'] .bubble-footer{color:#64748b}
html[data-theme='light'] .bubble-footer .rt{color:#475569}
html[data-theme='light'] .bubble-footer .icon-btn:hover{background:#f1f5f9;color:#0f172a}
html[data-theme='light'] .bubble table{background:#ffffff;border:1px solid #e2e8f0}
html[data-theme='light'] .bubble th,html[data-theme='light'] .bubble td{border:1px solid #e2e8f0}
html[data-theme='light'] .bubble th{background:#f1f5f9;color:#0f172a}
html[data-theme='light'] .bubble tr:nth-child(even){background:#f8fafc}

/* Toasts */
.toasts{position:fixed;left:50%;bottom:20px;transform:translateX(-50%);display:flex;flex-direction:column;gap:8px;z-index:9999}
.toast{min-width:200px;max-width:90vw;padding:10px 12px;border-radius:8px;font-size:14px;box-shadow:0 6px 20px rgba(0,0,0,.4);background:#111827;color:#e5e7eb;border:1px solid #1f2937;opacity:.98;animation:fadein .15s ease-out}
.toast.success{border-color:#065f46;background:#0b221e;color:#d1fae5}
.toast.error{border-color:#7f1d1d;background:#220b0b;color:#fecaca}
@keyframes fadein{from{opacity:0;transform:translate(-50%,10px)}to{opacity:.98;transform:translate(-50%,0)}}

/* History header filters */
header #filters{display:flex;align-items:center;gap:8px;background:var(--panel);border:1px solid var(--border);border-radius:999px;padding:6px 8px}
header #filters label{display:flex;align-items:center;gap:6px}
header #filters select,header #filters input[type=date]{height:32px;padding:6px 8px;border-radius:8px;border:1px solid var(--input-border);background:var(--input-bg);color:var(--fg);font-size:13px}
header #filters button{height:32px;padding:6px 10px;border-radius:8px;border:none;background:var(--primary);color:#fff;cursor:pointer}
header #filters button:hover{background:var(--primary-hover)}
header #filters .back-link{text-decoration:none;background:rgba(148,163,184,.18);color:var(--fg)}

.theme-toggle{border:1px solid var(--input-border);background:var(--input-bg);color:var(--fg);cursor:pointer}
.theme-toggle:hover{filter:brightness(0.98)}

/* Circular spinner for status column */
.spinner-circle{width:20px;height:20px;border:2px solid var(--border);border-top-color:var(--primary);border-radius:50%;animation:spin 1s linear infinite;display:inline-block;vertical-align:middle}

/* Linear progress bar for answer column */
.progress-bar-container{width:100%;height:4px;background:var(--border);border-radius:2px;overflow:hidden;margin-top:4px}
.progress-bar-fill{height:100%;background:var(--primary);border-radius:2px;transition:width 0.1s linear;width:0%}
