:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --navy: #0b1120;
  --navy-2: #131c31;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #10b981;
  --gold: #f59e0b;
  --warn: #d97706;
  --danger: #dc2626;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}
code, .mono { font-family: "JetBrains Mono", Consolas, monospace; font-size: 12px; }
.kpi-val, .client-item-meta, .ex-table input, code { font-variant-numeric: tabular-nums; }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, #2563eb 0%, #10b981 100%);
  color: #fff; font-weight: 800; font-size: 15px; letter-spacing: 0.5px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}
.client-item { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 8px; background: rgba(255,255,255,0.04); cursor: pointer; border: 1px solid transparent; transition: 0.15s; }
.client-item:hover { background: rgba(255, 255, 255, 0.1); }
.client-item.active { background: var(--primary); border-color: #60a5fa; }
.client-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255, 255, 255, 0.12); border: 1.5px solid #475569;
  color: #f8fafc; font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.client-item.active .client-avatar { background: #10b981; border-color: #6ee7b7; color: #0b1120; }
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 272px; background: var(--navy); color: #f8fafc; display: flex; flex-direction: column; padding: 18px 14px; flex-shrink: 0; }
.brand-title { font-size: 16px; font-weight: 800; letter-spacing: 0.6px; }
.brand-sub { font-size: 11.5px; color: #94a3b8; margin-top: 2px; }
.tg-pill { margin: 12px 0; padding: 7px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; background: #1e293b; border: 1px solid #334155; }
.tg-pill.ok { border-color: #10b981; color: #6ee7b7; }
.tg-pill.off { border-color: #f59e0b; color: #fcd34d; }
.sidebar-section { flex: 1; overflow-y: auto; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; font-size: 12px; text-transform: uppercase; color: #94a3b8; margin-bottom: 8px; }
.sidebar-search { width: 100%; margin-bottom: 8px; padding: 6px 9px; border-radius: 7px; border: 1px solid #334155; background: rgba(255,255,255,0.06); color: #f8fafc; font-size: 12.5px; }
.sidebar-search::placeholder { color: #94a3b8; }
.client-list { display: flex; flex-direction: column; gap: 5px; }
.client-item-name { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 5px; }
.client-item-meta { font-size: 11px; color: #cbd5e1; margin-top: 2px; }
.sidebar-footer { padding-top: 12px; border-top: 1px solid #1e293b; }

.main-area { flex: 1; padding: 20px 28px; overflow-x: hidden; max-width: 1560px; }
.topbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: -0.2px; }
.subline { font-size: 13px; color: var(--muted); margin-top: 3px; }
.sheet-picker-wrap { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
select, input, textarea { font-family: inherit; font-size: 13px; border: 1px solid var(--border); border-radius: 7px; padding: 6px 9px; background: var(--surface); color: var(--text); outline: none; transition: border-color 0.12s, box-shadow 0.12s; }
select:focus, input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14); }
.ico { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab { border: none; background: transparent; padding: 9px 14px; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel, .subpanel { display: none; }
.tab-panel.active, .subpanel.active { display: block; }

.sticky-toolbar { position: sticky; top: 0; z-index: 40; padding: 10px 14px; border-radius: 11px; background: rgba(255,255,255,0.92); backdrop-filter: blur(8px); border: 1px solid var(--border); box-shadow: 0 4px 12px rgba(15,23,42,0.06); }
.btn-icon { padding: 4px 7px; font-size: 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 700; }
.btn-icon:hover { border-color: var(--primary); color: var(--primary); }
.btn-icon-danger { padding: 4px 7px; font-size: 12px; border-radius: 6px; border: none; background: #fee2e2; color: var(--danger); cursor: pointer; font-weight: 700; }
.btn-icon-danger:hover { filter: brightness(0.95); }
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-thumb { background: rgba(100,116,139,0.35); border-radius: 99px; }

.nav-badge { background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 800; padding: 1px 6px; border-radius: 99px; line-height: 1.4; }
.nav-badge.hidden { display: none; }
.subtabs { display: inline-flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 14px; }
.subtab { border: none; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 700; cursor: pointer; transition: 0.15s; }
.subtab.active { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05); }
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.toolbar-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.surface-box, .soft-panel { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; }
.science-box { padding: 10px 12px; border: 1px solid #93c5fd; border-radius: 8px; background: #eff6ff; margin: 10px 0; }
.coach-split-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(350px, 0.9fr); gap: 16px; align-items: start; }
.video-row-card { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--surface-2); flex-wrap: wrap; }
.pain-alert-box { padding: 7px 10px; border-left: 4px solid var(--danger); background: #fef2f2; margin-bottom: 6px; font-size: 12.5px; border-radius: 4px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: auto; flex-shrink: 0; }
.dot-red { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,0.6); }
.dot-yellow { background: #f59e0b; box-shadow: 0 0 6px rgba(245,158,11,0.5); }
.dot-green { background: #10b981; }

.btn { border: none; border-radius: 7px; padding: 8px 13px; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: opacity 0.12s; }
.btn:hover { opacity: 0.92; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); opacity: 1; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-mini { border: none; background: rgba(255,255,255,0.14); color: #fff; border-radius: 5px; padding: 3px 8px; font-size: 11.5px; cursor: pointer; }
.btn-full { width: 100%; justify-content: center; }

.grid-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.field label { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.field input, .field select, .field textarea { width: 100%; }

table.ex-table, table.table { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.ex-table th, table.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; color: var(--muted); padding: 7px 6px; border-bottom: 1px solid var(--border); }
table.ex-table td, table.table td { padding: 6px 5px; border-bottom: 1px solid rgba(148,163,184,0.22); vertical-align: top; }
table.ex-table input { width: 100%; padding: 5px 7px; font-size: 12.5px; }
tr.top-set-row { background: #fefce8; }
.hint-pill { display: inline-block; margin-top: 4px; font-size: 11px; padding: 2px 7px; border-radius: 5px; background: #e0f2fe; color: #0369a1; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--primary); border-radius: 10px; padding: 14px; transition: transform 0.12s; }
.kpi-card:hover { transform: translateY(-1px); }
.kpi-red { border-top-color: var(--danger); }
.kpi-amber { border-top-color: var(--gold); }
.kpi-emerald { border-top-color: var(--accent); }
.kpi-blue { border-top-color: var(--primary); }
.kpi-label { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.kpi-val { font-size: 22px; font-weight: 800; margin-top: 4px; color: var(--navy); }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.triage-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: 14px; border-radius: 10px; background: linear-gradient(90deg, rgba(220,38,38,0.08), rgba(245,158,11,0.08)); border: 1px solid var(--border); }
.triage-pill { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 99px; padding: 4px 10px; font-size: 12px; font-weight: 700; cursor: pointer; }
.triage-pill:hover { border-color: var(--primary); }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 14px; }
.badge { padding: 3px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; display: inline-block; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-bad { background: #fee2e2; color: #991b1b; }
.badge-neutral { background: #e2e8f0; color: #334155; }
.alert { padding: 8px 11px; border-radius: 6px; font-size: 12.5px; font-weight: 500; border-left: 4px solid #64748b; }
.alert-warn { background: #fffbeb; color: #92400e; border-left-color: #f59e0b; }
.alert-info { background: #eff6ff; color: #1e40af; border-left-color: #3b82f6; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; z-index: 999; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.toast.hidden { display: none; }
.fb-row { display: flex; gap: 6px; align-items: center; }
.fb-row input { min-width: 190px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.chip-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 99px; padding: 4px 10px; font-size: 11.5px; font-weight: 600; cursor: pointer; }
.chip-btn:hover { background: var(--surface-2); }
.chip-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chat-thread { display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow-y: auto; padding: 10px; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--border); }
.chat-bubble { max-width: 86%; padding: 8px 12px; border-radius: 10px; font-size: 13px; line-height: 1.4; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.chat-in { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.chat-out { align-self: flex-end; background: #dbeafe; border: 1px solid #93c5fd; color: #0f172a; }
.chat-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.chat-compose { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.chat-compose input { flex: 1; min-width: 200px; }

body.dark-theme { --bg: #0b1120; --surface: #131c31; --surface-2: #19243d; --border: #26344e; --text: #f1f5f9; --muted: #94a3b8; }
body.dark-theme .sticky-toolbar { background: rgba(19, 28, 49, 0.92); }
body.dark-theme .btn-icon { background: #1e293b; border-color: #334155; color: #e2e8f0; }
body.dark-theme select, body.dark-theme input, body.dark-theme textarea { background: #0f172a; color: #f1f5f9; border-color: #334155; }
body.dark-theme .btn-secondary { background: #1e293b; color: #e2e8f0; border: 1px solid #334155; }
body.dark-theme .chat-out { background: #172554; border-color: #2563eb; color: #f8fafc; }
body.dark-theme .kpi-val, body.dark-theme .card-title { color: #f8fafc; }
body.dark-theme .science-box { background: #172554; border-color: #3b82f6; }
body.dark-theme .pain-alert-box { background: #450a0a; color: #fecaca; }
body.dark-theme tr.top-set-row { background: #422006; }
body.dark-theme .hint-pill { background: #0c4a6e; color: #bae6fd; }
body.dark-theme .badge-neutral { background: #334155; color: #e2e8f0; }
body.dark-theme .alert-warn { background: #451a03; color: #fde68a; }
body.dark-theme .alert-info { background: #172554; color: #bfdbfe; }
@media (max-width: 1180px) { .coach-split-grid { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .mobile-only { display: inline-flex; }
  .sidebar { display: none; width: 100%; padding: 12px; }
  .sidebar.mobile-open { display: flex; }
  .main-area { padding: 12px; }
  .chart-grid { grid-template-columns: 1fr; }
}

.mobile-only { display: none; }
.prev-pill { font-size: 11px; color: var(--muted); margin-top: 3px; font-weight: 600; }

.fc-modal-backdrop {
  position: fixed; inset: 0; z-index: 90; background: rgba(15, 23, 42, 0.78);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.fc-modal {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; max-width: 980px; width: 100%; max-height: 94vh; overflow-y: auto;
}
.fc-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.fc-canvas-wrap {
  background: #000; border-radius: 8px; overflow: hidden; display: flex; justify-content: center;
  border: 1px solid var(--border); touch-action: none;
}
#fc-draw-canvas { max-width: 100%; max-height: 62vh; cursor: crosshair; }
.btn-rec-live { background: #dc2626 !important; color: #fff !important; border-color: #ef4444 !important; }
.sheet-picker-box { display: inline-flex; align-items: center; gap: 8px; }
.sheet-picker-box.hidden-ctx { display: none; }
.tools-menu { position: relative; display: inline-block; }
.tools-menu > summary { list-style: none; cursor: pointer; }
.tools-menu > summary::-webkit-details-marker { display: none; }
.tools-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; min-width: 225px;
  background: var(--card-bg, #fff); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; box-shadow: 0 12px 28px rgba(15, 23, 42, .18); display: flex; flex-direction: column; gap: 5px;
}
.tools-dropdown .btn { width: 100%; justify-content: flex-start; text-align: left; }
.meta-collapsible { padding: 10px 14px; }
.meta-summary { display: flex; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer; list-style: none; flex-wrap: wrap; }
.meta-summary::-webkit-details-marker { display: none; }
.meta-toggle-lbl { font-size: 12px; font-weight: 600; color: var(--accent, #2563eb); }
.meta-body { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.day-filter-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.day-filter-pill.active { background: var(--accent, #2563eb) !important; color: #fff !important; border-color: var(--accent, #2563eb) !important; }
.day-card.hidden-day { display: none; }
.ex-meta-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; align-items: center; }
.btn-dirty { background: #d97706 !important; border-color: #b45309 !important; color: #fff !important; box-shadow: 0 0 0 2px rgba(217, 119, 6, .25); }
.setup-drawer { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.fatigue-grid { display: grid; grid-template-columns: 205px 1fr; gap: 16px; align-items: center; }
@media (max-width: 720px) { .fatigue-grid { grid-template-columns: 1fr; } }
.fatigue-svg-box { display: flex; justify-content: center; padding: 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.fatigue-svg { width: 100%; max-width: 195px; height: auto; }
.fatigue-bars { display: flex; flex-direction: column; gap: 8px; }
.fatigue-row-top { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.fatigue-track { height: 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.fatigue-fill { height: 100%; border-radius: 99px; transition: width 0.25s ease; }
.cockpit-cell { display: flex; align-items: center; gap: 8px; }
.cockpit-gauge { position: relative; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cockpit-gauge-txt { position: absolute; font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sparkline-wrap { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.sparkline-svg { display: block; overflow: visible; }
.editor-split-wrap.is-split { display: grid; grid-template-columns: 365px minmax(0, 1fr); gap: 14px; align-items: start; }
.review-split-aside { position: sticky; top: 68px; max-height: calc(100vh - 88px); overflow-y: auto; }
@media (max-width: 1020px) { .editor-split-wrap.is-split { grid-template-columns: 1fr; } .review-split-aside { position: static; max-height: none; } }
.fatigue-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.fatigue-sub { font-size: 11.5px; font-weight: 500; color: var(--muted); margin-top: 2px; }
