/* BitBot Institutional Command Center */
:root {
  --bg-deep: #04060d;
  --bg: #070b14;
  --surface: #0c1220;
  --surface-2: #111a2e;
  --surface-3: #162038;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(59, 130, 246, 0.25);
  --text: #eef2f8;
  --muted: #7b8ba8;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.35);
  --cyan: #22d3ee;
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.15);
  --red: #f43f5e;
  --red-dim: rgba(244, 63, 94, 0.15);
  --yellow: #fbbf24;
  --purple: #a78bfa;
  --sidebar-w: 240px;
  --topbar-h: 52px;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'DM Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--sans);
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-size: 15px;
  line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(59, 130, 246, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(167, 139, 250, 0.08), transparent);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-deep);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 0.4s, visibility 0.4s;
}
.loading-overlay.done { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-ring {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loader-text { color: var(--muted); font-size: 0.85rem; letter-spacing: 0.05em; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Error banner */
.error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9000;
  background: linear-gradient(90deg, #7f1d1d, #991b1b);
  color: #fecaca;
  padding: 10px 20px;
  font-size: 0.85rem;
  text-align: center;
  border-bottom: 1px solid rgba(254, 202, 202, 0.2);
}

/* App shell */
.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100vw;
}

/* Sidebar — desktop only (mobile uses bottom nav) */
.sidebar {
  display: none;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 800;
  font-size: 0.85rem;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 1.05rem; font-weight: 800; }
.brand-text span { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.2), transparent);
  color: var(--text);
  border: 1px solid var(--border-strong);
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-icon { font-size: 1rem; opacity: 0.8; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 18px;
  border-top: 1px solid var(--border);
}

.mode-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--green-dim);
  color: var(--green);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.sidebar-tagline {
  font-size: 0.72rem;
  color: var(--muted);
  font-style: italic;
}

/* Mobile bottom navigation */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: rgba(7, 11, 20, 0.96);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
  justify-content: space-around;
  align-items: stretch;
  gap: 2px;
}

.mob-nav-item {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.62rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 52px;
  transition: all 0.2s;
}

.mob-nav-item .mob-icon { font-size: 1.25rem; line-height: 1; }
.mob-nav-item.active {
  color: var(--text);
  background: rgba(59, 130, 246, 0.15);
}
.mob-nav-item.active .mob-icon { color: var(--cyan); }

/* Main wrap — full width on mobile */
.main-wrap {
  flex: 1;
  width: 100%;
  max-width: 100%;
  margin-left: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Content — bottom nav clearance on mobile */
.content {
  padding: 12px;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  flex: 1;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Topbar — mobile stacked compact */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(7, 11, 20, 0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px 12px;
  height: auto;
  min-height: var(--topbar-h);
}

.ticker-strip {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  overflow-y: hidden;
  flex: 1;
  width: 100%;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.ticker-item {
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
}

.topbar-status {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
}

.status-pill {
  padding: 6px 10px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

/* Hide less critical pills on small screens */
@media (max-width: 480px) {
  #agentCount, #clock { display: none; }
}

/* Desktop — sidebar layout */
@media (min-width: 769px) {
  .mobile-nav { display: none !important; }

  .sidebar {
    display: flex;
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #0a0f1c 0%, #070b14 100%);
    border-right: 1px solid var(--border);
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
  }

  .main-wrap {
    margin-left: var(--sidebar-w);
    width: calc(100% - var(--sidebar-w));
  }

  .content {
    padding: 20px;
    padding-bottom: 20px;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: var(--topbar-h);
  }

  .grid-2 { grid-template-columns: repeat(2, 1fr) !important; }
  .grid-3 { grid-template-columns: repeat(3, 1fr) !important; }
  .grid-4 { grid-template-columns: repeat(4, 1fr) !important; }
  .grid-split { grid-template-columns: 1.4fr 1fr !important; }

  .hero-banner {
    flex-direction: row;
    align-items: center;
    padding: 24px 28px;
  }

  .hero-title { font-size: 1.5rem; }
  .hero-stats { display: flex; gap: 32px; }
  .hero-stat { text-align: right; }

  .agent-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

@media (min-width: 1100px) {
  .grid-hero { grid-template-columns: 2fr 1fr 1fr !important; }
}

.ticker-item strong { color: var(--text); margin-right: 6px; }
.ticker-item .up { color: var(--green); }
.ticker-item .down { color: var(--red); }
.ticker-strip::-webkit-scrollbar { display: none; }

/* Mobile compact header (sidebar hidden) */
.mobile-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 20, 0.95);
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.mobile-brand .brand-icon {
  width: 36px;
  height: 36px;
  font-size: 0.75rem;
}

.mobile-brand .brand-text strong { font-size: 0.95rem; }
.mobile-brand .brand-text span {
  font-size: 0.62rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Mobile more sheet */
.mobile-more-sheet {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: flex-end;
}

.mobile-more-sheet.hidden { display: none !important; }

.mobile-more-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.mobile-more-panel {
  position: relative;
  width: 100%;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.mobile-more-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 4px;
}

.mobile-more-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

.mobile-more-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 52px;
  text-align: left;
}

.mobile-more-link span:first-child {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
  color: var(--cyan);
}

.status-pill.live {
  border-color: rgba(16, 185, 129, 0.5);
  color: var(--green);
  background: var(--green-dim);
  animation: pulse-live 2s ease infinite;
}

.status-pill.off { border-color: rgba(244, 63, 94, 0.5); color: var(--red); background: var(--red-dim); }
.status-pill.market-open { color: var(--green); border-color: rgba(16, 185, 129, 0.4); }
.status-pill.market-closed { color: var(--yellow); border-color: rgba(251, 191, 36, 0.3); }
.status-pill.clock { color: var(--cyan); }
.status-pill.sync { color: var(--muted); }

@keyframes pulse-live {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

/* Content area */
.panel { display: none; animation: fadeIn 0.3s ease; }
.panel.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Grid system */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-hero { grid-template-columns: 2fr 1fr 1fr; }
.grid-split { grid-template-columns: 1.4fr 1fr; }

/* Cards */
.card {
  background: linear-gradient(145deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 700;
}

.card-value {
  font-family: var(--mono);
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.2;
}

.card-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 6px;
}

.kpi-card { min-height: 110px; }
.kpi-card .card-value { font-size: 1.35rem; }

.pos { color: var(--green) !important; }
.neg { color: var(--red) !important; }

/* Hero banner */
.hero-banner {
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.hero-title {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(90deg, #fff, var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.hero-stats {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}

.hero-stat { text-align: right; }
.hero-stat-label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.hero-stat-value { font-family: var(--mono); font-size: 1.4rem; font-weight: 700; margin-top: 2px; }

/* Progress rings */
.ring-grid { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; }
.ring-item { text-align: center; }
.ring-wrap {
  width: 90px;
  height: 90px;
  position: relative;
  margin: 0 auto 8px;
}
.ring-wrap svg { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--surface-3); stroke-width: 6; }
.ring-fill { fill: none; stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset 0.6s; }
.ring-label { font-family: var(--mono); font-size: 0.85rem; font-weight: 700; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.ring-caption { font-size: 0.72rem; color: var(--muted); }

/* Gauges */
.gauge-row { margin-top: 12px; }
.gauge-label { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.gauge-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.gauge-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
}

/* Progress bars */
.progress-wrap { margin-top: 10px; }
.progress-bar {
  height: 8px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s;
}
.progress-fill.green { background: linear-gradient(90deg, #059669, var(--green)); }
.progress-fill.red { background: linear-gradient(90deg, #be123c, var(--red)); }
.progress-fill.blue { background: linear-gradient(90deg, var(--accent), var(--cyan)); }

/* Heatmap */
.heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}
.heat-cell {
  padding: 10px;
  border-radius: 8px;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--surface-3);
}
.heat-cell .heat-name { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.heat-cell .heat-val { font-family: var(--mono); font-size: 0.9rem; font-weight: 700; margin-top: 4px; }
.heat-cell.bull { background: var(--green-dim); border-color: rgba(16, 185, 129, 0.3); }
.heat-cell.bear { background: var(--red-dim); border-color: rgba(244, 63, 94, 0.3); }
.heat-cell.neutral { background: var(--surface-3); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th {
  padding: 10px 12px;
  text-align: left;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.78rem;
}
tr:hover td { background: rgba(255,255,255,0.02); }
td.reason-cell { font-family: var(--sans); font-size: 0.78rem; color: var(--muted); max-width: 280px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.badge-trade { background: rgba(59, 130, 246, 0.2); color: #93c5fd; border: 1px solid rgba(59, 130, 246, 0.3); }
.badge-skip { background: rgba(251, 191, 36, 0.15); color: #fde68a; border: 1px solid rgba(251, 191, 36, 0.25); }
.badge-notrade, .badge-hold { background: rgba(255,255,255,0.06); color: var(--muted); }
.badge-win { background: var(--green-dim); color: var(--green); }
.badge-loss { background: var(--red-dim); color: var(--red); }

/* Regime tags */
.regime-tag {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--mono);
}
.regime-TREND { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.regime-TRAP { background: var(--red-dim); color: #fca5a5; }
.regime-RANGE { background: rgba(251, 191, 36, 0.15); color: #fde68a; }
.regime-NEWS_VOLATILE { background: rgba(167, 139, 250, 0.2); color: #d8b4fe; }
.regime-UNCLEAR { background: rgba(255,255,255,0.06); color: var(--muted); }

/* Decision cards */
.decision-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.decision-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.decision-summary { font-size: 0.95rem; font-weight: 600; }

.rationale-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.rationale-block {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.rationale-block h4 {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--cyan);
  margin-bottom: 8px;
}
.rationale-block ul { list-style: none; }
.rationale-block li {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  line-height: 1.4;
}
.rationale-block li::before { content: '▸ '; color: var(--accent); }

/* News */
.news-feed { max-height: 320px; overflow-y: auto; }
.news-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.news-item:last-child { border-bottom: none; }
.news-title { font-size: 0.85rem; line-height: 1.4; }
.news-time { font-size: 0.68rem; color: var(--muted); margin-top: 4px; font-family: var(--mono); }

/* Charts */
.chart-box { height: 260px; position: relative; }
.chart-box canvas { max-height: 220px; }

/* Metric rows */
.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 0.82rem;
}
.metric-row span:first-child { color: var(--muted); }
.metric-row span:last-child { font-family: var(--mono); font-weight: 600; }

/* Shield panel */
.shield-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.shield-stat {
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  border: 1px solid var(--border);
}
.shield-stat-val { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; }
.shield-stat-label { font-size: 0.68rem; color: var(--muted); margin-top: 4px; text-transform: uppercase; }

/* Desktop-only responsive tweaks */
@media (min-width: 769px) and (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
  .grid-hero { grid-template-columns: 1fr !important; }
}

.tier-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(167, 139, 250, 0.15);
  color: var(--purple);
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

/* Agent Council */
.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.agent-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  border-left: 3px solid var(--muted);
}

.agent-card.agent-bull { border-left-color: var(--green); }
.agent-card.agent-bear { border-left-color: var(--red); }
.agent-card.agent-veto { border-left-color: #f97316; background: rgba(249, 115, 22, 0.08); }
.agent-card.agent-neutral { border-left-color: var(--muted); }

.agent-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.agent-name { font-weight: 700; font-size: 0.9rem; }
.agent-stance { font-family: var(--mono); font-size: 0.68rem; font-weight: 700; padding: 2px 8px; border-radius: 4px; background: rgba(255,255,255,0.06); }
.agent-bull .agent-stance { color: var(--green); }
.agent-bear .agent-stance { color: var(--red); }
.agent-veto .agent-stance { color: #f97316; }
.agent-role { font-size: 0.72rem; color: var(--muted); margin-bottom: 6px; }
.agent-conf { font-family: var(--mono); font-size: 0.68rem; color: var(--cyan); margin-bottom: 8px; }
.agent-summary { font-size: 0.82rem; line-height: 1.4; margin-bottom: 8px; }
.agent-reasoning { list-style: none; }
.agent-reasoning li { font-size: 0.75rem; color: var(--muted); padding: 2px 0; }
.agent-reasoning li::before { content: '▸ '; color: var(--accent); }

/* Debate feed */
.debate-feed { max-height: 400px; overflow-y: auto; }
.debate-line {
  padding: 8px 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.75rem;
  background: rgba(0,0,0,0.2);
  border-left: 2px solid var(--border);
}
.debate-veto { border-left-color: #f97316; background: rgba(249,115,22,0.08); }
.debate-consensus { border-left-color: var(--cyan); background: rgba(34,211,238,0.06); }
.debate-bull { border-left-color: var(--green); }
.debate-bear { border-left-color: var(--red); }

.debate-msg { padding: 10px 0; border-bottom: 1px solid var(--border); }
.debate-msg-from { font-weight: 700; color: var(--cyan); font-size: 0.78rem; }
.debate-msg-arrow { color: var(--muted); font-size: 0.72rem; margin: 0 6px; }
.debate-msg-type { font-family: var(--mono); font-size: 0.62rem; color: var(--purple); margin-left: 8px; }
.debate-msg-text { font-size: 0.82rem; color: var(--muted); margin-top: 4px; line-height: 1.4; }

.agent-card.agent-commander {
  border: 1px solid rgba(34, 211, 238, 0.4);
  background: linear-gradient(145deg, rgba(34, 211, 238, 0.08), var(--surface-2));
  box-shadow: 0 0 20px rgba(34, 211, 238, 0.1);
}

/* Admin panel */
.admin-field { margin-bottom: 14px; }
.admin-field label { display: block; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.admin-field input {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-3);
  color: var(--text); font-family: var(--mono); font-size: 0.9rem;
}
.admin-btn {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff; font-weight: 700; cursor: pointer; margin-top: 8px;
}
.admin-btn-danger { background: linear-gradient(135deg, #dc2626, #991b1b); }

.chart-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chart-tag { padding: 6px 10px; border-radius: 8px; font-size: 0.75rem; border: 1px solid var(--border); background: rgba(0,0,0,0.25); }
.chart-tag-candle { border-color: rgba(251, 191, 36, 0.3); color: #fde68a; }
.chart-tag-pattern { border-color: rgba(59, 130, 246, 0.3); color: #93c5fd; }
.chart-level { font-family: var(--mono); font-size: 0.72rem; padding: 2px 6px; border-radius: 4px; margin-right: 4px; }
.chart-level.support { background: var(--green-dim); color: var(--green); }
.chart-level.resistance { background: var(--red-dim); color: var(--red); }
.live-feed { max-height: none; overflow: visible; }
.live-feed-wrap { display: flex; flex-direction: column; gap: 8px; }
.live-feed-current {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(34, 211, 238, 0.35);
  background: rgba(34, 211, 238, 0.08);
}
.live-feed-current-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.live-feed-current-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--cyan); font-weight: 700; }
.live-feed-current-text { font-size: 0.88rem; font-weight: 600; line-height: 1.4; }
.live-feed-scroll-host { position: relative; }
.live-feed-scroll, .debate-feed-scroll {
  max-height: 320px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: auto;
  overscroll-behavior: contain;
}
.feed-jump-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 2;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(34, 211, 238, 0.45);
  background: rgba(7, 11, 20, 0.92);
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}
.feed-jump-btn:active { transform: scale(0.97); }
.live-feed-status { font-family: var(--mono); font-size: 0.72rem; color: var(--cyan); margin-bottom: 2px; }
.live-feed-item { padding: 10px 12px; margin-bottom: 6px; border-radius: 8px; background: rgba(0,0,0,0.2); border-left: 2px solid var(--border); }
.live-feed-from { font-weight: 700; color: var(--cyan); font-size: 0.78rem; }
.live-feed-arrow { color: var(--muted); font-size: 0.72rem; margin: 0 6px; }
.live-feed-type { font-family: var(--mono); font-size: 0.62rem; color: var(--purple); }
.live-feed-text { font-size: 0.8rem; color: var(--muted); margin-top: 4px; line-height: 1.4; }

/* Spy Command — admin intel chat */
.spy-chat-card { display: flex; flex-direction: column; }
.spy-chat-feed {
  max-height: 420px;
  overflow-y: auto;
  padding: 4px 2px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.spy-chat-msg {
  padding: 10px 12px;
  margin: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border-left: 3px solid var(--border);
}
.spy-chat-msg.spy-sev-high { border-left-color: var(--red); background: rgba(239, 68, 68, 0.06); }
.spy-chat-msg.spy-sev-med { border-left-color: var(--yellow); }
.spy-chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.spy-chat-from { font-weight: 700; color: var(--cyan); font-size: 0.76rem; }
.spy-chat-cat {
  font-family: var(--mono);
  font-size: 0.62rem;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.spy-cat-giant { background: rgba(167, 139, 250, 0.2); color: var(--purple); }
.spy-cat-peer { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.spy-cat-web { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.spy-cat-recon { background: rgba(123, 139, 168, 0.2); color: var(--muted); }
.spy-cat-skip { background: rgba(123, 139, 168, 0.1); color: var(--muted); opacity: 0.7; }
.spy-cat-action { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.spy-cat-verify { background: rgba(16, 185, 129, 0.18); color: var(--green); }
.spy-cat-verdict { background: rgba(167, 139, 250, 0.25); color: var(--purple); font-weight: 700; }
.spy-cat-override { background: rgba(239, 68, 68, 0.22); color: #fca5a5; font-weight: 700; }
.spy-tier-giant { color: var(--purple); font-weight: 700; }
.spy-tier-insider_hint { color: var(--cyan); font-weight: 600; }
.spy-tier-small { color: var(--muted); }
.spy-cat-default { background: rgba(255, 255, 255, 0.05); color: var(--muted); }
.spy-chat-time { margin-left: auto; font-family: var(--mono); font-size: 0.65rem; color: var(--muted); }
.spy-chat-text { font-size: 0.84rem; line-height: 1.45; color: var(--text); }

/* Master live chat — two-way conversation */
.master-live-chat {
  padding: 16px;
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.05);
  border: 1px solid rgba(251, 191, 36, 0.3);
  margin-bottom: 8px;
}
.master-live-status {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
  padding: 8px 12px;
  margin-bottom: 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.78rem;
  color: var(--muted);
}
.master-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: master-pulse 1.5s infinite;
}
@keyframes master-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.master-live-loc { color: var(--cyan); }

.ai-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  vertical-align: middle;
}
.ai-badge-ok { background: rgba(34, 197, 94, 0.15); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.35); }
.ai-badge-warn { background: rgba(251, 191, 36, 0.12); color: #fbbf24; border: 1px solid rgba(251, 191, 36, 0.35); }
.ai-badge-off { background: rgba(148, 163, 184, 0.12); color: #94a3b8; border: 1px solid rgba(148, 163, 184, 0.3); }
.master-bubble-feed {
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 4px;
  margin-bottom: 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.master-bubble-wrap { display: flex; margin-bottom: 10px; }
.master-bubble-wrap.master-out { justify-content: flex-end; }
.master-bubble-wrap.master-in { justify-content: flex-start; }
.master-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}
.master-out .master-bubble {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.35);
}
.master-in .master-bubble {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.25);
}
.master-bubble-status {
  background: rgba(16, 185, 129, 0.08) !important;
  border-color: rgba(16, 185, 129, 0.25) !important;
  font-size: 0.82rem;
}
.master-bubble-from {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cyan);
  margin-bottom: 4px;
}
.master-out .master-bubble-from { color: #fbbf24; }
.master-bubble-text { font-size: 0.88rem; line-height: 1.45; }
.master-bubble-time { font-size: 0.65rem; color: var(--muted); margin-top: 4px; text-align: right; }
.master-chat-textarea { min-height: 52px; resize: vertical; font-family: inherit; }
.master-chat-empty { padding: 16px; text-align: center; color: var(--muted); }

/* Master command boxes (legacy) */
.master-chat-box {
  margin-top: 16px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.06);
  border: 1px solid rgba(251, 191, 36, 0.35);
}
.master-active-order {
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: 8px;
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
  font-weight: 600;
  font-size: 0.88rem;
}
.master-cmd-history-wrap { max-height: 120px; overflow-y: auto; margin-bottom: 10px; }
.master-cmd-history {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.82rem;
}
.master-cmd-time { font-family: var(--mono); color: var(--muted); margin-right: 8px; font-size: 0.72rem; }
.master-cmd-form { display: flex; gap: 8px; flex-wrap: wrap; }
.master-cmd-input {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.3);
  color: var(--text);
  font-size: 0.9rem;
}
.master-cmd-btn { flex-shrink: 0; }
.spy-cat-master { background: rgba(251, 191, 36, 0.22); color: #fde68a; font-weight: 700; }
.debate-master {
  border-left: 3px solid #fbbf24 !important;
  background: rgba(251, 191, 36, 0.08) !important;
}
.debate-master .debate-msg-from { color: #fbbf24 !important; }

/* Desktop: hide mobile-only chrome */
@media (min-width: 769px) {
  .mobile-header { display: none; }
  .mobile-more-sheet { display: none !important; }
}

/* Mobile layout & touch-friendly UI */
@media (max-width: 768px) {
  .mobile-nav { display: flex; }
  .app-shell { flex-direction: column; }

  .grid-2, .grid-3, .grid-4, .grid-split, .grid-hero {
    grid-template-columns: 1fr !important;
  }

  .grid { gap: 12px; }

  .card {
    padding: 14px;
    width: 100%;
    max-width: 100%;
  }

  .kpi-card { min-height: auto; }
  .kpi-card .card-value { font-size: 1.2rem; }
  .card-value { font-size: 1.35rem; word-break: break-word; }

  .hero-banner {
    padding: 16px;
    flex-direction: column;
    align-items: stretch;
    text-align: left;
    gap: 14px;
  }

  .hero-title { font-size: 1.15rem; }
  .hero-sub { font-size: 0.8rem; line-height: 1.4; }

  .hero-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
  }

  .hero-stat { text-align: left; }
  .hero-stat-value { font-size: 1.15rem; }

  .metric-row {
    flex-wrap: wrap;
    gap: 4px 8px;
    align-items: flex-start;
    font-size: 0.85rem;
  }

  .metric-row span:last-child {
    text-align: right;
    max-width: 100%;
    word-break: break-word;
  }

  .agent-grid { grid-template-columns: 1fr; }
  .rationale-grid { grid-template-columns: 1fr; }
  .shield-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
  }

  table { font-size: 0.75rem; min-width: 520px; }
  th, td { padding: 10px 8px; }

  .chart-box { height: 220px; }

  .nav-item, .mob-nav-item, .admin-btn { min-height: 44px; }

  .admin-field input {
    font-size: 16px;
    min-height: 44px;
  }

  .debate-feed, .news-feed { max-height: none; }
  .live-feed-scroll, .debate-feed-scroll { max-height: 240px; }

  .decision-head { flex-direction: column; align-items: flex-start; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .ring-grid { gap: 12px; }
  .heatmap { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 600px) and (max-width: 768px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr) !important; }
  .content { padding: 16px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}
