/* Court Analytics design system — shared by every workspace page.
   Light and dark themes follow the operating system unless the header toggle stores a choice
   (data-theme on <html>). Video, camera previews and canvases stay on a dark "stage" in both
   themes so footage, overlays and drawn courts keep their contrast. */

:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --surface-3: #e3e9e6;
  --border: #d6dfda;
  --border-strong: #b7c4bd;
  --text: #13221c;
  --muted: #586a62;
  --subtle: #7b8b84;
  --accent: #1f7a4c;
  --accent-hover: #186540;
  --accent-text: #ffffff;
  --accent-soft: #e2f2e8;
  --accent-soft-text: #155c38;
  --link: #1f7a4c;
  --danger: #b3382f;
  --danger-soft: #fbe9e7;
  --focus: #2b6de0;
  --stage: #0c1512;
  --stage-border: #1f2c27;
  --shadow: 0 1px 2px rgb(16 34 27 / 6%), 0 2px 8px rgb(16 34 27 / 5%);
  --radius: 12px;
  --radius-sm: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* Legacy names still referenced by older markup. */
  --court-panel: var(--surface);
  --court-border: var(--border);
  --court-accent: var(--accent);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1512;
  --surface: #141f1b;
  --surface-2: #1a2723;
  --surface-3: #22322c;
  --border: #283a33;
  --border-strong: #3a5047;
  --text: #e8f0eb;
  --muted: #a0b2aa;
  --subtle: #7f938a;
  --accent: #c6ea6a;
  --accent-hover: #d6f387;
  --accent-text: #15210b;
  --accent-soft: #233322;
  --accent-soft-text: #d3ee8e;
  --link: #d3ee8e;
  --danger: #f08a7e;
  --danger-soft: #3a1f1c;
  --focus: #7fb4ff;
  --stage: #070d0b;
  --stage-border: #22312b;
  --shadow: 0 1px 2px rgb(0 0 0 / 35%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1512;
    --surface: #141f1b;
    --surface-2: #1a2723;
    --surface-3: #22322c;
    --border: #283a33;
    --border-strong: #3a5047;
    --text: #e8f0eb;
    --muted: #a0b2aa;
    --subtle: #7f938a;
    --accent: #c6ea6a;
    --accent-hover: #d6f387;
    --accent-text: #15210b;
    --accent-soft: #233322;
    --accent-soft-text: #d3ee8e;
    --link: #d3ee8e;
    --danger: #f08a7e;
    --danger-soft: #3a1f1c;
    --focus: #7fb4ff;
    --stage: #070d0b;
    --stage-border: #22312b;
    --shadow: 0 1px 2px rgb(0 0 0 / 35%);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
main { max-width: 1200px; margin: 0 auto; padding: 0 clamp(14px, 3vw, 32px) 64px; }
[hidden] { display: none !important; }

h1, h2, h3 { color: var(--text); line-height: 1.2; letter-spacing: -0.015em; }
h1 { font-size: clamp(1.6rem, 2.6vw, 2.1rem); font-weight: 700; margin: 28px 0 6px; }
h2 { font-size: 1.12rem; font-weight: 650; margin: 0 0 8px; }
h3 { font-size: .98rem; font-weight: 650; margin: 22px 0 6px; }
p { margin: 6px 0 12px; }
main > p, section > p, article > p, details > p, .page-header p { color: var(--muted); max-width: 78ch; }
small { display: block; color: var(--subtle); font-size: .82rem; margin: 6px 0; }
a { color: var(--link); text-underline-offset: 2px; }
pre { font: .86rem/1.5 var(--mono); white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
hr { border: 0; border-top: 1px solid var(--border); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- App header (injected by the server) ---------- */
.app-header {
  position: relative; z-index: 20;
  display: flex; align-items: center; gap: 10px 24px; flex-wrap: wrap;
  margin: 0 calc(-1 * clamp(14px, 3vw, 32px)) 8px;
  padding: 10px clamp(14px, 3vw, 32px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; font-size: .98rem; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; flex: none; }
.brand .mark-court { fill: var(--accent); }
.brand .mark-lines { stroke: var(--accent-text); }
.workspace-nav.sport-nav { display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 0; flex: 1 1 100%; order: 3; align-items: center; }
.sport-links { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sport-links strong { font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--subtle); }
.sport-links > div { display: flex; flex-wrap: wrap; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.sport-links a {
  display: inline-flex; align-items: center; min-height: 30px; padding: 4px 11px;
  border-radius: 7px; color: var(--muted); text-decoration: none; font-weight: 550; font-size: .85rem; white-space: nowrap;
}
.sport-links a:hover { color: var(--text); background: var(--surface-3); }
.sport-links a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
button.theme-toggle { margin: 0 0 0 auto; min-height: 32px; padding: 4px 10px; font-size: .8rem; color: var(--muted); }
.theme-toggle svg { width: 15px; height: 15px; }
@media (max-width: 900px) { .sport-links { flex-wrap: wrap; } }

/* ---------- Page header ---------- */
.page-header, .review-header { margin: 18px 0; }
.page-header h1, .review-header h1 { margin: 10px 0 6px; font-size: clamp(1.6rem, 2.6vw, 2.1rem); line-height: 1.15; }
.page-header p, .review-header p { font-size: 1rem; max-width: 72ch; color: var(--muted); }

/* ---------- Cards ---------- */
section, article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin: 14px 0;
  box-shadow: var(--shadow);
  min-width: 0;
}
section article, section section { box-shadow: none; background: var(--surface-2); }
section { scroll-margin-top: 60px; }
.views, .grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.views > article, .grid > article { margin: 0; }
.views > article { position: relative; }

/* ---------- Controls ---------- */
button, .review-actions a, #coachLink, .workspace-nav:not(.sport-nav) a {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px; margin: 4px 6px 4px 0;
  font: 550 .9rem/1.2 var(--font);
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s;
}
button:hover:not(:disabled), .review-actions a:hover, #coachLink:hover, .workspace-nav:not(.sport-nav) a:hover {
  background: var(--surface-2); border-color: var(--subtle);
}
button.primary, .review-actions button {
  background: var(--accent); color: var(--accent-text); border-color: var(--accent);
}
button.primary:hover:not(:disabled), .review-actions button:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
button.danger:hover:not(:disabled) { background: var(--danger-soft); }
button:disabled { opacity: .45; cursor: not-allowed; }
button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-soft-text); border-color: var(--accent); }

label { color: var(--text); font-size: .88rem; font-weight: 550; margin: 6px 14px 6px 0; display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), select, textarea {
  font: 400 .9rem/1.3 var(--font);
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  min-height: 36px; padding: 6px 10px; max-width: 100%;
}
input::placeholder { color: var(--subtle); }
input:disabled, select:disabled { opacity: .55; }
input[type=number] { width: 7.5em; font-variant-numeric: tabular-nums; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
input[type=range] { accent-color: var(--accent); min-width: 160px; flex: 1 1 240px; }
input[type=file] { font: .86rem var(--font); color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button {
  font: 550 .86rem var(--font); color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 6px 12px; margin-right: 10px; cursor: pointer;
}

/* Status lines: quiet callouts so state changes are easy to spot. */
output { display: block; margin: 10px 0; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
output:empty { display: none; }
.status, #captureReadiness, #matchState, #status, #message, #instructions, #syncStatus, #sessionStatus, #phoneState,
#bufferState, #threeStatus, #analysisStatus, #gatewayStatus, #pairHelp, #singleMessage, #stats {
  padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); color: var(--accent-soft-text);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; max-width: none;
}

details { margin: 10px 0; }
details > summary { cursor: pointer; color: var(--text); font-weight: 600; font-size: .9rem; padding: 6px 0; }
details > summary::marker { color: var(--subtle); }
details.help { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px 14px; max-width: 78ch; }
details.help > summary { color: var(--muted); font-weight: 550; }
details.help[open] { padding-bottom: 6px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { color: var(--muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tbody th { font-weight: 600; color: var(--muted); }
tbody tr:hover td { background: var(--surface-2); }
#matchReview, .tableScroll, #moveTable, #swingTable, #gripTable, #jobs { overflow-x: auto; }

/* ---------- Media stage ---------- */
video, canvas, iframe { max-width: 100%; }
video, canvas { display: block; width: 100%; height: auto; background: var(--stage); border: 1px solid var(--stage-border); border-radius: var(--radius-sm); margin: 10px 0; }
video { aspect-ratio: 16 / 9; }
#analysisOverlay { border: 0; background: transparent; margin: 0; }
#views img { max-width: 100%; border-radius: var(--radius-sm); }
#demoReplay { border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* ---------- Layout helpers ---------- */
.review-actions, .section-links, .workspace-nav:not(.sport-nav) { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 14px; }
.section-links {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 8px 0; margin: 0 0 6px; border-bottom: 1px solid var(--border);
}
.section-links a {
  display: inline-flex; align-items: center; min-height: 30px; padding: 3px 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); text-decoration: none; font-size: .84rem; font-weight: 550;
}
.section-links a:hover { color: var(--text); border-color: var(--border-strong); }

.appTabs { display: flex; gap: 2px; margin: 22px 0 6px; padding: 3px; width: max-content; max-width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.appTabs button { margin: 0; border: 0; background: transparent; color: var(--muted); min-height: 34px; }
.appTabs button:hover:not(:disabled) { background: var(--surface-3); }
.appTabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; margin: 8px 0; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 16px; }
.settings label { display: grid; gap: 6px; margin: 0; }
.analyticsGrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 20px; margin-top: 16px; }
.analyticsControls, .tagControls { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }

#trendCharts svg { width: 100%; max-width: 38rem; display: block; }
#trendCharts article { margin: 0; background: var(--surface-2); box-shadow: none; }
#trendCharts .trend-grid { margin-block: 1rem; }
#trendCharts h3 { margin-top: 0; }

#metrics strong, .report-number { font-size: 1.45rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Phone camera page ---------- */
#phone { max-width: 560px; margin: 0 auto; }
#phone button { min-height: 46px; padding: 8px 20px; font-size: 1rem; }

@media (max-width: 540px) {
  section, article { padding: 16px; }
  .review-actions :is(a, button) { flex: 1 1 9rem; }
}

@media print {
  .app-header, .section-links { display: none !important; }
  body { background: #fff; color: #000; }
  section, article { box-shadow: none; break-inside: avoid; }
}

/* Signed-in account chip and sign-out in the app header */
.account-menu { display: flex; align-items: center; gap: 6px; margin-left: 8px; }
.account-chip { display: grid; line-height: 1.1; padding: 3px 10px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; border: 1px solid var(--border); }
.account-chip:hover { background: var(--surface-2); }
.account-chip span { font-weight: 650; font-size: .82rem; }
.account-chip small { color: var(--muted); font-size: .7rem; }
button.sign-out { min-height: 32px; padding: 4px 10px; font-size: .8rem; color: var(--muted); }

/* Sport switch in the header: Tennis | Football. The active sport's tools appear below it. */
.sport-switch { display: inline-flex; gap: 2px; padding: 3px; margin-left: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.sport-switch a { padding: 5px 14px; border-radius: 7px; font-size: .86rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.sport-switch a:hover { color: var(--text); background: var(--surface-3); }
.sport-switch a[aria-current="true"] { background: var(--accent); color: var(--accent-text); }
