/* ============================================================
   Serevo — main stylesheet
   Uses CSS custom properties set in base.html:
     --brand-accent, --brand-accent-light
   ============================================================ */

/* ---------- reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --text:      #1a1a2e;
  --text-muted:#6b7280;
  --border:    #e5e7eb;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(0,0,0,.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0f1117;
    --surface:   #1a1c25;
    --text:      #e4e4e7;
    --text-muted:#9ca3af;
    --border:    #2a2d38;
    --shadow:    0 1px 3px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:        #0f1117;
  --surface:   #1a1c25;
  --text:      #e4e4e7;
  --text-muted:#9ca3af;
  --border:    #2a2d38;
  --shadow:    0 1px 3px rgba(0,0,0,.3);
  color-scheme: dark;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

a { color: var(--brand-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- nav ---------- */
nav {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: relative;
}
nav .brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--brand-accent);
  letter-spacing: -.02em;
}
nav .demo-badge {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-accent-light);
  color: var(--brand-accent);
}
nav .nav-links {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}
nav .nav-links a {
  font-size: .875rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 0;
}
nav .nav-links a:hover,
nav .nav-links a.active { color: var(--brand-accent); text-decoration: none; }

/* ── Nav dropdowns ── */
.nav-dropdown {
  position: relative;
}
.nav-dropdown-btn {
  background: none;
  border: none;
  font-size: .875rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 0;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 3px;
}
.nav-dropdown-btn:hover,
.nav-dropdown.has-active > .nav-dropdown-btn {
  color: var(--brand-accent);
}
.nav-dropdown-btn .caret {
  font-size: .65rem;
  transition: transform .2s;
}
.nav-dropdown:hover .nav-dropdown-btn .caret {
  transform: rotate(180deg);
}
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  min-width: 180px;
  padding: 6px 0;
  z-index: 1000;
}
.nav-dropdown:hover .nav-dropdown-menu {
  display: block;
}
.nav-dropdown-menu a {
  display: block;
  padding: 8px 16px;
  font-size: .85rem;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}
.nav-dropdown-menu a:hover {
  background: var(--hover, rgba(0,0,0,.04));
  color: var(--brand-accent);
}
.nav-dropdown-menu a.active {
  color: var(--brand-accent);
  font-weight: 600;
}

nav .user-name {
  margin-left: auto;
  font-size: .875rem;
  color: var(--text-muted);
}

/* hamburger button — hidden on desktop */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin-left: auto;
  flex-direction: column;
  gap: 4px;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}

/* ---------- main ---------- */
main {
  flex: 1;
  padding: 32px 24px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  overflow-x: hidden;
}

/* ---------- footer ---------- */
footer {
  padding: 20px 24px;
  text-align: center;
  font-size: .8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ---------- login card ---------- */
.login-card {
  max-width: 400px;
  margin: 80px auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 {
  font-size: 1.6rem;
  color: var(--brand-accent);
  margin-bottom: 4px;
}
.login-card > p {
  color: var(--text-muted);
  font-size: .9rem;
  margin-bottom: 28px;
}
.login-card form { text-align: left; }
.login-card label,
.login-card .form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.login-card input[type="email"],
.login-card input[type="password"],
.login-card input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .95rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.login-card input:focus {
  border-color: var(--brand-accent);
}
.login-card .hint {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 8px;
}
.login-card .hint code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .75rem;
}
.login-card button {
  width: 100%;
  margin-top: 20px;
  padding: 11px;
  border: none;
  border-radius: 6px;
  background: var(--brand-accent);
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.login-card button:hover { opacity: .88; }
.login-card .error {
  margin-top: 16px;
  padding: 10px;
  border-radius: 6px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: .85rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .login-card .error {
    background: #2d1515;
    color: #fca5a5;
  }
}

/* ---------- dashboard ---------- */
.dashboard h1 { font-size: 1.5rem; margin-bottom: 4px; }
.dashboard .subtitle { color: var(--text-muted); margin-bottom: 28px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 1rem; margin-bottom: 6px; }
.card p { font-size: .85rem; color: var(--text-muted); margin-bottom: 12px; }

.badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 3px 10px;
  border-radius: 999px;
}
.badge.coming-soon {
  background: var(--brand-accent-light);
  color: var(--brand-accent);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background .15s, border-color .15s;
  min-height: 44px; /* touch target */
}
.btn-primary {
  background: var(--brand-accent);
  color: #fff;
  border-color: var(--brand-accent);
}
.btn-primary:hover { opacity: .9; text-decoration: none; }
.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover { border-color: var(--brand-accent); color: var(--brand-accent); text-decoration: none; }
.btn-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover { opacity: .9; }
.btn-sm { padding: 4px 12px; font-size: .8rem; min-height: 36px; }

/* ---------- forms ---------- */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* prevents iOS zoom on focus */
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 2px var(--brand-accent-light);
}

/* ---------- modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  box-shadow: 0 8px 30px rgba(0,0,0,.15);
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { font-size: 1.2rem; margin-bottom: 1rem; }

/* ---------- status badges ---------- */
.status-badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: capitalize;
}
.status-ok, .status-complete, .status-connected { background: #d1fae5; color: #065f46; }
.status-error { background: #fee2e2; color: #991b1b; }
.status-untested, .status-pending, .status-configured { background: #fef3c7; color: #92400e; }
.status-processing { background: #dbeafe; color: #1e40af; }
.status-not-configured { background: var(--bg); color: var(--text-muted); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    .status-ok, .status-complete, .status-connected { background: #064e3b; color: #6ee7b7; }
    .status-error { background: #7f1d1d; color: #fca5a5; }
    .status-untested, .status-pending, .status-configured { background: #78350f; color: #fde68a; }
    .status-processing { background: #1e3a5f; color: #93c5fd; }
  }
}

/* ---------- data tables ---------- */
.data-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  white-space: nowrap;
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-muted);
}

/* ---------- page headers ---------- */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; margin-bottom: 4px; }
.page-header .subtitle { color: var(--text-muted); font-size: .95rem; }

/* ---------- card links ---------- */
.card-link { text-decoration: none; color: inherit; transition: border-color .15s; }
.card-link:hover { border-color: var(--brand-accent); text-decoration: none; }

/* ---------- connections grid ---------- */
.connections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
}

/* ---------- column hints ---------- */
.column-hints {
  background: var(--brand-accent-light);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 1rem;
  font-size: .85rem;
}
.column-hints p { color: var(--text); margin-bottom: 4px; }

/* ---------- people section ---------- */
.people-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0;
}
.people-header h1 { font-size: 1.5rem; margin-bottom: 2px; }
.people-header .subtitle { color: var(--text-muted); font-size: .9rem; }

.tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}
.tab-bar a {
  padding: 10px 20px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-bar a:hover { color: var(--text); }
.tab-bar a.active {
  color: var(--brand-accent);
  border-bottom-color: var(--brand-accent);
  font-weight: 600;
}

/* ---------- text helpers ---------- */
.text-muted { color: var(--text-muted); }

/* ============================================================
   RESPONSIVE — mobile first adjustments
   ============================================================ */

@media (max-width: 768px) {
  /* show hamburger */
  .nav-toggle {
    display: flex;
  }

  /* hide nav links by default on mobile */
  nav .nav-links {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding-top: 8px;
  }
  nav.open .nav-links {
    display: flex;
  }
  nav .nav-links > a {
    padding: 10px 0;
    width: 100%;
    border-bottom: 1px solid var(--border);
    font-size: .95rem;
  }
  nav .nav-links > a:last-child {
    border-bottom: none;
  }
  /* Mobile dropdowns: inline toggle instead of hover */
  .nav-dropdown {
    width: 100%;
    border-bottom: 1px solid var(--border);
  }
  .nav-dropdown-btn {
    padding: 10px 0;
    width: 100%;
    font-size: .95rem;
    justify-content: space-between;
  }
  .nav-dropdown:hover .nav-dropdown-menu {
    display: none;
  }
  .nav-dropdown.open .nav-dropdown-menu {
    display: block;
  }
  .nav-dropdown-menu {
    position: static;
    transform: none;
    box-shadow: none;
    border: none;
    border-radius: 0;
    padding: 0 0 4px 16px;
    min-width: 0;
  }
  .nav-dropdown-menu a {
    padding: 8px 0;
    font-size: .9rem;
  }
  nav .user-name {
    margin-left: 0;
    padding: 10px 0 4px;
    font-size: .85rem;
    width: 100%;
    border-bottom: 1px solid var(--border);
  }

  /* layout */
  nav { padding: 12px 16px; }
  main { padding: 20px 16px; }
  footer { padding: 16px; }

  /* login */
  .login-card { margin-top: 32px; padding: 28px 20px; }
  .login-card h1 { font-size: 1.3rem; }

  /* cards */
  .card-grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 20px; }

  /* settings grid */
  .connections-grid { grid-template-columns: 1fr; }

  /* page headers */
  .page-header h1 { font-size: 1.25rem; }
  .people-header h1 { font-size: 1.25rem; }

  /* tab bar — scroll on small screens */
  .tab-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-bar a { white-space: nowrap; padding: 10px 14px; font-size: .8rem; }

  /* modals */
  .modal { padding: 20px; }
  .modal-overlay { padding: .5rem; align-items: flex-end; }

  /* buttons — stack on small screens */
  .btn { padding: 10px 18px; }
}

@media (max-width: 480px) {
  .card-grid { grid-template-columns: 1fr; }
  .dashboard h1 { font-size: 1.2rem; }
}

/* ── Stat card value/label styling ────────────────────── */
.stat-row .card .stat-val,
.stat-row .stat-card .stat-val {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--brand-accent);
  line-height: 1.2;
}
.stat-row .card .stat-label,
.stat-row .stat-card .stat-label {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Responsive form grids ─────────────── */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 1rem; }
.form-grid-7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: .5rem; }

@media (max-width: 768px) {
  .form-grid-2,
  .form-grid-3,
  .form-grid-4 { grid-template-columns: 1fr; }
  .form-grid-7 { grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); }

  /* ── mobile button sizing ── */
  .btn-sm { min-height: 36px; padding: 8px 12px; font-size: .8rem; }
  .btn-xs { min-height: 32px; padding: 6px 10px; }

  /* ── tab bars scroll on mobile ── */
  .tab-strip { overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .tab-strip a, .tab-strip button { white-space: nowrap; }

  /* ── flex rows wrap on mobile ── */
  .flex-wrap-mobile { flex-wrap: wrap !important; }

  /* ── dialogs ── */
  dialog { width: 90vw !important; max-width: 440px; }

  /* ── search results fixed positioning on mobile ── */
  #searchResults {
    position: fixed !important;
    left: 16px !important;
    right: 16px !important;
    top: 56px !important;
    width: auto !important;
  }
}

@media (max-width: 600px) {
  .form-grid-2 { grid-template-columns: 1fr; }
}

/* ── Sortable table headers ─────────────── */
table.sortable thead th { cursor: pointer; user-select: none; white-space: nowrap; }
table.sortable thead th:hover { background: var(--bg-hover, rgba(0,0,0,0.04)); }
table.sortable thead th[data-sort="none"] { cursor: default; }
table.sortable thead th[data-sort="none"]:hover { background: inherit; }
.sort-indicator { font-size: 0.75em; opacity: 0.3; }
th[data-sort-dir] .sort-indicator { opacity: 0.7; }

/* ── Filter bar helpers ─────────────────── */
.filter-bar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; margin-bottom: 1rem; }
.filter-bar label { font-size: 0.82rem; font-weight: 600; display: flex; flex-direction: column; gap: 0.25rem; }
.filter-bar input, .filter-bar select { padding: 0.4rem 0.6rem; border: 1px solid var(--border, #d1d5db); border-radius: 6px; font-size: 0.85rem; }
.filter-bar .filter-clear { align-self: flex-end; font-size: 0.8rem; color: var(--brand-accent); cursor: pointer; border: none; background: none; padding: 0.4rem 0; }

/* ── Stat card rows — responsive, no side-scroll ────── */
.stat-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.stat-row > .card,
.stat-row > .stat-card,
.stat-row > [class*="stat"] {
  flex: 1 1 120px;
  min-width: 0;
  text-align: center;
}
@media (max-width: 600px) {
  .stat-row { gap: .5rem; }
  .stat-row > .card,
  .stat-row > .stat-card,
  .stat-row > [class*="stat"] { flex: 1 1 calc(50% - .5rem); padding: 14px 10px; }
}

/* ── Global anti-scroll: prevent any flex row from overflowing main ── */
main { overflow-x: hidden; }
main > *, main > * > * { max-width: 100%; }

/* ── Stat cards used across pages — override inline min-width ── */
.stat-card {
  min-width: 0 !important;
  flex: 1 1 0%;
}

/* ── Stats row pattern (attendance, etc.) ── */
.stats-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.stats-row > .stat,
.stats-row > [class*="stat"] {
  flex: 1 1 0%;
  min-width: 0;
}
@media (max-width: 600px) {
  .stats-row { gap: .5rem; }
  .stats-row > .stat,
  .stats-row > [class*="stat"] { flex: 1 1 calc(50% - .5rem); }
}

/* ── Score panels / metric rows — prevent overflow from inline min-width ── */
.score-panel,
.metric-row,
.kpi-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.score-panel > *,
.metric-row > *,
.kpi-row > * {
  flex: 1 1 0%;
  min-width: 0 !important;
}

/* ── Section cards — full-width stacking, no overflow ── */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

/* ── Tables that must scroll — contained within card ── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -24px;
  padding: 0 24px;
}
@media (max-width: 768px) {
  .table-scroll { margin: 0 -20px; padding: 0 20px; }
}

/* ---------- multi-select LOB/PU picker ---------- */
.ms-picker { position: relative; display: inline-block; }
.ms-picker-btn {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: .85rem; background: var(--bg); color: var(--text);
  cursor: pointer; min-width: 180px; text-align: left;
  display: flex; justify-content: space-between; align-items: center;
  white-space: nowrap;
}
.ms-picker-btn::after { content: "▾"; margin-left: 8px; font-size: .7rem; }
.ms-dropdown {
  display: none; position: absolute; top: 100%; left: 0; z-index: 200;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
  max-height: 300px; overflow-y: auto; min-width: 240px; padding: 6px;
  margin-top: 2px;
}
.ms-dropdown.open { display: block; }
.ms-dropdown .ms-search {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 4px; font-size: .82rem; margin-bottom: 4px;
  background: var(--bg); color: var(--text);
}
.ms-dropdown label {
  display: flex !important; align-items: center; gap: 6px; padding: 4px 6px;
  font-size: .82rem; cursor: pointer; border-radius: 4px; flex-direction: row !important;
}
.ms-dropdown label:hover { background: var(--brand-accent-light, #edf2ff); }
.ms-dropdown label input[type="checkbox"] { width: auto !important; min-width: 14px; margin: 0; flex-shrink: 0; }
.ms-actions { display: flex; gap: 8px; padding: 4px 6px; font-size: .75rem; }
.ms-actions a { cursor: pointer; color: var(--brand-accent, #3b82f6); text-decoration: none; }
