/* ==========================================================================
   THSBA Portal — theme.css
   Unified design system. Palette from thsba.net (primary #000095, red #F44336).
   Self-contained: no build step, no external fonts (system stacks only),
   light + dark aware. Load this INSTEAD of the old template main.css.
   ========================================================================== */

:root {
  --font-brand: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* light theme */
  --bg: #F1F3F9;
  --surface: #FFFFFF;
  --surface-2: #EDF0F8;
  --border: #DBE0EE;
  --border-strong: #C5CDE3;
  --text: #14172B;
  --text-muted: #545B76;
  --text-faint: #838AA4;
  --brand-navy: #000095;      /* THSBA primary blue */
  --brand-navy-2: #16169F;
  --accent: #000095;          /* primary interactive */
  --accent-strong: #1E1EB0;
  --accent-soft: #E2E3F6;
  --accent-ink: #00006B;
  --pop: #D8352C;             /* THSBA red accent */
  --pop-strong: #B4271F;
  --pop-soft: #FBE2E0;
  --good: #1F7A4D;
  --good-soft: #DDEEE3;
  --warn: #A6650F;
  --warn-soft: #F6E7CE;
  --crit: #C0392B;
  --shadow-sm: 0 1px 2px rgba(0,0,80,.06), 0 1px 3px rgba(0,0,80,.08);
  --shadow-md: 0 6px 16px rgba(0,0,80,.09), 0 2px 6px rgba(0,0,80,.06);
  --shadow-lg: 0 18px 44px rgba(0,0,80,.16);
  --radius: 12px;
  --radius-sm: 8px;
  --maxw: 1120px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0A0D1F;
    --surface: #14182E;
    --surface-2: #1C2140;
    --border: #2A3058;
    --border-strong: #363D6B;
    --text: #E8EAF6;
    --text-muted: #A3A9C6;
    --text-faint: #7B8199;
    --brand-navy: #0A0A7A;
    --brand-navy-2: #16169C;
    --accent: #6E74FF;
    --accent-strong: #8F94FF;
    --accent-soft: #1E2154;
    --accent-ink: #C7CAFF;
    --pop: #FF6155;
    --pop-strong: #FF8377;
    --pop-soft: #3A1A18;
    --good: #4FB483;
    --good-soft: #12362A;
    --warn: #D6A24E;
    --warn-soft: #3A2E17;
    --crit: #E1806F;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 8px 20px rgba(0,0,0,.4);
    --shadow-lg: 0 22px 50px rgba(0,0,0,.55);
  }
}
:root[data-theme="light"] {
  --bg:#F1F3F9; --surface:#FFFFFF; --surface-2:#EDF0F8; --border:#DBE0EE;
  --border-strong:#C5CDE3; --text:#14172B; --text-muted:#545B76; --text-faint:#838AA4;
  --brand-navy:#000095; --brand-navy-2:#16169F; --accent:#000095; --accent-strong:#1E1EB0;
  --accent-soft:#E2E3F6; --accent-ink:#00006B; --pop:#D8352C; --pop-strong:#B4271F; --pop-soft:#FBE2E0;
  --good:#1F7A4D; --good-soft:#DDEEE3; --warn:#A6650F; --warn-soft:#F6E7CE; --crit:#C0392B;
  --shadow-sm:0 1px 2px rgba(0,0,80,.06),0 1px 3px rgba(0,0,80,.08);
  --shadow-md:0 6px 16px rgba(0,0,80,.09),0 2px 6px rgba(0,0,80,.06);
  --shadow-lg:0 18px 44px rgba(0,0,80,.16);
}
:root[data-theme="dark"] {
  --bg:#0A0D1F; --surface:#14182E; --surface-2:#1C2140; --border:#2A3058;
  --border-strong:#363D6B; --text:#E8EAF6; --text-muted:#A3A9C6; --text-faint:#7B8199;
  --brand-navy:#0A0A7A; --brand-navy-2:#16169C; --accent:#6E74FF; --accent-strong:#8F94FF;
  --accent-soft:#1E2154; --accent-ink:#C7CAFF; --pop:#FF6155; --pop-strong:#FF8377; --pop-soft:#3A1A18;
  --good:#4FB483; --good-soft:#12362A; --warn:#D6A24E; --warn-soft:#3A2E17; --crit:#E1806F;
  --shadow-sm:0 1px 2px rgba(0,0,0,.3); --shadow-md:0 8px 20px rgba(0,0,0,.4);
  --shadow-lg:0 22px 50px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui); background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; line-height: 1.5;
}
a { color: inherit; }
h1,h2,h3,h4 { margin: 0; text-wrap: balance; }
button { font-family: inherit; }
.tnum { font-variant-numeric: tabular-nums; }

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

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, var(--brand-navy), var(--brand-navy-2));
  color: #EAF4F3; box-shadow: var(--shadow-sm);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0 22px;
  height: 62px; display: flex; align-items: center; gap: 26px;
}
.brand { display: flex; align-items: baseline; gap: 9px; text-decoration: none; }
.brand .mark { font-family: var(--font-brand); font-size: 25px; font-weight: 700; letter-spacing: .5px; color: #fff; }
.brand .mark .dot { color: var(--pop); }
.brand .sub { font-size: 11px; text-transform: uppercase; letter-spacing: .18em; color: #9AA0D8; font-weight: 600; }
.waterline { height: 3px; background: linear-gradient(90deg, transparent, var(--pop) 22%, #FF6E64 50%, var(--pop) 78%, transparent); opacity: .95; }

.nav { display: flex; gap: 4px; margin-left: 8px; flex-wrap: wrap; }
.nav a { text-decoration: none; color: #C4C9EE; font-size: 14px; font-weight: 500; padding: 8px 12px; border-radius: 8px; line-height: 1; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { color: #fff; background: rgba(255,255,255,.07); box-shadow: inset 0 -2px 0 var(--pop); border-radius: 8px 8px 0 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.05); color: #D7DBF5; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.admin { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--pop); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.admin .who { font-size: 13px; line-height: 1.2; }
.admin .who b { color: #fff; font-weight: 600; display: block; }
.admin .who span { color: #9AA0CE; }

main { flex: 1; max-width: var(--maxw); width: 100%; margin: 0 auto; padding: 26px 22px 40px; }

/* eyebrow + page head */
.eyebrow { font-family: var(--font-brand); font-style: italic; color: var(--pop); font-size: 15px; margin-bottom: 4px; }
.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 27px; letter-spacing: -.01em; }
.page-head p { margin: 6px 0 0; color: var(--text-muted); font-size: 14px; max-width: 66ch; }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.stat .label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stat .num { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; }
.stat .sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

/* ---------- section title ---------- */
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 8px 0 14px; }
.section-title h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: 700; }
.section-title .rule { flex: 1; height: 1px; background: var(--border); }

/* ---------- card grid ---------- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); text-decoration: none; color: inherit; display: flex; gap: 14px; align-items: flex-start; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card .ic { flex: 0 0 42px; width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong); }
.card .body h3 { font-size: 16px; font-weight: 650; }
.card .body p { margin: 3px 0 0; font-size: 13px; color: var(--text-muted); }
.card .count { margin-top: 9px; font-size: 12px; font-weight: 600; color: var(--accent-strong); }

/* ---------- toolbar + fields ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.search input { width: 100%; padding: 10px 12px 10px 34px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--bg); color: var(--text); font-size: 14px; }
.field, input.form-control, select.field {
  padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn { border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer; font-size: 14px; font-weight: 600; padding: 10px 15px; display: inline-flex; align-items: center; gap: 7px; text-decoration: none; line-height: 1.2; }
.btn-primary { background: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #0A0E24; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-strong); }
.btn-danger { background: var(--pop-soft); color: var(--pop-strong); border-color: transparent; }
.btn-danger:hover { background: var(--pop); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

/* ---------- table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; min-width: 760px; }
table.data thead th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
table.data tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--accent-soft); }
.who-cell { display: flex; align-items: center; gap: 11px; }
.who-cell .av { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-navy); color: #D6DAFF; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.who-cell .nm { font-weight: 600; }
.who-cell .em { font-size: 12px; color: var(--text-muted); }
.thsba-no { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-muted); }
.cell-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- status pill ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.paid { color: var(--good); background: var(--good-soft); }
.pill.unpaid { color: var(--warn); background: var(--warn-soft); }
.pill.neutral { color: var(--text-muted); background: var(--surface-2); }

/* ---------- pagination ---------- */
.pager { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.pager-info { font-size: 13px; color: var(--text-muted); }
.pager-controls { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager-controls .field { padding: 6px 10px; font-size: 12.5px; width: auto; }
.pager-controls .btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty svg { color: var(--text-faint); margin-bottom: 10px; }

/* ---------- login ---------- */
.login-wrap { flex: 1; display: grid; place-items: center; padding: 40px 22px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden; }
.login-hero { background: linear-gradient(160deg, var(--brand-navy) 20%, #23239E); padding: 30px 30px 26px; color: #EAEDFB; position: relative; overflow: hidden; }
.login-hero .mark { font-family: var(--font-brand); font-size: 30px; font-weight: 700; color: #fff; }
.login-hero .mark .dot { color: #FF6E64; }
.login-hero p { margin: 6px 0 0; font-size: 13px; color: #AEB4E8; }
.login-hero .ripple { position: absolute; right: -40px; bottom: -70px; width: 200px; height: 200px; border-radius: 50%; border: 1.5px solid rgba(255,110,100,.30); box-shadow: 0 0 0 22px rgba(255,110,100,.07), 0 0 0 52px rgba(255,110,100,.04); }
.login-body { padding: 24px 30px 30px; }
.field-group { margin-bottom: 15px; }
.field-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.field-group input { width: 100%; padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--bg); color: var(--text); font-size: 14px; }
.login-body .btn-primary { width: 100%; justify-content: center; margin-top: 6px; padding: 12px; }
.login-foot { margin-top: 14px; text-align: center; font-size: 13px; color: var(--text-muted); }
.login-foot a { color: var(--accent-strong); text-decoration: none; font-weight: 600; }
.login-foot a:hover { text-decoration: underline; }

/* ---------- footer ---------- */
.site-footer { background: var(--brand-navy); color: #A8C6C8; margin-top: auto; }
.footer-inner { max-width: var(--maxw); margin: 0 auto; padding: 22px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: 13px; }
.footer-inner .fbrand { font-family: var(--font-brand); color: #fff; font-weight: 700; font-size: 16px; }
.footer-inner .copy { color: #9298C4; }
.socials { margin-left: auto; display: flex; gap: 8px; }
.socials a { width: 32px; height: 32px; border-radius: 8px; background: rgba(255,255,255,.06); display: grid; place-items: center; color: #C3C8EE; text-decoration: none; }
.socials a:hover { background: var(--pop); color: #fff; }

/* ---------- legacy content compatibility ----------
   Scoped to `.legacy` so pages that still use the old template markup
   (forms, ul.divided, .button) get themed without rewriting their bindings.
   Does NOT leak into the rebuilt table pages. */
.legacy { font-size: 14px; color: var(--text); }
.legacy h2 { font-size: 20px; margin: 18px 0 10px; }
.legacy h3 { font-size: 16px; margin: 16px 0 6px; }
.legacy h4 { font-size: 14px; color: var(--text-muted); font-weight: 600; margin: 4px 0; }
.legacy label { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.legacy p, .legacy article { line-height: 1.55; }
.legacy input[type="text"], .legacy input[type="password"], .legacy input[type="email"],
.legacy input.form-control, .legacy input:not([type]), .legacy textarea, .legacy select {
  padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit;
  margin: 4px 0; max-width: 440px; width: 100%;
}
.legacy input[type="file"] { font-size: 13px; color: var(--text-muted); margin: 6px 0; }
.legacy input[type="checkbox"], .legacy input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; vertical-align: middle; margin-right: 8px; }
.legacy button, .legacy .button, .legacy a.button {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; text-decoration: none;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font-size: 13.5px; font-weight: 600; padding: 8px 13px; margin: 4px 6px 4px 0; line-height: 1.2;
}
.legacy button:hover, .legacy .button:hover, .legacy a.button:hover { border-color: var(--accent); color: var(--accent-strong); }
.legacy a.button { background: var(--accent); color: #fff; border-color: transparent; }
:root[data-theme="dark"] .legacy a.button { color: #0A0E24; }
.legacy a.button:hover { background: var(--accent-strong); color: #fff; }
.legacy ul { list-style: none; padding-left: 0; margin: 8px 0; }
.legacy ul.divided > li { padding: 14px 0; border-bottom: 1px solid var(--border); }
.legacy ul.divided > li:last-child { border-bottom: 0; }
.legacy ul.actions { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.legacy ul.actions > li { padding: 2px 0; }
.legacy ul.menu { display: flex; flex-wrap: wrap; gap: 8px; }
.legacy .image.featured img, .legacy img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .cards { grid-template-columns: 1fr 1fr; }
  .nav { display: none; }
}
@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
  .admin .who { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
}
