/* Baseball Manager. Plain CSS, no build step. */

:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f8f6f1;
  --line: #e3ded2;
  --line-strong: #cfc8b8;
  --ink: #1b2230;
  --ink-2: #414a5c;
  --muted: #5b6475;
  --primary: #1d4f91;
  --primary-ink: #ffffff;
  --primary-soft: #e6eefa;
  --accent: #c8102e;
  --danger: #b42318;
  --good: #1a7f37;
  --bad: #b42318;
  --focus: #2a78d6;
  /* Chart: one validated series hue (slot 1 of the dataviz reference palette). */
  --series-1: #2a78d6;
  --grid: #ebe7dd;
  --shadow: 0 1px 2px rgb(27 34 48 / 6%), 0 4px 14px rgb(27 34 48 / 6%);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f141c;
    --surface: #182030;
    --surface-2: #1d2638;
    --line: #2a3448;
    --line-strong: #3a465e;
    --ink: #e8ebf1;
    --ink-2: #c3c9d6;
    --muted: #9aa4b6;
    --primary: #6ea2e8;
    --primary-ink: #0b1220;
    --primary-soft: #1f3150;
    --accent: #ef5a6f;
    --danger: #f2777a;
    --good: #4ac26b;
    --bad: #f2777a;
    --focus: #6ea2e8;
    --series-1: #3987e5;
    --grid: #253045;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 25%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  min-height: 100vh;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: var(--danger); font-size: 0.9rem; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.num { font-variant-numeric: tabular-nums; }

/* --- Controls ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small-btn { min-height: 32px; padding: 4px 10px; font-size: 0.875rem; }
.btn.icon-btn { min-width: 36px; min-height: 36px; padding: 4px; }
.link {
  background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
input, select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 9px 11px;
  min-height: 42px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.pin-input { font-family: var(--mono); font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; }
.row-input { display: flex; gap: 8px; align-items: flex-end; }

/* --- Loading & sign-in --------------------------------------------------- */

.loading { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border-radius: 16px;
  border-top: 4px solid var(--accent);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex; flex-direction: column; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-lg h1 { font-size: 1.4rem; }
.logo { width: 30px; height: 30px; flex: none; }
.logo circle { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.logo .stitch { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-dasharray: 2.2 1.6; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* --- App shell ----------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand-name { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1 1 auto; min-width: 0; }
.tabs a {
  padding: 7px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 600; font-size: 0.95rem; white-space: nowrap;
}
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.account-button { margin-left: auto; padding: 4px 8px 4px 4px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--primary); color: var(--primary-ink);
  font-size: 0.78rem; font-weight: 700;
}
.user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }

.nudge {
  margin: 12px auto 0; max-width: 1100px; width: calc(100% - 32px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--primary-soft); border-radius: var(--radius); padding: 10px 14px; font-size: 0.92rem;
}

.view { max-width: 1100px; margin: 0 auto; padding: 20px 16px 64px; display: flex; flex-direction: column; gap: 20px; }
.view:focus { outline: none; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head .titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-head h1 { overflow-wrap: anywhere; }
.crumbs { font-size: 0.875rem; color: var(--muted); }
.crumbs a { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.section { padding: 16px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.empty { text-align: center; padding: 36px 16px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty p { max-width: 420px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.pos { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.warn { color: var(--danger); }

/* --- Franchise cards ---------------------------------------------------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.franchise-card {
  display: flex; flex-direction: column; gap: 10px; padding: 16px; color: inherit;
  border-top: 3px solid var(--accent);
}
.franchise-card:hover { text-decoration: none; border-color: var(--line-strong); border-top-color: var(--accent); }
.franchise-card h2 { overflow-wrap: anywhere; }
.facts { display: flex; gap: 18px; flex-wrap: wrap; }
.fact { display: flex; flex-direction: column; }
.fact b { font-size: 1.25rem; }
.fact span { font-size: 0.78rem; color: var(--muted); }

/* --- Season chips ----------------------------------------------------- */

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  min-height: 34px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip.add { border-style: dashed; color: var(--primary); }

/* --- Tables --------------------------------------------------------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { padding: 9px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
td { font-variant-numeric: tabular-nums; }
td.name { white-space: normal; min-width: 140px; }
td.name a { font-weight: 600; color: var(--ink); }
td.name .badge { margin-left: 6px; vertical-align: 1px; }
td.left, th.left { text-align: left; }
td.dim { color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td.actions { width: 1%; padding-right: 0; }
td.actions .row { justify-content: flex-end; flex-wrap: nowrap; }
.sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 1; }
th .link { color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; }
th[aria-sort] .link, th .link:hover { color: var(--ink); text-decoration: none; }
@media (max-width: 640px) {
  td.name { min-width: 120px; max-width: 150px; }
  .sticky-col { box-shadow: 1px 0 0 var(--line); }
}

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { flex: 1 1 200px; }

/* --- Charts ------------------------------------------------------------ */

.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.chart-card { position: relative; padding: 12px 14px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-width: 0; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.chart-title { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.chart-value { font-size: 1.35rem; font-weight: 650; color: var(--ink); }
.chart-delta { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.chart-delta.good { color: var(--good); }
.chart-delta.bad { color: var(--bad); }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; margin-top: 4px; }
.chart-svg .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart-svg .axis-text { fill: var(--muted); font-size: 10px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart-svg .end-label { fill: var(--ink); font-size: 11px; font-weight: 650; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart-svg .series-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .series-area { fill: var(--series-1); opacity: 0.1; }
.chart-svg .series-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart-svg .crosshair { stroke: var(--line-strong); stroke-width: 1; }
.chart-svg .hit { fill: transparent; cursor: default; outline: none; }
.chart-svg .hit:focus-visible { fill: color-mix(in srgb, var(--focus) 10%, transparent); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 2;
  transform: translate(-50%, calc(-100% - 10px));
  background: var(--ink); color: var(--surface);
  border-radius: 7px; padding: 5px 9px; font-size: 0.8rem; white-space: nowrap;
  box-shadow: var(--shadow);
}
.tooltip b { font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.tooltip span { opacity: 0.75; margin-left: 6px; }
.chart-note { font-size: 0.85rem; }

/* --- Lists in dialogs -------------------------------------------------- */

.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; min-width: 0;
}
.list-row .grow { display: flex; flex-direction: column; min-width: 0; }
.list-row .grow > * { overflow: hidden; text-overflow: ellipsis; }
.list-row .row { flex-wrap: nowrap; }

.copy-box { display: flex; gap: 8px; }
.copy-box input { font-family: var(--mono); font-size: 0.8rem; }

/* --- Dialogs --------------------------------------------------------- */

.dialog {
  border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--ink);
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
.dialog-sm { width: min(400px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgb(10 14 22 / 45%); }
.dialog-form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 16px 0 20px; }
.dialog-body { padding: 16px 20px; overflow-y: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid var(--line); }
.dialog > form > .error, .dialog-form > .error { padding: 0 20px 8px; }
.fields-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 0; min-width: 0; }
legend { font-weight: 700; font-size: 0.85rem; padding: 0 4px; }
.hint { font-size: 0.78rem; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; }
.check input { width: 18px; height: 18px; min-height: 0; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 100; max-width: calc(100vw - 32px); font-size: 0.92rem;
}
.toast.toast-error { background: var(--danger); color: #fff; }

/* --- Phones ------------------------------------------------------------ */

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding-bottom: 0; }
  .tabs { order: 3; flex-basis: 100%; margin: 0 -6px; overflow-x: auto; }
  .tabs a { padding: 8px 10px 10px; border-radius: 8px 8px 0 0; }
  .user-name { display: none; }
  .account-button { padding: 4px; }
  h1 { font-size: 1.3rem; }
  .view { padding-top: 16px; gap: 16px; }
  .section { padding: 14px; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  .hide-sm { display: none; }
}
.list-row b .badge { margin-left: 6px; vertical-align: 1px; }
