/* ══════════════════════════════════════════════════════════
   OpenClaw Mission Control — Glass-morphism Design System
   ══════════════════════════════════════════════════════════ */

:root {
  --bg-base: #0a0e14;
  --bg-elevated: rgba(18, 24, 38, 0.6);
  --bg-glass: rgba(20, 28, 48, 0.75);
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-glass: rgba(255, 255, 255, 0.1);
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-glow: rgba(139, 92, 246, 0.25);
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.4);
  --yellow: #eab308;
  --yellow-glow: rgba(234, 179, 8, 0.4);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.4);
  --gray: #64748b;
  --sidebar-w: 220px;
  --sidebar-collapsed-w: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

/* ── Light theme ─────────────────────────────────────── */
[data-theme="light"] {
  --bg-base: #f1f5f9;
  --bg-elevated: rgba(255, 255, 255, 0.7);
  --bg-glass: rgba(255, 255, 255, 0.75);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-glass: rgba(0, 0, 0, 0.1);
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
}

/* ── Reset ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-base);
  background-image: radial-gradient(ellipse 80% 60% at 50% -20%, rgba(139,92,246,0.08) 0%, transparent 60%),
                    radial-gradient(ellipse 60% 40% at 30% 100%, rgba(56,189,248,0.04) 0%, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────────────── */
#mc-app { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border-glass);
  display: flex; flex-direction: column;
  z-index: 100;
  transition: width var(--transition);
}
.sidebar__logo {
  padding: 1.25rem 1.25rem 0.75rem;
  font-size: 0.85rem; font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 0.5rem;
}
.sidebar__logo-icon { font-size: 1.2rem; }
.sidebar__nav { flex: 1; padding: 0.5rem; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.nav-item--active {
  background: var(--accent-glow);
  border-color: rgba(139,92,246,0.2);
  color: var(--accent);
  font-weight: 500;
}
.nav-item__icon { font-size: 1rem; width: 1.2rem; text-align: center; flex-shrink: 0; }
.nav-item__badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-weight: 600;
}
.sidebar__footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.8rem; color: var(--text-muted);
}
.health-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.health-dot--ok { background: var(--green); box-shadow: 0 0 6px var(--green-glow); }
.health-dot--warn { background: var(--yellow); box-shadow: 0 0 6px var(--yellow-glow); }
.health-dot--err { background: var(--red); box-shadow: 0 0 6px var(--red-glow); }
.theme-btn {
  margin-left: auto;
  background: transparent; border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.6rem;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
}
.theme-btn:hover { color: var(--text-primary); border-color: var(--border-glass); }

/* ── Main Content ────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
}

/* ── Top Bar ─────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 50;
}
.topbar__left { display: flex; align-items: center; gap: 0.75rem; }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.live-indicator {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.8rem; color: var(--text-muted);
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); animation: pulse-dot 2s infinite;
}
.live-dot--stale { background: var(--yellow); animation: none; }
.live-dot--dead { background: var(--red); animation: none; }
@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--green-glow); }
  50% { opacity: 0.5; box-shadow: 0 0 8px var(--green-glow); }
}
.topbar__timestamp { font-size: 0.8rem; color: var(--text-muted); }
.refresh-btn {
  background: transparent; border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.65rem;
  color: var(--text-secondary);
  cursor: pointer; font-size: 0.85rem;
  transition: all var(--transition);
}
.refresh-btn:hover { color: var(--text-primary); border-color: var(--border-glass); }
.refresh-btn:active { transform: scale(0.95); }
.refresh-btn--spinning { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tab Content ─────────────────────────────────────── */
.tab-content { display: none; padding: 1.5rem; }
.tab-content--active { display: block; }

/* ── Glass Card ──────────────────────────────────────── */
.glass-card {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: all var(--transition);
}
.glass-card:hover { border-color: rgba(255,255,255,0.15); }

/* ── Stat Cards Grid ─────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex; flex-direction: column;
  gap: 0.25rem;
}
.stat-card__label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card__value { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.stat-card__sub { font-size: 0.8rem; color: var(--text-secondary); }
.stat-card__sub--recent { color: var(--green); }
.stat-card__sub--warn { color: var(--yellow); }

/* ── Section ─────────────────────────────────────────── */
.section { margin-bottom: 1.5rem; }
.section__header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.75rem 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
}
.section__header:hover { color: var(--text-primary); }
.section__body {  }
.section__body--collapsed { display: none; }

/* ── Mini Charts ─────────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.chart-card {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius);
  padding: 1rem;
}
.chart-card__title { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; }
.chart-card canvas { width: 100% !important; height: 120px !important; }
.chart-card__labels { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--text-muted); margin-top: 0.4rem; }

/* ── Tables ──────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius);
}
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
thead th {
  text-align: left;
  padding: 0.7rem 1rem;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
tbody td { padding: 0.6rem 1rem; border-bottom: 1px solid var(--border-subtle); color: var(--text-secondary); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.03); }

/* ── Status Badges ───────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
}
.badge--info { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge--warn { background: rgba(234,179,8,0.15); color: #facc15; }
.badge--error { background: rgba(239,68,68,0.15); color: #f87171; }
.status-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
}
.status-dot--active { background: var(--green); box-shadow: 0 0 6px var(--green-glow); }
.status-dot--idle { background: var(--yellow); box-shadow: 0 0 6px var(--yellow-glow); }
.status-dot--aborted { background: var(--red); box-shadow: 0 0 6px var(--red-glow); }
.status-dot--historical { background: var(--gray); }

/* ── Agent Card Grid ─────────────────────────────────── */
.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.agent-card {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.agent-card:hover { border-color: rgba(139,92,246,0.3); }
.agent-card__top { display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 0.6rem; }
.agent-card__emoji { font-size: 1.5rem; line-height: 1; }
.agent-card__info { flex: 1; min-width: 0; }
.agent-card__name { font-weight: 600; font-size: 0.95rem; color: var(--text-primary); }
.agent-card__role { font-size: 0.78rem; color: var(--text-muted); }
.agent-card__model {
  display: inline-block;
  font-size: 0.72rem;
  background: rgba(139,92,246,0.1);
  color: var(--accent);
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  margin-top: 0.2rem;
}
.agent-card__status {
  position: absolute; top: 0.75rem; right: 0.75rem;
}
.agent-card__stats {
  display: flex; gap: 1rem;
  font-size: 0.78rem; color: var(--text-muted);
  flex-wrap: wrap;
}
.agent-card__stats span { white-space: nowrap; }
.agent-card__activity { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ── Topology ────────────────────────────────────────── */
.topo-note {
  font-size: 0.8rem; color: var(--text-muted);
  padding: 0.5rem 0 1rem;
}
.topo-tree { padding: 1rem 0; overflow-x: auto; }
.topo-node {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius);
  margin: 0.25rem;
  cursor: pointer;
  transition: all var(--transition);
}
.topo-node:hover { border-color: var(--accent); }
.topo-node--selected { border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }
.topo-node__emoji { font-size: 1.2rem; }
.topo-node__name { font-weight: 500; font-size: 0.85rem; }
.topo-node__model {
  font-size: 0.7rem;
  color: var(--accent);
  background: rgba(139,92,246,0.1);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
}
.topo-children {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  padding-left: 2rem; margin: 0.5rem 0;
  border-left: 1px solid var(--border-subtle);
}
.topo-divider {
  border: none; border-top: 1px solid var(--border-subtle);
  margin: 1.5rem 0 1rem;
}
.topo-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; }

/* ── Logs ────────────────────────────────────────────── */
.filter-row {
  display: flex; gap: 0.75rem; margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filter-row select, .filter-row input {
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  color: var(--text-primary);
  font-size: 0.85rem;
  backdrop-filter: blur(8px);
}
.filter-row select option { background: #1a1f2e; color: #e2e8f0; }
.filter-row input::placeholder { color: var(--text-muted); }
.log-row { cursor: pointer; }
.log-row td:first-child { white-space: nowrap; }
.log-expand td { padding: 0; }
.log-expand__inner {
  padding: 0.5rem 1rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(0,0,0,0.15);
  display: flex; gap: 1.5rem; flex-wrap: wrap;
}
.pagination {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.75rem 0; justify-content: center;
  font-size: 0.8rem; color: var(--text-muted);
}
.pagination button {
  background: transparent; border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.65rem;
  color: var(--text-secondary);
  cursor: pointer; font-size: 0.78rem;
}
.pagination button:hover { border-color: var(--border-glass); color: var(--text-primary); }
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* ── Budget Alerts ───────────────────────────────────── */
.budget-alerts { display: flex; flex-direction: column; gap: 0.5rem; }
.budget-alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--yellow);
  background: rgba(234,179,8,0.08);
  font-size: 0.85rem;
}
.budget-alert--critical { border-left-color: var(--red); background: rgba(239,68,68,0.08); }
.budget-alert__title { font-weight: 500; margin-bottom: 0.2rem; }
.budget-alert__msg { color: var(--text-secondary); font-size: 0.82rem; }

/* ── Info Banner ─────────────────────────────────────── */
.info-banner {
  display: flex; align-items: flex-start; gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  background: rgba(59,130,246,0.08);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}
.info-banner__icon { font-size: 1rem; flex-shrink: 0; }

/* ── Empty State ─────────────────────────────────────── */
.state-empty {
  text-align: center; padding: 2rem;
  color: var(--text-muted); font-size: 0.9rem;
}

/* ── Loading ─────────────────────────────────────────── */
.state-loading {
  text-align: center; padding: 3rem;
  color: var(--text-muted);
}
.spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-bottom: 0.75rem;
}

/* ── Alert Strip ─────────────────────────────────────── */
.alert-strip {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  margin-bottom: 1rem;
}
.alert-strip--info { background: rgba(59,130,246,0.08); color: #60a5fa; }
.alert-strip--warn { background: rgba(234,179,8,0.08); color: #facc15; }
.alert-strip--error { background: rgba(239,68,68,0.08); color: #f87171; }
.alert-strip__text { flex: 1; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1024px) {
  .chart-grid { grid-template-columns: 1fr; }
  .agent-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  :root { --sidebar-w: var(--sidebar-collapsed-w); }
  .sidebar__logo span, .nav-item span:not(.nav-item__icon), .nav-item__badge,
  .sidebar__footer span, .sidebar__footer .theme-btn { display: none; }
  .sidebar__logo { justify-content: center; padding: 1rem 0.5rem; }
  .nav-item { justify-content: center; padding: 0.65rem; }
  .topbar { padding: 0.65rem 1rem; }
  .tab-content { padding: 1rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .agent-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .topbar__timestamp { display: none; }
}

/* ── Detail Panel (overlay) ──────────────────────────── */
.detail-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: none;
  backdrop-filter: blur(4px);
}
.detail-overlay--open { display: block; }
.detail-panel {
  position: fixed; top: 0; right: 0;
  width: 420px; max-width: 100vw; height: 100vh;
  background: var(--bg-base);
  border-left: 1px solid var(--border-glass);
  z-index: 201;
  display: none;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0,0,0,0.3);
}
.detail-panel--open { display: flex; }
.detail-panel__header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}
.detail-panel__title { font-weight: 600; flex: 1; }
.detail-panel__close {
  background: transparent; border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.6rem;
  color: var(--text-secondary);
  cursor: pointer;
}
.detail-panel__body { flex: 1; overflow-y: auto; padding: 1.25rem; }

/* ── Misc ────────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.loading-dots::after { content: '...'; animation: dots 1.5s steps(4) infinite; }
@keyframes dots { 25% { content: ''; } 50% { content: '.'; } 75% { content: '..'; } 100% { content: '...'; } }
