/* ════════════════════════════════════════════════════════════════════
   NPO Accounting — UI styled after HAN-AY Accounting design language.
   Plain CSS (no Tailwind build step) to keep the project portable.

   Uses a system font stack — no external font fetch. Pages render
   instantly even on first load with no external requests.
   ════════════════════════════════════════════════════════════════════ */

/* Heritage Mission System tokens — see DESIGN.md. Self-hosted variable
   fonts: Source Serif 4 for headings ("voice of record"), Work Sans for
   body and data. Peso sign (₱) falls back to the system stack. */
@font-face {
  font-family: "Source Serif 4";
  src: url("../fonts/source-serif-4-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Work Sans";
  src: url("../fonts/work-sans-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  /* ── Heritage semantic tokens (DESIGN.md) ── */
  --surface:                 #fbf9f4;
  --surface-dim:             #dbdad5;
  --surface-container-lowest:#ffffff;
  --surface-container-low:   #f5f3ee;
  --surface-container:       #f0eee9;
  --surface-container-high:  #eae8e3;
  --surface-container-highest:#e4e2dd;
  --on-surface:              #1b1c19;
  --on-surface-variant:      #43474d;
  --outline:                 #73777e;
  --outline-variant:         #c3c7ce;
  --primary:                 #00172a;
  --on-primary:              #ffffff;
  --primary-container:       #0d2c45;
  --on-primary-container:    #7994b2;
  --secondary:               #745b00;
  --secondary-container:     #fecf32;
  --on-secondary-container:  #705900;
  --tertiary-container:      #5c0013;
  --on-tertiary-container:   #ff5364;
  --error:                   #ba1a1a;
  --error-container:         #ffdad6;
  --on-error-container:      #93000a;
  --pattern-blue:            #2e5b9a;
  --pattern-black:           #1a1a1a;
  --border-muted:            #00172a26;   /* 1px borders: 15% navy, per spec */

  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-sans:  "Work Sans", system-ui, -apple-system, "Segoe UI", Roboto,
                "Helvetica Neue", Arial, sans-serif;

  /* ── Legacy aliases → Heritage values.
     Templates and older rules reference these names; remapping the values
     reskins every consumer without touching call sites. ── */
  --slate-50:  #fbf9f4;   /* surface / page background */
  --slate-100: #f5f3ee;   /* surface-container-low */
  --slate-200: #e4e2dd;   /* hairlines, table rules */
  --slate-300: #c3c7ce;   /* outline-variant */
  --slate-400: #73777e;   /* outline */
  --slate-500: #73777e;   /* muted text */
  --slate-600: #43474d;   /* secondary text */
  --slate-700: #30312e;   /* strong text */
  --slate-800: #1b1c19;   /* headings */
  --slate-900: #1b1c19;   /* on-surface */

  /* primary: deep navy replaces blue */
  --primary-50:  #cfe5ff;
  --primary-100: #cfe5ff;
  --primary-500: #2d4963;
  --primary-600: #0d2c45;
  --primary-700: #00172a;
  --primary-800: #001d33;

  /* status — palette has no green: affirmative states use primary navy,
     warnings use secondary gold, danger uses error red (DESIGN.md) */
  --emerald-50:  #cfe5ff;
  --emerald-500: #2d4963;
  --emerald-600: #0d2c45;
  --emerald-700: #00172a;
  --amber-50:    #ffe08a;
  --amber-600:   #745b00;
  --amber-700:   #574400;
  --rose-50:     #ffdad6;
  --rose-500:    #ff5364;
  --rose-600:    #ba1a1a;
  --rose-700:    #93000a;

  /* sidebar: primary navy block */
  --sb-bg-from:  #00172a;
  --sb-bg-to:    #001d33;
  --sb-hover:    #0d2c45;
  --sb-text:     #7994b2;
  --sb-text-active: #ffffff;
  --sb-border:   #0d2c45;
  --sb-section:  #46617c;

  /* shape: soft, architectural (DESIGN.md "rounded") */
  --radius-sm: 0.25rem;   /* buttons, inputs */
  --radius:    0.25rem;
  --radius-lg: 0.5rem;    /* cards */
  --radius-xl: 0.75rem;

  /* elevation: borders over shadows; ambient navy only on hover */
  --shadow-sm:   0 0 0 1px var(--border-muted);
  --shadow-card: 0 0 0 1px var(--border-muted);
  --shadow-card-hover: 0 4px 16px -2px #00172a1f, 0 2px 8px -2px #00172a14;
  --shadow-button: none;
}

* { box-sizing: border-box; }

html {
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--surface);
  color: var(--on-surface);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Headings carry the serif "voice of record" (DESIGN.md typography). */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  color: var(--on-surface);
  font-weight: 600;
  margin: 0 0 12px;
}
h1 { font-size: 24px; line-height: 32px; }
h2 { font-size: 18px; line-height: 26px; }
h3 { font-size: 15px; line-height: 22px; }

a {
  color: var(--primary-600);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

::-webkit-scrollbar       { width: 22px; height: 22px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 999px; border: 4px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--slate-400); background-clip: padding-box; border: 4px solid transparent; }

/* ── Layout ─────────────────────────────────────────────────────────── */

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 256px;
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--sb-bg-from) 0%, var(--sb-bg-to) 100%);
  overflow: hidden;
  z-index: 30;
  transition: transform 200ms ease;
}

/* Collapsed sidebar: slide off-screen and reclaim the main column. */
html.sb-collapsed .sidebar { transform: translateX(-100%); }
html.sb-collapsed .main    { margin-left: 0; }

.sb-logo {
  padding: 16px;
  border-bottom: 1px solid var(--sb-border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.sb-logo-square {
  width: 36px; height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-700) 100%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px;
}
.sb-logo-text { line-height: 1.2; }
.sb-logo-text .name { color: #fff; font-weight: 700; font-size: 14px; }
.sb-logo-text .sub  { color: var(--sb-section); font-size: 11px; }
/* Uploaded company logo replaces the initial square when present. */
.sb-logo-img {
  width: 36px; height: 36px;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  flex-shrink: 0;
}

.sb-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
  scrollbar-width: none;
}
.sb-nav::-webkit-scrollbar { display: none; }

.sb-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sb-section);
  padding: 10px 12px 6px;
  margin: 0;
}

.sb-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2.5px 12px;
  border-radius: var(--radius);
  color: var(--sb-text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  margin-bottom: 2.5px;
  transition: background 120ms, color 120ms;
  position: relative;
}
.sb-link:hover {
  background: var(--sb-hover);
  color: var(--sb-text-active);
  text-decoration: none;
}
.sb-link svg {
  flex-shrink: 0;
  width: 15px; height: 15px;
}
.sb-link .chevron {
  margin-left: auto;
  opacity: 0;
  transition: opacity 120ms;
}
.sb-link:hover .chevron { opacity: 0.3; }
/* Active nav: sun-yellow accent bar (gradient layer — no layout shift,
   no inset shadow) per DESIGN.md "highlights" role for Secondary. */
.sb-link.active {
  background: linear-gradient(90deg, var(--secondary-container) 0 3px, var(--primary-600) 3px);
  color: #fff;
  font-weight: 600;
}
.sb-link.active:hover {
  background: linear-gradient(90deg, var(--secondary-container) 0 3px, var(--primary-700) 3px);
}

/* Sidebar shortcut hint — small, faded, ghost-like; brighter on hover. */
.sb-link kbd,
.sb-link .nav-kbd {
  margin-left: auto;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 9px;
  line-height: 1;
  padding: 0;
  min-width: 0;
  height: auto;
  background: transparent;
  border: 0;
  color: var(--sb-section);
  opacity: 0.55;
  letter-spacing: 0;
}
.sb-link:hover kbd,
.sb-link:hover .nav-kbd { opacity: 0.9; color: var(--sb-text-active); }
.sb-link.active kbd,
.sb-link.active .nav-kbd { color: rgba(255,255,255,0.7); opacity: 0.75; }
/* Hide the chevron when a shortcut hint is shown — they'd both fight for the
   right edge of the link. */
.sb-link:has(kbd) .chevron,
.sb-link:has(.nav-kbd) .chevron { display: none; }

.sb-user {
  flex-shrink: 0;
  padding: 12px;
  border-top: 1px solid var(--sb-border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sb-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary-600);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  object-fit: cover;
}
img.sb-avatar { background: var(--slate-200); }
.sb-user-info { min-width: 0; flex: 1; }
.sb-user-info .name { color: #e4e2dd; font-size: 13px; font-weight: 600; line-height: 1.2; }
.sb-user-info .role { color: var(--sb-section); font-size: 11px; text-transform: capitalize; line-height: 1.3; }

/* main column */
.main {
  flex: 1;
  margin-left: 256px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 200ms ease;
}

.topbar {
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--slate-200);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.breadcrumb {
  display: flex; align-items: center; gap: 4px;
  font-size: 13px;
  min-width: 0;
}
.breadcrumb a {
  color: var(--slate-400);
  display: flex; align-items: center;
}
.breadcrumb a:hover { color: var(--slate-600); text-decoration: none; }
.breadcrumb .sep { color: var(--slate-300); margin: 0 2px; }
.breadcrumb .current { color: var(--slate-800); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 4px; }

/* Sidebar collapse toggle — circular handle straddling the sidebar's right
   edge so it is unmistakably clickable. Slides to the viewport's left edge
   when the sidebar is collapsed. */
.sidebar-toggle {
  position: fixed;
  top: 64px;            /* sits just below the 56px topbar */
  left: 242px;          /* 256px sidebar - 14px (half of 28px button) -> straddles edge */
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: 50%;
  color: var(--slate-600);
  cursor: pointer;
  padding: 0;
  transition: left 200ms ease, color 120ms, background 120ms, transform 120ms;
  z-index: 40;          /* above sidebar (30) and topbar (20) */
}
.sidebar-toggle:hover {
  color: var(--primary-600);
  background: #fff;
  box-shadow: 0 4px 12px #00172a2e, 0 2px 4px #00172a14;
  transform: scale(1.08);
}
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}
.sidebar-toggle svg { width: 16px; height: 16px; stroke-width: 2.5; }

/* When collapsed: hop to the viewport edge. */
html.sb-collapsed .sidebar-toggle { left: 12px; }

/* Chevron swap: show "left" arrow when open ("click to hide"), "right" arrow
   when collapsed ("click to show"). */
.sidebar-toggle .when-open,
.sidebar-toggle .when-closed { display: inline-flex; align-items: center; }
.sidebar-toggle .when-closed { display: none; }
html.sb-collapsed .sidebar-toggle .when-open   { display: none; }
html.sb-collapsed .sidebar-toggle .when-closed { display: inline-flex; }

.sidebar-toggle .when-open,
.sidebar-toggle .when-closed { display: inline-flex; align-items: center; }
.sidebar-toggle .when-closed { display: none; }
html.sb-collapsed .sidebar-toggle .when-open   { display: none; }
html.sb-collapsed .sidebar-toggle .when-closed { display: inline-flex; }
.topbar-right .sep { width: 1px; height: 20px; background: var(--slate-200); margin: 0 8px; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user .who { text-align: right; }
.topbar-user .who .name { font-size: 12px; font-weight: 600; color: var(--slate-700); line-height: 1.2; }
.topbar-user .who .role { font-size: 11px; color: var(--slate-400); line-height: 1.3; text-transform: capitalize; }

.btn-icon {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  background: transparent;
  border: 0;
  color: var(--slate-500);
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.btn-icon:hover { background: var(--slate-100); color: var(--slate-700); }

.logout-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--slate-500);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 120ms;
  font-family: inherit;
}
.logout-btn:hover { color: var(--rose-600); background: var(--rose-50); }

.page {
  flex: 1;
  padding: 24px;
  max-width: 1600px;
  width: 100%;
}

/* ── Sticky sheet-tab strips ───────────────────────────────────────────
   Tabs (D/PFR, CV, Liquidation, Master Data, Staff, etc.) stay pinned
   under the topbar (56px) when scrolling. The page background bleed-
   through is masked with the same slate-50 used by body. */
.tabs {
  position: sticky;
  top: 56px;
  z-index: 10;
  background: var(--slate-50);
  /* Inline margin in the partials sets top:8px — keep that off the
     sticky position so the strip sits flush against the topbar. */
  margin-top: 0 !important;
  padding-top: 8px;
}
@media print { .tabs { position: static !important; } }

.footer-bar {
  padding: 12px 24px;
  border-top: 1px solid var(--slate-100);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px;
  color: var(--slate-400);
}

/* ── Components ─────────────────────────────────────────────────────── */

.card {
  background: var(--surface-container-lowest);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-lg);
}
.card-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--slate-100);
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
}
.card-header h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--slate-600); }
.card-body { padding: 14px; }
.card-table { padding: 0; }
.card-table table { margin: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* Sticky table header — every table's column-header row pins below the
   56px topbar AND below the sticky tab strip (~40px) as the user scrolls.
   On pages without a tab strip the thead floats ~40px below the topbar,
   which is acceptable; the alternative would be the strip overlapping the
   thead because they share the same sticky offset.

   Opt-out: any table with class `no-sticky-thead`, or any table inside a
   container with class `no-sticky-thead`, falls back to normal scroll.
   Used by wide forms (e.g. Asset Reconciliation Form) where the table is
   nested in a horizontally-scrolling parent — sticky thead is viewport-
   relative, so it can't track horizontal scroll inside the parent and
   would otherwise misalign with the body columns.

   IMPORTANT: stickiness lives ONLY on the `th` cells. Making the `<thead>`
   element sticky too (as it was) double-sticks the header — the thead box and
   its th cells pin at the same offset, which lets data rows bleed ABOVE the
   header and detaches it mid-table. Sticky on `<th>` is the widely-supported
   pattern; the thead element must stay in normal flow. */
table thead th {
  position: sticky;
  top: 96px;
  z-index: 2;
  background: var(--surface-container-low);
  border-bottom: 1px solid var(--outline-variant);
}
table.no-sticky-thead thead th,
.no-sticky-thead table thead th {
  position: static;
  top: auto;
}
@media print {
  table thead, table thead th {
    position: static;
  }
}

.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 600;
  /* Primary action: deep navy + sun-yellow text (DESIGN.md Buttons). */
  color: var(--secondary-container);
  background: var(--primary-600);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  transition: background 120ms;
}
.btn:hover { background: var(--primary-container); color: var(--secondary-container) !important; text-decoration: none; }
.btn:active { background: var(--primary); }

.btn-secondary {
  background: var(--surface-container-lowest);
  color: var(--on-surface-variant);
  border: 1px solid var(--border-muted);
  font-weight: 500;
}
.btn-secondary:hover {
  background: var(--surface-container-low);
  border-color: var(--outline-variant);
  color: var(--on-surface) !important;
}

/* Sun-yellow call-to-action per DESIGN.md ("Donate" / "Join" weight). */
.btn-cta {
  background: var(--secondary-container);
  color: var(--primary);
}
.btn-cta:hover { background: #efc122; color: var(--primary) !important; }

.btn-danger {
  background: var(--error);
  color: #fff;
}
.btn-danger:hover { background: var(--on-error-container); color: #fff !important; }

.btn-ghost {
  background: transparent;
  color: var(--on-surface-variant);
}
.btn-ghost:hover { background: var(--surface-container); color: var(--on-surface) !important; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; gap: 4px; }
.btn-xs svg { width: 11px; height: 11px; }

kbd, .kbd {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 10px;
  font-weight: 600;
  min-width: 14px;
  padding: 0 4px;
  height: 16px;
  border-radius: 4px;
  background: rgba(255,255,255,0.9);
  color: var(--slate-600);
  border: 1px solid var(--slate-200);
  margin-left: 4px;
  line-height: 1;
}
kbd:empty { display: none; }

/* tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 13px;
}
th, td {
  padding: 6px 12px;
  text-align: left;
  border-bottom: 1px solid var(--slate-100);
}
th {
  background: var(--slate-50);
  color: var(--slate-500);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
tbody tr:hover { background: var(--slate-50); }
/* Numeric column: right-align both header and body cells, and use
   tabular-nums so digits line up. The monospace font + larger size
   apply only to the data cells — headers keep the uniform `th` style
   (11px uppercase) so every column header looks the same. */
td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
td.num {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 13px;
}
tr.total td {
  font-weight: 700;
  background: var(--slate-50);
  color: var(--slate-900);
  border-top: 2px solid var(--slate-200);
}

code { font-family: 'JetBrains Mono', Menlo, monospace; font-size: 12px; color: var(--slate-700); }

/* forms — minimalist density */
.field { display: flex; flex-direction: column; margin-bottom: 8px; }
.field > label {
  font-size: 10px;
  font-weight: 600;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="search"],
select, textarea {
  padding: 5px 9px;
  font: inherit;
  font-size: 12px;
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  color: var(--slate-900);
  transition: border-color 120ms;
}
/* High-contrast focus per DESIGN.md: 2px primary-navy ring. */
input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px #00172a29;
}
textarea { resize: vertical; min-height: 44px; }
input[type="checkbox"], input[type="radio"] { width: auto; padding: 0; }
.errors { color: var(--rose-600); font-size: 11px; margin-top: 2px; }
.help-text { color: var(--slate-500); font-size: 10px; margin-top: 2px; }
.actions { display: flex; gap: 6px; margin-top: 12px; }

/* Checkbox-list multi-selects (e.g. Client.departments) — compact 2-col grid */
.field ul {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 12px;
}
.field ul li label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 400;
  color: var(--slate-700);
  text-transform: none; letter-spacing: 0; margin: 0;
}

/* badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-draft     { background: var(--slate-100);   color: var(--slate-600); }
.badge-posted    { background: var(--emerald-50);  color: var(--emerald-700); }
.badge-cancelled, .badge-reversed { background: var(--rose-50); color: var(--rose-700); }
.badge-active    { background: #cfe5ff; color: #00172a; }
.badge-inactive  { background: #ffdad6; color: #93000a; }
.badge-role-super       { background: #cfe5ff; color: #2e5b9a; }
.badge-role-accountant  { background: #cfe5ff; color: #2e5b9a; }
.badge-role-bookkeeper  { background: #cfe5ff; color: #00172a; }
.badge-role-viewer      { background: var(--slate-100); color: var(--slate-600); }

/* D/PFR (RCA) transaction status badges — four user-facing states.
   Color logic: amber pending → blue ready-for-CV → violet paid-not-liquidated
   → emerald done. Disapproved / Cancelled stay red / slate respectively. */
.badge-rca-fa  { background: #ffe08a; color: #574400; }   /* For Approval — amber */
.badge-rca-auu { background: #cfe5ff; color: #00172a; }   /* Approved-Unpaid-Unliquidated — blue */
.badge-rca-apu { background: #cfe5ff; color: #2e5b9a; }   /* Approved-Paid-Unliquidated — violet */
.badge-rca-apl { background: #cfe5ff; color: #00172a; }   /* Approved-Paid-Liquidated — emerald */
.badge-rca-draft       { background: var(--slate-100); color: var(--slate-600); }
.badge-rca-disapproved { background: #ffdad6; color: #93000a; }
.badge-rca-cancelled   { background: var(--slate-100); color: var(--slate-500); text-decoration: line-through; }
/* Tag chip appended to AUU rows that already have a Liquidation filed —
   signals the FR is fully accounted for, just waiting on payment. */
.badge-rca-liq         { background: #cfe5ff; color: #2e5b9a; font-weight: 700; letter-spacing: 0.04em; }

/* ── Hover-popover preview for the D/PFR "Entries" column ───────────
   Pure-CSS hover — no JS needed. Anchored to the trigger button; pops
   up above-left so it doesn't get clipped by the rightmost column.
   The whole popover stays on hover (no flicker) because the wrapper
   container is what carries the `:hover` state. */
.je-hover-wrap {
  position: relative;
  display: inline-block;
}
.je-popover {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  width: min(520px, 80vw);
  background: #fff;
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 10px 12px;
  z-index: 200;
  text-align: left;
  display: none;
  font-size: 11.5px;
  color: var(--slate-700, #30312e);
}
.je-hover-wrap:hover .je-popover,
.je-hover-wrap:focus-within .je-popover {
  display: block;
}
.je-popover-head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--slate-500, #73777e);
  border-bottom: 1px solid var(--slate-200, #e4e2dd);
  padding-bottom: 4px;
  margin-bottom: 6px;
}
.je-popover-block + .je-popover-block {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--slate-200, #e4e2dd);
}
.je-popover-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 4px;
}
.je-popover-meta strong { font-weight: 600; color: var(--slate-900, #1b1c19); }
.je-popover-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
}
.je-popover-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--slate-500, #73777e);
  padding: 2px 6px;
  border-bottom: 1px solid var(--slate-200, #e4e2dd);
}
.je-popover-table td {
  padding: 3px 6px;
  border-bottom: 1px dotted var(--slate-100, #f5f3ee);
  vertical-align: top;
}
.je-popover-table td.num,
.je-popover-table th.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.je-popover-table .acct-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--primary-600, #0d2c45);
  font-weight: 600;
}

.icon-action {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 0; background: transparent;
  color: var(--slate-500);
  cursor: pointer;
  transition: background 120ms, color 120ms;
  font-family: inherit;
}
.icon-action:hover { background: var(--slate-100); color: var(--slate-700); }
.icon-action.edit:hover    { background: #cfe5ff; color: #00172a; }
.icon-action.key:hover     { background: #ffe08a; color: #574400; }
.icon-action.delete:hover  { background: var(--rose-50); color: var(--rose-700); }
.icon-action svg { width: 14px; height: 14px; }

.pill-toggle {
  display: inline-flex; align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  transition: background 120ms;
}
.pill-toggle.deactivate { border-color: #ffb3b4; color: var(--rose-600); }
.pill-toggle.deactivate:hover { background: var(--rose-50); }
.pill-toggle.activate { border-color: #adc9e9; color: #00172a; }
.pill-toggle.activate:hover { background: #cfe5ff; }

/* kpi card */
.kpi {
  background: var(--surface-container-lowest);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi .kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate-500);
}
.kpi .kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--slate-900);
  font-variant-numeric: tabular-nums;
  font-family: 'JetBrains Mono', Menlo, monospace;
  letter-spacing: -0.02em;
}
.kpi .kpi-sub { font-size: 11px; color: var(--slate-400); margin-top: 2px; }

/* grid */
.grid { display: grid; gap: 10px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } }

/* messages */
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.msg {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
}
.msg-success { background: var(--emerald-50); color: var(--emerald-700); border-color: #adc9e9; }
.msg-error   { background: var(--rose-50);    color: var(--rose-700);    border-color: #ffdad9; }
.msg-warning { background: var(--amber-50);   color: var(--amber-700);   border-color: #ffe08a; }
.msg-info    { background: var(--primary-50); color: var(--primary-700); border-color: var(--primary-100); }

/* page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Category chips — pattern palette at 10% bg, full-opacity text
   (DESIGN.md Chips & Tags) ── */
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.chip-navy { background: #00172a1a; color: var(--primary); }
.chip-blue { background: #2e5b9a1a; color: var(--pattern-blue); }
.chip-red  { background: #5c00131a; color: var(--tertiary-container); }
.chip-gold { background: #fecf3229; color: var(--on-secondary-container); }
.page-title { display: flex; flex-direction: column; gap: 1px; }
.page-title h1 { margin: 0; font-size: 18px; }
.page-title .subtitle { font-size: 12px; color: var(--slate-500); }
.page-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* toolbar (filters above tables) */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { font-size: 13px; }

/* small + muted helpers */
.small { font-size: 11px; }
.muted { color: var(--slate-500); }
.pos   { color: var(--emerald-600); }
.neg   { color: var(--rose-600); }

/* reports */
.report-header { text-align: center; margin-bottom: 24px; }
.report-header h1 { margin: 0 0 4px; font-size: 18px; }
.report-header h2 { font-size: 16px; color: var(--slate-700); font-weight: 600; margin: 0 0 4px; }
.report-header .subtitle { color: var(--slate-500); font-size: 13px; }

.print-area {
  background: #fff;
  padding: 32px 36px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-muted);
}
.print-area table { border: 0; }
.print-area table th, .print-area table td { border-color: var(--slate-100); }

@media print {
  .sidebar, .sidebar-toggle, .topbar, .footer-bar, .toolbar, .page-actions, .messages, .actions { display: none !important; }
  body { background: #fff; }
  .main { margin-left: 0; }
  .page { padding: 0; }
  .print-area { border: 0; padding: 0; }
  a { color: inherit; }
}

/* ── Login — split card: navy hero panel + centered form panel ──────── */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 20% 10%, #2d496314, transparent 60%),
    radial-gradient(1000px 500px at 80% 90%, #fecf321a, transparent 60%),
    var(--surface);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 880px;
  display: grid;
  grid-template-columns: 5fr 6fr;
  background: #fff;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-muted);
  overflow: hidden;
  padding: 0;
}

/* Left hero: deep navy with a radiant gold glow behind the logo. */
.login-hero {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  min-height: 520px;
  padding: 36px 32px 44px;
  background:
    radial-gradient(420px 420px at 50% 32%, #fecf3226, transparent 70%),
    linear-gradient(180deg, var(--primary-container) 0%, var(--primary) 55%, #001d33 100%);
  color: #fff;
}
/* Optional uploaded hero media (image / animated GIF). When set, the
   media IS the panel: every overlay (logo medallion, welcome text,
   pattern strip) is hidden so the upload shows unobstructed. */
.login-hero .hero-media {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.login-hero.has-media .hero-logo,
.login-hero.has-media h2,
.login-hero.has-media .tagline { display: none; }
.login-hero.has-media::after { content: none; }
.login-hero .hero-logo {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 148px; height: 148px;
  border-radius: 50%;
  background: #fff;
  object-fit: contain;
  border: 4px solid #fecf3252;
}
.login-hero h2 {
  font-family: var(--font-serif);
  font-size: 30px;
  line-height: 36px;
  color: #fff;
  margin: 0;
}
.login-hero .tagline {
  font-size: 13px;
  color: var(--on-primary-container);
  margin: 0;
}
/* Triangular pattern strip along the hero's bottom edge. */
.login-hero::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 8px;
  background: repeating-linear-gradient(90deg,
    var(--secondary-container)   0 24px,
    var(--on-tertiary-container) 24px 48px,
    var(--pattern-blue)          48px 72px,
    var(--pattern-black)         72px 96px);
  -webkit-mask: conic-gradient(from -45deg at 50% 100%, #0000 90deg, #1a1a1a 0) 50% / 16px 100%;
          mask: conic-gradient(from -45deg at 50% 100%, #0000 90deg, #1a1a1a 0) 50% / 16px 100%;
}

/* Right panel: client logo centered above the Login heading. */
.login-panel {
  padding: 44px 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  text-align: center;
}
.login-brand .sq,
.login-brand .sq-img {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border-muted);
  object-fit: contain;
}
.login-brand .sq {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-700));
  color: #fff;
  font-weight: 800; font-size: 24px;
  border: 0;
}
.login-brand .who {
  font-size: 13px;
  font-weight: 600;
  color: var(--on-surface-variant);
  line-height: 1.2;
}
.login-brand .who .sub {
  font-size: 11px; color: var(--slate-500); font-weight: 500;
}
.login-panel h2 {
  text-align: center;
  font-size: 26px;
  line-height: 34px;
  margin: 0 0 18px;
}
.login-panel input {
  padding: 9px 11px;
  font-size: 13px;
}

@media (max-width: 760px) {
  .login-card { grid-template-columns: 1fr; max-width: 420px; }
  .login-hero { display: none; }
  .login-panel { padding: 32px 28px; }
}

/* ── Mobile / responsive ──────────────────────────────────────────────
   The app is desktop-first (fixed 256px sidebar + margin-left main column).
   On narrow screens the sidebar becomes an off-canvas drawer opened by a
   hamburger in the topbar, the main column goes full width, and wide tables
   scroll. Every override below lives inside a @media block, so the desktop
   layout is byte-for-byte unchanged. */

/* Hamburger button — lives in the topbar markup but is hidden until the
   mobile breakpoint kicks in. */
.mobile-nav-toggle {
  display: none;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  margin-right: 4px;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  color: var(--slate-600);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.mobile-nav-toggle:hover { background: var(--slate-100); color: var(--slate-800); }
.mobile-nav-toggle svg { width: 20px; height: 20px; stroke-width: 2.2; }

/* Scrim behind the open drawer — only ever shown on mobile while open. */
.sb-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 50;
}

/* `screen and` is essential: a printed page is ~816px (Letter) / ~794px (A4)
   wide, which is BELOW this breakpoint, so without the `screen` qualifier these
   mobile rules — especially `.page table { display: block }` — would leak into
   print and shrink-wrap every table to the left with whitespace on the right. */
@media screen and (max-width: 860px) {
  /* Sidebar → off-canvas drawer: hidden by default, slides in on open. */
  .sidebar {
    transform: translateX(-100%);
    width: 84vw;
    max-width: 300px;
    border-right: 1px solid var(--border-muted);
    z-index: 60;                 /* above the backdrop (50) */
  }
  html.sb-mobile-open .sidebar { transform: translateX(0); }
  html.sb-mobile-open .sb-backdrop { display: block; }
  /* Lock the page behind the drawer so only the menu scrolls. */
  html.sb-mobile-open, html.sb-mobile-open body { overflow: hidden; }

  /* Main column is always full width on mobile, regardless of the desktop
     collapse state remembered in localStorage. */
  .main { margin-left: 0 !important; }

  /* The desktop floating collapse handle is replaced by the hamburger. */
  .sidebar-toggle { display: none !important; }
  .mobile-nav-toggle { display: inline-flex; }

  /* Condense the topbar to fit a phone. */
  .topbar { height: 52px; padding: 0 10px; }
  .topbar-user .who { display: none; }       /* keep just the avatar */
  .topbar-right .sep { margin: 0 4px; }
  .logout-btn span { display: none; }        /* icon-only sign out */
  .logout-btn { padding: 6px; }
  /* Hamburger + breadcrumb hug the left; sign-out/avatar stay right. The
     breadcrumb truncates rather than shoving the right cluster off-screen. */
  .breadcrumb { font-size: 12px; margin-right: auto; overflow: hidden; }
  .breadcrumb .current {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  .page { padding: 14px 12px; }
  .footer-bar { flex-direction: column; gap: 2px; text-align: center; padding: 12px; }

  /* Wide tables: each one becomes its own horizontal scroll container so it
     never forces the whole viewport wide. display:block makes the table
     scrollable; rows still align via an anonymous table box. */
  .page table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Sticky thead / tab offsets are tuned for the desktop topbar stack and
     misalign once tables become scroll containers — relax them on mobile. */
  .page table thead { position: static; }
  .tabs { position: static; top: auto; }

  .print-area { padding: 16px 14px; }
  .page-header { align-items: flex-start; }
}

/* Phone-specific fine tuning. (screen-only — never applies during print.) */
@media screen and (max-width: 520px) {
  .page { padding: 12px 10px; }
  .page-title h1 { font-size: 16px; }
  .topbar-user .sb-avatar { width: 28px; height: 28px; }
}
