:root {
  --font-sans: 'Google Sans', 'Google Sans Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'Google Sans Code', 'Google Sans', ui-monospace, SFMono-Regular, 'Segoe UI', sans-serif;

  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-alt: #f0f4f9;
  --border: #dfe5ef;
  --border-strong: #c8d2e2;
  --text: #131c2b;
  --text-muted: #526077;
  --accent: #1a66f0;
  --accent-soft: #e8f0fe;
  --accent-text: #114ec2;

  --fact-bg: #ecfdf5;
  --fact-border: #a7f3d0;
  --fact-text: #065f46;

  --insight-bg: #eef2ff;
  --insight-border: #c7d2fe;
  --insight-text: #3730a3;

  --sales-bg: #fffbeb;
  --sales-border: #fde68a;
  --sales-text: #92400e;

  --live-red: #dc2626;
  --live-bg: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --sidebar-w: 272px;
}

html[data-theme="dark"] {
  --bg: #0c111b;
  --surface: #131a27;
  --surface-alt: #1b2436;
  --border: #253147;
  --border-strong: #344462;
  --text: #eef3fb;
  --text-muted: #98a6be;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.16);
  --accent-text: #8ab4ff;

  --fact-bg: rgba(16, 185, 129, 0.13);
  --fact-border: rgba(16, 185, 129, 0.35);
  --fact-text: #6ee7b7;

  --insight-bg: rgba(99, 102, 241, 0.15);
  --insight-border: rgba(129, 140, 248, 0.35);
  --insight-text: #c7d2fe;

  --sales-bg: rgba(245, 158, 11, 0.14);
  --sales-border: rgba(245, 158, 11, 0.36);
  --sales-text: #fcd34d;

  --live-red: #f87171;
  --live-bg: rgba(239, 68, 68, 0.15);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.45);
}

html { font-size: 16px; }
html[data-scale="110"] { font-size: 17.6px; }
html[data-scale="120"] { font-size: 19.2px; }

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.tabular { font-variant-numeric: tabular-nums; }
.code-font { font-family: var(--font-mono); }

.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  transition: width 0.2s ease, transform 0.22s ease;
}

.app-shell.collapsed .sidebar {
  width: 76px;
}
.app-shell.collapsed .brand-copy,
.app-shell.collapsed .sidebar-search,
.app-shell.collapsed .nav-group-label,
.app-shell.collapsed .nav-text,
.app-shell.collapsed .nav-badge,
.app-shell.collapsed .nav-link,
.app-shell.collapsed .sidebar-footer {
  display: none;
}
.app-shell.collapsed .nav-item,
.app-shell.collapsed .nav-action {
  justify-content: center;
  padding: 10px;
}
.app-shell.collapsed #btn-collapse-sidebar svg {
  transform: rotate(180deg);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.brand-copy strong {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}
.brand-copy span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar-search {
  position: relative;
  padding: 12px 14px 6px;
}
.sidebar-search .search-icon {
  position: absolute;
  left: 24px;
  top: 23px;
  color: var(--text-muted);
  pointer-events: none;
}
.sidebar-search input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  outline: none;
}
.sidebar-search input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 16px;
}

.nav-group { margin-bottom: 18px; }
.nav-group-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 0 8px 6px;
}

.nav-item, .nav-action {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
  margin-bottom: 3px;
}
.nav-item:hover, .nav-action:hover {
  background: var(--surface-alt);
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.nav-action.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.nav-action.primary:hover { opacity: 0.92; background: var(--accent); }

.nav-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
}
.nav-item.active .nav-badge {
  background: rgba(26, 102, 240, 0.15);
  color: var(--accent-text);
}
#badge-live-dot.is-live {
  background: var(--live-bg);
  color: var(--live-red);
}

.tier-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex-shrink: 0;
}
.tier-dot.t1 { background: #10b981; }
.tier-dot.t2 { background: #3b82f6; }
.tier-dot.t3 { background: #f59e0b; }

.nav-link {
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
}
.nav-link:hover { background: var(--surface-alt); color: var(--text); }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.scale-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.scale-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 7px;
  cursor: pointer;
}
.scale-btn.active { background: var(--accent-soft); color: var(--accent-text); }

.theme-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 10px;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.auth-status-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}
.status-dot.admin { background: #10b981; }
.mini-link {
  margin-left: auto;
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
  font-size: 0.78rem;
}

/* Main Area */
.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.25;
}
.subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.clock-pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-alt); }

.btn-outline, .btn-primary {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--border);
}
.btn-outline { background: var(--surface); color: var(--text); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { opacity: 0.92; }

.content {
  padding: 20px 24px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.kpi-value { font-size: 1.7rem; font-weight: 700; line-height: 1.15; }
.kpi-meta { font-size: 0.78rem; color: var(--text-muted); }

/* Cards & Sections */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 1.12rem; font-weight: 700; }
.panel-kicker {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-text);
  margin-bottom: 4px;
}

.digest-headline {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 4px 0 10px;
  line-height: 1.35;
}
.digest-summary {
  margin: 0 0 18px;
  font-size: 0.96rem;
  color: var(--text);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.three-col {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.sub-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.sub-card h3 {
  margin: 0 0 8px;
  font-size: 0.92rem;
  font-weight: 700;
}
.sub-card p { margin: 0; font-size: 0.86rem; color: var(--text-muted); }

/* Session cards */
.session-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease;
}
.session-card:hover { border-color: var(--border-strong); }

.session-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.pill-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
}
.pill.tier-1 { background: var(--fact-bg); border-color: var(--fact-border); color: var(--fact-text); }
.pill.tier-2 { background: var(--insight-bg); border-color: var(--insight-border); color: var(--insight-text); }
.pill.tier-3 { background: var(--sales-bg); border-color: var(--sales-border); color: var(--sales-text); }
.pill.live { background: var(--live-bg); border-color: rgba(220,38,38,0.35); color: var(--live-red); }
.pill.score { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }

.session-title {
  margin: 0 0 8px;
  font-size: 1.08rem;
  font-weight: 700;
  cursor: pointer;
}
.session-title:hover { color: var(--accent-text); }
.session-summary { margin: 0 0 12px; font-size: 0.9rem; color: var(--text-muted); }

/* 3-label evidence blocks */
.label-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.label-box {
  border-radius: 12px;
  padding: 12px 13px;
  border: 1px solid var(--border);
}
.label-box.fact { background: var(--fact-bg); border-color: var(--fact-border); }
.label-box.insight { background: var(--insight-bg); border-color: var(--insight-border); }
.label-box.sales { background: var(--sales-bg); border-color: var(--sales-border); }

.label-box h4 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.label-box.fact h4 { color: var(--fact-text); }
.label-box.insight h4 { color: var(--insight-text); }
.label-box.sales h4 { color: var(--sales-text); }

.label-box ul {
  margin: 0;
  padding-left: 16px;
  font-size: 0.84rem;
}
.label-box li { margin-bottom: 4px; }

.session-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.tool-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tool-tag {
  font-size: 0.76rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-alt);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}
.modal-card.modal-wide { max-width: 880px; }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 2px 0 0; font-size: 1.12rem; }
.modal-kicker { font-size: 0.76rem; font-weight: 700; color: var(--accent-text); text-transform: uppercase; }
.modal-body { padding: 18px 20px; overflow-y: auto; }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; }
.field input, .field select, .field textarea {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
}
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.transcript-box {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
  color: var(--text);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  background: var(--text);
  color: var(--surface);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  max-width: 380px;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.mobile-only { display: none; }
.mobile-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 35;
}

@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .label-grid, .three-col { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .desktop-only { display: none; }
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    width: 280px;
    max-width: 86vw;
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { padding: 12px 14px; }
  .topbar h1 { font-size: 1.05rem; }
  .subtitle { display: none; }
  .clock-pill { display: none; }
  .content { padding: 14px 12px 36px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-card { padding: 12px; }
  .kpi-value { font-size: 1.35rem; }
  .two-col, .form-row { grid-template-columns: 1fr; }
  .panel { padding: 15px 14px; }
}
