/* ResearchClaw Dashboard — Dark theme */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-card: #1c2128;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --success: #3fb950;
  --warning: #d29922;
  --error: #f85149;
  --purple: #bc8cff;
  --font-mono: 'SF Mono', 'Fira Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* Layout */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}

/* Header */
.header {
  grid-column: 1 / -1;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 10;
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

.header .status-badge {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 500;
}

.status-badge.running { background: rgba(59,130,246,0.2); color: var(--accent); }
.status-badge.completed { background: rgba(63,185,80,0.2); color: var(--success); }
.status-badge.failed { background: rgba(248,81,73,0.2); color: var(--error); }
.status-badge.idle { background: rgba(139,148,158,0.2); color: var(--text-secondary); }

/* Sidebar */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
}

.sidebar-section {
  padding: 0 16px;
  margin-bottom: 24px;
}

.sidebar-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  margin: 2px 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-item.active { background: rgba(88,166,255,0.15); color: var(--accent); }

/* Main content */
.main {
  overflow-y: auto;
  padding: 24px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 4px;
}

.stat-card .value.accent { color: var(--accent); }
.stat-card .value.success { color: var(--success); }
.stat-card .value.error { color: var(--error); }

/* Pipeline stages */
.pipeline-stages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.stage-cell {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-size: 12px;
  text-align: center;
  transition: all 0.2s;
}

.stage-cell .stage-num { font-weight: 700; color: var(--text-muted); }
.stage-cell .stage-name { color: var(--text-secondary); margin-top: 2px; font-size: 11px; }
.stage-cell.done { border-color: var(--success); }
.stage-cell.done .stage-num { color: var(--success); }
.stage-cell.running { border-color: var(--accent); background: rgba(88,166,255,0.1); animation: pulse 2s infinite; }
.stage-cell.running .stage-num { color: var(--accent); }
.stage-cell.failed { border-color: var(--error); }
.stage-cell.failed .stage-num { color: var(--error); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Progress bar */
.progress-bar {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-bar .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* Chat panel */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px - 48px);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.chat-msg {
  margin-bottom: 16px;
  max-width: 80%;
}

.chat-msg.user {
  margin-left: auto;
}

.chat-msg .bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
}

.chat-msg.user .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant .bubble {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.chat-input-area input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.chat-input-area input:focus { border-color: var(--accent); }

.chat-input-area button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 20px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}

.chat-input-area button:hover { background: var(--accent-hover); }

/* Log viewer */
.log-viewer {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  padding: 12px;
  max-height: 400px;
  overflow-y: auto;
  color: var(--text-secondary);
}

.log-viewer .log-line { white-space: pre-wrap; word-break: break-all; }

/* Charts */
.chart-container {
  position: relative;
  height: 300px;
  margin: 16px 0;
}

/* Responsive */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px auto 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    overflow-x: auto;
    padding: 8px;
  }
  .sidebar-section { margin-bottom: 0; }
  .nav-item { white-space: nowrap; padding: 6px 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .pipeline-stages { grid-template-columns: repeat(4, 1fr); }
  .chat-msg { max-width: 90%; }
}

/* Voice button */
.voice-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s;
}

.voice-btn:hover { border-color: var(--accent); color: var(--accent); }
.voice-btn.recording { background: var(--error); border-color: var(--error); color: #fff; animation: pulse 1s infinite; }

/* Hidden sections */
.view { display: none; }
.view.active { display: block; }

/* ---- Light theme (data-theme="light" on <html>; dark remains the default) ---- */
:root[data-theme="light"] {
  --bg-primary: #f6f8fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #eef1f4;
  --bg-card: #ffffff;
  --border: #d0d7de;
  --text-primary: #1f2328;
  --text-secondary: #57606a;
  --text-muted: #6e7781;
  --accent: #0969da;
  --accent-hover: #218bff;
  --success: #1a7f37;
  --warning: #9a6700;
  --error: #cf222e;
  --purple: #8250df;
  --shadow: 0 1px 3px rgba(31, 35, 40, 0.12);
}

/* ============================================================
   Glass design system — modern translucent look (dark + light)
   ============================================================ */
:root {
  --glass-bg: rgba(28, 33, 40, 0.55);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-highlight: rgba(255, 255, 255, 0.04);
  --mesh-1: rgba(56, 139, 253, 0.13);
  --mesh-2: rgba(163, 113, 247, 0.10);
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}
:root[data-theme="light"] {
  --glass-bg: rgba(255, 255, 255, 0.62);
  --glass-border: rgba(15, 23, 42, 0.08);
  --glass-highlight: rgba(255, 255, 255, 0.65);
  --mesh-1: rgba(9, 105, 218, 0.09);
  --mesh-2: rgba(130, 80, 223, 0.07);
  --shadow: 0 8px 32px rgba(15, 23, 42, 0.10);
}

body {
  background:
    radial-gradient(900px 600px at 85% -10%, var(--mesh-1), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, var(--mesh-2), transparent 60%),
    var(--bg-primary);
  background-attachment: fixed;
}

.card, .header, .sidebar {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
}
.card {
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight);
  padding: 24px;
}
.header { border-bottom: 1px solid var(--glass-border); }
.sidebar { border-right: 1px solid var(--glass-border); }

.nav-item {
  border-radius: 10px;
  margin: 2px 8px;
  transition: background .15s ease, transform .1s ease;
}
.nav-item:hover { background: var(--glass-highlight); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(88,166,255,0.16), transparent);
  border-left: 2px solid var(--accent);
}

/* Buttons */
.g-btn {
  padding: 10px 20px; border-radius: 10px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--glass-border); cursor: pointer;
  background: var(--glass-bg); color: var(--text-primary);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: transform .1s ease, box-shadow .15s ease, opacity .15s;
}
.g-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.g-btn:active { transform: translateY(0); }
.g-btn:disabled { opacity: .55; cursor: default; transform: none; }
.g-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border: none; color: #fff;
}
.g-btn.success { background: linear-gradient(135deg, var(--success), #2ea043); border: none; color: #fff; }
.g-btn.subtle { font-weight: 500; }
.g-btn.danger { color: var(--error); }

/* Pills / badges */
.g-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--glass-border); background: var(--glass-bg);
}
.g-pill.running { color: var(--accent); }
.g-pill.completed, .g-pill.ready { color: var(--success); }
.g-pill.failed { color: var(--error); }
.g-pill.running::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); animation: pulse 1.4s ease infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1);} 50% { opacity: .35; transform: scale(.8);} }

/* Inputs */
.g-input, .g-select, .g-textarea {
  width: 100%; padding: 11px 14px; border-radius: 10px; font-size: 14px;
  background: var(--bg-tertiary); color: var(--text-primary);
  border: 1px solid var(--glass-border); outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  font-family: var(--font-sans);
}
.g-input:focus, .g-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,166,255,.15); }

/* Toasts */
#toast-root { position: fixed; top: 68px; right: 18px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.g-toast {
  min-width: 260px; max-width: 380px; padding: 12px 16px; border-radius: 12px;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: var(--shadow); font-size: 13px; color: var(--text-primary);
  animation: toast-in .22s ease; display: flex; gap: 10px; align-items: flex-start;
}
.g-toast.success { border-left: 3px solid var(--success); }
.g-toast.error { border-left: 3px solid var(--error); }
.g-toast.info { border-left: 3px solid var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px);} to { opacity: 1; transform: none;} }

/* Stage rail */
.stage-rail { display: flex; flex-direction: column; gap: 2px; }
.stage-phase { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted); margin: 12px 0 4px; }
.stage-item { display: flex; gap: 10px; align-items: flex-start; padding: 7px 10px; border-radius: 10px; font-size: 13px; }
.stage-item .dot { width: 18px; height: 18px; border-radius: 50%; flex: none; margin-top: 1px;
  display: flex; align-items: center; justify-content: center; font-size: 11px;
  border: 2px solid var(--border); color: transparent; }
.stage-item.done .dot { background: var(--success); border-color: var(--success); color: #fff; }
.stage-item.active { background: linear-gradient(90deg, rgba(88,166,255,0.12), transparent); }
.stage-item.active .dot { border-color: var(--accent); position: relative; }
.stage-item.active .dot::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s ease infinite; }
.stage-item.active .stage-label { color: var(--accent); font-weight: 600; }
.stage-item.pending { opacity: .55; }
.stage-summary { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* Collapsible Advanced nav group */
.sidebar details.advanced summary {
  list-style: none; cursor: pointer; padding: 8px 20px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .8px; color: var(--text-muted);
}
.sidebar details.advanced summary::after { content: " ▸"; }
.sidebar details.advanced[open] summary::after { content: " ▾"; }

/* Chat dock */
.chat-dock { display: flex; flex-direction: column; border: 1px solid var(--glass-border); border-radius: var(--radius); overflow: hidden; }
.chat-msgs { max-height: 260px; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 85%; padding: 9px 13px; border-radius: 14px; font-size: 13px; line-height: 1.5; }
.chat-msg.me { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-hover)); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.ai { align-self: flex-start; background: var(--bg-tertiary); border: 1px solid var(--glass-border); border-bottom-left-radius: 4px; }

/* Live run progress */
.progress-track {
  height: 6px; border-radius: 999px; background: var(--bg-tertiary);
  overflow: hidden; margin-top: 10px; border: 1px solid var(--glass-border);
}
.progress-fill {
  height: 100%; width: 2%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  background-size: 200% 100%;
  animation: progress-sheen 2.2s linear infinite;
  transition: width .8s ease;
}
@keyframes progress-sheen { 0% { background-position: 0% 0; } 100% { background-position: -200% 0; } }

.dot-throb {
  width: 14px; height: 14px; border-radius: 50%; margin-top: 3px; flex: none;
  background: var(--accent);
  animation: throb 1.5s ease infinite;
}
@keyframes throb {
  0%, 100% { box-shadow: 0 0 0 0 rgba(88,166,255,.45); }
  50% { box-shadow: 0 0 0 9px rgba(88,166,255,0); }
}

.ellipsis::after {
  content: ""; display: inline-block; width: 1.2em; text-align: left;
  animation: ellipsis 1.6s steps(4) infinite;
}
@keyframes ellipsis {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; }
}

/* Live sidebar entry */
#live-run-nav { display: flex; align-items: center; gap: 8px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; animation: throb 1.5s ease infinite; }
.stage-item:hover { background: var(--glass-highlight); }
.stage-redo:hover { color: var(--accent); border-color: var(--accent); }
.mode-opt:has(input:checked) { border-color: var(--accent); background: linear-gradient(90deg, rgba(88,166,255,0.08), transparent); }
