/*
 * Team Manager dashboard.
 *
 * Colours follow the project's data-visualisation palette. Availability is a
 * *status* encoding (good / critical / neutral), not a categorical one.
 *
 * Important accessibility note on the availability colours: measured against
 * both surfaces, good (#0ca30c) and critical (#d03b3b) sit at CVD Delta E 4.1
 * under deuteranopia — far below the 8 threshold. Red/green is the natural
 * reading of "in" and "out", so we keep it, but that means hue can never be
 * the only channel. Every availability value therefore also carries a glyph
 * and a written word, and every meter segment carries its own number. Colour
 * is strictly redundant here; remove it and nothing becomes unreadable.
 */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --hairline: #e1e0d9;
  --baseline: #c3c2b7;
  --border-ring: rgba(11, 11, 11, 0.10);

  --accent: #2a78d6;
  --accent-ink: #ffffff;

  --status-good: #0ca30c;
  --status-critical: #d03b3b;
  --status-pending: #898781;
  --status-warning: #fab219;

  /* Unfilled meter track: a lighter step of the same neutral, so the bar
     reads as one object rather than a fill floating on the page. */
  --track: #e1e0d9;

  --radius: 10px;
  --radius-sm: 6px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --hairline: #2c2c2a;
    --baseline: #383835;
    --border-ring: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --track: #2c2c2a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --hairline: #2c2c2a;
  --baseline: #383835;
  --border-ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --track: #2c2c2a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute;
  left: -9999px;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
  z-index: 10;
  background: var(--surface-1);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Header ------------------------------------------------------------ */

.app-header {
  background: var(--surface-1);
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  z-index: 5;
}

.app-header__inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
}

.app-header__brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  flex: none;
}

.team-picker {
  font: inherit;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  max-width: 220px;
}
.team-picker:hover { border-color: var(--hairline); }

.tabs { display: flex; gap: 4px; margin-left: auto; }

.tab {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-weight: 500;
}
.tab:hover { background: var(--page); color: var(--text-primary); }
.tab[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }

.app-header__user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-email { color: var(--text-muted); font-size: 13px; }

/* --- Layout ----------------------------------------------------------- */

.main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.loading { color: var(--text-muted); }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap);
  margin: 0 0 20px;
  flex-wrap: wrap;
}

h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-secondary); font-weight: 600; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0 0 var(--gap);
}

.card--tight { padding: 14px 18px; }

.muted { color: var(--text-muted); }
.empty { color: var(--text-muted); padding: 20px 0; text-align: center; }

/* --- Buttons and forms ------------------------------------------------ */

.btn {
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.5; cursor: default; filter: none; }

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--hairline);
}
.btn--ghost:hover { background: var(--page); color: var(--text-primary); filter: none; }

.btn--danger { background: transparent; color: var(--status-critical); border-color: var(--hairline); }
.btn--danger:hover { background: var(--page); filter: none; }

.btn--sm { padding: 5px 10px; font-size: 13px; }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }

label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }

input, select, textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); }

.field { flex: 1 1 160px; }
.field--sm { flex: 0 0 110px; }
.field--time { flex: 0 0 130px; }

/* Bottom-align inputs regardless of a label wrapping onto two lines. */
.form-row > .field { display: flex; flex-direction: column; justify-content: flex-end; }

/* --- Availability: stat tiles ----------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 0 0 14px;
}

/* The availability block sits directly on the page, so it needs its own
   breathing room before the next card. */
.availability { margin: 0 0 var(--gap); }

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius);
  padding: 14px 16px;
}

/* The glyph and the label are what carry meaning; the colour is redundant. */
.tile__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 6px;
}

.tile__value {
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  /* Proportional figures: these are standalone values, not a column. */
}

.glyph {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
  flex: none;
}
.glyph--yes { background: var(--status-good); }
.glyph--no { background: var(--status-critical); }
.glyph--pending { background: var(--status-pending); }

/* --- Availability: stacked meter -------------------------------------- */

.meter {
  display: flex;
  /* 2px surface gap between stacked segments, per the mark spec. The
     background is the surface rather than a track colour: the segments always
     sum to the whole, so a visible track would be a phantom, and a grey track
     would be indistinguishable from the grey "no reply" fill. */
  gap: 2px;
  height: 10px;
  background: var(--surface-1);
  border-radius: 5px;
}

.meter__seg { min-width: 0; }
.meter__seg--yes { background: var(--status-good); }
.meter__seg--no { background: var(--status-critical); }
.meter__seg--pending { background: var(--status-pending); }
/* 4px rounded data-ends on the outer edges only. */
.meter__seg:first-child { border-radius: 5px 0 0 5px; }
.meter__seg:last-child { border-radius: 0 5px 5px 0; }

.meter-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.meter-legend__item { display: flex; align-items: center; gap: 6px; }

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}
.swatch--yes { background: var(--status-good); }
.swatch--no { background: var(--status-critical); }
.swatch--pending { background: var(--status-pending); }

/* --- Lists ------------------------------------------------------------ */

.rows { list-style: none; margin: 0; padding: 0; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--hairline);
}
.row:last-child { border-bottom: 0; }

.row__main { flex: 1; min-width: 0; }
.row__name { font-weight: 500; }
.row__meta { font-size: 13px; color: var(--text-muted); }
.row__actions { display: flex; gap: 6px; flex: none; }

/* The status pill pairs colour with a glyph and a word. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 3px 10px 3px 4px;
  border-radius: 999px;
  background: var(--page);
  border: 1px solid var(--hairline);
  flex: none;
}

.fixture {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0 0 12px;
}
.fixture:hover { border-color: var(--baseline); }

.fixture__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 4px;
  flex-wrap: wrap;
}

.fixture__when { font-weight: 600; }
.fixture__where { font-size: 13px; color: var(--text-muted); margin: 0 0 12px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--page);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 2px 8px;
}

.badge--cancelled { color: var(--status-critical); }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Separates the creation form from the list of existing series above it, so
   the two do not read as one block. */
.series-form {
  margin-top: 14px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
}

/* Deliberately loud. An admin should not be able to forget which club's
   families they are looking at. */
.admin-banner {
  background: #fff4e5;
  border: 1px solid var(--status-warning);
  border-left: 4px solid var(--status-warning);
  color: #5c3d00;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .admin-banner {
    background: #2a1f05;
    color: #f5d99a;
  }
}

/* --- Invite picker ---------------------------------------------------- */

.invitees {
  margin: 14px 0 0;
  padding: 12px 14px;
  background: var(--page);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
}

.invitees__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  flex-wrap: wrap;
}
.invitees__head label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.invitees__head .btn { margin-left: 0; }
.invitees__head span { margin-right: auto; }

.invitees__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 4px 12px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 4px 0;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
}
.checkbox input { margin: 0; accent-color: var(--accent); }

/* A skipped week stays visible but recedes, so the pattern is still legible
   without the cancelled session competing for attention. */
.fixture--cancelled { opacity: 0.62; }
.fixture--cancelled .fixture__when { text-decoration: line-through; }

/* --- Sign in ---------------------------------------------------------- */

.signin {
  max-width: 380px;
  margin: 12vh auto 0;
  text-align: center;
}
.signin h1 { margin: 0 0 8px; }
.signin p { color: var(--text-secondary); margin: 0 0 24px; }

/* --- Toasts ----------------------------------------------------------- */

.toast-stack {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
}

.toast {
  background: var(--surface-1);
  border: 1px solid var(--border-ring);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  max-width: 460px;
}
.toast--error { border-left-color: var(--status-critical); }
.toast--good { border-left-color: var(--status-good); }

/* --- Small screens ---------------------------------------------------- */

@media (max-width: 620px) {
  /* Keep three columns: these are three short numbers a coach reads together,
     and stacking them pushes the replies list off the screen. */
  .tiles { gap: 8px; }
  .tile { padding: 10px 11px; }
  .tile__label { font-size: 11px; gap: 4px; margin-bottom: 4px; }
  .tile__value { font-size: 24px; }
  .glyph { width: 15px; height: 15px; font-size: 9px; }

  .app-header__inner { padding: 10px 14px; gap: 10px; }
  .tabs { margin-left: auto; }
  /* The signed-in address is reassurance, not information a coach needs on a
     phone; dropping it keeps the header to a single row. */
  .user-email { display: none; }
  .main { padding: 18px 14px 48px; }
  .page-head { gap: 10px; }
}

/* Where hue is unavailable entirely, the glyphs and words still carry it. */
@media (forced-colors: active) {
  .glyph, .swatch, .meter__seg { forced-color-adjust: none; }
}
