:root {
  --navy: #0f2039;
  --navy-light: #1c3a5e;
  --header-bg: #c83c44;
  --accent: #c8442d;
  --accent-light: #e0f2fe;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1a2330;
  --muted: #5b6b7c;
  --border: #dde3ea;
  --success: #1e7d45;
  --error: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--header-bg);
  color: #fff;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  color: #fff;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar .brand-logo {
  height: 34px;
  width: auto;
  display: block;
}

.topbar nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

.topbar nav a {
  color: #cbd8e8;
  text-decoration: none;
  font-size: 0.95rem;
  padding: 0.4rem 0;
}

.topbar nav a:hover, .topbar nav a.active {
  color: #fff;
  border-bottom: 2px solid var(--accent);
}

.topbar .logout {
  color: #93a5ba;
  font-size: 0.85rem;
}

.print-button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.55);
  color: #fff;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}
.print-button:hover { background: rgba(255, 255, 255, 0.15); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

h1 { font-size: 1.6rem; margin-bottom: 0.25rem; }
h2 { font-size: 1.2rem; margin-top: 2rem; }
.subtitle { color: var(--muted); margin-top: 0; margin-bottom: 1.5rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  text-align: center;
}
.stat-box .value { font-size: 1.8rem; font-weight: 700; color: var(--navy); }
.stat-box .label { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--card);
}
th, td {
  text-align: left;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: #eef2f7;
  color: var(--navy);
  position: sticky;
  top: 0;
}
tr:hover td { background: #fafbfd; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

a.button, button.button, input[type=submit].button {
  display: inline-block;
  background: var(--navy);
  color: #fff;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
}
a.button:hover, button.button:hover { background: var(--navy-light); }
a.button.secondary, button.button.secondary {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--border);
}
button.button.danger { background: var(--error); }

form.inline { display: inline; }

.form-row { margin-bottom: 1rem; }
.form-row label { display: block; font-weight: 600; margin-bottom: 0.3rem; font-size: 0.9rem; }
.form-row input[type=text], .form-row input[type=password], .form-row input[type=file], .form-row select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
}

.filters { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .form-row { margin-bottom: 0; min-width: 160px; }

.flash { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.95rem; }
.flash.success { background: #e5f5ea; color: var(--success); border: 1px solid #bfe3cc; }
.flash.error { background: #fbe9e7; color: var(--error); border: 1px solid #f2c1bc; }

.login-wrap {
  max-width: 380px;
  margin: 8rem auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  text-align: center;
}
.login-wrap h1 { color: var(--navy); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.name-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.6rem;
}
.name-grid a {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
}
.name-grid a:hover { border-color: var(--navy); }

.chart-wrap { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin-bottom: 1.5rem; }

.strikezone-wrap { max-width: 420px; height: 420px; margin-left: 0; margin-right: auto; position: relative; }

.charts-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: flex-start;
}
.charts-row .chart-col { flex: 1 1 420px; max-width: 460px; }
.charts-row .chart-col h3 { margin-top: 0; }

.zone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1rem;
}
.zone-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}
.zone-card h4 { margin: 0 0 0.6rem; font-size: 0.95rem; color: var(--navy); }
.mini-strikezone-wrap { height: 310px; position: relative; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* ---------------------------------------------------------------------
   Print / "Download PDF" (triggered by window.print() from the topbar
   button, saved via the browser's own Print dialog). Landscape gives the
   wide box-score tables room to breathe, and every rule below exists to
   stop a table row, chart, or stat card from being sliced in half by a
   page break -- individual pages can still span multiple printed pages,
   they just never cut a record or a chart in the middle to do it.
   --------------------------------------------------------------------- */
@media print {
  @page {
    size: landscape;
    margin: 0.5in;
  }

  body { background: #fff; }

  /* Nothing interactive belongs in a printed report. */
  .topbar, .filters, .card, .flash {
    display: none !important;
  }

  main {
    max-width: none;
    padding: 0;
  }

  a { color: inherit; text-decoration: none; }

  table { font-size: 0.72rem; }
  th, td { padding: 0.3rem 0.4rem; }
  /* Sticky headers can duplicate/overlap when a browser paginates for
     print -- disable it and repeat the header the normal print way. */
  th { position: static; }
  /* Let a table itself span as many pages as it needs to (a 160-row
     session dump can't fit on one page no matter what) -- but repeat the
     header on every page it spans, glue that header to the first row so
     it's never left alone at the bottom of a page, and never let a single
     row get sliced in half by the page boundary. */
  table { break-inside: auto; page-break-inside: auto; }
  thead {
    display: table-header-group;
    break-after: avoid;
    page-break-after: avoid;
  }
  tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* These are small, fixed-height blocks (a stat line, a single chart) --
     forcing the whole block to the next page rather than splitting it
     only ever costs a little blank space at the bottom of a page. */
  .stat-box,
  .chart-wrap,
  .zone-card,
  .charts-row .chart-col {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Keep a heading glued to the block that follows it rather than left
     stranded alone at the bottom of a page. */
  h1, h2, h3, h4 {
    break-after: avoid;
    page-break-after: avoid;
  }

  canvas { max-width: 100%; }
}
