/* ============================================================
   Welfare Accounting — design tokens
   Palette: paper-ledger neutrals + deep ledger-green + stamp gold
   Type: Sora (display) / Inter (UI) / IBM Plex Mono (figures)
   ============================================================ */
:root{
  --bg: #F6F4EE;
  --surface: #FFFFFF;
  --surface-soft: #FBFAF6;
  --ink: #1C2B22;
  --ink-soft: #5B6960;
  --ink-faint: #8B968D;
  --primary: #0B6E4F;
  --primary-dark: #084F39;
  --primary-soft: #E4F0EA;
  --accent: #C98A2C;
  --accent-soft: #F6EAD3;
  --border: #E3DFD3;
  --danger: #B3261E;
  --danger-soft: #F8E6E4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28,43,34,0.06), 0 4px 16px rgba(28,43,34,0.05);
  --font-display: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-body: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Consolas', 'Courier New', monospace;
}

*{ box-sizing: border-box; }

/* The [hidden] attribute is toggled by app.js to switch between the login
   screen and the app shell. Without this rule, author styles below that set
   display:flex on .login-screen/.app-shell would silently override the
   browser's default [hidden]{display:none}, since author CSS always beats
   the user-agent stylesheet regardless of selector specificity — so both
   screens would render stacked on top of each other. */
[hidden]{ display: none !important; }
html,body{ height: 100%; }
body{
  margin:0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4{ font-family: var(--font-display); margin:0; color: var(--ink); }
code{ font-family: var(--font-mono); background: var(--surface-soft); padding: 1px 5px; border-radius: 4px; }
a{ color: var(--primary); }

/* ---------- Ledger stamp mark (signature element) ---------- */
.ledger-mark{
  width: 52px; height: 52px;
  display:flex; align-items:center; justify-content:center;
  font-family: var(--font-display); font-weight:700; font-size: 18px;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 8px;
  position: relative;
  transform: rotate(-2deg);
}
.ledger-mark::after{
  content:"";
  position:absolute; inset: 4px;
  border: 1px solid var(--primary);
  border-radius: 5px;
  opacity: .5;
}
.ledger-mark.small{ width:36px; height:36px; font-size:13px; }

/* ---------- Login screen ---------- */
.login-screen{
  min-height:100vh; display:flex; align-items:center; justify-content:center;
  background:
    repeating-linear-gradient(180deg, transparent, transparent 27px, rgba(28,43,34,0.035) 28px),
    var(--bg);
  padding: 24px;
}
.login-card{
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  text-align:center;
}
.login-card h1{ font-size: 22px; margin-top: 16px; }
.login-sub{ color: var(--ink-soft); font-size: 13px; margin: 6px 0 24px; }
.login-card form{ text-align:left; display:flex; flex-direction:column; gap:14px; }
.login-card label{ font-size:13px; font-weight:600; color: var(--ink-soft); display:flex; flex-direction:column; gap:6px; }
.login-hint{ font-size:11.5px; color: var(--ink-faint); margin-top:18px; line-height:1.5; }

/* ---------- Inputs / buttons ---------- */
input, select, textarea{
  font-family: var(--font-body);
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus{
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}
label{ font-size:13px; color: var(--ink-soft); font-weight:600; }

.btn{
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .12s ease;
}
.btn:focus-visible{ outline: 2px solid var(--accent); outline-offset:2px; }
.btn-primary{ background: var(--primary); color: #fff; }
.btn-primary:hover{ background: var(--primary-dark); }
.btn-ghost{ background: transparent; color: var(--ink-soft); border-color: var(--border); }
.btn-ghost:hover{ background: var(--surface-soft); color: var(--ink); }
.btn-accent{ background: var(--accent); color: #fff; }
.btn-danger{ background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-sm{ padding: 5px 10px; font-size: 12px; }
.btn-block{ width:100%; }
.form-error{ background: var(--danger-soft); color: var(--danger); font-size: 12.5px; padding: 8px 10px; border-radius: 6px; }

/* ---------- App shell ---------- */
/* height (not min-height) + overflow:hidden locks the whole shell to exactly
   the viewport — nothing here scrolls as a single page. The sidebar and the
   main content area each get their own independent scroll region below, so
   scrolling a long list never drags the nav out of view. */
.app-shell{ display:flex; height:100vh; overflow:hidden; }
.sidebar{
  width: 232px; flex-shrink:0;
  background: var(--primary-dark);
  color: #EAF3EE;
  display:flex; flex-direction:column;
  padding: 20px 14px;
  height:100vh; overflow:hidden;
}
.brand{ display:flex; align-items:center; gap:10px; padding: 4px 6px 20px; border-bottom: 1px solid rgba(255,255,255,0.12); margin-bottom: 14px;}
.brand .ledger-mark{ border-color:#EAF3EE; color:#EAF3EE; }
.brand .ledger-mark::after{ border-color:#EAF3EE; }
.brand-name{ font-family: var(--font-display); font-weight:600; font-size:14px; line-height:1.25; }
.brand-sub{ font-size:11px; color: #AFCFC0; }

.main-nav{ flex:1; display:flex; flex-direction:column; gap:2px; overflow-y:auto; }
.main-nav::-webkit-scrollbar{ width:6px; }
.main-nav::-webkit-scrollbar-track{ background:transparent; }
.main-nav::-webkit-scrollbar-thumb{ background:rgba(255,255,255,0.18); border-radius:3px; }
.main-nav::-webkit-scrollbar-thumb:hover{ background:rgba(255,255,255,0.3); }
.main-nav{ scrollbar-width:thin; scrollbar-color:rgba(255,255,255,0.18) transparent; }
.nav-section{ font-size:10.5px; text-transform:uppercase; letter-spacing:.06em; color:#7FAE9A; margin: 14px 8px 4px; }
.nav-item{
  display:flex; align-items:center; gap:9px;
  padding: 8px 10px; border-radius: 7px;
  font-size: 13.5px; font-weight:500; color:#D6E9DF;
  cursor:pointer; text-decoration:none;
}
.nav-item:hover{ background: rgba(255,255,255,0.08); }
.nav-item.active{ background: rgba(255,255,255,0.14); color:#fff; }
.nav-dot{ width:6px; height:6px; border-radius:50%; background: var(--accent); flex-shrink:0; }

.sidebar-footer{ border-top: 1px solid rgba(255,255,255,0.12); padding-top: 12px; margin-top: 10px; }
.user-badge{ font-size:12.5px; color:#D6E9DF; margin-bottom:8px; }
.user-badge .role-tag{ display:inline-block; background: rgba(255,255,255,0.14); color:#fff; border-radius:4px; padding:1px 6px; font-size:10.5px; margin-top:3px; }
.sidebar-footer .btn-ghost{ color:#D6E9DF; border-color: rgba(255,255,255,0.25); }
.sidebar-footer .btn-ghost:hover{ background: rgba(255,255,255,0.1); color:#fff; }

.content{ flex:1; min-width:0; display:flex; flex-direction:column; height:100vh; overflow:hidden; }
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding: 20px 32px; border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink:0;
}
.page-content{ padding: 26px 32px 60px; flex:1; overflow-y:auto; }

/* ---------- Notification bell ---------- */
.topbar-right{ display:flex; align-items:center; gap:12px; }
.notif-bell-wrap{ position:relative; }
.notif-bell-count{
  position:absolute; top:-4px; right:-4px; background:var(--danger); color:#fff;
  font-size:10px; font-weight:700; line-height:1; min-width:16px; height:16px;
  border-radius:8px; display:flex; align-items:center; justify-content:center; padding:0 3px;
}
.notif-dropdown{
  position:absolute; top:calc(100% + 8px); right:0; width:340px; max-height:420px; overflow-y:auto;
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  box-shadow:var(--shadow); z-index:200;
}
.notif-dropdown-header{ display:flex; justify-content:space-between; align-items:center; padding:12px 14px; border-bottom:1px solid var(--border); font-weight:600; font-size:13px; }
.notif-item{ padding:12px 14px; border-bottom:1px solid var(--border); cursor:pointer; font-size:13px; }
.notif-item:hover{ background:var(--surface-soft); }
.notif-item:last-child{ border-bottom:none; }
.notif-item.unread{ background:rgba(11,110,79,0.05); }
.notif-item-title{ font-weight:600; margin-bottom:2px; }
.notif-item-message{ color:var(--ink-soft); font-size:12px; }
.notif-item-time{ color:var(--ink-faint); font-size:11px; margin-top:4px; }
.notif-empty{ padding:24px 14px; text-align:center; color:var(--ink-faint); font-size:13px; }

/* ---------- Cards / tables ---------- */
.card{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
.card-header{ display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
.card-title{ font-family: var(--font-display); font-size: 15px; font-weight:600; }

table{ width:100%; border-collapse: collapse; font-size: 13.5px; }
thead th{
  text-align:left; font-size:11px; text-transform:uppercase; letter-spacing:.04em;
  color: var(--ink-faint); font-weight:600; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
tbody td{ padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td{ border-bottom:none; }
tbody tr:hover{ background: var(--surface-soft); }
.num{ font-family: var(--font-mono); text-align:right; font-variant-numeric: tabular-nums; white-space:nowrap; }
.mono{ font-family: var(--font-mono); }
.text-soft{ color: var(--ink-soft); }
.text-faint{ color: var(--ink-faint); font-size:12px; }
.text-danger{ color: var(--danger); }

.badge{ display:inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight:600; }
.badge-green{ background: var(--primary-soft); color: var(--primary-dark); }
.badge-gold{ background: var(--accent-soft); color: #8A5B10; }
.badge-red{ background: var(--danger-soft); color: var(--danger); }
.badge-grey{ background: var(--surface-soft); color: var(--ink-soft); border:1px solid var(--border); }

/* ---------- KPI stat cards ---------- */
.stat-grid{ display:grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 16px; margin-bottom: 22px; }
.stat-grid-compact{ grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: 10px; }
.stat-grid-compact .stat-card{ padding: 10px 14px; }
.stat-grid-compact .stat-label{ font-size: 11px; }
.stat-grid-compact .stat-value{ font-size: 18px; }
.stat-card{ background: var(--surface); border:1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-label{ font-size:11.5px; color: var(--ink-faint); text-transform:uppercase; letter-spacing:.04em; margin-bottom:8px; }
.stat-value{ font-family: var(--font-mono); font-size: 24px; font-weight:600; color: var(--primary-dark); }
.stat-sub{ font-size:11.5px; color: var(--ink-faint); margin-top:4px; }

/* ---------- Dashboard quick-count cards ---------- */
.quick-count-row{ display:grid; grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: 14px; margin-bottom: 22px; }
.quick-count-card{
  display:block; text-decoration:none;
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); transition: border-color .12s ease;
}
.quick-count-card:hover{ border-color: var(--primary); }
.quick-count-value{ font-family: var(--font-mono); font-size: 21px; font-weight:600; color: var(--primary-dark); }
.quick-count-label{ font-size:12px; color: var(--ink-soft); margin-top:2px; }

/* ---------- Two-column card row (dashboard) ---------- */
.two-col{ display:grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px){ .two-col{ grid-template-columns: 1fr; } }

/* ---------- Forms in modals/panels ---------- */
.form-grid{ display:grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full{ grid-column: 1 / -1; }
.field{ display:flex; flex-direction:column; gap:5px; }

/* ---------- Modal ---------- */
.modal-backdrop{
  position: fixed; inset:0; background: rgba(20,28,23,0.45);
  display:flex; align-items:flex-start; justify-content:center; padding: 40px 16px;
  overflow-y:auto; z-index: 100;
}
.modal{
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  width: fit-content; min-width: min(480px, 100%); max-width: min(92vw, 1200px);
  padding: 24px 26px;
}
.modal table{ display:block; overflow-x:auto; max-width:100%; }
.modal.modal-wide{ max-width: min(960px, 92vw); }
.modal.modal-sm{ max-width: min(480px, 92vw); min-width: min(320px, 100%); }
.modal.modal-md{ max-width: min(720px, 92vw); }
.modal.modal-lg{ max-width: min(960px, 92vw); }
.modal.modal-xl{ max-width: min(1100px, 92vw); }
.clickable-row{ cursor:pointer; }
.clickable-row:hover{ background:var(--surface-soft); }
.modal-header{ display:flex; align-items:center; justify-content:space-between; margin-bottom:18px; }
.modal-close{ background:none; border:none; font-size:20px; cursor:pointer; color: var(--ink-faint); line-height:1;}
.modal-actions{ display:flex; justify-content:flex-end; gap:10px; margin-top:20px; }

/* ---------- Searchable/paginated list controls ---------- */
.list-toolbar{ display:flex; align-items:center; gap:16px; margin-bottom:16px; flex-wrap:wrap; }
.list-search{ max-width:280px; flex-shrink:0; }
.list-pagesize{ display:flex; align-items:center; gap:8px; }
.list-pagesize label{ font-size:13px; color:var(--ink-soft); font-weight:500; }
.list-pagesize select{ width:auto; padding:7px 9px; }
.list-count{ margin-left:auto; }
.list-column-filters{ display:flex; gap:12px; flex-wrap:wrap; margin-bottom:14px; padding:12px 14px; background:var(--surface-soft); border:1px solid var(--border); border-radius:8px; }
.list-colfilter{ display:flex; flex-direction:column; gap:4px; min-width:130px; flex:1; }
.list-colfilter label{ font-size:11px; text-transform:uppercase; letter-spacing:.03em; color:var(--ink-faint); font-weight:600; }
.list-colfilter input, .list-colfilter select{ padding:6px 9px; font-size:13px; }
.list-pagination{ display:flex; align-items:center; gap:4px; justify-content:center; margin-top:18px; flex-wrap:wrap; }

/* ---------- Icon-only action buttons ---------- */
.btn-icon{ width:30px; height:30px; padding:0; display:inline-flex; align-items:center; justify-content:center; }

/* ---------- Sortable list headers ---------- */
.list-sortable-th{ cursor:pointer; user-select:none; white-space:nowrap; }
.list-sortable-th:hover{ color:var(--brand); }
.list-sortable-th.sort-asc::after{ content:" \25B2"; font-size:10px; opacity:0.7; }
.list-sortable-th.sort-desc::after{ content:" \25BC"; font-size:10px; opacity:0.7; }

/* ---------- Class & Section box grid (School Dashboard) ---------- */
.class-section-grid{ display:grid; grid-template-columns:repeat(auto-fill, minmax(120px, 1fr)); gap:12px; }
.class-section-box{
  border:1px solid var(--border); border-radius:var(--radius); padding:14px 12px;
  text-align:center; background:var(--surface-soft);
}
.class-section-box-class{ font-weight:600; font-size:13.5px; }
.class-section-box-section{ font-size:11.5px; color:var(--ink-faint); margin-top:2px; }
.class-section-box-count{ font-size:22px; font-weight:700; color:var(--brand); margin-top:8px; }

/* ---------- Build credit ---------- */
.build-credit{ text-align:center; font-size:10px; color:var(--ink-faint); opacity:0.6; margin-top:10px; }

/* ---------- Empty state ---------- */
.empty-state{ text-align:center; padding: 40px 20px; color: var(--ink-faint); }
.empty-state .ledger-mark{ margin: 0 auto 14px; opacity:.5; }

/* ---------- Toast ---------- */
#toast-container{ position: fixed; bottom: 20px; right: 20px; display:flex; flex-direction:column; gap:8px; z-index: 200; }
.toast{
  background: var(--ink); color:#fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow); min-width: 220px;
}
.toast.error{ background: var(--danger); }
.toast.success{ background: var(--primary); }

/* ---------- Utility ---------- */
.flex{ display:flex; align-items:center; gap:10px; }
.gap-8{ gap:8px; }
.mt-16{ margin-top:16px; }
.section-title{ font-family: var(--font-display); font-size: 13px; font-weight:600; color: var(--primary-dark); text-transform:uppercase; letter-spacing:.03em; border-bottom: 2px solid var(--primary-soft); padding-bottom:6px; margin: 22px 0 10px; }
.section-title:first-child{ margin-top:0; }

/* Mobile hamburger button */
.mobile-menu-btn{
  display:none;
  align-items:center;
  justify-content:center;
  width:38px; height:38px;
  border:none;
  background:transparent;
  border-radius:7px;
  cursor:pointer;
  color:var(--ink);
  flex-shrink:0;
  padding:0;
}
.mobile-menu-btn:hover{ background:var(--surface-soft); }

@media (max-width: 860px){
  .sidebar{ display:none; position:fixed; top:0; left:0; height:100vh; z-index:999; width:240px; overflow-y:auto; }
  .sidebar.sidebar-open{ display:flex !important; }
  .mobile-menu-btn{ display:inline-flex !important; }
  .page-content, .topbar{ padding-left:16px; padding-right:16px; }
  .form-grid{ grid-template-columns:1fr; }
}

@media (min-width: 861px){
  .mobile-menu-btn{ display:none !important; }
  .sidebar{ display:flex !important; position:relative; }
}

/* ---------- Dashboard customizer ---------- */
.dash-widget{ margin-bottom:16px; }
.dash-widget-hidden{ border: 1px dashed var(--border); border-radius: 10px; padding: 4px; }
.dash-widget-controls{
  display:flex; justify-content:space-between; align-items:center;
  background: var(--primary-soft); border-radius: 8px 8px 0 0;
  padding: 6px 12px; font-size: 13px;
}
.dash-widget-name{ font-weight:600; color: var(--primary-dark); }
.dash-widget-buttons{ display:flex; gap:6px; }
.dash-widget-buttons .btn{ padding: 2px 10px; }
