:root {
  --bg: #0b0e13;
  --surface: #141922;
  --surface-2: #1b212c;
  --surface-3: #232b38;
  --border: #262d3a;
  --text: #e7e9ee;
  --muted: #8791a1;
  --crimson: #b3182b;
  --crimson-dark: #8a1220;
  --crimson-light: #d64a5a;
  --crimson-bright: #ff2d2d;
  --green: #22a35a;
  --green-dark: #17753e;
  --green-soft: #12321f;
  --red-soft: #3a1418;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

/* ---------- Brand ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.brand h1 {
  font-size: 1.15rem;
  margin: 0;
  white-space: nowrap;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* ---------- Public/admin top bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.topbar h1 { font-size: 1.15rem; margin: 0; white-space: nowrap; }

.sidebar-toggle-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.season-picker {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.season-picker select {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.topbar-link {
  color: var(--muted);
  font-size: 0.88rem;
  text-decoration: none;
  padding: 8px 4px;
}

.topbar-link:hover { color: var(--text); }

/* ---------- Admin app shell / sidebar ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.2;
}

#tabs.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 12px;
}

.sidebar-nav .tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.92rem;
  text-align: left;
  font-family: inherit;
}

.sidebar-nav .tab-btn:hover { background: var(--surface-2); color: var(--text); }
.sidebar-nav .tab-btn.active {
  background: var(--crimson);
  color: #fff;
  font-weight: 600;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 900px) {
  .sidebar-toggle-btn { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: -260px;
    height: 100vh;
    z-index: 60;
    transition: left 0.2s ease;
    box-shadow: 0 0 0 100vmax rgba(0,0,0,0);
  }
  .sidebar.open {
    left: 0;
    box-shadow: 0 0 0 100vmax rgba(0,0,0,0.5);
  }
}

/* ---------- View toggle (Performance / Match Results) ---------- */
.view-toggle {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 4px;
}

.view-toggle-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
}

.view-toggle-btn:hover { color: var(--text); }
.view-toggle-btn.active { background: var(--crimson); color: #fff; font-weight: 600; }

/* ---------- KPI cards ---------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 700px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
}

.kpi-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
}

.kpi-sub {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 4px;
  min-height: 1em;
}

/* ---------- Form chips ---------- */
.form-chips {
  display: flex;
  gap: 4px;
}

.form-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}

.form-chip.form-w { background: var(--green-soft); color: #5fd68e; }
.form-chip.form-l { background: var(--red-soft); color: #f0838c; }
.form-chip.form-split { background: var(--surface-3); color: var(--muted); }

.result-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}

.result-pill.result-won { background: var(--green-soft); color: #5fd68e; }
.result-pill.result-lost { background: var(--red-soft); color: #f0838c; }
.result-pill.result-bye { background: var(--surface-3); color: var(--muted); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-card);
}

.login-card .brand { justify-content: center; margin-bottom: 4px; }
.login-card .brand h1 { font-size: 1.2rem; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.login-card input {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--surface-2);
  color: var(--text);
}
.login-card .hint { color: var(--crimson-light); text-align: center; margin: 0; }
.login-card .topbar-link { color: var(--muted); text-align: center; }
.login-card .topbar-link:hover { color: var(--text); }

main {
  max-width: 1100px;
  width: 100%;
  margin: 24px auto;
  padding: 0 16px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.panel-header h2 { margin: 0; font-size: 1.1rem; font-weight: 700; }

/* ---------- Cards / tables ---------- */
.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
}

.data-table th, .data-table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.data-table th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table.sortable th { cursor: pointer; user-select: none; }
.data-table.sortable th.no-sort { cursor: default; }
.data-table.sortable th:hover { color: var(--text); }
.data-table.sortable th.sorted::after { content: " ▾"; }
.data-table.sortable th.sorted.asc::after { content: " ▴"; }

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.inline-form input, .inline-form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

button {
  background: var(--crimson);
  color: #fff;
  border: none;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  font-family: inherit;
}

button:hover { background: var(--crimson-dark); }

a#exportBtn {
  display: inline-block;
  background: var(--crimson);
  color: #fff;
  border: none;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  text-decoration: none;
}
a#exportBtn:hover { background: var(--crimson-dark); }
button.danger { background: #7c2530; }
button.danger:hover { background: #641c25; }
button.secondary { background: var(--surface-3); color: var(--text); }
button.secondary:hover { background: var(--surface-2); }

.card-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.card-form label { font-size: 0.85rem; display: flex; align-items: center; gap: 4px; color: var(--muted); }
.card-form input[type=text], .card-form input[type=date] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

.hint { color: var(--muted); font-size: 0.82rem; margin-top: 8px; }

.weeks-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.week-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.week-chip:hover { border-color: var(--crimson); }
.week-chip.selected { background: var(--crimson); color: #fff; border-color: var(--crimson); }
.week-chip .del { opacity: 0.6; }
.week-chip .del:hover { opacity: 1; }

.week-entry-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
}

.week-entry-panel .table-scroll {
  border: none;
  box-shadow: none;
  background: transparent;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

select.singles-result, select.doubles-result {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font: inherit;
  font-weight: 600;
  min-width: 120px;
  background: var(--surface-2);
  color: var(--text);
}

select.result-none { background: var(--surface-2); color: var(--muted); font-weight: 400; }
select.result-won { background: var(--green-soft); color: #5fd68e; border-color: #245c3c; }
select.result-lost { background: var(--red-soft); color: #f0838c; border-color: #6b2a30; }

.week-details-form {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin: 0 0 16px;
}

.week-details-form label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.78rem;
  color: var(--muted);
}

.week-details-form input, .week-details-form select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface-3);
  color: var(--text);
}

.week-details-form input[type=number] { width: 80px; }
.week-details-form input[type=text] { width: 160px; }

.week-entry-panel input[type=number] {
  width: 56px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.78rem;
  background: var(--green-soft);
  color: #5fd68e;
}

.pill.sub { background: #3a2d12; color: #e0ab53; }
.pill.ex { background: var(--red-soft); color: #f0838c; }

#playersBody input[type=text], #playersBody input[type=date] {
  width: 100%;
  min-width: 90px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font: inherit;
  color: inherit;
}

#playersBody input[type=text]:hover, #playersBody input[type=date]:hover,
#playersBody input[type=text]:focus, #playersBody input[type=date]:focus {
  border-color: var(--border);
  background: var(--surface-2);
}

#playersBody input[type=checkbox] { width: 16px; height: 16px; }
#playersBody td:nth-child(5) input { min-width: 220px; }

td.actions { white-space: nowrap; }
td.actions button { padding: 4px 9px; font-size: 0.8rem; margin-right: 4px; }

::selection { background: var(--crimson); color: #fff; }

input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--crimson-light);
  outline-offset: 1px;
}
