/*
 * HTSA SMS — application styles.
 * Calm, warm, committee-friendly. No third-party UI kit; plain CSS on the
 * tokens in tokens.css. Mobile: the sidebar collapses to a drawer at 1024px,
 * verified clean down to 360px.
 */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  background-image: var(--page-bg);
  background-attachment: fixed;
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--maroon); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
.display { font-family: var(--font-serif); font-weight: 700; }

/* ------------------------------------------------------------------ *
 * Shell
 * ------------------------------------------------------------------ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(180deg, #fffaf2, #f4ead8);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
}
.brand__mark {
  width: 44px; height: 44px;
  border-radius: 14px;
  background: var(--grad-maroon);
  color: #fff;
  display: grid; place-items: center;
  font-family: var(--font-serif); font-size: 22px; font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.brand__name { font-weight: 800; font-size: 17px; }
.brand__sub { font-size: var(--fs-xs); color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) var(--space-3) var(--space-4); }
.nav__item {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--fs-sm);
  border: 1px solid transparent;
}
.nav__item:hover { background: var(--maroon-wash); color: var(--maroon); }
.nav__item.is-active {
  background: var(--nav-active);
  color: var(--maroon-deep);
  border-color: rgba(123, 30, 43, 0.18);
  box-shadow: inset 3px 0 0 var(--maroon);
}
.nav__num {
  width: 22px; height: 22px; flex: 0 0 22px;
  border-radius: 7px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  background: var(--surface-3); color: var(--muted);
}
.nav__item.is-active .nav__num { background: var(--maroon); color: #fff; }

.sidebar__foot {
  margin-top: auto;
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--line);
  font-size: var(--fs-xs);
  color: var(--muted);
  display: flex; align-items: center; gap: var(--space-2);
}

/* Workspace */
.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.7);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar__eyebrow { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.topbar__title { font-size: var(--fs-h4); font-weight: 700; }
.topbar__spacer { margin-left: auto; }
.topbar__user { display: flex; align-items: center; gap: var(--space-3); font-size: var(--fs-sm); flex-wrap: wrap; }

.main { padding: var(--space-6); max-width: var(--content-max); width: 100%; }

/* Drawer toggle (mobile, no JS) */
.drawer-toggle { display: none; }
.drawer-btn, .drawer-scrim { display: none; }

/* ------------------------------------------------------------------ *
 * Page header & layout helpers
 * ------------------------------------------------------------------ */
.page-head { margin-bottom: var(--space-6); }
.page-head__eyebrow { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold); font-weight: 700; }
.page-head__title { font-size: var(--fs-display); margin: 4px 0; }
.page-head__desc { color: var(--muted); max-width: 70ch; }

.stack { display: flex; flex-direction: column; gap: var(--space-6); }
.row { display: flex; gap: var(--space-4); flex-wrap: wrap; align-items: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
}
.card__title { font-size: var(--fs-h4); font-weight: 700; margin-bottom: var(--space-2); }
.card__desc { color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--space-4); }

.grid { display: grid; gap: var(--space-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* Stat cards */
.stat {
  background: linear-gradient(180deg, #fffaf2, #f2e7d5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}
.stat__label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat__value { font-size: 32px; font-weight: 800; color: var(--maroon-deep); line-height: 1.1; margin-top: 4px; }
.stat__sub { font-size: var(--fs-xs); color: var(--muted); margin-top: 4px; }

/* Quick links */
.quicklinks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); }
.quicklink {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #fffaf2, #f2e7d5);
  border: 1px solid var(--line);
  text-decoration: none; color: var(--text);
  min-height: var(--tap);
}
.quicklink:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.quicklink strong { font-size: var(--fs-body); }
.quicklink span { font-size: var(--fs-xs); color: var(--muted); }

/* Empty / placeholder state */
.empty {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-5); border-radius: var(--radius-md);
  background: var(--gold-wash); border: 1px solid var(--gold-soft);
  color: #6b4f12; font-size: var(--fs-sm);
}
.empty__icon { font-size: 22px; }

/* Key / value */
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--space-6); }
.kv__row { display: flex; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) 0; border-bottom: 1px solid var(--line); }
.kv__row:last-child { border-bottom: none; }
.kv__key { color: var(--muted); font-size: var(--fs-sm); }
.kv__val { font-weight: 600; text-align: right; }

/* Tables */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: var(--space-3); border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
.table td { padding: var(--space-3); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: center; font-variant-numeric: tabular-nums; }
.table tr.is-disabled td { opacity: .55; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 700;
  background: var(--surface-3); color: var(--muted);
}
.badge--maroon { background: var(--maroon-wash); color: var(--maroon); }
.badge--gold { background: var(--gold-wash); color: #6b4f12; }
.badge--sage { background: rgba(82,105,90,0.14); color: var(--sage); }
.badge--red { background: rgba(179,48,58,0.12); color: var(--red); }

/* Tag list — compact sample chips (data quality, profiles) */
.tag-list { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0 0; padding: 0; }
.tag-list li {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-pill); padding: 4px 12px;
  font-size: var(--fs-xs); font-weight: 600;
}
.tag-list a { text-decoration: none; }

/* Section note (small intro, not a full card) */
.section-note {
  margin: 0;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--maroon-wash);
  border: 1px solid var(--line);
  font-size: var(--fs-sm);
  color: var(--muted);
}
.section-note strong { color: var(--maroon-deep); }

/* ------------------------------------------------------------------ *
 * Forms & buttons
 * ------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding: 0 var(--space-5);
  border-radius: var(--radius-pill); border: 1px solid transparent;
  font-weight: 700; font-size: var(--fs-sm); cursor: pointer; text-decoration: none;
  background: var(--surface-3); color: var(--text);
}
.btn--primary { background: var(--grad-maroon); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--line-strong); color: var(--maroon); }
.btn--danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn--danger:hover { background: var(--red); color: #fff; }
.btn--sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--fs-xs); }
.btn:hover { box-shadow: var(--shadow-sm); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--muted); }
.field-hint { font-size: var(--fs-xs); color: var(--muted); }
.field-error { font-size: var(--fs-xs); font-weight: 600; color: var(--red); }
.form-errors {
  margin: var(--space-3) 0; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--red); border-left-width: 4px;
  border-radius: var(--radius-sm); background: rgba(179, 48, 58, 0.07); color: var(--maroon-deep);
}
.form-errors ul { margin: 6px 0 0; padding-left: 1.2em; }
.form-errors li { font-size: var(--fs-sm); }
.input, .select, .textarea {
  min-height: var(--tap); padding: 10px var(--space-3);
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: #fffdf9; color: var(--text); font: inherit; font-size: var(--fs-sm); width: 100%;
}
.textarea { min-height: 80px; }

/* Search autocomplete (progressive enhancement; the form works without JS) */
.ac { position: relative; flex: 1 1 220px; min-width: 200px; }
.filters .ac .input, .ac .input { width: 100%; min-width: 0; }
.ac__panel {
  position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  max-height: 340px; overflow-y: auto; padding: 4px;
}
.ac__panel[hidden] { display: none; }
.ac__item {
  display: block; text-decoration: none; color: var(--text);
  padding: 8px 10px; border-radius: var(--radius-sm);
}
.ac__item:hover, .ac__item.is-active { background: var(--surface-3); }
.ac__label { display: block; font-weight: 700; font-size: var(--fs-sm); }
.ac__meta { display: block; font-size: var(--fs-xs, 12px); color: var(--muted); }
.ac__msg { padding: 10px; font-size: var(--fs-sm); color: var(--muted); }

/* Form theme helpers */
.field-check { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-sm); font-weight: 600; color: var(--text); cursor: pointer; margin-bottom: var(--space-3); }
.field-check input[type="checkbox"] { width: 18px; height: 18px; flex: 0 0 auto; }
.field-errors { margin: 4px 0 0; padding-left: 1.1em; }
.field--error .input, .field--error .select, .field--error .textarea { border-color: var(--red); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-top: var(--space-5); }

/* Configuration hub tiles */
.confgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.conftile {
  display: flex; flex-direction: column; gap: 4px;
  padding: var(--space-5); border-radius: var(--radius-md);
  background: linear-gradient(180deg, #fffaf2, #f2e7d5); border: 1px solid var(--line);
  text-decoration: none; color: var(--text); min-height: var(--tap);
}
.conftile:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.conftile__name { font-weight: 700; font-size: var(--fs-body); color: var(--maroon-deep); }
.conftile__count { font-size: var(--fs-xs); color: var(--muted); }
.conftile__desc { font-size: var(--fs-xs); color: var(--muted); }

/* Toolbar above a config list */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }

/* Inline filter bar (roster search) */
.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.filters .input, .filters .select { width: auto; min-width: 150px; flex: 0 1 auto; }
.filters .field-check { margin-bottom: 0; }

/* Profile quick-jump segmented nav */
.subnav { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.subnav a {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 var(--space-4);
  border-radius: var(--radius-pill); font-size: var(--fs-sm); font-weight: 700;
  text-decoration: none; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line);
}
.subnav a:hover { color: var(--maroon); background: var(--maroon-wash); }

/* Section header with an action on the right */
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }

/* Flash messages */
.flashes { display: grid; gap: var(--space-2); margin-bottom: var(--space-5); }
.flash { padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: 600; }
.flash--success { background: rgba(82,105,90,0.14); color: var(--sage); border: 1px solid rgba(82,105,90,0.25); }
.flash--error { background: rgba(179,48,58,0.12); color: var(--red); border: 1px solid rgba(179,48,58,0.25); }
.flash--warning { background: var(--gold-wash); color: #6b4f12; border: 1px solid rgba(199,155,58,0.35); }

/* Privacy note */
.privacy {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  background: var(--maroon-wash); border: 1px solid rgba(123,30,43,0.16);
  font-size: var(--fs-xs); color: var(--maroon-deep);
}

/* ------------------------------------------------------------------ *
 * Login (standalone, outside the shell) — the committee gate: deep
 * maroon backdrop with soft gold light, one centred cream card.
 * Mobile-first: full-width card, 48px tap targets, no overflow at 360px.
 * ------------------------------------------------------------------ */
.login {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: var(--space-5) var(--space-4); box-sizing: border-box;
  background:
    radial-gradient(circle at 18% 12%, rgba(199, 155, 58, 0.28), transparent 42%),
    radial-gradient(circle at 85% 92%, rgba(199, 155, 58, 0.16), transparent 46%),
    linear-gradient(160deg, #4a0f19 0%, var(--maroon) 55%, var(--maroon-deep) 100%);
}
.login__card {
  width: 100%; max-width: 420px; box-sizing: border-box;
  background: var(--surface); border: 1px solid rgba(199, 155, 58, 0.35);
  border-radius: var(--radius-lg); box-shadow: 0 24px 60px rgba(20, 6, 9, 0.45);
  padding: clamp(24px, 6vw, 40px);
}
.login__crest {
  width: 56px; height: 56px; margin: 0 auto var(--space-4);
  display: flex; align-items: center; justify-content: center;
  background: var(--maroon-deep); border: 2px solid var(--gold); border-radius: 16px;
  color: #fff; font-family: Georgia, 'Times New Roman', serif; font-size: 30px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(93, 20, 32, 0.35);
}
.login__name { text-align: center; font-family: 'Playfair Display', Georgia, serif; font-size: 26px; font-weight: 700; color: var(--maroon-deep); line-height: 1.15; }
.login__eyebrow { text-align: center; margin-top: 4px; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.14em; color: var(--gold); font-weight: 700; }
.login__desc { text-align: center; margin: var(--space-2) 0 var(--space-5); font-size: 14px; color: var(--muted); line-height: 1.5; }
.login__notice {
  margin-bottom: var(--space-4); padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--gold-wash); border: 1px solid rgba(199, 155, 58, 0.4);
  color: #6b4f12; font-size: 14px; line-height: 1.45;
}
.login__error {
  margin-bottom: var(--space-4); padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--maroon-wash); border: 1px solid rgba(179, 48, 58, 0.35);
  color: var(--maroon-deep); font-size: 14px; line-height: 1.45;
}
.login__card .field label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.login__card .field { margin-bottom: var(--space-4); }
/* 16px input text stops iOS zoom-on-focus; ~48px boxes are easy tap targets. */
.login__card .input { width: 100%; box-sizing: border-box; padding: 13px 14px; font-size: 16px; border-radius: var(--radius-sm); }
.login__submit { width: 100%; padding: 14px 16px; font-size: 16px; border-radius: var(--radius-sm); }
.login__foot { margin-top: var(--space-5); text-align: center; font-size: 12px; color: var(--muted); line-height: 1.5; }
@media (max-width: 400px) {
  .login { padding: var(--space-3); }
}

/* ------------------------------------------------------------------ *
 * Responsive — sidebar becomes a drawer at 1024px
 * ------------------------------------------------------------------ */
@media (max-width: 1100px) {
  .grid--4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid--3, .quicklinks, .confgrid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kv { grid-template-columns: 1fr; }
}

@media (max-width: 1024px) {
  .drawer-btn {
    display: inline-grid; place-items: center;
    width: var(--tap); height: var(--tap);
    border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
    background: var(--surface); cursor: pointer; font-size: 20px; color: var(--maroon);
  }
  .sidebar {
    position: fixed; z-index: 60; left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .drawer-toggle:checked ~ .shell .sidebar { transform: translateX(0); }
  .drawer-toggle:checked ~ .shell .drawer-scrim { display: block; }
  .drawer-scrim {
    position: fixed; inset: 0; z-index: 55;
    background: rgba(35,27,21,0.4);
  }
}

@media (min-width: 1025px) {
  .drawer-scrim { display: none !important; }
}

@media (max-width: 720px) {
  .main { padding: var(--space-4); }
  .grid--2, .grid--3, .grid--4, .quicklinks, .confgrid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .row { justify-content: stretch; }
  .toolbar .btn { flex: 1 1 auto; }
  .topbar { padding: var(--space-3) var(--space-4); }
  .tablewrap .table { min-width: 520px; }
  .filters .input, .filters .select { width: 100%; flex: 1 1 100%; }
  .stat__value { font-size: 26px; }
  .page-head__title { font-size: 26px; }
}
