/* ── Race to 1,000 — Dhalia branded styles ── */

:root {
  --navy: #1C2D4A;
  --navy-light: #2A4066;
  --gold: #F5A623;
  --gold-soft: #F5A62318;
  --white: #FFFFFF;
  --surface: #F5F6F8;
  --surface-card: #FFFFFF;
  --text: #1E2432;
  --text-secondary: #5A6171;
  --text-muted: #8E95A4;
  --border: #E2E5EB;
  --border-strong: #CDD1D9;
  --positive: #18845A;
  --positive-bg: #18845A14;
  --warning: #C47A1A;
  --warning-bg: #C47A1A14;
  --critical: #C43D3D;
  --critical-bg: #C43D3D14;
  --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Consolas', 'Courier New', monospace;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { font-size: 15px; }

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--surface);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1rem;
  width: 100%;
}

main.container {
  flex: 1;
  padding-top: 1.5rem;
  padding-bottom: 3rem;
}

/* ── Header ── */
.site-header {
  background: var(--navy);
  color: var(--white);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 56px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--white);
  flex-shrink: 0;
}

.logo-icon { font-size: 1.25rem; }
.logo-text {
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--gold);
}
.logo-text strong { font-weight: 700; }

.nav {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}

.nav-link {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.87rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}
.nav-link:hover { color: var(--white); background: rgba(255,255,255,0.1); }
.nav-link.active { color: var(--gold); background: rgba(245,166,35,0.12); }

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  flex-shrink: 0;
}
.user-name { font-weight: 600; }
.user-office { color: rgba(255,255,255,0.5); }
.btn-logout {
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  padding: 0.3rem 0.6rem;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  transition: all 0.15s;
}
.btn-logout:hover { color: var(--white); border-color: rgba(255,255,255,0.4); }

/* ── Footer ── */
.site-footer {
  background: var(--navy);
  color: rgba(255,255,255,0.4);
  text-align: center;
  padding: 1rem;
  font-size: 0.78rem;
  margin-top: auto;
}

/* ── Page titles ── */
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.25rem;
}
.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin-bottom: 1.5rem;
}

/* ── Cards ── */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card-header {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* ── Score cards grid ── */
.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.score-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.score-card .score-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.score-card .score-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.3rem;
}
.score-card.highlight {
  border-color: var(--gold);
  background: linear-gradient(135deg, var(--gold-soft), var(--surface-card));
}
.score-card.highlight .score-value { color: var(--gold); }

/* ── Rank badge ── */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--navy);
  color: var(--gold);
  font-weight: 800;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}
.rank-badge.top3 { background: var(--gold); color: var(--navy); }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-card);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}
thead { background: var(--surface); }
th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-align: left;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(0,0,0,0.015); }

/* ── Status chips ── */
.chip {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.15em 0.55em;
  border-radius: 3px;
}
.chip-pass { background: var(--positive-bg); color: var(--positive); }
.chip-pending { background: var(--warning-bg); color: var(--warning); }
.chip-fail { background: var(--critical-bg); color: var(--critical); }
.chip-critical { background: var(--critical-bg); color: var(--critical); }
.chip-warning { background: var(--warning-bg); color: var(--warning); }

/* ── Gate indicators ── */
.gate-check { color: var(--positive); font-weight: 700; }
.gate-fail { color: var(--critical); font-weight: 700; }
.gate-pending { color: var(--warning); font-weight: 700; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--navy-light); }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { opacity: 0.9; }
.btn-secondary {
  background: var(--surface-card);
  color: var(--navy);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--surface); border-color: var(--navy); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-approve { background: var(--positive); color: var(--white); }
.btn-reject { background: var(--critical); color: var(--white); }
.btn-copy {
  background: var(--surface-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}
.btn-copy:hover { border-color: var(--navy); color: var(--navy); }
.btn-copy.copied { background: var(--positive-bg); color: var(--positive); border-color: var(--positive); }

/* Plain, unstyled <button> or <a> that inherits .btn but no fill —
   guard against future bare "btn" usage looking like a link */
.btn:not([class*="btn-"]) {
  background: var(--surface-card);
  color: var(--navy);
  border: 1px solid var(--border-strong);
}

/* ── Forms (login) ── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}
.auth-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}
.auth-header {
  background: var(--navy);
  color: var(--gold);
  text-align: center;
  padding: 1.5rem;
}
.auth-header h1 {
  font-size: 1.25rem;
  margin: 0;
}
.auth-header p {
  color: rgba(255,255,255,0.6);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}
.auth-body { padding: 1.5rem; }
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}
.form-control {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  caret-color: var(--text);
  transition: border-color 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(28,45,74,0.1);
}
.form-control-otp {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.4em;
  font-variant-numeric: tabular-nums;
}
.form-error {
  background: var(--critical-bg);
  color: var(--critical);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.btn-full { width: 100%; justify-content: center; }

.btn:disabled,
.btn.is-busy {
  opacity: 0.65;
  cursor: wait;
  pointer-events: none;
}
.btn.is-busy::after {
  content: '';
  width: 0.85em;
  height: 0.85em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.65s linear infinite;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

.auth-error-body { text-align: center; }
.auth-error-message { margin-bottom: 1rem; }

/* ── Alert box ── */
.alert {
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 1rem;
}
.alert-info { background: rgba(28,45,74,0.06); border-left: 3px solid var(--navy); }
.alert-warning { background: var(--warning-bg); border-left: 3px solid var(--warning); }
.alert-success { background: var(--positive-bg); border-left: 3px solid var(--positive); }
.alert-critical { background: var(--critical-bg); border-left: 3px solid var(--critical); }

/* ── Page-level actions row (buttons under the page title) ── */
.page-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

/* ── Back link ── */
.back-link {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 0.5rem;
}
.back-link:hover { color: var(--navy); text-decoration: underline; }

/* ── Filter / search bar ── */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}
.filter-bar .form-control { width: auto; }

/* ── Helper / muted note text ── */
.helper-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}
.helper-text:last-child { margin-bottom: 0; }
.field-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.result-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* ── Key/value summary table (used on detail & edit views) ── */
.kv-table { width: 100%; font-size: 0.88rem; border-collapse: collapse; }
.kv-table tr td {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.kv-table tr:last-child td { border-bottom: none; }
.kv-table td:first-child { color: var(--text-secondary); }
.kv-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.kv-table tr.kv-total td {
  font-weight: 700;
  color: var(--navy);
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
  padding-top: 0.6rem;
}

/* ── Sub-heading inside a section (e.g. "Gate overrides") ── */
.subsection-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--navy);
  margin: 1.25rem 0 0.5rem;
}
.subsection-title:first-child { margin-top: 0; }

/* ── Inline checkbox row ── */
.checkbox-row {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text);
}
.checkbox-field.stacked {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ── File input (matches .form-control sizing) ── */
input[type="file"].form-control {
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}

/* ── Next steps ── */
.next-steps {
  list-style: none;
  padding: 0;
}
.next-steps li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.next-steps li:last-child { border-bottom: none; }
.next-steps .step-icon {
  flex-shrink: 0;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  margin-top: 0.15rem;
}

/* ── Chart container ── */
.chart-container {
  position: relative;
  height: 250px;
  margin: 1rem 0;
}

/* ── Flag cards ── */
.flag-list { display: flex; flex-direction: column; gap: 0.75rem; }
.flag-item {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}
.flag-item.severity-critical { border-left: 3px solid var(--critical); }
.flag-item.severity-warning { border-left: 3px solid var(--warning); }
.flag-detail { flex: 1; }
.flag-detail .flag-type {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
}
.flag-detail .flag-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.flag-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

/* ── Flag tabs & pager ── */
.flag-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}
.flag-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.flag-tab:hover { border-color: var(--border-strong); }
.flag-tab.active { background: var(--navy); border-color: var(--navy); color: var(--white); }
.flag-tab-count {
  display: inline-block;
  margin-left: 0.3rem;
  font-size: 0.72rem;
  opacity: 0.75;
}
.flag-pager {
  display: flex;
  gap: 0.35rem;
  justify-content: center;
  margin-top: 1rem;
}
.flag-page-btn {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 2rem;
  padding: 0.3rem 0.5rem;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}
.flag-page-btn:hover { border-color: var(--border-strong); }
.flag-page-btn.active { background: var(--navy); border-color: var(--navy); color: var(--white); }

/* ── Config form groups ── */
.config-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
}
.config-group {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.config-group-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.85rem;
}
.config-field { margin-bottom: 0.85rem; }
.config-field:last-child { margin-bottom: 0; }
.config-field label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

/* ── Sections ── */
.section { margin-bottom: 2rem; }
.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--gold);
  display: inline-block;
}

/* ── Two column layout ── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* ── Equal-height paired panels (e.g. leaderboard + branch standings) ── */
.grid-2-equal { align-items: stretch; }
.equal-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.panel-header .section-title { margin-bottom: 0; }
.equal-panel .table-wrap {
  flex: 1;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* Scrolls to match the height of its sibling panel instead of its own
   content — a fixed max-height would cap it short and leave empty space
   below when the sibling (e.g. branch standings) is taller. A floor keeps
   it from collapsing to nothing when the sibling is very short. */
.table-wrap-scroll {
  overflow-y: auto;
  min-height: 200px;
}
.table-wrap-scroll thead th {
  position: sticky;
  top: 0;
  background: var(--surface-card);
  z-index: 1;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  html { font-size: 14px; }
  .header-inner { gap: 0.5rem; }
  .nav { gap: 0; }
  .nav-link { padding: 0.5rem 0.5rem; font-size: 0.8rem; }
  .user-menu { gap: 0.4rem; }
  .user-office { display: none; }
  .score-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .score-card .score-value { font-size: 1.8rem; }
}

@media (max-width: 480px) {
  .score-grid { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .score-card { padding: 0.8rem; }
  .score-card .score-value { font-size: 1.5rem; }
}

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