:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f5132;
  --brand-2: #198754;
  --accent: #e8f5ee;
  --danger: #c0392b;
  --warn: #b7791f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}

/* ---------- main menu ---------- */
.mainnav {
  position: sticky; top: 0; z-index: 60;
  background: #12291c;
  display: flex; align-items: center; gap: 2px;
  padding: 0 12px; flex-wrap: wrap;
}
.mainnav a {
  color: #cfe3d6; text-decoration: none; font-size: 13.5px; font-weight: 600;
  padding: 11px 13px; border-bottom: 3px solid transparent;
}
.mainnav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.mainnav a.active { color: #fff; border-bottom-color: #2fb877; background: rgba(255,255,255,.08); }
.mainnav .nav-spacer { flex: 1; }
.mainnav .nav-user { color: #9fc0aa; font-size: 12.5px; padding: 0 8px; }
.mainnav .nav-brand {
  display: flex; align-items: center;
  background: #fff; border-radius: 8px;
  padding: 3px 10px; margin: 5px 10px 5px 0;
  border-bottom: none;
}
.mainnav .nav-brand img { height: 26px; width: auto; display: block; }
.mainnav .nav-brand:hover { background: #fff; opacity: .92; }
.topbar { top: var(--navh, 42px); }
/* desktop: the links wrapper is layout-transparent; mobile turns it into a drawer */
.mainnav .nav-links { display: contents; }
.nav-toggle {
  display: none; margin-left: auto; background: none; border: none; color: #cfe3d6;
  font-size: 22px; padding: 8px 12px; cursor: pointer; border-radius: 6px;
}

/* Masters dropdown */
.nav-drop { position: relative; display: inline-block; }
.nav-drop .nav-menu {
  display: none; position: absolute; top: 100%; left: 0; z-index: 70;
  background: #12291c; min-width: 150px; border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,.3); padding: 4px 0;
}
.nav-drop:hover .nav-menu, .nav-drop:focus-within .nav-menu { display: block; }
.nav-drop .nav-menu a { display: block; padding: 10px 16px; border-bottom: none; border-left: 3px solid transparent; }
.nav-drop .nav-menu a.active { border-left-color: #2fb877; border-bottom-color: transparent; }
.nav-drop.active .drop-toggle { color: #fff; border-bottom-color: #2fb877; background: rgba(255,255,255,.08); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.topbar .logo { font-weight: 700; font-size: 16px; letter-spacing: .3px; }
.topbar .logo small { display: block; font-weight: 400; font-size: 11px; opacity: .75; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .9; text-align: right; }
.topbar select, .topbar input[type="date"] {
  border: none; border-radius: 6px; padding: 7px 10px; font-size: 14px;
  background: rgba(255,255,255,.95); color: var(--ink); font-family: inherit;
}
.topbar .btn { margin: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--brand-2); color: #fff; border: none;
  padding: 8px 16px; border-radius: 7px;
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: rgba(255,255,255,.15); }
.btn.gray { background: #475569; }
.btn.outline { background: #fff; color: var(--brand); border: 1px solid var(--brand-2); }

/* ---------- layout ---------- */
.wrap { max-width: 1250px; margin: 18px auto 90px; padding: 0 16px; }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  margin-bottom: 16px; overflow: hidden;
}
.card h2 {
  margin: 0; padding: 11px 16px;
  font-size: 13px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--brand); background: var(--accent);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.card h2 .hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); font-size: 12px; }
.card .body { padding: 14px 16px; }

/* ---------- entry grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px 14px;
}
.fld { display: flex; flex-direction: column; gap: 3px; }
.fld label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.fld input[type="text"], .fld input[type="password"], .fld textarea, input.num {
  font-family: inherit; font-size: 15px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  background: #fff; color: var(--ink); width: 100%;
}
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input.num:focus, .fld input:focus, .fld textarea:focus, .rt input:focus {
  outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: var(--brand-2);
}
input.num.filled { background: #f7fcf9; }
.fld textarea { resize: vertical; min-height: 60px; }

/* ---------- recon table ---------- */
.rt { width: 100%; border-collapse: collapse; font-size: 14px; }
.rt th, .rt td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: right; white-space: nowrap; }
.rt th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #fafbfc; }
.rt th:first-child, .rt td:first-child { text-align: left; }
.rt td.prod { font-weight: 600; font-size: 13px; }
.rt input { width: 108px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; text-align: right; font-size: 14px; font-family: inherit; font-variant-numeric: tabular-nums; }
.rt input:read-only { background: #f1f5f9; color: var(--muted); border-style: dashed; }
.rt td.calc { font-variant-numeric: tabular-nums; font-weight: 600; }
.rt td.linked { color: var(--muted); font-variant-numeric: tabular-nums; }
.diff-pos { color: var(--brand-2); }
.diff-neg { color: var(--danger); }
.diff-zero { color: var(--muted); }

/* recon validation (Opening entered => Closing required) */
.rt input.invalid { border-color: var(--danger); background: #fdecec; }
.rt input.invalid:focus { outline-color: var(--danger); }
.fld-err {
  color: var(--danger); font-size: 11px; font-weight: 600;
  margin-top: 3px; white-space: normal; max-width: 120px; text-align: left; line-height: 1.3;
}
.vsummary {
  background: #fdecec; border: 1px solid #f3b3ad; color: #8c2f28;
  padding: 12px 16px; border-radius: 8px; margin: 0 0 14px;
  font-size: 13.5px; white-space: pre-line; line-height: 1.5;
}

/* ---------- footer save bar ---------- */
.savebar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  background: #fff; border-top: 1px solid var(--line);
  box-shadow: 0 -4px 12px rgba(16,24,40,.06);
  display: flex; align-items: center; gap: 18px;
  padding: 10px 22px; flex-wrap: wrap;
}
.savebar .totals { display: flex; gap: 22px; flex: 1; flex-wrap: wrap; }
.tot { display: flex; flex-direction: column; }
.tot .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.tot .val { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tot .val.main { color: var(--brand); }
.status { font-size: 13px; color: var(--muted); min-width: 130px; text-align: right; }
.status.saved { color: var(--brand-2); font-weight: 600; }
.status.dirty { color: var(--warn); font-weight: 600; }
.status.error { color: var(--danger); font-weight: 600; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0f5132 0%, #1a7a4a 60%, #23945c 100%); }
.login-card { background: #fff; border-radius: 14px; padding: 34px 38px; width: 100%; max-width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; color: var(--brand); }
.login-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
.login-card .fld { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: 15px; margin-top: 6px; }
.err { color: var(--danger); font-size: 13.5px; min-height: 18px; margin: 6px 0 0; }

/* ---------- admin summary table ---------- */
.sum { width: 100%; border-collapse: collapse; font-size: 14px; }
.sum th, .sum td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: right; }
.sum th:first-child, .sum td:first-child { text-align: left; }
.sum th { background: #fafbfc; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.sum td { font-variant-numeric: tabular-nums; }
.sum tr:hover td { background: #f6faf7; }
.sum td.branch { font-weight: 600; cursor: pointer; color: var(--brand); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.ok { background: #d1f2e0; color: #0f5132; }
.badge.pending { background: #fdecec; color: #b02a37; }
.sum tfoot td { font-weight: 700; border-top: 2px solid var(--ink); }

kbd {
  background: #eef2f6; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; font-size: 11px; font-family: inherit;
}
.keys { color: var(--muted); font-size: 12.5px; }

dialog {
  border: none; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.3); padding: 24px;
  width: 340px; max-width: min(92vw, 480px);          /* never wider than the phone */
  max-height: 88vh; overflow-y: auto;                 /* long dialogs scroll inside */
}
dialog .dlg-scroll { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
dialog table.users { border-collapse: separate; border-spacing: 0; }
dialog table.users th { position: sticky; top: 0; background: #f4f6f9; z-index: 1; }
dialog table.users th, dialog table.users td { padding: 7px 12px; font-size: 13.5px; white-space: nowrap; }
dialog table.users tr:last-child td { border-bottom: none; }
.btn.small { padding: 4px 12px; font-size: 12px; }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog h3 { margin: 0 0 14px; }
dialog .fld { margin-bottom: 12px; }
dialog .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ---------- toast notifications (replace blocking alert() popups) ---------- */
#toastHost {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(480px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  background: #1c2733; color: #fff; border-radius: 10px; padding: 11px 18px;
  font-size: 14px; line-height: 1.4; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  opacity: 0; transform: translateY(-8px); transition: opacity .25s, transform .25s;
  max-width: 100%; pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { background: #0f5132; }
.toast.err { background: #b02a37; }

/* ---------- bottom navigation (branch users on phones) ---------- */
.bottomnav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 80;
  background: #12291c; border-top: 1px solid rgba(255,255,255,.1);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; text-align: center; color: #9fc0aa; text-decoration: none;
  font-size: 11px; font-weight: 600; padding: 7px 2px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.bottomnav a span { font-size: 19px; line-height: 1; }
.bottomnav a.active { color: #fff; }
@media (max-width: 860px) {
  .bottomnav { display: flex; }
  body.has-bottomnav .wrap { margin-bottom: 120px; }
}

/* ---------- collapsible topbar tools on phones (busy screens like Reconciliation) ---------- */
.topbar .tools-toggle { display: none; }
.topbar .topbar-tools { display: contents; }
@media (max-width: 720px) {
  .topbar .tools-toggle { display: inline-flex; }
  .topbar .topbar-tools { display: none; }
  .topbar .topbar-tools.open { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; padding: 4px 0 6px; }
}

/* keyboard accessibility: visible focus ring on every control */
.btn:focus-visible, .mainnav a:focus-visible, .nav-toggle:focus-visible,
select:focus-visible, input[type="date"]:focus-visible {
  outline: 2px solid #2fb877; outline-offset: 2px;
}

/* ---------- responsive breakpoints: 980 (tables scroll) · 860 (nav drawer) · 720 (compact) ---------- */
@media (max-width: 980px) {
  .sum { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* mobile / small-tablet navigation: hamburger + full-width drawer, tap-to-open submenus */
@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .mainnav { padding: 0 8px; }
  .mainnav .nav-links {
    display: none; flex-direction: column; width: 100%;
    padding-bottom: 6px; max-height: calc(100vh - 60px); overflow-y: auto;
  }
  .mainnav .nav-links.open { display: flex; }
  .mainnav .nav-links a { padding: 13px 14px; border-bottom: 1px solid rgba(255,255,255,.07); border-left: 3px solid transparent; }
  .mainnav .nav-links a.active { border-bottom-color: rgba(255,255,255,.07); border-left-color: #2fb877; }
  .mainnav .nav-spacer { display: none; }
  .mainnav .nav-user { padding: 10px 14px 2px; }
  .nav-drop { display: block; }
  .nav-drop .nav-menu { position: static; display: none; box-shadow: none; border-radius: 0; padding-left: 14px; min-width: 0; }
  .nav-drop.open > .nav-menu { display: block; }
  .nav-drop:hover .nav-menu { display: none; }          /* hover must not fight the tap toggle */
  .nav-drop.open > .nav-menu { display: block; }
}

@media (max-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .savebar { gap: 10px; padding: 8px 14px; }
  .savebar .totals { gap: 12px; }
  .tot .val { font-size: 16px; }
  .rt { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .wrap { margin-bottom: 150px; }                       /* room for the wrapped save bar */
  .topbar { gap: 8px; padding: 8px 12px; }
  .topbar .logo { font-size: 15px; }
  .card .body { padding: 12px; }
  .status { min-width: 0; }
}

/* touch devices: comfortable targets for the small row buttons */
@media (pointer: coarse) {
  .btn.small { padding: 8px 12px; font-size: 13px; }
  .mainnav a, .nav-toggle { min-height: 44px; display: flex; align-items: center; }
  .topbar select, .topbar input[type="date"] { min-height: 38px; }
}

/* ---------- totals strip ----------
   One line of figures instead of a wall of boxes, so the list below it is on
   screen straight away. Green for the headline numbers, .light for a second
   line under it, .chips for a per-service / per-branch split. */
.sumline { display:flex; flex-wrap:wrap; align-items:center; gap:14px; padding:9px 12px; background:#0f5132;
           color:#fff; border-radius:10px; font-size:13px; }
.sumline .big { font-size:18px; font-weight:700; font-variant-numeric:tabular-nums; }
.sumline i { font-style:normal; color:#bbf7d0; }
.sumline b { font-weight:700; font-variant-numeric:tabular-nums; }
.sumline .wait { color:#fde68a; }
.sumline .due { color:#fecaca; }
.sumline .more { margin-left:auto; background:rgba(255,255,255,.15); border:none; color:#fff; border-radius:999px;
                 padding:5px 12px; font-family:inherit; font-size:12px; cursor:pointer; }
.sumline .more:hover { background:rgba(255,255,255,.28); }
.sumline.light { background:#fff; color:#0f172a; border:1px solid #e2e8f0; }
.sumline.light i { color:#64748b; }
.sumline.light .wait { color:#92400e; }
.sumline.light .due { color:#b91c1c; }
.sumline + .sumline, .sumline + .chips, .chips + .sumline { margin-top:8px; }
.chips { display:flex; flex-wrap:wrap; gap:8px; }
.chips span { background:#f8fafc; border:1px solid #e2e8f0; border-radius:8px; padding:5px 10px; font-size:12.5px; }
.chips b { font-variant-numeric:tabular-nums; }
@media print {
  .sumline { background:#fff !important; color:#000 !important; border:1px solid #999; }
  .sumline i, .sumline .due, .sumline .wait { color:#333 !important; }
}
