/*
 * Day (default/light) theme. Every color that should flip between day and
 * night lives here as a variable - see the :root[data-theme="night"] block
 * below for the dark equivalents, and renderer/js/theme.js for how the
 * data-theme attribute gets set and how --accent/--accent-dark get
 * overridden with a color derived from the uploaded league logo (that JS
 * override, an inline style on <html>, wins over both of these blocks
 * automatically - no extra wiring needed here).
 *
 * --danger/--success (the TEXT colors used for status/error messaging) and
 * the suspended-certification flash colors are deliberately NOT themed -
 * alert colors should stay visually consistent and attention-grabbing
 * regardless of day/night, only their pale *background* tints
 * (--danger-bg/--success-bg, used for badges/buttons) adapt for contrast.
 */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --sidebar-bg: #17233b;
  --sidebar-active: #24365c;
  --sidebar-border: #2a3b5e;
  --sidebar-nav-hover: #1d2c4a;
  --sidebar-section-label: #6b7fa3;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e2e6ec;
  --danger: #dc2626;
  --danger-bg: #fde8e8;
  --success: #16a34a;
  --success-bg: #e7f7ee;
  --btn-secondary-bg: #eef1f6;
  --btn-secondary-bg-hover: #e2e6ec;
  --table-header-bg: #f8f9fb;
  --row-hover-bg: #f5f8ff;
  --hover-bg-soft: #f1f5f9;
  --photo-panel-bg: #f8fafc;
  --row-just-closed-bg: #fef3c7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* Night (dark) theme - activated via <html data-theme="night">, toggled by
   the topbar day/night button (see app.js/theme.js). */
:root[data-theme="night"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --sidebar-bg: #0b1220;
  --sidebar-active: #1e2a44;
  --sidebar-border: #1f2c47;
  --sidebar-nav-hover: #16213a;
  --sidebar-section-label: #64748b;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --text: #e5e7eb;
  --text-muted: #94a3b8;
  --border: #2e3b52;
  --danger-bg: #4c1d1d;
  --success-bg: #10321f;
  --btn-secondary-bg: #263449;
  --btn-secondary-bg-hover: #2f4160;
  --table-header-bg: #16213a;
  --row-hover-bg: #182338;
  --hover-bg-soft: #223049;
  --photo-panel-bg: #16213a;
  --row-just-closed-bg: #4a3a12;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.login-view {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--sidebar-bg), var(--accent));
}
.login-card {
  background: var(--panel);
  padding: 40px;
  border-radius: 12px;
  width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { display: block; max-width: 100%; max-height: 90px; margin: 0 auto 14px; object-fit: contain; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .subtitle { margin: 0 0 24px; color: var(--text-muted); font-size: 13px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--text-muted); }
.login-card input {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.form-hint {
  background: var(--bg-muted, rgba(127,127,127,0.12)); border-radius: 6px;
  padding: 10px 12px; font-size: 13px; color: var(--text-muted); margin-bottom: 14px;
}

/* ---------- Buttons ---------- */
.btn { border: none; border-radius: 6px; padding: 8px 14px; font-size: 13px; font-weight: 500; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--text); }
.btn-secondary:hover { background: var(--btn-secondary-bg-hover); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { filter: brightness(0.93); }
.btn-link { background: none; color: var(--accent); padding: 6px 8px; }
.btn-block { width: 100%; padding: 10px; margin-top: 6px; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

/* ---------- App shell ---------- */
.app-view { display: flex; height: 100vh; }
.sidebar { width: 230px; background: var(--sidebar-bg); color: #cbd5e1; display: flex; flex-direction: column; padding: 18px 0; flex-shrink: 0; overflow: hidden; }
.sidebar-brand { color: #fff; font-weight: 700; font-size: 15px; padding: 0 20px 18px; border-bottom: 1px solid var(--sidebar-border); margin-bottom: 10px; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.sidebar-logo { max-width: 36px; max-height: 36px; object-fit: contain; border-radius: 4px; background: #fff; flex-shrink: 0; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.nav-item { text-align: left; background: none; border: none; color: #cbd5e1; padding: 10px 12px; border-radius: 6px; font-size: 13.5px; }
.nav-item:hover { background: var(--sidebar-nav-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-section { margin: 14px 0 4px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--sidebar-section-label); }

.main-column { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 56px; background: var(--panel); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 22px; flex-shrink: 0; }
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-muted); }
.content { flex: 1; overflow: auto; padding: 20px 24px; }

/* ---------- Toolbars / filters ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.toolbar .spacer { flex: 1; }

/* ---------- Tables ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--table-header-bg); font-weight: 600; color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; cursor: pointer; user-select: none; }
tbody tr:hover { background: var(--row-hover-bg); cursor: pointer; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-archived { background: var(--danger-bg); color: var(--danger); }
.badge-active { background: var(--success-bg); color: var(--success); }

/* Suspended-certification highlight - a slow (1.2s, well under the ~3Hz
   photosensitive-seizure threshold) bold-red flash on the whole row, so a
   suspended player/coach jumps out while scanning the list. */
@keyframes suspended-flash {
  0%, 100% { background: #fecaca; color: #7f1d1d; }
  50% { background: #fff5f5; color: var(--danger); }
}
tr.row-suspended { font-weight: 700; animation: suspended-flash 1.2s ease-in-out infinite; }
tr.row-suspended:hover { animation-play-state: paused; }
tr.row-suspended td { color: inherit; }
.suspended-badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700;
  letter-spacing: 0.03em; text-transform: uppercase;
  animation: suspended-flash 1.2s ease-in-out infinite;
}
/* Brief highlight on whatever row was just opened/closed in the Players or
   Coaches list, so re-scrolling the table back to that row (see players.js/
   coaches.js's scrollToRow()) is obvious even before the fade finishes -
   plain background fade rather than the suspended-flash animation above
   (that one's an ongoing indefinite alert; this is a one-time "here it is"
   cue that has to actually finish and get out of the way). */
@keyframes just-closed-fade {
  0% { background: var(--row-just-closed-bg); }
  100% { background: transparent; }
}
tr.row-just-closed { animation: just-closed-fade 1.6s ease-out; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tab-btn { background: none; border: none; padding: 9px 14px; font-size: 13px; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- Modal ---------- */
.modal-host { position: fixed; inset: 0; background: rgba(15,23,42,0.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow: auto; z-index: 100; }
.modal { background: var(--panel); border-radius: 10px; width: 640px; max-width: 100%; padding: 22px 26px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); position: relative; }
.modal h2 { margin-top: 0; font-size: 17px; padding-right: 28px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
/* Top action bar for each Reports tab: title on the left, Generate/Print
   buttons on the right, on one line above the form. */
.report-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 16px; }
.report-actions h3 { margin: 0; flex: 1; min-width: 220px; }
.modal-close-x { position: absolute; top: 14px; right: 16px; width: 28px; height: 28px; line-height: 26px; text-align: center; background: none; border: none; border-radius: 6px; font-size: 20px; color: var(--text-muted); cursor: pointer; padding: 0; }
.modal-close-x:hover { background: var(--hover-bg-soft); color: var(--text); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid.full { grid-template-columns: 1fr; }
.form-grid label { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }
.form-grid input, .form-grid select, .form-grid textarea { padding: 8px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; }
.span-2 { grid-column: span 2; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
/* Locked Park select + its "Change Park Affiliation" unlock button, side by side */
.field-with-button { display: flex; gap: 6px; align-items: center; }
.field-with-button select { flex: 1; }
.field-with-button select:disabled { background: var(--hover-bg-soft); color: var(--text-muted); }

/* ---------- List header (live count + filter collapse) ---------- */
.list-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.list-header h2 { margin: 0; font-size: 18px; }
.filter-panel.collapsed { display: none; }
.filter-group { display: flex; align-items: center; gap: 6px; font-size: 13px; border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; background: var(--panel); }
.filter-group-label { color: var(--text-muted); font-size: 12px; margin-right: 2px; white-space: nowrap; }
.filter-group label { display: flex; align-items: center; gap: 3px; white-space: nowrap; cursor: pointer; }
.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 10px 0; }

.empty-state { padding: 40px; text-align: center; color: var(--text-muted); font-size: 13px; }
.small-muted { color: var(--text-muted); font-size: 12px; }
.section-title { font-size: 14px; font-weight: 600; margin: 22px 0 10px; }
.history-line { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.history-line .ts { color: var(--text-muted); font-size: 11px; }

/* ---------- Progress bar (Backup/Restore) ---------- */
.progress-track { background: var(--border); border-radius: 6px; height: 10px; overflow: hidden; margin-top: 10px; }
.progress-fill { background: var(--accent); height: 100%; width: 0%; transition: width 0.15s ease; }
.progress-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Photo panel (Player/Coach) ---------- */
.photo-panel { display: flex; gap: 16px; align-items: flex-start; padding: 14px; background: var(--photo-panel-bg); border-radius: 8px; margin-bottom: 14px; }
.photo-preview { width: 120px; height: 120px; border-radius: 8px; background: var(--border); object-fit: cover; flex-shrink: 0; }
.photo-actions { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.photo-actions-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Webcam capture, with zoom-before-snapping ---------- */
.webcam-viewport { width: 100%; max-width: 480px; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 8px; background: #000; position: relative; }
.webcam-video, .webcam-canvas { width: 100%; height: 100%; object-fit: cover; }
.webcam-video { transform-origin: center center; transition: transform 0.06s linear; }
.webcam-zoom-row { background: var(--hover-bg-soft); border-radius: 8px; padding: 6px 10px; }
.photo-zoom-pct { color: var(--text-muted); font-size: 12px; min-width: 42px; text-align: center; }
