/* =====================================================================
   CSS Custom Properties
   ===================================================================== */
:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #0c1a2e;
  --text-soft: #4a5568;
  --text-muted: #94a3b8;
  --brand: #0ea5e9;
  --brand-strong: #0284c7;
  --brand-accent: #f59e0b;
  --brand-subtle: #e0f2fe;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 3px rgba(12, 26, 46, 0.07);
  --shadow: 0 4px 16px rgba(12, 26, 46, 0.08);
  --shadow-lg: 0 10px 30px rgba(12, 26, 46, 0.12);
  --sidebar-w: 220px;
}

/* =====================================================================
   Base
   ===================================================================== */
html {
  font-size: 16px;
  position: relative;
  min-height: 100%;
}

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

main {
  padding-bottom: 2rem;
}

a {
  color: var(--brand);
  text-decoration: none;
  transition: color 0.15s ease, opacity 0.15s ease;
}

a:hover {
  color: var(--brand-strong);
}

h1, h2, h3, .page-title, .stat-value, .login-brand-title, .login-form-title {
  font-family: "Space Grotesk", "Inter", "Segoe UI", system-ui, sans-serif;
}

/* =====================================================================
   App shell
   ===================================================================== */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-main {
  flex: 1;
  animation: pageFadeIn 0.2s ease;
}

@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================================
   Desktop Sidebar
   ===================================================================== */
.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #0a0f1e 0%, #111827 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 2px 0 20px rgba(0, 0, 0, 0.2);
  flex-direction: column;
  z-index: 1030;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.app-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.1rem 1rem;
  color: #fff;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.app-sidebar-brand:hover { color: #fff; opacity: 0.9; }

.app-sidebar-logo {
  height: 1.75rem;
  width: auto;
  mix-blend-mode: screen;
  flex-shrink: 0;
}

.app-sidebar-nav {
  flex: 1;
  list-style: none;
  padding: 0.5rem 0;
  margin: 0;
}

.app-sidebar-nav li { display: contents; }

.sidebar-label {
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #475569;
  padding: 0.85rem 1rem 0.2rem;
  display: block;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 1rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-right: 0.75rem;
  transition: color 0.15s ease, background-color 0.15s ease;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link i {
  font-size: 0.9rem;
  width: 1rem;
  flex-shrink: 0;
  text-align: center;
}

.sidebar-link:hover {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.07);
}

.sidebar-link.active {
  color: #e0f2fe;
  background: rgba(14, 165, 233, 0.18);
}

.sidebar-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.2rem;
  bottom: 0.2rem;
  width: 3px;
  background: var(--brand);
  border-radius: 0 3px 3px 0;
}

.sidebar-link.text-danger-soft { color: #f87171; }
.sidebar-link.text-danger-soft:hover { color: #fca5a5; background: rgba(239, 68, 68, 0.1); }

.app-sidebar-footer {
  padding: 0.6rem 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.sidebar-user-link {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: #64748b;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: color 0.15s;
  padding: 0.35rem 0.25rem;
}

.sidebar-user-link:hover { color: #94a3b8; }
.sidebar-user-link i { font-size: 1rem; flex-shrink: 0; }

.sidebar-icon-btn {
  color: #475569 !important;
  padding: 0.35rem 0.45rem;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s ease !important;
  text-decoration: none;
}

.sidebar-icon-btn:hover { color: #94a3b8 !important; }

/* =====================================================================
   Mobile Top Bar
   ===================================================================== */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: linear-gradient(90deg, #0a0f1e 0%, #111827 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 1rem;
}

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

.app-topbar-brand:hover { color: #fff; }

.app-topbar-logo {
  height: 1.5rem;
  width: auto;
  mix-blend-mode: screen;
}

.app-topbar-right { display: flex; align-items: center; }

.app-topbar-btn {
  color: #94a3b8;
  font-size: 1rem;
  padding: 0.4rem 0.5rem;
  line-height: 1;
  transition: color 0.15s ease !important;
}

.app-topbar-btn:hover { color: #e2e8f0 !important; }
.app-topbar-btn .bi { font-size: 1.1rem; }
.app-topbar-hamburger .bi { font-size: 1.4rem; }

/* =====================================================================
   Mobile Offcanvas Menu
   ===================================================================== */
.mobile-offcanvas {
  background: linear-gradient(180deg, #0a0f1e 0%, #0e1628 100%);
  width: 260px !important;
}

.mobile-offcanvas .offcanvas-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.9rem 1.25rem;
}

.mobile-offcanvas .offcanvas-title {
  color: #e2e8f0;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.mobile-offcanvas .btn-close { filter: invert(1) grayscale(1) brightness(1.5); opacity: 0.7; }

.mobile-menu-nav { list-style: none; padding: 0.5rem 0; margin: 0; }
.mobile-menu-nav li { display: contents; }

.mobile-menu-section-label {
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #475569;
  padding: 0.85rem 1.25rem 0.2rem;
  display: block;
}

.mobile-menu-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 1.25rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.15s ease, background 0.15s ease;
  width: 100%;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.mobile-menu-link:hover, .mobile-menu-link.active {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.07);
}

.mobile-menu-link i { font-size: 0.95rem; width: 1.1rem; text-align: center; flex-shrink: 0; }

/* =====================================================================
   Mobile Bottom Nav
   ===================================================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 58px;
  background: linear-gradient(0deg, #08101f 0%, #0a0f1e 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  flex-direction: row;
  align-items: stretch;
  z-index: 1031;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  color: #475569;
  text-decoration: none;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: color 0.15s ease;
  padding: 0.35rem 0;
}

.bottom-nav-item i { font-size: 1.35rem; line-height: 1; transition: transform 0.15s ease; }

.bottom-nav-item:hover, .bottom-nav-item.active { color: var(--brand); }
.bottom-nav-item.active i { transform: translateY(-1px); }

/* =====================================================================
   Content wrap (sidebar offset + bottom-nav clearance)
   ===================================================================== */
.app-content-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

@media (min-width: 992px) {
  .app-content-wrap { margin-left: var(--sidebar-w); }
}

@media (max-width: 991.98px) {
  .app-content-wrap { padding-bottom: 58px; }
}

/* =====================================================================
   Content cards
   ===================================================================== */
.content-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  box-shadow: var(--shadow);
  padding: 1.5rem;
  transition: box-shadow 0.2s ease;
}

.content-card:hover { box-shadow: var(--shadow-lg); }

.content-card > .page-header {
  padding-bottom: 1rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

/* =====================================================================
   Page header
   ===================================================================== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.page-subtitle {
  margin: 0.3rem 0 0;
  color: var(--text-soft);
  font-size: 0.875rem;
  font-weight: 500;
}

/* =====================================================================
   Hero sections
   ===================================================================== */
.page-hero {
  background: linear-gradient(135deg, #0a0f1e 0%, #0c2c44 60%, #0ea5e9 100%);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 1.5rem), 0 100%);
  padding: 2.5rem 2rem 3.5rem;
  color: white;
  margin-bottom: 1.5rem;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.hero {
  padding: 2rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--brand-subtle) 0%, var(--surface) 80%);
  border: 1px solid var(--brand-subtle);
}

.app-main .bg-light:not(pre) { background-color: rgba(248, 249, 250, 0.72) !important; }

.hero h1 { font-weight: 700; margin-bottom: 0.75rem; }

.hero p { color: var(--text-soft); font-size: 1.05rem; margin-bottom: 1.25rem; }

.empty-state {
  border: 1px dashed #bae6fd;
  background: linear-gradient(180deg, #f0f9ff 0%, var(--bg) 100%);
  border-radius: var(--radius-md);
  padding: 1rem 1.2rem;
  color: #475569;
  transition: border-color 0.2s ease;
}

.empty-state:hover { border-color: var(--brand); }

/* =====================================================================
   Help accordion
   ===================================================================== */
.page-help-accordion {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: linear-gradient(135deg, #f0f9ff 0%, var(--surface-muted) 100%);
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.08);
  overflow: hidden;
}

.page-help-accordion .accordion-item { border: 0; background: transparent; }

.page-help-accordion .accordion-button {
  font-weight: 600;
  background: transparent;
  box-shadow: none;
  color: var(--text);
}

.page-help-accordion .accordion-button:not(.collapsed) {
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
}

.page-help-accordion .accordion-button:focus {
  box-shadow: 0 0 0 0.2rem rgba(14, 165, 233, 0.2);
}

.page-help-accordion-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
  flex-shrink: 0;
}

.page-help-accordion-title { flex: 1; text-align: start; }

.page-help-accordion .accordion-body {
  background: rgba(255, 255, 255, 0.45);
  border-top: 1px solid var(--border);
}

.page-help-accordion .accordion-body section.mb-5 { margin-bottom: 1rem !important; }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: box-shadow 0.15s ease, transform 0.15s ease, filter 0.15s ease, background-color 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  border: 0;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--brand-strong), #0369a1);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.btn-secondary {
  border: 1px solid var(--border-strong);
  background: var(--surface-muted);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface);
  border-color: var(--brand);
  color: var(--brand);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.15);
}

/* =====================================================================
   Tables
   ===================================================================== */
.table-modern { margin: 0; border-radius: var(--radius-md); overflow: hidden; }

.table-modern thead th {
  background-color: var(--surface-muted);
  border-bottom: 2px solid var(--border-strong);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-soft);
  padding: 0.7rem 1rem;
}

.table-modern > :not(caption) > * > * { padding: 0.85rem 1rem; }

.table-modern tbody tr:hover { background: #f0f9ff; }
.table-modern tbody tr { transition: background-color 0.15s ease; }
.table-modern td a { font-weight: 600; }

/* Elimination rounds table */
.table-elimination .elim-col-scoring { min-width: 18rem; }
.table-elimination .elim-table-of-select { max-width: 12rem; }
.table-elimination .elim-score-select { width: 4.5rem; }
.table-elimination .elim-opponent-input { min-width: 10rem; }
.table-elimination .elim-opponent-inline { flex: 0 1 auto; max-width: min(14rem, 100%); min-width: 0; }

@media (max-width: 767.98px) {
  .table-elimination-wrap.table-responsive { overflow-x: visible; }

  .table-elimination thead {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }

  .table-elimination tbody { display: block; }

  .table-elimination tbody tr {
    display: block; margin-bottom: 1rem; border: 1px solid var(--border);
    border-radius: var(--radius-md); background: #fff; box-shadow: var(--shadow-sm); overflow: hidden;
  }

  .table-elimination tbody tr:hover { background: #fff; }

  .table-elimination tbody td {
    display: block; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  }

  .table-elimination tbody td:last-child { border-bottom: none; }

  .table-elimination tbody td::before {
    display: block; content: attr(data-label); font-size: 0.7rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-soft); margin-bottom: 0.45rem;
  }

  .table-elimination tbody tr.elim-empty-row td::before { display: none; }
  .table-elimination tbody tr.elim-empty-row td { text-align: center; padding: 1.25rem 1rem; }

  .table-elimination .elim-table-of-select,
  .table-elimination .elim-opponent-input { width: 100%; max-width: none; min-width: 0; }

  .table-elimination .elim-scoring-controls { width: 100%; justify-content: flex-start; gap: 0.5rem 0.75rem; }
  .table-elimination .elim-score-select { width: auto; min-width: 4.75rem; flex: 1 1 auto; max-width: 8rem; }
  .table-elimination td.elim-actions-cell { text-align: left !important; }
  .table-elimination .elim-actions-inner { width: 100%; justify-content: stretch !important; }
  .table-elimination .elim-actions-inner .btn { flex: 1 1 auto; min-height: 44px; }
  .table-elimination .elim-actions-inner form { flex: 1 1 auto; display: flex; }
  .table-elimination .elim-actions-inner form .btn { width: 100%; }
}

/* =====================================================================
   Form controls
   ===================================================================== */
.form-control, .form-select, textarea.form-control {
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.2s ease;
}

.form-control:hover, .form-select:hover, textarea.form-control:hover { border-color: #7dd3fc; }

.form-control:focus, .form-select:focus, textarea.form-control:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.form-label { font-weight: 600; font-size: 0.88rem; color: var(--text); }

.list-group-item { transition: background-color 0.2s ease, border-color 0.2s ease; }
.list-group-item:hover { background: #f0f9ff; border-color: var(--brand-subtle); }

/* =====================================================================
   Status badges
   ===================================================================== */
.status-badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.2rem 0.55rem; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
}

.status-badge::before { content: ""; width: 0.45rem; height: 0.45rem; border-radius: 50%; }

.status-badge.success { background: #ecfdf5; color: #166534; }
.status-badge.success::before { background: #22c55e; }
.status-badge.neutral { background: #f1f5f9; color: #334155; }
.status-badge.neutral::before { background: #94a3b8; }

/* =====================================================================
   Footer
   ===================================================================== */
.app-footer, .footer.app-footer {
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}

.footer.app-footer { position: static; width: 100%; white-space: normal; line-height: normal; }

.app-footer .container {
  padding-top: 0.9rem; padding-bottom: 0.9rem; color: var(--text-soft); font-size: 0.85rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}

/* =====================================================================
   Focus ring
   ===================================================================== */
.btn:focus, .btn:active:focus, .form-control:focus, .form-check-input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.18);
}

/* =====================================================================
   Identity / login pages
   ===================================================================== */
.identity-pages { overflow: visible; }
.identity-pages h1:not(.page-title) { margin: 0 0 1rem; font-size: 1.75rem; font-weight: 700; color: var(--text); }
.identity-pages h2 { margin: 0 0 0.75rem; font-size: 1.125rem; font-weight: 600; color: var(--text-soft); }
.identity-pages h3 { margin: 0 0 1rem; font-size: 1.25rem; font-weight: 700; color: var(--text); }
.identity-pages h4 { margin: 1rem 0 0.75rem; font-size: 1rem; font-weight: 600; color: var(--text); }
.identity-pages hr { border-color: var(--border); opacity: 1; }
.identity-pages .form-label { font-weight: 600; color: var(--text); }
.identity-pages .checkbox label { font-weight: 500; }

/* =====================================================================
   Login split panel
   ===================================================================== */
.login-split {
  display: flex; min-height: calc(100vh - 160px); border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}

.login-brand-panel {
  display: flex; flex-direction: column; justify-content: center;
  width: 42%; flex-shrink: 0;
  background: linear-gradient(145deg, #0a1628 0%, #1e3a5f 50%, #0f2a4a 100%);
  padding: 3rem 2.5rem; color: #e2e8f0; position: relative; overflow: hidden;
}

.login-brand-panel::before {
  content: ""; position: absolute; inset: 0;
  background-image: url("/images/fencing-watermark.png");
  background-repeat: no-repeat; background-position: center right -40px;
  background-size: 75%; opacity: 0.07; pointer-events: none;
}

.login-brand-logo {
  height: 3rem; width: auto; margin-bottom: 1.75rem; object-fit: contain;
  mix-blend-mode: screen; position: relative; z-index: 1;
}

.login-brand-title {
  font-size: 2rem; font-weight: 800; color: #fff; margin: 0 0 0.75rem;
  line-height: 1.2; letter-spacing: -0.03em; position: relative; z-index: 1;
}

.login-brand-tagline {
  font-size: 1rem; color: #94a3b8; margin: 0 0 2.25rem;
  line-height: 1.65; position: relative; z-index: 1;
}

.login-brand-features { display: flex; flex-direction: column; gap: 0.9rem; position: relative; z-index: 1; }

.login-feature { display: flex; align-items: center; gap: 0.85rem; font-size: 0.9rem; color: #cbd5e1; font-weight: 500; }

.login-feature i {
  width: 2rem; height: 2rem; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(14, 165, 233, 0.18); border-radius: 50%; color: #7dd3fc; flex-shrink: 0; font-size: 1rem;
}

.login-form-panel { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--surface); padding: 2.5rem 2rem; }

.login-form-inner { width: 100%; max-width: 380px; }

.login-form-title { font-size: 1.6rem; font-weight: 800; color: var(--text); margin: 0 0 0.25rem; letter-spacing: -0.02em; }

.login-form-subtitle { font-size: 0.9rem; color: var(--text-soft); margin: 0 0 1.75rem; }

.login-divider {
  display: flex; align-items: center; gap: 0.75rem; margin: 1.5rem 0;
  color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}

.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

@media (max-width: 767.98px) {
  .login-split { flex-direction: column; min-height: unset; }
  .login-brand-panel { width: 100%; padding: 2rem 1.5rem; }
  .login-brand-features { display: none; }
  .login-brand-tagline { display: none; }
  .login-form-panel { padding: 2rem 1.5rem; }
}

/* =====================================================================
   Dashboard stat strip
   ===================================================================== */
.stat-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

.stat-card {
  display: flex; align-items: center; gap: 1rem;
  background: linear-gradient(var(--surface), var(--surface)) padding-box,
              linear-gradient(135deg, var(--brand), var(--brand-accent)) border-box;
  border: 2px solid transparent;
  border-radius: var(--radius-md); padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

.stat-info { min-width: 0; }

.stat-icon {
  width: 2.75rem; height: 2.75rem; border-radius: var(--radius-sm); background: #e0f2fe;
  color: var(--brand); display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; flex-shrink: 0;
}

.stat-icon--events { background: #fef3c7; color: #d97706; }
.stat-icon--pools { background: #f0fdf4; color: #16a34a; }
.stat-icon--submitted { background: #dcfce7; color: #15803d; }

.stat-value { font-size: 1.65rem; font-weight: 800; color: var(--text); line-height: 1; letter-spacing: -0.02em; }

.stat-label { font-size: 0.75rem; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.2rem; }

.stat-delta { font-size: 0.7rem; font-weight: 600; margin-top: 0.15rem; color: var(--text-muted); }
.stat-delta.positive { color: #16a34a; }
.stat-delta.negative { color: #dc2626; }

@media (max-width: 767.98px) { .stat-strip { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 479px) { .stat-strip { grid-template-columns: 1fr 1fr; } }

/* =====================================================================
   Admin invite form group
   ===================================================================== */
.invite-form-group {
  background: var(--surface-muted); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 1rem 1.25rem; margin-bottom: 1.5rem;
}

/* =====================================================================
   Social login buttons
   ===================================================================== */
.btn-social {
  display: inline-flex; align-items: center; gap: 0.75rem; padding: 0.6rem 1.25rem;
  font-size: 0.95rem; font-weight: 600; border-radius: var(--radius-sm);
  transition: box-shadow 0.2s ease, filter 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
  text-align: left; justify-content: flex-start;
}

.btn-social-icon { width: 20px; height: 20px; flex-shrink: 0; }

.btn-google { background: #ffffff; color: #3c4043; border: 1px solid #dadce0; }
.btn-google:hover { background: #f8f9fa; border-color: #c6c9cc; box-shadow: 0 2px 8px rgba(0,0,0,0.1); color: #3c4043; }

.btn-microsoft { background: #ffffff; color: #5e5e5e; border: 1px solid #8c8c8c; }
.btn-microsoft:hover { background: #f2f2f2; border-color: #6e6e6e; box-shadow: 0 2px 8px rgba(0,0,0,0.1); color: #5e5e5e; }

/* =====================================================================
   Identity manage layout
   ===================================================================== */
.identity-manage-intro .page-title { margin-bottom: 0.35rem; }
.identity-manage-layout { margin-top: 0.25rem; }
.identity-manage-layout > aside { position: relative; z-index: 1; }
.identity-manage-layout .identity-manage-body { position: relative; z-index: 2; }

.identity-manage-nav .nav.nav-pills { gap: 0.35rem; }

.identity-manage-nav .nav.nav-pills .nav-link {
  border-radius: var(--radius-sm); padding: 0.45rem 0.75rem; font-weight: 600; color: var(--text);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.identity-manage-nav .nav.nav-pills .nav-link:hover { background-color: var(--surface-muted); color: var(--brand-strong); }
.identity-manage-nav .nav.nav-pills .nav-link.active { background: linear-gradient(135deg, var(--brand), var(--brand-strong)); color: #ffffff; }
.identity-manage-body > :first-child { margin-top: 0; }

/* =====================================================================
   Fencer names field (Create Pool)
   ===================================================================== */
.fencer-names-field {
  display: flex; align-items: stretch; border: 1px solid #ced4da;
  border-radius: 0.375rem; overflow: hidden; background-color: #fff;
}

.fencer-names-field:focus-within { border-color: #7dd3fc; box-shadow: 0 0 0 0.25rem rgba(14, 165, 233, 0.2); }

.fencer-line-numbers {
  flex: 0 0 auto; display: flex; flex-direction: column; justify-content: flex-start;
  width: 2rem; padding: 0.375rem 0.35rem 0.375rem 0.5rem;
  background-color: var(--surface-muted, #f8fafc); border-right: 1px solid var(--border, #e5e7eb);
  color: var(--text-soft, #6b7280); font-family: inherit; font-size: 1rem; line-height: 1.5;
  font-variant-numeric: tabular-nums; user-select: none; text-align: right;
}

.fencer-line-numbers .fencer-line-num {
  display: flex; align-items: center; justify-content: flex-end;
  flex: 0 0 auto; min-height: calc(1em * 1.5); line-height: 1.5;
}

.fencer-names-field textarea.fencer-names-textarea {
  border: none; border-radius: 0; resize: vertical; font-size: 1rem; line-height: 1.5;
  padding: 0.375rem 0.75rem; min-height: calc(8 * 1.5em + 0.75rem);
}

.fencer-names-field textarea.fencer-names-textarea:focus { box-shadow: none; }

/* =====================================================================
   Pool scoring grid
   ===================================================================== */
.pool-grid-table {
  --my-fencer-edge: #212529;
  table-layout: auto;
  border-collapse: separate;
  border-spacing: 0;
}

.pool-grid-table th, .pool-grid-table td {
  white-space: nowrap;
  overflow: hidden;
  transition: background-color 0.2s ease, color 0.15s ease;
}

.pool-grid-table .sticky-number {
  position: sticky; left: 0; min-width: 48px; width: 48px;
  background-color: #fff; z-index: 3; box-shadow: 1px 0 0 #dee2e6;
}

.pool-grid-table thead .sticky-number { z-index: 4; }

.pool-grid-scroll { overflow-x: auto; }

.pool-grid-table .name-column { min-width: 112px; }

.pool-grid-table td:not(.sticky-number):not(.name-column),
.pool-grid-table th:not(.sticky-number):not(.name-column) { min-width: 80px; width: 80px; }

.pool-grid-table .score-select {
  min-width: 0; width: 100%; max-width: 100%; box-sizing: border-box;
  padding-left: 0.45rem; padding-right: 1.35rem; font-size: 0.9rem; text-overflow: clip;
}

.pool-grid-table tbody tr.my-fencer-row > td:not(.readonly-score-win):not(.readonly-score-loss) {
  background-color: #fff8e1;
  box-shadow: inset 0 2px 0 0 var(--my-fencer-edge), inset 0 -2px 0 0 var(--my-fencer-edge);
}

.pool-grid-table tbody tr.my-fencer-row > td.sticky-number {
  box-shadow: 1px 0 0 #dee2e6, inset 0 2px 0 0 var(--my-fencer-edge), inset 0 -2px 0 0 var(--my-fencer-edge);
}

.pool-grid-table tbody tr.my-fencer-row > td.readonly-score-win,
.pool-grid-table tbody tr.my-fencer-row > td.readonly-score-loss {
  box-shadow: inset 0 2px 0 0 var(--my-fencer-edge), inset 0 -2px 0 0 var(--my-fencer-edge);
}

.pool-grid-table thead th.my-fencer-column {
  background-color: #fff3cd;
  box-shadow: inset 2px 0 0 0 var(--my-fencer-edge), inset -2px 0 0 0 var(--my-fencer-edge);
}

.pool-grid-table tbody td.my-fencer-column-cell {
  box-shadow: inset 2px 0 0 0 var(--my-fencer-edge), inset -2px 0 0 0 var(--my-fencer-edge);
}

.pool-grid-table tbody tr.my-fencer-row > td.my-fencer-column-cell {
  box-shadow:
    inset 0 2px 0 0 var(--my-fencer-edge), inset 0 -2px 0 0 var(--my-fencer-edge),
    inset 2px 0 0 0 var(--my-fencer-edge), inset -2px 0 0 0 var(--my-fencer-edge);
}

.pool-grid-table thead tr > th { border-bottom: 2px solid #212529; }

.pool-grid-table .readonly-score { display: inline-block; min-width: 2.5rem; font-weight: 700; }

.pool-grid-table .readonly-score-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 100%;
  color: inherit; text-decoration: none;
}

.pool-grid-table .readonly-score-btn:hover { color: inherit; text-decoration: none; }

.pool-grid-table td.readonly-score-win {
  background: linear-gradient(135deg, #14532d, #166534);
  color: #bbf7d0;
}

.pool-grid-table td.readonly-score-loss {
  background: linear-gradient(135deg, #7f1d1d, #991b1b);
  color: #fecaca;
}

.pool-grid-table td.standings-first { color: var(--brand-accent); font-weight: 700; }

/* Results-import review: fade bouts that already exist and won't be changed. */
.pool-grid-table td.import-existing-cell { opacity: 0.55; }

/* Mobile score entry bottom sheet */
.score-entry-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.15);
  z-index: 2000; padding: 1rem; display: none; flex-direction: column; gap: 0.75rem; max-height: 70vh; overflow-y: auto;
}

.score-entry-sheet.open { display: flex; }

.score-entry-sheet-header {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: 0.9rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
}

.score-entry-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }

.score-entry-option {
  min-height: 52px; font-weight: 600; font-size: 0.88rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-muted); cursor: pointer;
  transition: background 0.15s, border-color 0.15s; padding: 0.5rem; text-align: center;
}

.score-entry-option.win { background: #dcfce7; border-color: #86efac; color: #166534; }
.score-entry-option.win:hover { background: #bbf7d0; border-color: #4ade80; }
.score-entry-option.loss { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.score-entry-option.loss:hover { background: #fecaca; border-color: #f87171; }

@media (max-width: 767.98px) {
  .pool-grid-table .name-column { min-width: 104px; }
  .pool-grid-table .sticky-number { position: sticky; left: 0; min-width: 44px; width: 44px; }
  .pool-grid-table td:not(.sticky-number):not(.name-column),
  .pool-grid-table th:not(.sticky-number):not(.name-column) { min-width: 78px; width: 78px; }
  .pool-grid-table .score-select { font-size: 0.86rem; padding-left: 0.4rem; padding-right: 1.25rem; }
}

/* =====================================================================
   Bracket tree view
   ===================================================================== */
.bracket-tree {
  display: flex; flex-direction: row-reverse; gap: 1.5rem;
  overflow-x: auto; padding: 1rem 0; align-items: center;
}

.bracket-round { display: flex; flex-direction: column; align-items: stretch; min-width: 160px; }

.bracket-round-label {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); text-align: center; margin-bottom: 0.75rem;
}

.bracket-bout {
  display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--surface); box-shadow: var(--shadow-sm); margin-bottom: 1rem;
  transition: box-shadow 0.15s ease;
}

.bracket-bout:hover { box-shadow: var(--shadow); }

.bracket-slot {
  padding: 0.5rem 0.75rem; font-size: 0.8rem; font-weight: 500; border-bottom: 1px solid var(--border);
  position: relative; min-height: 36px; display: flex; align-items: center;
}

.bracket-slot:last-child { border-bottom: none; }

.bracket-slot--winner { border-left: 3px solid var(--brand-accent); font-weight: 700; color: var(--text); background: #fffbeb; }

.bracket-slot--score { font-size: 0.75rem; color: var(--text-muted); margin-left: auto; font-weight: 600; }

/* =====================================================================
   Dark Mode
   ===================================================================== */

[data-bs-theme="dark"] .dark-icon,
[data-bs-theme="light"] .light-icon { display: none; }
[data-bs-theme="dark"] .light-icon,
[data-bs-theme="light"] .dark-icon { display: inline; }

[data-bs-theme="dark"] {
  --bg: #0a0f1e;
  --surface: #111827;
  --surface-muted: #1a2234;
  --text: #e2e8f0;
  --text-soft: #94a3b8;
  --text-muted: #64748b;
  --brand: #38bdf8;
  --brand-strong: #7dd3fc;
  --brand-accent: #fbbf24;
  --brand-subtle: #0c2c44;
  --border: #1e3048;
  --border-strong: #2d4a6e;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.50);
}

[data-bs-theme="dark"] body { background: var(--bg); }

[data-bs-theme="dark"] .content-card { background: var(--surface); border-color: var(--border); border-left-color: var(--brand); }
[data-bs-theme="dark"] .content-card > .page-header { border-bottom-color: var(--border); }

[data-bs-theme="dark"] .table-modern thead th { color: var(--text-soft); background-color: var(--surface-muted); border-bottom-color: var(--border-strong); }
[data-bs-theme="dark"] .table-modern tbody tr:hover { background: #1a2840; }

[data-bs-theme="dark"] .btn-secondary { background: #1e3048; color: #e2e8f0; border-color: var(--border-strong); }
[data-bs-theme="dark"] .btn-secondary:hover { background: #2d4060; color: #f1f5f9; border-color: var(--brand); }

[data-bs-theme="dark"] .hero { background: linear-gradient(135deg, var(--brand-subtle) 0%, var(--surface) 80%); border-color: var(--border); }

[data-bs-theme="dark"] .empty-state { border-color: var(--border); background: linear-gradient(180deg, #162030 0%, #0a0f1e 100%); color: var(--text-soft); }
[data-bs-theme="dark"] .empty-state:hover { border-color: var(--brand); }

[data-bs-theme="dark"] .page-help-accordion { background: linear-gradient(135deg, #0c2c44 0%, var(--surface-muted) 100%); border-color: var(--border); }
[data-bs-theme="dark"] .page-help-accordion .accordion-button:not(.collapsed) { background: rgba(30, 48, 72, 0.6); }
[data-bs-theme="dark"] .page-help-accordion .accordion-body { background: rgba(10, 15, 30, 0.4); border-top-color: var(--border); }

[data-bs-theme="dark"] .status-badge.success { background: #14532d; color: #86efac; }
[data-bs-theme="dark"] .status-badge.success::before { background: #4ade80; }
[data-bs-theme="dark"] .status-badge.neutral { background: #1e293b; color: #94a3b8; }
[data-bs-theme="dark"] .status-badge.neutral::before { background: #64748b; }

[data-bs-theme="dark"] .app-footer, [data-bs-theme="dark"] .footer.app-footer { background: rgba(10, 15, 30, 0.9); border-top-color: var(--border); }

[data-bs-theme="dark"] .list-group-item:hover { background: #162030; border-color: var(--border-strong); }

[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select, [data-bs-theme="dark"] textarea.form-control { border-color: var(--border); }

[data-bs-theme="dark"] .fencer-names-field { background-color: var(--surface); border-color: var(--border-strong); }
[data-bs-theme="dark"] .fencer-names-field textarea.fencer-names-textarea { background-color: var(--surface); color: var(--text); }

[data-bs-theme="dark"] .app-main .bg-light:not(pre) { background-color: rgba(30, 41, 59, 0.72) !important; }

[data-bs-theme="dark"] .pool-grid-table .sticky-number { background-color: var(--surface); box-shadow: 1px 0 0 var(--border); }
[data-bs-theme="dark"] .pool-grid-table thead tr > th { border-bottom-color: var(--text); }
[data-bs-theme="dark"] .pool-grid-table td.readonly-score-win { background: linear-gradient(135deg, #14532d, #166534); color: #bbf7d0; }
[data-bs-theme="dark"] .pool-grid-table td.readonly-score-loss { background: linear-gradient(135deg, #7f1d1d, #991b1b); color: #fecaca; }
[data-bs-theme="dark"] .pool-grid-table tbody tr.my-fencer-row > td:not(.readonly-score-win):not(.readonly-score-loss) { background-color: #2d2a00; }
[data-bs-theme="dark"] .pool-grid-table thead th.my-fencer-column { background-color: #2d2a00; }
[data-bs-theme="dark"] .pool-grid-table tbody tr.my-fencer-row > td.sticky-number { box-shadow: 1px 0 0 var(--border), inset 0 2px 0 0 var(--my-fencer-edge), inset 0 -2px 0 0 var(--my-fencer-edge); }

[data-bs-theme="dark"] .table-elimination tbody tr { background: var(--surface); border-color: var(--border); }
[data-bs-theme="dark"] .table-elimination tbody td::before { color: var(--text-soft); }
[data-bs-theme="dark"] .table-elimination tbody td { border-bottom-color: var(--border); }

[data-bs-theme="dark"] .btn-google { background: #1e3048; color: #e2e8f0; border-color: var(--border-strong); }
[data-bs-theme="dark"] .btn-google:hover { background: #2d4060; color: #f1f5f9; }
[data-bs-theme="dark"] .btn-microsoft { background: #1e3048; color: #e2e8f0; border-color: var(--border-strong); }
[data-bs-theme="dark"] .btn-microsoft:hover { background: #2d4060; color: #f1f5f9; }

[data-bs-theme="dark"] .login-form-panel { background: var(--surface); }
[data-bs-theme="dark"] .login-split { border-color: var(--border); }

[data-bs-theme="dark"] .stat-card {
  background: linear-gradient(var(--surface), var(--surface)) padding-box,
              linear-gradient(135deg, var(--brand), var(--brand-accent)) border-box;
}

[data-bs-theme="dark"] .stat-icon { background: #0c2c44; color: var(--brand); }
[data-bs-theme="dark"] .stat-icon--events { background: #451a03; color: #fbbf24; }
[data-bs-theme="dark"] .stat-icon--pools { background: #14532d; color: #4ade80; }
[data-bs-theme="dark"] .stat-icon--submitted { background: #14532d; color: #4ade80; }

[data-bs-theme="dark"] .invite-form-group { background: var(--surface-muted); border-color: var(--border); }

[data-bs-theme="dark"] .score-entry-sheet { background: var(--surface); border-top-color: var(--border); }
[data-bs-theme="dark"] .score-entry-option { background: var(--surface-muted); border-color: var(--border); color: var(--text); }
[data-bs-theme="dark"] .score-entry-option.win { background: #14532d; border-color: #166534; color: #bbf7d0; }
[data-bs-theme="dark"] .score-entry-option.loss { background: #7f1d1d; border-color: #991b1b; color: #fecaca; }

[data-bs-theme="dark"] .bracket-bout { background: var(--surface); border-color: var(--border); }
[data-bs-theme="dark"] .bracket-slot { border-bottom-color: var(--border); }
[data-bs-theme="dark"] .bracket-slot--winner { background: rgba(251, 191, 36, 0.1); border-left-color: var(--brand-accent); }

.theme-toggle-btn { font-size: 1rem; padding: 0.35rem 0.6rem; line-height: 1; }
