/* =====================================================================
   TimeSheet – Techno Main Salt Lake
   Mobile-first stylesheet. Light theme by default, dark via
   html[data-theme="dark"]. No external fonts or frameworks.
   ===================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --font-sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, "Noto Sans", sans-serif;
  --font-serif: Georgia, "Times New Roman", "Noto Serif", serif;
  --font-mono: Consolas, "SFMono-Regular", Menlo, monospace;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef1f6;
  --border: #dde2ea;
  --border-strong: #c3cad6;
  --text: #182334;
  --text-muted: #5a6577;
  --primary: #1d3f72;
  --primary-hover: #163259;
  --primary-soft: #e6ecf5;
  --on-primary: #ffffff;
  --accent: #8c2f39;          /* oxblood – used sparingly */
  --accent-soft: #f7e9ea;
  --gold: #a87b16;
  --success: #1f6b43;
  --success-soft: #e5f3eb;
  --warning: #8a5a00;
  --warning-soft: #fdf3dc;
  --danger: #a3262f;
  --danger-soft: #fbe8e9;
  --info: #1d4f8c;
  --info-soft: #e7eff9;
  --focus: #2563c4;
  --shadow-sm: 0 1px 2px rgba(16, 32, 64, .06);
  --shadow: 0 1px 2px rgba(16, 32, 64, .05), 0 4px 16px rgba(16, 32, 64, .06);
  --shadow-lg: 0 12px 40px rgba(16, 32, 64, .18);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --topbar-h: 60px;
  --sidebar-w: 268px;
  --tap: 44px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0f1520;
  --surface: #161e2c;
  --surface-2: #1a2333;
  --surface-3: #202b3e;
  --border: #2b3850;
  --border-strong: #3b4a66;
  --text: #e6ebf3;
  --text-muted: #a3aec0;
  --primary: #8db4ec;
  --primary-hover: #a9c7f2;
  --primary-soft: #1d2c46;
  --on-primary: #0d1a2e;
  --accent: #e39aa2;
  --accent-soft: #3a2328;
  --gold: #e0b85a;
  --success: #6fd3a0;
  --success-soft: #16301f;
  --warning: #f1c567;
  --warning-soft: #33290f;
  --danger: #f39aa0;
  --danger-soft: #3a1c20;
  --info: #9cc2f5;
  --info-soft: #172a45;
  --focus: #9cc2f5;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 18px rgba(0, 0, 0, .25);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
img, svg { max-width: 100%; }
code { font-family: var(--font-mono); font-size: .9em; background: var(--surface-3); padding: .1em .35em; border-radius: 4px; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
:focus:not(:focus-visible) { outline: none; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: .75rem; top: -3rem; z-index: 200;
  background: var(--primary); color: var(--on-primary); padding: .6rem 1rem; border-radius: var(--radius-sm);
  text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: .75rem; color: var(--on-primary); }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 1.2em; height: 1.2em; flex: none; vertical-align: -.2em;
  fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}

.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--font-mono); font-size: .85rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.optional { font-weight: 400; color: var(--text-muted); font-size: .85em; }
.stack-sm > * + * { margin-top: .75rem; }

/* ---------- Brand ---------- */
.brand { display: inline-flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--text); min-width: 0; }
.brand:hover { color: var(--text); }
.brand-mark { width: 36px; height: 36px; flex: none; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.bm-bg { fill: var(--primary); }
.bm-line { stroke: var(--on-primary); stroke-width: 2.6; stroke-linecap: round; fill: none; opacity: .92; }
.bm-dot { fill: var(--gold); }
.bm-hand { stroke: #1b2233; stroke-width: 1.6; stroke-linecap: round; fill: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand-inst {
  font-family: var(--font-serif); font-size: .72rem; letter-spacing: .06em; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-app { font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; color: var(--text); }
.brand-center { justify-content: center; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .5rem;
  padding: 0 .75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.topbar .brand { flex: 1 1 auto; }
.topbar-actions { display: flex; align-items: center; gap: .35rem; flex: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); padding: 0;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn .icon { width: 1.35rem; height: 1.35rem; }

.theme-icon-dark { display: none; }
html[data-theme="dark"] .theme-icon-light { display: none; }
html[data-theme="dark"] .theme-icon-dark { display: inline-flex; }
.theme-icon-light, .theme-icon-dark { align-items: center; }
.theme-icon-light { display: inline-flex; }

.user-chip {
  display: inline-flex; align-items: center; gap: .5rem; text-decoration: none; color: var(--text);
  padding: .25rem; border-radius: 999px; min-height: var(--tap);
}
.user-chip:hover { background: var(--surface-3); color: var(--text); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700;
}
.user-chip-text { display: none; flex-direction: column; line-height: 1.2; }
.user-chip-name { font-weight: 600; font-size: .9rem; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-role { font-size: .75rem; color: var(--text-muted); }

/* ---------- Shell & sidebar ---------- */
.shell { display: block; min-height: calc(100vh - var(--topbar-h)); }
.main { padding: 1rem .875rem 2rem; max-width: 1200px; margin: 0 auto; outline: none; }

.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 100;
  width: min(85vw, var(--sidebar-w));
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto; overscroll-behavior: contain;
  padding: .5rem .75rem 1.25rem;
  transform: translateX(-102%);
  transition: transform .22s ease;
  display: flex; flex-direction: column;
  visibility: hidden;
}
body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); visibility: visible; }
.nav-backdrop { position: fixed; inset: 0; z-index: 90; background: rgba(10, 18, 32, .45); }
body.nav-open { overflow: hidden; }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: .25rem .25rem .5rem; }
.sidebar-title { font-weight: 650; }
.nav-section { padding: .35rem 0; }
.nav-section + .nav-section { border-top: 1px solid var(--border); }
.nav-heading { font-size: .78rem; font-weight: 600; color: var(--text-muted); margin: .5rem .6rem .25rem; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list form { margin: 0; }
.nav-link {
  display: flex; align-items: center; gap: .7rem; width: 100%;
  min-height: var(--tap); padding: .5rem .7rem;
  border-radius: var(--radius-sm); border: 0; background: none;
  color: var(--text); text-decoration: none; font: inherit; font-size: .95rem; text-align: left; cursor: pointer;
}
.nav-link .icon { color: var(--text-muted); }
.nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; box-shadow: inset 3px 0 0 var(--primary); }
.nav-link.is-active .icon { color: var(--primary); }
.nav-footer { margin-top: auto; }

@media (min-width: 1024px) {
  .nav-toggle, .sidebar-head { display: none; }
  .shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h));
    transform: none; visibility: visible; width: auto; box-shadow: none; z-index: 10; padding-top: 1rem;
  }
  .nav-backdrop { display: none !important; }
  .main { padding: 1.75rem 2rem 3rem; width: 100%; }
  .topbar { padding: 0 1.25rem; }
}
@media (min-width: 640px) {
  .user-chip { padding-right: .75rem; }
  .user-chip-text { display: flex; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin-bottom: .2rem; }
.page-sub { color: var(--text-muted); margin: 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.back-link { display: inline-flex; align-items: center; gap: .35rem; font-size: .9rem; margin-bottom: .5rem; text-decoration: none; min-height: 32px; }
.page-footer { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--border); color: var(--text-muted); font-size: .8rem; }
.page-footer p { margin: 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1.25rem;
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.card-head .card-title { margin: 0; }
.card-title { font-size: 1.1rem; margin-bottom: .85rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.card-subtitle { font-size: 1rem; margin: 1rem 0 .5rem; }
.count-pill {
  display: inline-block; min-width: 1.8rem; padding: .05rem .5rem; border-radius: 999px;
  background: var(--surface-3); color: var(--text-muted); font-size: .8rem; font-weight: 600; text-align: center;
  font-variant-numeric: tabular-nums;
}
@media (min-width: 768px) { .card { padding: 1.35rem 1.5rem; } }

.two-col { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
.two-col > .card { margin-bottom: 0; }
@media (min-width: 1024px) {
  .two-col { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .two-col-wide { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
}
.two-col + * { margin-top: 1.25rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: var(--tap); padding: .55rem 1.05rem;
  border: 1px solid transparent; border-radius: var(--radius);
  font: inherit; font-size: .95rem; font-weight: 600; line-height: 1.2;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: var(--on-primary); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
html[data-theme="dark"] .btn-danger { color: #1b0a0c; }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); color: #fff; }
.btn-quiet { background: transparent; color: var(--primary); }
.btn-quiet:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary); }
.btn-quiet-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-quiet-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.btn-sm { min-height: 36px; padding: .35rem .7rem; font-size: .875rem; }
.btn-lg { min-height: 50px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 1.1rem; height: 1.1rem; border-radius: 50%;
  border: 2px solid var(--on-primary); border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; margin-bottom: .9rem; }
.field label, .label-like { font-weight: 600; font-size: .9rem; }
.field-hint { font-size: .82rem; color: var(--text-muted); margin: 0; }
.field-error { color: var(--danger); font-size: .85rem; margin: 0; font-weight: 500; }
.field-error::before { content: "⚠ "; }
.static-value { margin: 0; padding: .6rem 0; font-family: var(--font-mono); }

input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="tel"],
input[type="date"], input[type="number"], select, textarea {
  width: 100%; min-height: var(--tap);
  padding: .55rem .75rem;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
input[type="date"] { min-width: 0; appearance: auto; }
select {
  appearance: none; padding-right: 2.2rem; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); outline: none; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); background-color: var(--danger-soft); }
input::placeholder { color: var(--text-muted); opacity: .75; }
html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.85); }
input[data-uppercase] { text-transform: uppercase; font-family: var(--font-mono); letter-spacing: .03em; }
input[data-uppercase]::placeholder { text-transform: none; font-family: var(--font-sans); letter-spacing: 0; }

.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.input-icon > input { padding-left: 2.4rem; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 3.2rem; }
.password-toggle {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  width: 42px; height: 40px; border: 0; background: none; color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
}
.password-toggle:hover { color: var(--text); }
.password-toggle .pw-hide { display: none; }
.password-toggle[aria-pressed="true"] .pw-show { display: none; }
.password-toggle[aria-pressed="true"] .pw-hide { display: inline-flex; }
.pw-show { display: inline-flex; }

.form-grid { display: grid; gap: 0 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: flex-end; margin-top: .5rem; }
.form-card { max-width: 860px; }

.check-group { border: 0; padding: 0; margin: 1rem 0 0; }
.check-group legend { font-weight: 600; margin-bottom: .5rem; padding: 0; }
.check-row {
  display: flex; align-items: center; gap: .75rem; min-height: var(--tap);
  padding: .45rem .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: .45rem; cursor: pointer; background: var(--surface-2);
}
.check-row:hover { border-color: var(--border-strong); }
.check-row input { width: 20px; height: 20px; accent-color: var(--primary); flex: none; margin: 0; }
.check-row:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.check-text { flex: 1; }

.inline-search { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline-search .input-icon { flex: 1 1 14rem; }
.inline-search select { width: auto; min-width: 11rem; }

/* ---------- Alerts / status ---------- */
.flash-stack:empty { display: none; }
.alert {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .75rem .9rem; margin-bottom: 1rem;
  border-radius: var(--radius); border: 1px solid; border-left-width: 4px;
  font-size: .95rem;
}
.alert > .icon { margin-top: .1rem; }
.alert p { margin: 0; flex: 1; }
.alert-success { background: var(--success-soft); border-color: var(--success); color: var(--text); }
.alert-success > .icon { color: var(--success); }
.alert-error { background: var(--danger-soft); border-color: var(--danger); color: var(--text); }
.alert-error > .icon { color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--text); }
.alert-warning > .icon { color: var(--warning); }
.alert-info { background: var(--info-soft); border-color: var(--info); color: var(--text); }
.alert-info > .icon { color: var(--info); }
.alert-close {
  flex: none; border: 0; background: none; color: var(--text-muted); cursor: pointer;
  width: 32px; height: 32px; margin: -.3rem -.35rem -.3rem 0; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
}
.alert-close:hover { background: rgba(127, 127, 127, .15); color: var(--text); }
.form-status:empty { display: none; }
.form-status .alert { margin-bottom: 1rem; }
.note { display: flex; gap: .5rem; align-items: flex-start; font-size: .88rem; margin-top: .75rem; }
.note .icon { margin-top: .15rem; }

/* ---------- Badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .12rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 650;
  border: 1px solid transparent; white-space: nowrap; vertical-align: middle;
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.badge-success::before { content: "●"; font-size: .6rem; }
.badge-muted { background: var(--surface-3); color: var(--text-muted); border-color: var(--border); }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 35%, transparent); }

.chip-list { list-style: none; margin: .4rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  display: inline-flex; align-items: center; gap: .15rem;
  padding: .2rem .25rem .2rem .7rem; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary); font-size: .85rem; font-weight: 600;
}
.chip form { margin: 0; display: inline-flex; }
.chip-remove {
  border: 0; background: none; color: inherit; cursor: pointer;
  width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
}
.chip-remove:hover { background: rgba(127, 127, 127, .2); }
.chip-remove .icon { width: 1rem; height: 1rem; }

/* ---------- Welcome / date stamp ---------- */
.welcome { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.welcome-text { flex: 1 1 16rem; min-width: 0; }
.welcome-greeting { margin: 0; color: var(--text-muted); font-family: var(--font-serif); font-style: italic; font-size: 1.05rem; }
.welcome h1 { font-size: 1.6rem; margin-bottom: .6rem; }

.date-stamp {
  display: inline-flex; align-items: stretch; flex: none;
  border: 1.5px solid var(--accent); border-radius: var(--radius);
  color: var(--accent); background: var(--surface);
  transform: rotate(-1.5deg);
  box-shadow: var(--shadow-sm);
}
.date-stamp-day {
  font-family: var(--font-serif); font-size: 2.1rem; font-weight: 700; line-height: 1;
  padding: .45rem .6rem; border-right: 1.5px dashed var(--accent); display: flex; align-items: center;
  font-variant-numeric: tabular-nums;
}
.date-stamp-rest { display: flex; flex-direction: column; justify-content: center; padding: .35rem .7rem; font-size: .8rem; font-weight: 600; letter-spacing: .02em; }
.date-stamp-rest span + span { font-weight: 400; opacity: .85; }

.dept-switcher { margin-bottom: 1rem; }
.welcome .dept-switcher { margin-bottom: 0; }
.dept-form { display: flex; flex-direction: column; gap: .3rem; max-width: 30rem; }
.dept-form label { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; font-size: .9rem; color: var(--text-muted); }
.dept-control { display: flex; gap: .5rem; }
.dept-control select { font-weight: 600; border-color: var(--primary); }
.dept-single { display: flex; align-items: center; gap: .5rem; margin: 0; padding: .55rem .8rem; background: var(--primary-soft); border-radius: var(--radius); color: var(--primary); width: fit-content; max-width: 100%; }
.dept-single .muted { margin-right: .35rem; }

/* ---------- Ledger (dashboard statistics) ---------- */
.ledger { padding: 0; overflow: hidden; }
.ledger-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem;
  padding: 1rem; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.ledger-head h2 { margin: 0; font-size: 1rem; }
.ledger-period { color: var(--primary); }
.ledger > .alert { margin: 1rem 1rem 0; }
.period-form { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.period-form select { width: auto; min-width: 10rem; }
.period-custom { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; width: 100%; }
.period-custom label { font-size: .85rem; font-weight: 600; }
.period-custom input { width: auto; flex: 1 1 9rem; }
.ledger-rows { list-style: none; margin: 0; padding: 0; }
.ledger-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "icon label value" "links links links";
  align-items: center; gap: .35rem .85rem; padding: .95rem 1rem;
  background-image: linear-gradient(to right, var(--border) 40%, transparent 0);
  background-size: 8px 1px; background-repeat: repeat-x; background-position: bottom;
}
.ledger-row:last-child { background-image: none; }
.ledger-icon {
  grid-area: icon; width: 40px; height: 40px; border-radius: var(--radius);
  background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center;
}
.ledger-label { grid-area: label; font-weight: 600; }
.ledger-value {
  grid-area: value; font-family: var(--font-serif); font-size: 2rem; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums lining-nums; color: var(--text); text-align: right;
}
.ledger-links { grid-area: links; display: flex; gap: .4rem; justify-content: flex-end; }
@media (min-width: 640px) {
  .ledger-row { grid-template-columns: auto minmax(0, 1fr) auto auto; grid-template-areas: "icon label value links"; padding: 1rem 1.5rem; }
  .ledger-head { padding: 1rem 1.5rem; }
  .period-custom { width: auto; }
}

.summary-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); margin-bottom: 1.25rem; overflow: hidden;
}
.summary-item {
  display: flex; flex-direction: column; gap: .15rem; padding: 1rem 1.1rem; text-decoration: none; color: var(--text);
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: 0 -1px -1px 0;
}
.summary-item:hover { background: var(--surface-2); color: var(--text); }
.summary-value { font-family: var(--font-serif); font-size: 1.9rem; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.summary-label { font-size: .85rem; color: var(--text-muted); }
.summary-item.needs-attention .summary-value { color: var(--accent); }
.summary-item.needs-attention { box-shadow: inset 3px 0 0 var(--accent); }

/* ---------- Quick actions ---------- */
.quick-actions h2 { font-size: 1rem; margin-bottom: .75rem; }
.qa-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
@media (min-width: 768px) { .qa-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.qa-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: .6rem;
  min-height: 92px; padding: .9rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  color: var(--text); text-decoration: none; font-weight: 600; font-size: .92rem; line-height: 1.3;
  box-shadow: var(--shadow-sm); transition: border-color .15s, transform .15s;
}
.qa-tile .icon { width: 1.5rem; height: 1.5rem; color: var(--primary); }
.qa-tile:hover { border-color: var(--primary); color: var(--text); transform: translateY(-1px); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: .25rem; overflow-x: auto; margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border); scrollbar-width: thin;
}
.tab {
  display: inline-flex; align-items: center; gap: .45rem; white-space: nowrap;
  min-height: var(--tap); padding: .5rem .9rem; margin-bottom: -1px;
  color: var(--text-muted); text-decoration: none; font-weight: 600; font-size: .92rem;
  border-bottom: 3px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Entry rows ---------- */
.entry-form { padding: 1rem; }
.entry-rows { display: flex; flex-direction: column; gap: .85rem; }
.entry-row {
  margin: 0; padding: .85rem .9rem .2rem; min-width: 0;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2);
}
.entry-row-title { font-size: .85rem; font-weight: 700; color: var(--primary); padding: 0 .35rem; }
.entry-row-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 .85rem; }
.entry-row-remove { display: flex; justify-content: flex-end; margin: -.25rem 0 .6rem; }
.btn-remove:disabled { visibility: hidden; }
.entry-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: 1rem;
  padding-top: 1rem; border-top: 1px solid var(--border);
}
.row-count { margin: 0; flex: 1; font-size: .9rem; }
.entry-actions [data-submit] { width: 100%; }
@media (min-width: 480px) {
  .entry-row-fields.cols-3, .entry-row-fields.cols-4, .entry-row-fields.cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .entry-actions [data-submit] { width: auto; }
}
@media (min-width: 1100px) {
  .entry-row { padding: .6rem .9rem .1rem; }
  .entry-row-fields.cols-3 { grid-template-columns: 11rem minmax(0, 1fr) 10rem auto; }
  .entry-row-fields.cols-4 { grid-template-columns: 11rem 10rem minmax(0, 1fr) 9rem auto; }
  .entry-row-fields.cols-5 { grid-template-columns: 10.5rem 9rem minmax(0, 1fr) 8rem 10.5rem auto; }
  .entry-row-remove { margin: 1.55rem 0 .9rem; align-items: flex-start; }
}
@media (min-width: 480px) and (max-width: 1099.98px) {
  .entry-row-remove { grid-column: 1 / -1; }
}

/* ---------- Filters & results ---------- */
.filter-card { padding: 1rem; }
.filter-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 .9rem; }
@media (min-width: 480px) { .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .field-search { grid-column: 1 / -1; } }
@media (min-width: 1024px) {
  .filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .field-search { grid-column: span 2; }
}
.filter-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.filter-actions .btn { flex: 1 1 auto; }
@media (min-width: 640px) { .filter-actions .btn { flex: 0 0 auto; } }

.records-app.is-loading .table-wrap { opacity: .55; transition: opacity .2s; }
.results-card { padding: 0; overflow: hidden; }
.results-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; padding: 1rem 1rem .6rem; }
.results-title { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.results-summary { margin: 0; font-size: .88rem; font-variant-numeric: tabular-nums; }
.results-card .pagination { padding: .5rem 1rem 1rem; }
.empty-results, .empty-state { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }
.empty-icon { width: 2.25rem !important; height: 2.25rem !important; color: var(--border-strong); margin-bottom: .5rem; }
.empty-state { background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }
.empty-state h2 { color: var(--text); }

/* ---------- Data tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: .7rem 1rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.data-table th { font-size: .8rem; font-weight: 650; color: var(--text-muted); background: var(--surface-2); white-space: nowrap; }
.data-table th.num, .data-table td.num { text-align: right; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.card > .table-wrap { margin: 0 -1rem; width: calc(100% + 2rem); }
@media (min-width: 768px) { .card > .table-wrap { margin: 0 -1.5rem; width: calc(100% + 3rem); } }
.results-card > .table-wrap, .ledger > .table-wrap { margin: 0 !important; width: 100% !important; }
.col-actions { text-align: right !important; }
.row-actions { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.audit-meta { font-size: .82rem; color: var(--text-muted); max-width: 26rem; word-break: break-word; }

/* Phones: every table row becomes a labelled card (screen only).
   Each cell shows its column label above the value, two cells per line. */
@media screen and (max-width: 767.98px) {
  .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .data-table, .data-table tbody { display: block; width: 100%; }
  .data-table tbody tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem 1rem;
    margin: 0 0 .75rem; padding: .8rem .9rem; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); box-shadow: var(--shadow-sm);
  }
  .data-table tbody tr:hover { background: var(--surface); }
  .data-table td { display: block; padding: 0; border: 0; text-align: left !important; word-break: break-word; min-width: 0; }
  .data-table td::before {
    content: attr(data-label); display: block; margin-bottom: .1rem;
    font-weight: 600; font-size: .75rem; color: var(--text-muted);
  }
  .data-table td:first-child, .data-table td.cell-actions, .data-table td.col-actions, .data-table td.audit-meta { grid-column: 1 / -1; }
  .data-table td:first-child { font-weight: 650; padding-bottom: .5rem; border-bottom: 1px dashed var(--border); }
  .data-table td.cell-actions, .data-table td.col-actions { padding-top: .6rem; border-top: 1px dashed var(--border); }
  .data-table td.cell-actions::before, .data-table td.col-actions::before { display: none; }
  .row-actions { justify-content: stretch; }
  .row-actions .btn { flex: 1 1 auto; min-height: var(--tap); }
  .results-card .table-wrap { padding: 0 .75rem; }
  .card > .table-wrap { margin: 0; width: 100%; }
}
@media (max-width: 400px) {
  .topbar .brand-inst { max-width: 9.5rem; }
  .brand-inst { letter-spacing: .02em; font-size: .66rem; }
  .brand-mark { width: 32px; height: 32px; }
}

/* ---------- Pagination ---------- */
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .35rem; margin-top: 1rem; }
.page-btn, .page-num {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  min-width: var(--tap); min-height: var(--tap); padding: .35rem .75rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text); text-decoration: none; font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.page-btn:hover:not(:disabled):not(.is-disabled), .page-num:hover:not(.is-current) { background: var(--surface-3); color: var(--text); }
.page-num.is-current { background: var(--primary); border-color: var(--primary); color: var(--on-primary); cursor: default; opacity: 1; }
.page-btn.is-disabled, .page-btn:disabled { opacity: .45; cursor: not-allowed; }
.page-gap { padding: 0 .25rem; color: var(--text-muted); }
@media (max-width: 420px) { .page-btn span { display: none; } }

/* ---------- Detail view ---------- */
.detail-card { max-width: 760px; }
.detail-list { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.detail-list > div { display: grid; grid-template-columns: minmax(7rem, 35%) minmax(0, 1fr); gap: 1rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.detail-list dt { font-weight: 600; color: var(--text-muted); font-size: .9rem; }
.detail-list dd { margin: 0; word-break: break-word; }
.detail-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.detail-actions form { margin: 0; }

/* ---------- Mapping ---------- */
.mapping-list { list-style: none; margin: 0; padding: 0; }
.mapping-item { padding: .8rem 0; border-bottom: 1px solid var(--border); }
.mapping-item:last-child { border-bottom: 0; }
.mapping-hod { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .2rem; }
.mapping-hod a { text-decoration: none; color: var(--text); }
.mapping-hod a:hover { color: var(--primary); }
.mapping-form { margin-top: .5rem; }

/* ---------- Login & setup ---------- */
.login-page { min-height: 100vh; background: var(--bg); }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); }
.login-intro { display: none; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 1.25rem .9rem; }
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 1.35rem 1.25rem 1.5rem;
}
.login-card-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: 1.5rem; }
.login-title { font-size: 1.45rem; margin-bottom: .25rem; }
.login-lead { font-size: .92rem; margin-bottom: 1.25rem; }
.login-form .btn-block { margin-top: .5rem; }
.forgot { margin-top: 1.25rem; font-size: .9rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.forgot summary { cursor: pointer; color: var(--primary); font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.forgot p { margin: .5rem 0 0; color: var(--text-muted); }

@media (min-width: 900px) {
  .login-shell { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
  .login-intro {
    display: flex; align-items: flex-end;
    background: #14305a;
    background-image:
      linear-gradient(160deg, rgba(20, 48, 90, .96), rgba(12, 28, 54, .98)),
      repeating-linear-gradient(0deg, transparent 0 31px, rgba(255, 255, 255, .05) 31px 32px);
    color: #e9eef7; padding: 3rem;
  }
  .login-intro-inner { max-width: 26rem; }
  .login-inst { font-family: var(--font-serif); font-size: 1.05rem; letter-spacing: .08em; margin-bottom: .25rem; color: #c9d5e8; }
  .login-app { font-size: 3rem; font-weight: 750; letter-spacing: -.02em; line-height: 1; margin-bottom: 2rem; color: #fff; }
  .login-points { list-style: none; margin: 0 0 2rem; padding: 0; }
  .login-points li { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-top: 1px solid rgba(255, 255, 255, .14); font-size: 1.02rem; }
  .login-points .icon { color: #e0b85a; width: 1.35rem; height: 1.35rem; }
  .login-foot { color: #b7c4da; font-size: .92rem; margin: 0; }
  .login-panel { padding: 2rem; }
  .login-card { padding: 2rem 2rem 2.25rem; }
}
.setup-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem .9rem; }
.setup-card { max-width: 480px; }
.setup-steps { padding-left: 1.25rem; }
.setup-steps li { margin-bottom: .5rem; }

/* ---------- Error page ---------- */
.plain-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem; }
.error-card {
  width: 100%; max-width: 480px; text-align: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 2rem 1.5rem;
}
.error-card .brand { margin-bottom: 1.5rem; }
.error-code { font-size: .8rem; font-weight: 700; color: var(--accent); letter-spacing: .06em; margin-bottom: .25rem; }
.error-message { color: var(--text-muted); }
.error-detail { text-align: left; font-size: .75rem; background: var(--surface-3); padding: .75rem; border-radius: var(--radius-sm); overflow: auto; max-height: 14rem; }
.error-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: 1.25rem; }

/* ---------- Print preview window (screen) ---------- */
.print-page { background: var(--surface-3); }
.print-toolbar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: .5rem; justify-content: center;
  padding: .75rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.print-sheet {
  background: #fff; color: #111; max-width: 210mm; margin: 1rem auto; padding: 14mm 12mm;
  box-shadow: var(--shadow); font-size: 10.5pt;
}
.print-header { text-align: center; border-bottom: 2px solid #1d3f72; padding-bottom: 8px; margin-bottom: 10px; }
.print-inst { font-family: var(--font-serif); font-size: 15pt; font-weight: 700; letter-spacing: .08em; margin: 0; color: #111; }
.print-app { font-size: 11pt; font-weight: 600; margin: 2px 0 4px; color: #1d3f72; }
.print-title { font-size: 13pt; margin: 4px 0 0; color: #111; }
.print-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px 16px; margin: 0 0 12px; font-size: 9.5pt; }
.print-meta div { display: flex; gap: 6px; }
.print-meta dt { font-weight: 700; min-width: 6.5em; }
.print-meta dt::after { content: ":"; }
.print-meta dd { margin: 0; }
.print-warning { border: 1px solid #a87b16; background: #fdf3dc; padding: 6px 8px; font-size: 9pt; }
.print-table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
.print-table th, .print-table td { border: 1px solid #9aa4b4; padding: 4px 6px; text-align: left; vertical-align: top; }
.print-table th { background: #e8edf5; font-weight: 700; }
.print-table .col-sl { width: 2.6em; text-align: right; }
.print-empty { text-align: center !important; padding: 16px !important; color: #555; }
.print-total { margin-top: 8px; font-size: 9.5pt; }
.print-signatures { display: flex; justify-content: space-between; gap: 2rem; margin-top: 48px; font-size: 9.5pt; }
.print-signatures div { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 0 1 40%; }
.sig-line { display: block; width: 100%; border-top: 1px solid #333; }
@media screen and (max-width: 767.98px) {
  .print-sheet { margin: 0; padding: 1rem; max-width: none; }
  .print-meta { grid-template-columns: minmax(0, 1fr); }
  .print-table-wrap { overflow-x: auto; }
}

/* ---------- Motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .date-stamp { transform: none; }
}
