:root {
  --show-poster-width: 120px;
  /* Body text color, captured here because Pico redefines --pico-color
     to the link blue inside every <a> (see .brand below). */
  --brand-text-color: var(--pico-color);
}

/* Pico's <nav><ul>...</ul></nav> groups default to flex-wrap: nowrap --
   fine for the anonymous 3-item nav, but the logged-in nav (username
   badge, Account, and role-gated Review reports / Manage users, plus Log
   out and the timezone widget) is wide enough to overflow the page
   horizontally rather than wrap, on a narrow phone screen and equally on
   a desktop browser window that isn't maximized. Only one <nav> exists
   in the whole app (the header, see layout-header.php), so this is safe
   to apply unscoped. No media query needed -- flex-wrap: wrap only
   kicks in once the items genuinely don't fit the available width. */
header.container nav ul {
  flex-wrap: wrap;
  row-gap: 0.4rem;
}
/* Pico vertically centers the nav's two <ul> columns against each other
   by default -- fine when both are one line tall, but once the links
   column wraps to several lines (above) that centers the single-line
   "tvtimes" logo column partway down instead of pinning it to the top. */
header.container nav {
  align-items: flex-start;
}

/* Site logo: the TV-clock mark (assets/img/brand/logo-mark.svg) plus the
   "tvtimes" wordmark as live text, "tv" in the body color and "times" in
   the primary blue. Used in the header nav (layout-header.php) and above
   the form on the pre-login pages (layout-header-auth.php). */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--brand-text-color);
  text-decoration: none;
}
.brand strong {
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.brand strong span {
  color: var(--pico-primary);
}
.brand-auth {
  text-align: center;
}

.admin-badge {
  background: var(--pico-primary);
  color: var(--pico-primary-inverse);
  padding: 0.15rem 0.5rem;
  border-radius: 0.3rem;
  font-size: 0.8rem;
}

/* status / source badges, used in both search results and episode rows */
.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}
/* episode.status */
.status-verified { background: #1f7a3f; color: #fff; }
.status-provisional { background: #a06a00; color: #fff; }
.status-locked { background: #555555; color: #fff; }

/* episode.source */
.source-tvmaze { background: #2f5ea8; color: #fff; }
.source-network_default { background: #6a3fa0; color: #fff; }
.source-trakt { background: #a02f5e; color: #fff; }
.source-simkl { background: #2fa08e; color: #fff; }
.source-manual { background: #333333; color: #fff; }

/* shows.production_status -- deliberately separate class prefix from
   episode.status above; they're different enums and previously shared
   a "status-*" prefix that meant these never actually matched a rule. */
.show-status-continuing { background: #1f7a3f; color: #fff; }
.show-status-ended { background: #555555; color: #fff; }
.show-status-cancelled { background: #7a1f1f; color: #fff; }
.show-status-in_development { background: #a06a00; color: #fff; }

/* show detail: our-DB info alongside live TVmaze info */
.show-info-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 768px) {
  .show-info-grid { grid-template-columns: 1fr; }
}

.tvmaze-summary-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.show-poster {
  width: var(--show-poster-width);
  border-radius: 0.4rem;
  flex-shrink: 0;
}

/* season picker -- a dropdown scales from a 2-season show to a
   50+-season one without changing shape, unlike a row of boxes */
#season-select {
  max-width: 16rem;
  margin-bottom: 1rem;
}

/* episode table */
.tvmaze-episode {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
}
.episode-thumb {
  width: 80px;
  border-radius: 0.3rem;
  flex-shrink: 0;
}
.episode-summary {
  font-size: 0.85rem;
  color: var(--pico-muted-color);
  margin: 0.2rem 0;
}
#episodes-table td, #episodes-table th {
  vertical-align: top;
}
#episodes-table th:first-child, #episodes-table td:first-child {
  width: 1.5rem;
  text-align: center;
}

/* Below this width the 7-column table (especially the TVmaze thumbnail +
   summary column) no longer fits -- reflow each <tr> into a 2-column grid
   instead: checkbox + episode number stay in a narrow left column (a
   fixed left edge to anchor on when scanning down the page), everything
   else (air date, air time, status/source, TVmaze) stacks in a column to
   its right, each field on its own line so date sits directly over time
   rather than the two competing for space on one line. Grid auto-
   placement (not explicit row assignment) is what makes this work with
   no markup changes: the checkbox and episode-number cells are pinned to
   column 1 via the selector below, and land in rows 1-2 there simply
   because they're the first two cells in the row; every other cell is
   left at the default column 2 and stacks below in DOM order. Cell
   classes/selectors used by show-detail.js (.cell-air-date etc.) are
   untouched, only display changes, so the override-editing code path
   keeps working unmodified. */
@media (max-width: 700px) {
  #episodes-table thead { display: none; }
  #episodes-table, #episodes-table tbody, #episodes-table tr { display: block; width: 100%; }
  #episodes-table tr {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.7rem;
    row-gap: 0.3rem;
    align-items: start;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
  }
  #episodes-table td {
    display: block;
    border: none;
    padding: 0;
    grid-column: 2;
  }
  #episodes-table td:first-child,
  #episodes-table td.cell-episode-num {
    grid-column: 1;
  }
  /* Inline label ("Air date (UTC): ", "Status: ", ...) in front of any
     cell that carries data-label -- see show-detail.js. Cells without
     one (checkbox, episode number, TVmaze) render unlabeled. */
  #episodes-table td[data-label]::before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: var(--pico-muted-color);
  }
  #episodes-table td.tvmaze-cell {
    margin-top: 0.2rem;
  }
}

/* Same "reflow the table below 700px" idea as #episodes-table above, but
   as a full block-per-cell stacked card rather than a flex-wrapped row --
   these tables' cells hold form controls (email input, level/action
   <select>s) that need full row width to stay usable on a phone, not a
   compact multi-item first line. Shared by the admin users table and the
   report-review table (see admin/users.php, admin/reports.php) so any
   future *editable* admin table reuses it instead of a new bespoke
   breakpoint -- a read-only scan list like search results wants the
   tighter .search-results-table pattern below instead; the per-field
   labeled stacking here reads as far too sprawling once there's no
   input to justify the extra clarity and dozens of rows to scroll past. */
@media (max-width: 700px) {
  .stack-table thead { display: none; }
  .stack-table, .stack-table tbody, .stack-table tr { display: block; width: 100%; }
  .stack-table tr {
    display: block;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
  }
  .stack-table td {
    display: block;
    border: none;
    padding: 0.25rem 0;
  }
  /* A cell left genuinely empty (no dash, nothing) -- e.g. search's
     Flagship column for a non-flagship show -- drops out entirely
     instead of leaving a blank "Flagship: " line on every row. */
  .stack-table td:empty {
    display: none;
  }
  .stack-table td[data-label]::before {
    content: attr(data-label) ": ";
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--pico-muted-color);
    margin-bottom: 0.15rem;
  }
  .stack-table td select,
  .stack-table td input[type="email"],
  .stack-table td input[type="text"] {
    width: 100%;
  }
}

/* Search results (see assets/js/search.js): a read-only, often 50-row
   list -- title on its own full-width line, then status/flagship and the
   two dates as an explicitly-placed 2x2 grid indented beneath it, so
   each show stays a tight, predictable block instead of the 5-line
   stacked card .stack-table would produce. Explicit grid-column/grid-row
   placement per cell (not just letting them wrap inline) is deliberate:
   relying on natural text wrap to keep a "hanging indent" only holds up
   for the first line -- content long enough to wrap (a longer status
   like "In Development", or just a narrower phone) would drop back to
   the unindented left edge on the wrapped line, undoing the whole point
   of indenting it. .sr-field-label gives the two otherwise-bare dates
   enough context to tell them apart (mobile-only -- desktop already has
   that context from the column header). */
.sr-field-label {
  display: none;
}
@media (max-width: 700px) {
  .search-results-table thead { display: none; }
  .search-results-table, .search-results-table tbody {
    display: block;
    width: 100%;
  }
  .search-results-table tr {
    display: grid;
    grid-template-columns: 1.25rem auto auto 1fr;
    column-gap: 0.6rem;
    row-gap: 0.2rem;
    align-items: start;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
  }
  .search-results-table td {
    border: none;
    padding: 0;
    font-size: 0.85rem;
    color: var(--pico-muted-color);
  }
  .search-results-table td:first-child { /* title -- full width, not indented */
    grid-column: 1 / -1;
    font-size: 1rem;
    color: inherit;
  }
  .search-results-table td:nth-child(2) { grid-column: 2; grid-row: 2; } /* status */
  .search-results-table td:nth-child(3) { grid-column: 2; grid-row: 3; } /* premiered */
  .search-results-table td:nth-child(4) { grid-column: 3; grid-row: 3; } /* ended */
  .search-results-table td:last-child { grid-column: 3; grid-row: 2; } /* flagship */
  .search-results-table td:empty {
    display: none;
  }
  .sr-field-label {
    display: inline;
    font-weight: 600;
  }
}

/* flagship toggle, on the show detail page */
.flagship-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  margin: 0.3rem 0 1rem;
}
#flagship-status {
  font-size: 0.85rem;
  color: var(--pico-muted-color);
}

/* episode selection action bar */
.episode-actions {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--pico-card-background-color);
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 0.4rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}
.episode-actions button {
  width: auto;
  margin: 0;
  padding: 0.3rem 0.8rem;
}
/* Groups the 2-3 action buttons as one flex item (see show.php) so they
   wrap together as a unit, rather than each button being a sibling of
   the "N selected" count text in the same wrapping flex row -- on a
   narrow screen that mixed everything into one ragged, hard-to-scan
   wrap. Desktop is unaffected: at that width nothing wraps, so this
   still reads as "N selected [buttons...]" on one line either way. */
.episode-actions-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}
@media (max-width: 700px) {
  .episode-actions {
    flex-direction: column;
    align-items: stretch;
  }
  /* The parent's flex-basis:100% "force a new row" hack on these two
     (below) only makes sense in the default row direction -- in column
     direction it would size their height, not width, so it's neutralized
     here now that flex-direction: column already puts every child,
     including these two, on its own full-width row. */
  #episode-actions-panel,
  #episode-actions-status {
    flex-basis: auto;
  }
}
#episode-actions-panel {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.8rem;
  margin-top: 0.5rem;
}
#episode-actions-panel label {
  font-size: 0.85rem;
}
#episode-actions-panel textarea {
  min-width: 16rem;
}
.date-only-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  white-space: nowrap;
}
#episode-actions-status {
  flex-basis: 100%;
  font-size: 0.85rem;
  color: var(--pico-muted-color);
}
.cell-air-date input, .cell-air-time input {
  padding: 0.2rem;
  font-size: 0.85rem;
}
.remove-override-btn {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  margin-top: 0.2rem;
  width: auto;
}

/* report review pages -- see admin/reports.php */
.link-warning {
  border-left: 4px solid var(--pico-del-color);
  background: var(--pico-card-background-color);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
}
.report-note {
  font-family: var(--pico-font-family-monospace, monospace);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 28rem;
}
.open-show-btn {
  width: auto;
  margin: 0.3rem 0 0;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
}
/* outline on <tr> doesn't reliably paint across browsers -- background
   on the cells themselves does, so that's the actual highlight; the
   left border is just a second, redundant visual cue. */
.episode-highlighted td {
  background-color: rgba(255, 200, 0, 0.18);
  box-shadow: inset 3px 0 0 0 var(--pico-primary);
}
.modal-field {
  width: 100%;
}
.note-modal-error {
  color: var(--pico-del-color);
  font-size: 0.9rem;
}
#reports-tbody td:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
#reports-tbody td:last-child button {
  width: auto;
  margin: 0;
}
#bucket-picker {
  display: inline-block;
  margin-bottom: 1rem;
}
#bucket-select {
  width: auto;
}

/* System insights (admin/system-insights.php): an API key row with an
   hour flagged as unusually busy. */
tr.flagged td { color: var(--pico-del-color); font-weight: 600; }
