/* =============================================================================
   TOFFA coach platform | styles
   Layout: navy sidebar (desktop) or bottom tab bar (phone), white header with
   the report-style title and gold subtitle, a light filter band with a gold
   rule, then the page. Colours are tokens; a club's theme (clubs.theme in the
   database) overrides --brand, --brand-2, --accent, --tint and --tint-2.
   ========================================================================== */

:root {
  /* TOFFA defaults (login page); replaced by the club palette after login */
  --brand:   #171546;   /* sidebar, headings        (report: navy)  */
  --brand-2: #29266d;   /* links, active states      (report: blue)  */
  --accent:  #C8993A;   /* rules, highlights         (report: gold)  */
  --tint:    #e2e3f1;   /* filter band, table stripes (report: light) */
  --tint-2:  #a6a8cf;   /* secondary text on brand   (report: mid)   */

  --ink:     #0d1633;
  --muted:   #55607d;
  --faint:   #8c95ad;
  --bg:      #f3f5fa;
  --surface: #ffffff;
  --line:    #dfe4ef;
  --on-brand:#ffffff;

  --win:  #1e8f52;
  --draw: #7d879f;
  --loss: #cf3d3d;

  --display: "Barlow Condensed", "Arial Narrow", Arial, sans-serif;
  --body:    "Barlow", Arial, "Helvetica Neue", sans-serif;

  --side-w: 232px;
  --radius: 6px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.selectable { user-select: all; font-weight: 600; color: var(--brand-2); overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Boot ---------- */
.boot {
  min-height: 100%; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; color: var(--muted);
  font-family: var(--display); letter-spacing: .12em; text-transform: uppercase; font-size: 13px;
}
.boot-mark {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--tint); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login / gate ---------- */
.gate {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding-block: 32px; padding-left: var(--gutter-l); padding-right: var(--gutter-r);
  background:
    linear-gradient(180deg, transparent 0 62%, rgba(0,0,0,.04) 62% 100%),
    var(--brand);
}
.gate-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border-radius: var(--radius);
  padding: 32px 28px 26px;
  box-shadow: 0 18px 40px rgba(5, 8, 30, .28);
}
.gate-logo { display: block; width: 100%; max-width: 300px; height: auto; margin: 0 auto; }
.gate-rule { height: 3px; width: 56px; background: var(--accent); margin: 22px 0 16px; }
.gate-title {
  font-family: var(--display); font-weight: 700; font-size: 30px; line-height: 1.05;
  margin: 0; color: var(--brand); text-transform: uppercase; letter-spacing: .01em; text-wrap: balance;
}
.gate-sub { margin: 8px 0 20px; color: var(--muted); }
.gate-help { margin: 18px 0 0; font-size: 13.5px; color: var(--muted); }
.gate-foot { margin: 0; color: var(--tint-2); font-size: 12.5px; letter-spacing: .04em; text-align: center; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 6px; }
.form label { font-weight: 600; font-size: 13.5px; color: var(--ink); margin-top: 8px; }
.form input {
  width: 100%; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--surface); font-size: 16px;   /* 16px stops iOS zooming in */
}
.form input:focus { border-color: var(--brand-2); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 18%, transparent); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-show {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--brand-2); font-weight: 600; font-size: 13px;
  padding: 6px 8px; cursor: pointer; border-radius: 4px;
}
.form-error { margin: 6px 0 0; color: var(--loss); font-size: 13.5px; font-weight: 500; }
.form-ok { margin: 6px 0 0; color: var(--win); font-size: 13.5px; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius); padding: 11px 18px; font-weight: 600; cursor: pointer;
  border: 1.5px solid transparent; transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--brand); color: var(--on-brand); margin-top: 16px; }
.btn-primary:hover { background: var(--brand-2); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-ghost { background: none; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--faint); }

/* ---------- App frame ---------- */
.app { min-height: 100%; display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }

.sidebar {
  background: var(--brand); color: var(--on-brand);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  padding: 22px 0 18px;
}
.side-club { padding: 0 20px 18px; border-bottom: 1px solid rgba(255,255,255,.12); display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.side-logo { width: 68px; height: 68px; object-fit: contain; background: #fff; border-radius: 50%; padding: 7px; box-shadow: 0 0 0 2px var(--accent); }
.side-club-name { font-family: var(--display); font-size: 21px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; line-height: 1.05; }
.club-switch { width: 100%; background: rgba(255,255,255,.08); color: var(--on-brand); border: 1px solid rgba(255,255,255,.2); border-radius: 4px; padding: 6px 8px; }
.club-switch option { color: var(--ink); }

.nav { list-style: none; margin: 14px 0 0; padding: 0; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; color: var(--tint-2); text-decoration: none; font-weight: 600;
  border-left: 3px solid transparent;
}
.nav a:hover { color: var(--on-brand); background: rgba(255,255,255,.05); }
.nav a[aria-current="page"] { color: var(--on-brand); background: rgba(255,255,255,.09); border-left-color: var(--accent); }
.nav svg { width: 20px; height: 20px; flex: none; }
.nav .nav-soon { margin-left: auto; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--tint-2); opacity: .8; font-weight: 500; }

.side-foot { padding: 14px 20px 0; border-top: 1px solid rgba(255,255,255,.12); display: flex; flex-direction: column; gap: 8px; }
.side-foot-label { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--tint-2); }
.side-toffa { width: 150px; background: #fff; border-radius: 3px; padding: 4px 6px; }

.main { min-width: 0; display: flex; flex-direction: column; }

/* Header: report-style title with gold italic subtitle */
.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding-block: 18px 16px; padding-left: max(28px, env(safe-area-inset-left, 0px)); padding-right: max(28px, env(safe-area-inset-right, 0px));
}
.top-logo { display: none; width: 38px; height: 38px; object-fit: contain; flex: none; }
.top-titles { min-width: 0; flex: 1; }
.page-title {
  margin: 0; font-family: var(--display); font-weight: 700; font-size: 30px; line-height: 1;
  color: var(--brand); text-transform: uppercase; letter-spacing: .01em; text-wrap: balance;
}
.page-sub { margin: 5px 0 0; color: var(--accent); font-style: italic; font-weight: 500; font-size: 14px; }

.user { position: relative; flex: none; }
.user-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--accent);
  background: var(--brand); color: var(--on-brand); font-weight: 700; cursor: pointer; text-transform: uppercase;
}
.user-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30;
  min-width: 230px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(10, 20, 50, .16); padding: 6px;
}
.user-email { padding: 10px 10px 8px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow-wrap: anywhere; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px; border-radius: 4px; cursor: pointer; font-weight: 500; }
.menu-item:hover { background: var(--tint); }

/* Filter band: light tint with a gold rule, like the report section labels */
.filters {
  background: var(--tint); border-bottom: 3px solid var(--accent);
  padding-left: max(28px, env(safe-area-inset-left, 0px)); padding-right: max(28px, env(safe-area-inset-right, 0px));
  position: sticky; top: 0; z-index: 20;
}
.filters-toggle { display: none; }
.filters-body { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 18px; padding-block: 12px; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field label { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--brand); }
.field select {
  min-width: 170px; max-width: 100%; padding: 8px 32px 8px 10px; border: 1.5px solid transparent; border-radius: 4px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2355607d' stroke-width='1.8'/%3E%3C/svg%3E") no-repeat right 10px center;
  appearance: none; cursor: pointer; font-weight: 600; font-size: 14.5px;
}
.field select:hover { border-color: var(--tint-2); }
#f-match { min-width: 260px; }
.btn-reset { background: none; border: 0; color: var(--brand-2); font-weight: 600; cursor: pointer; padding: 8px 4px; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Pages ---------- */
.view {
  flex: 1; outline: none;
  padding-block: 24px 48px; padding-left: max(28px, env(safe-area-inset-left, 0px)); padding-right: max(28px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 22px;
  max-width: 1320px; width: 100%;
}

.section-h {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 0 0 10px;
}
.section-h h2 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 20px; text-transform: uppercase; letter-spacing: .02em; color: var(--brand); }
.section-h .hint { color: var(--muted); font-size: 13px; font-style: italic; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }

/* Season strip */
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.strip > div { padding: 14px 18px; border-right: 1px solid var(--line); min-width: 0; }
.strip > div:last-child { border-right: 0; }
.strip .k { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.strip .v { font-family: var(--display); font-size: 30px; font-weight: 700; color: var(--brand); line-height: 1.1; font-variant-numeric: tabular-nums; }
.strip .v small { font-size: 16px; color: var(--muted); font-weight: 600; }
.strip .s { font-size: 12.5px; color: var(--muted); }
.form-dots { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: 4px; }

.pill { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 4px; color: #fff; font-weight: 700; font-size: 12.5px; font-family: var(--body); }
.pill.W { background: var(--win); } .pill.D { background: var(--draw); } .pill.L { background: var(--loss); }

/* Results */
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.result {
  text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 10px; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.result:hover { border-color: var(--tint-2); }
.result[aria-pressed="true"] { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.result-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.result-mid { display: flex; align-items: center; gap: 10px; }
.result-opp { flex: 1; min-width: 0; font-weight: 700; font-size: 16px; color: var(--ink); overflow-wrap: anywhere; }
.result-score { font-family: var(--display); font-weight: 700; font-size: 26px; color: var(--brand); font-variant-numeric: tabular-nums; }
.xgbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.xgbar .track { height: 6px; background: var(--tint); border-radius: 3px; overflow: hidden; display: flex; }
.xgbar .us { background: var(--brand); }
.xgbar .them { background: var(--loss); opacity: .55; margin-left: auto; }

/* Selection stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.stat .k { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--display); font-size: 28px; font-weight: 700; color: var(--brand); line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12.5px; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); font-style: italic; margin: 10px 0 0; }

/* Table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
table.data th, table.data td { padding: 9px 12px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand);
  background: var(--tint); border-bottom: 2px solid var(--accent); cursor: pointer; user-select: none;
  position: sticky; top: 0;
}
table.data thead th[aria-sort="descending"]::after { content: " ↓"; }
table.data thead th[aria-sort="ascending"]::after { content: " ↑"; }
table.data tbody tr:nth-child(even) { background: color-mix(in srgb, var(--tint) 35%, transparent); }
table.data tbody tr:hover { background: var(--tint); }
.jersey { display: inline-grid; place-items: center; min-width: 26px; height: 22px; padding: 0 4px; border-radius: 3px; background: var(--brand); color: var(--on-brand); font-size: 12px; font-weight: 700; margin-right: 8px; }
.low { color: var(--faint); }

/* Coming soon */
.soon { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; align-items: center; }
.soon h2 { margin: 0 0 8px; font-family: var(--display); font-size: 26px; text-transform: uppercase; color: var(--brand); }
.soon p { margin: 0 0 12px; color: var(--muted); max-width: 60ch; }
.soon ul { margin: 0; padding-left: 18px; color: var(--ink); }
.soon li { margin: 4px 0; }
.soon .when { display: inline-block; margin-top: 14px; font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.soon svg { width: 100%; height: auto; display: block; }

.error-box { border-left: 4px solid var(--loss); }
.empty { color: var(--muted); padding: 22px; text-align: center; }

/* Dialog */
.dialog { border: 0; border-radius: var(--radius); padding: 24px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 24px 60px rgba(5, 8, 30, .3); }
.dialog::backdrop { background: rgba(10, 14, 40, .45); }
.dialog-title { margin: 0 0 4px; font-family: var(--display); font-size: 24px; text-transform: uppercase; color: var(--brand); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.dialog-actions .btn-primary { margin-top: 0; }

/* ---------- Phone ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }

  /* Sidebar becomes a bottom tab bar */
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 40;
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    flex-direction: row;
  }
  .side-club, .side-foot { display: none; }
  .nav { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; margin: 0; width: 100%; }
  .nav a { flex-direction: column; gap: 3px; padding: 9px 4px 8px; font-size: 11.5px; border-left: 0; border-top: 3px solid transparent; text-align: center; }
  .nav a[aria-current="page"] { border-top-color: var(--accent); }
  .nav .nav-soon { display: none; }

  .topbar { padding-block: 12px; padding-left: var(--gutter-l); padding-right: var(--gutter-r); gap: 10px; }
  .top-logo { display: block; }
  .page-title { font-size: 23px; }
  .page-sub { font-size: 12.5px; }

  /* Filters collapse behind a summary button */
  .filters { padding-left: var(--gutter-l); padding-right: var(--gutter-r); }
  .filters-toggle {
    display: flex; width: 100%; align-items: center; gap: 10px; background: none; border: 0; padding: 11px 0; cursor: pointer; text-align: left;
  }
  .filters-toggle-label { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--brand); flex: none; }
  .filters-summary { flex: 1; min-width: 0; font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .filters-toggle::after { content: ""; width: 10px; height: 10px; border-right: 2px solid var(--brand); border-bottom: 2px solid var(--brand); transform: rotate(45deg) translateY(-3px); flex: none; transition: transform .15s; }
  .filters-toggle[aria-expanded="true"]::after { transform: rotate(-135deg) translateY(-3px); }
  .filters-body { display: none; flex-direction: column; align-items: stretch; padding-top: 0; }
  .filters.open .filters-body { display: flex; }
  .field select, #f-match { min-width: 0; width: 100%; font-size: 16px; }

  .view { padding-block: 16px 32px; padding-left: var(--gutter-l); padding-right: var(--gutter-r); gap: 18px; }
  .strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strip > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .strip > div:nth-child(odd) { border-right: 1px solid var(--line); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .soon { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
