/* ============================================================
   Design tokens — single source of truth. Airtable-style:
   light chrome, white cards on neutral bg, soft pastel accents.
   ============================================================ */
:root {
  /* Surfaces & neutrals */
  --c-app-bg: #f7f7f8;
  --c-surface: #ffffff;
  --c-ink: #1f2937;
  --c-muted: #6b7280;
  --c-border: #e5e7eb;
  --c-th-bg: #f9fafb;
  --c-hover: #f9fafb;
  --c-highlight: #eff4ff;   /* matched-player row */
  --c-overlay: rgba(15, 23, 42, .35);

  /* Accent */
  --c-accent: #2d7ff9;
  --c-accent-weak: #e0edff;
  --c-danger: #dc2626;

  /* League pastel pairs (bg tint + text/accent) */
  --league-a-bg: #e0edff; --league-a-fg: #1d4ed8;
  --league-b-bg: #dcfce7; --league-b-fg: #15803d;
  --league-c-bg: #fef3c7; --league-c-fg: #b45309;
  --league-d-bg: #f3e8ff; --league-d-fg: #7e22ce;

  /* Typography */
  --font-base: system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-base: 14px;
  --fs-sm: 12px;
  --fs-xs: 11px;

  /* Spacing */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;

  /* Layout: content column capped and centered; chrome stays full-width */
  --layout-max: 1280px;

  /* Radius */
  --radius: 8px; --radius-sm: 6px; --radius-pill: 999px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .10);

  /* Day grid dims (--slot-h mirrors SLOT_H in src/views/day.js) */
  --slot-h: 26px; --grid-col-w: 130px; --grid-timecol-w: 56px;
}

* { box-sizing: border-box; }
body { font-family: var(--font-base); margin: 0; color: var(--c-ink); background: var(--c-app-bg); }
h1 { font-size: 20px; font-weight: 600; margin: 0 0 var(--sp-3); }
h3 { font-size: var(--fs-base); font-weight: 600; margin: var(--sp-4) 0 var(--sp-2); }
.day-title { font-size: 18px; font-weight: 700; }
a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--c-muted); }

/* Top bar (light chrome) */
#topbar { display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp-3) max(var(--sp-4), calc((100% - var(--layout-max)) / 2)); background: var(--c-surface); color: var(--c-ink);
  border-bottom: 1px solid var(--c-border); box-shadow: var(--shadow-sm); flex-wrap: wrap; gap: var(--sp-3); }
#nav { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
#nav a { color: var(--c-ink); font-size: 15px; font-weight: 500; line-height: 1.2; cursor: pointer;
  padding: var(--sp-2) var(--sp-4); border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface); }
#nav a:hover { background: var(--c-hover); border-color: var(--c-accent); text-decoration: none; }
#nav a.active { background: var(--c-accent); color: #fff; border-color: transparent; font-weight: 600; }
#nav a.active:hover { background: var(--c-accent); }
#controls { display: flex; gap: var(--sp-2); align-items: center; }

main { padding: var(--sp-4) max(var(--sp-4), calc((100% - var(--layout-max)) / 2)); }

/* Cards */
.card { background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: var(--sp-4); margin-bottom: var(--sp-4); }
.home-row { padding: var(--sp-2) 0; border-bottom: 1px solid var(--c-border); }
.home-row:last-child { border-bottom: none; }

/* Buttons (bare button = secondary; .btn-primary = accent) */
button { background: var(--c-surface); border: 1px solid var(--c-border); color: var(--c-ink);
  border-radius: var(--radius-sm); padding: var(--sp-1) var(--sp-3); font: inherit; font-size: var(--fs-base); cursor: pointer; }
button:hover { background: var(--c-hover); }
button:disabled { opacity: .5; cursor: default; }
button.btn-primary { background: var(--c-accent); color: #fff; border-color: transparent; }
button.btn-primary:hover { filter: brightness(.95); background: var(--c-accent); }

/* Inputs */
input, select { border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-2); background: var(--c-surface); color: var(--c-ink); font: inherit; font-size: var(--fs-base); }
input:focus, select:focus { outline: none; border-color: var(--c-accent); box-shadow: 0 0 0 3px var(--c-accent-weak); }

.filters { margin: 0 0 var(--sp-3); display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

/* Tables (Airtable-style: hairline rows, muted uppercase headers) */
table { border-collapse: collapse; width: 100%; }
th, td { padding: var(--sp-2) var(--sp-3); text-align: left; font-size: var(--fs-base); border-bottom: 1px solid var(--c-border); }
th { background: var(--c-th-bg); color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; font-size: var(--fs-xs); font-weight: 600; }
tbody tr:hover td { background: var(--c-hover); }
tr.filtered-hit td { background: var(--c-highlight); }
.mark { color: var(--c-accent); font-weight: 600; }

/* League schedule cards (compact, table-like: when · pairs · score) */
.match-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--sp-3);
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm); padding: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-2); }
.match-card:hover { border-color: var(--c-accent); }
.match-when { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
.match-when .date { font-size: var(--fs-xs); font-weight: 600; color: var(--c-muted); text-transform: uppercase; letter-spacing: .03em; }
.match-when .time { font-size: var(--fs-lg); font-weight: 700; color: var(--c-accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
.match-pairs { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.match-pairs .pair { font-size: var(--fs-base); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.match-pairs .vs { font-size: 10px; font-weight: 700; letter-spacing: .1em; color: var(--c-muted); text-transform: uppercase; }
.match-end { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.match-end .score { font-size: var(--fs-base); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.match-end .court { font-size: var(--fs-xs); color: var(--c-muted); white-space: nowrap; }

/* League week tables: fixed layout, rounded card-clipped container */
table.sched { table-layout: fixed; border: 1px solid var(--c-border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm); margin-bottom: var(--sp-4); }
table.sched th, table.sched td { overflow-wrap: anywhere; }
table.sched tbody tr:last-child td { border-bottom: none; }

/* Tag-chips */
.chip { display: inline-flex; align-items: center; padding: 2px var(--sp-2);
  border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 600; }
.chip.lg-a { background: var(--league-a-bg); color: var(--league-a-fg); }
.chip.lg-b { background: var(--league-b-bg); color: var(--league-b-fg); }
.chip.lg-c { background: var(--league-c-bg); color: var(--league-c-fg); }
.chip.lg-d { background: var(--league-d-bg); color: var(--league-d-fg); }
.legend { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3); }

/* Day grid */
.grid { border-collapse: collapse; width: 100%; table-layout: fixed; }
.grid th, .grid td { height: var(--slot-h); vertical-align: top; padding: 2px; border: 1px solid var(--c-border); }
.grid th { background: var(--c-th-bg); color: var(--c-muted); text-align: center; vertical-align: middle;
  text-transform: uppercase; letter-spacing: .04em; font-weight: 700; font-size: var(--fs-xs); }
.grid .timecol { width: var(--grid-timecol-w); background: var(--c-th-bg); color: var(--c-muted); font-size: var(--fs-xs);
  text-align: right; padding: 3px 6px 0 2px; font-variant-numeric: tabular-nums; }
.grid td.blockcell { padding: 0; }
.cellfill { display: flex; flex-direction: column; gap: 1px; box-sizing: border-box; overflow: hidden; }
.block { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px;
  border-radius: var(--radius-sm); font-size: var(--fs-xs); line-height: 1.2; padding: 2px var(--sp-1);
  cursor: pointer; overflow: hidden; box-shadow: var(--shadow-sm); }
.block .pair { font-weight: 600; overflow-wrap: anywhere; }
.block .vs-div { height: 1px; background: currentColor; opacity: .22; flex: none; }
.block.lg-a { background: var(--league-a-bg); color: var(--league-a-fg); border-left: 3px solid var(--league-a-fg); }
.block.lg-b { background: var(--league-b-bg); color: var(--league-b-fg); border-left: 3px solid var(--league-b-fg); }
.block.lg-c { background: var(--league-c-bg); color: var(--league-c-fg); border-left: 3px solid var(--league-c-fg); }
.block.lg-d { background: var(--league-d-bg); color: var(--league-d-fg); border-left: 3px solid var(--league-d-fg); }
.block.clash { outline: 2px solid var(--c-danger); outline-offset: -2px; }

/* Modal (reuses .card) */
#modal { position: fixed; inset: 0; background: var(--c-overlay); display: flex; align-items: center; justify-content: center; }
#modal .card { min-width: 320px; box-shadow: var(--shadow-md); margin: 0; }
#modal .card label { display: block; margin-bottom: var(--sp-2); font-size: var(--fs-sm); color: var(--c-muted); }
#modal .card input, #modal .card select { display: block; width: 100%; margin-top: 2px; }
#modal .card > div > div:last-child { display: flex; gap: var(--sp-2); margin-top: var(--sp-3); }

/* Toast */
#toast { position: fixed; bottom: var(--sp-4); left: 50%; transform: translateX(-50%);
  background: var(--c-ink); color: #fff; padding: var(--sp-2) var(--sp-4); border-radius: var(--radius); box-shadow: var(--shadow-md); }

/* Import diff rows */
.change-row { border-bottom: 1px solid var(--c-border); padding: var(--sp-2) 0; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
