/* ============================================================================
   FORMULA1 PAINTS ERP v2 — Cloudflare-dashboard light theme
   ========================================================================== */

:root {
  --orange: #f6821f;
  --orange-dark: #9a5c00;
  --orange-tint: #fdeedc;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --line: #e6e8ec;
  --text: #1c1f24;
  --muted: #6b7280;
  --green: #157f3d;
  --green-bg: #e2f5e9;
  --red: #c5221f;
  --red-bg: #fdeceb;
  --amber: #935f00;
  --amber-bg: #fdf3d8;
  --gray-bg: #eef0f3;
  --radius: 10px;
  --side-w: 248px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.error { color: var(--red); }
a { color: var(--orange-dark); }

/* ============ LOGIN ============ */
#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1000px 500px at 80% -10%, #fdf1e3 0%, transparent 60%),
    radial-gradient(800px 400px at -10% 110%, #fdf1e3 0%, transparent 55%),
    var(--bg);
  padding: 1rem;
}
.login-box {
  width: 400px; max-width: 100%;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 2rem; box-shadow: 0 10px 40px rgba(20,30,50,.08);
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand h1 { font-size: 20px; margin-top: .6rem; }
.brand-dot {
  display: inline-block; width: 14px; height: 14px; border-radius: 4px;
  background: linear-gradient(135deg, #fbad41, var(--orange));
}
.form-error {
  background: var(--red-bg); color: var(--red);
  border: 1px solid #f6c7c5; border-radius: 8px;
  padding: .5rem .75rem; font-size: 13px; margin: .5rem 0;
}

/* ============ TOPBAR ============ */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: 56px; z-index: 60;
  background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: .9rem; padding: 0 1rem;
}
.topbar-brand { display: flex; align-items: center; gap: .5rem; font-size: 15px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; }
.user-chip { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.icon-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--gray-bg); }

/* ============ SIDEBAR (Cloudflare light) ============ */
.shell { display: flex; padding-top: 56px; min-height: 100vh; }
.sidebar {
  width: var(--side-w); flex-shrink: 0;
  position: sticky; top: 56px; height: calc(100vh - 56px);
  overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: space-between;
  transition: margin-left .18s ease;
}
.sidebar.collapsed { margin-left: calc(var(--side-w) * -1); }
.nav-group { padding: .35rem 0; }
.nav-group-title {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); padding: .8rem 1rem .35rem;
  display: flex; align-items: center; gap: .35rem; cursor: pointer; user-select: none;
}
.nav-group-title .chev { width: 12px; height: 12px; transition: transform .15s; }
.nav-group.collapsed .chev { transform: rotate(-90deg); }
.nav-group.collapsed .nav-item { display: none; }
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem 1rem .5rem 1.25rem; color: var(--text);
  text-decoration: none; font-size: 13.5px; border-left: 3px solid transparent;
  cursor: pointer;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .75; }
.nav-item:hover { background: #f3f4f6; }
.nav-item.active {
  background: var(--orange-tint); color: var(--orange-dark);
  border-left-color: var(--orange); font-weight: 600;
}
.nav-item.active svg { opacity: 1; }
.nav-badge {
  margin-left: auto; background: var(--orange); color: #fff;
  border-radius: 999px; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center;
  padding: 0 6px;
}
.sidebar-foot { padding: 1rem; border-top: 1px solid var(--line); }
.side-backdrop { display: none; }

/* ============ CONTENT ============ */
.content { flex: 1; padding: 1.5rem; min-width: 0; }
.page-head { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; }
.head-actions { margin-left: auto; display: flex; gap: .5rem; }
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1.1rem;
}
.panel h3 { font-size: 15px; margin-bottom: .7rem; }
.denied-box {
  max-width: 480px; margin: 4rem auto; text-align: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 2.5rem 2rem;
}

/* ============ BUTTONS / CHIPS ============ */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: .45rem .85rem; border-radius: 8px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--gray-bg); }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.primary:hover { background: #e5761a; }
.btn.ghost { background: transparent; }
/* cont-138: an ACTIVE filter button (the Today pick) must stay visible — the
   plain .btn.ghost rule above has the same specificity as .btn.primary but
   comes LATER, so it used to win and paint the pressed Today button
   white-on-transparent (invisible button AND text). The third class here wins
   on specificity and restores the solid orange pressed state. */
.btn.ghost.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.ghost.primary:hover { background: #e5761a; }
.btn.danger { color: var(--red); border-color: #f2b8b6; }
.btn.danger:hover { background: var(--red-bg); }
.btn.small { padding: .25rem .6rem; font-size: 12.5px; border-radius: 7px; }
.btn.full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.chip {
  display: inline-block; background: var(--orange-tint); color: var(--orange-dark);
  border: 1px solid #f6d4ab; border-radius: 999px; padding: .2rem .7rem;
  font-size: 12.5px; font-weight: 700;
}
/* ============ CARDS ============ */
.cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: .8rem; margin-bottom: 1.1rem;
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem 1rem; display: flex; flex-direction: column; gap: .25rem;
}
.card-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 21px; font-weight: 700; }
.card.warn .card-value { color: var(--amber); }
.card.danger .card-value { color: var(--red); }

/* Report Summary — printed-report sheet (cont-177/177b): the screen mirrors
   the printed document — company band, From/To/Printed meta, uppercase
   sections, ruled lines with the amount right-aligned and the View button
   at the far right of every line and breakdown */
.rs-sheet { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.2rem .6rem; max-width: 820px; }
.rs-band { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  padding-bottom: .7rem; border-bottom: 2px solid var(--line); margin-bottom: .55rem; }
.rs-company { font-weight: 800; font-size: 16px; }
.rs-company-sub { font-size: 12px; color: var(--muted); }
.rs-doctype { font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: 13px; padding-top: .25rem; }
.rs-meta { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; font-size: 12.5px; color: var(--muted);
  padding-bottom: .7rem; border-bottom: 1px solid var(--line); }
.rs-meta strong { color: var(--text); }
.rs-foot { margin-top: .6rem; padding-top: .55rem; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted); }
.rs-section-title { text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
  font-size: 11.5px; color: var(--muted); margin: .9rem 0 .15rem; }   /* cont-191: was used with no rule — headings fell back to plain body text */
.rs-line { display: flex; align-items: center; gap: .75rem; padding: .5rem 0;
  border-bottom: 1px dashed var(--line); }
.rs-line:last-child { border-bottom: none; }
.rs-line-label { flex: 1; font-weight: 600; }
.rs-line-amt { font-weight: 700; min-width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.rs-line-actions { flex: 0 0 auto; }
.rs-line-sub { padding: .35rem 0 .35rem 1.1rem; }
.rs-line-sub .rs-line-label { font-weight: 400; color: var(--muted); }
.rs-line-sub .rs-line-amt { font-weight: 600; }
@media print { .rs-line-actions { display: none !important; } }
.rs-card .card-value { font-size: 22px; }
.rs-card-top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.rs-subs { margin-top: .35rem; display: flex; flex-direction: column; }
.rs-sub { display: flex; align-items: center; gap: .5rem; padding-top: .35rem;
  border-top: 1px dashed var(--line); font-size: 12.5px; color: var(--muted); }
.rs-sub span:first-child { flex: 1; }
.rs-sub .rs-amt { font-weight: 700; color: var(--text); }

/* Dashboard — live cockpit (cont-176) */
.dash-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 1rem; align-items: start; margin-top: 1rem; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-col { display: flex; flex-direction: column; gap: 1rem; }
.dash-col .panel { margin-bottom: 0; }
.dash-queue-row { display: flex; align-items: center; gap: .6rem; padding: .45rem 0;
  border-bottom: 1px dashed var(--line); }
.dash-queue-row:last-child { border-bottom: none; }
.dash-queue-row .dq-label { flex: 1; }
.dash-queue-row .dq-count { font-weight: 700; min-width: 2.2rem; text-align: right; }
.dash-queue-row .dq-count.hot { color: #c0392b; font-weight: 800; }  /* cont-178: pending counts render red */
.live-chip { display: inline-flex; align-items: center; gap: .45rem; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #2e9e5b; display: inline-block; }
.live-chip.live-off .live-dot { background: var(--muted); }

/* ============ TABLES ============ */
table { width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
th { background: #fafbfc; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: .3rem; }
th.actions-col { width: 1%; }   /* cont-191: the marker th finally gets its rule — squeeze the actions column to content width */
.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
/* cont-193: wide tables scroll sideways INSIDE their wrapper (core.js
   wrapTables slides every data table into one of these) instead of
   stretching the page or getting clipped on phones. Harmless on desktop —
   it only scrolls when the table is genuinely wider than its panel. */
.tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============ BADGES ============ */
.badge {
  display: inline-block; border-radius: 999px; padding: .15rem .6rem;
  font-size: 11.5px; font-weight: 700; text-transform: capitalize;
}
.badge.draft            { background: var(--gray-bg); color: var(--muted); }
.badge.pending_approval { background: var(--amber-bg); color: var(--amber); }
.badge.approved         { background: var(--green-bg); color: var(--green); }
.badge.rejected         { background: var(--red-bg); color: var(--red); }
.badge.active           { background: var(--green-bg); color: var(--green); }
.badge.inactive         { background: var(--red-bg); color: var(--red); }
.badge.deleted          { background: var(--red-bg); color: var(--red); }
/* cont-138: the derived "Delivered" bill state and the confirmed sales
   return read PLAIN — no chip background (owner request), unlike the
   pending/approved states which keep theirs */
.badge.confirmed        { background: transparent; color: var(--text); }
.badge.delivered        { background: transparent; color: var(--text); }

/* ============ cont-134: bills audit UI ============ */
/* cont-135: the RED second confirmation — Edit/Del on an APPROVED bill opens
   a warning-styled ask FIRST; the panel and the Yes button are red */
.danger-panel {
  border: 1px solid #f2b8b6; border-left: 4px solid var(--red);
  background: var(--red-bg); color: var(--red);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 10px;
  font-size: 13.5px; line-height: 1.5;
}
.btn.danger-solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn.danger-solid:hover { background: #a91c1a; }
/* the small "Modified after approved" note under a bill number + its hover
   tooltip (a styled panel, NOT the bare title attribute) */
.mod-tip {
  position: relative; display: inline-block; margin-left: 7px;
  font-size: 10.5px; font-weight: 600; color: var(--amber);
  cursor: help; border-bottom: 1px dotted var(--amber);
}
/* cont-136: the bills-list variant sits UNDER the bill number (a second
   line) — inline it made the number column unnecessarily wide */
.mod-tip.under { margin-left: 0; margin-top: 2px; }
/* cont-136: fixed-header popups (the stock-movements pattern) — the BOX
   never scrolls, only the body does, so the head (title + Close) stays put;
   the body carries its own rounded edge so the scrollbar never clips the
   popup's rounded corner */
.modal-scroll-body { max-height: 74vh; overflow: auto; border-radius: 10px; }
.mod-tip-box {
  display: none; position: absolute; left: 0; top: calc(100% + 6px); z-index: 60;
  width: max-content; max-width: 320px; padding: 9px 12px;
  background: #fffdfa; color: #333; border: 1px solid var(--line);
  border-left: 4px solid var(--amber); border-radius: 8px;
  box-shadow: 0 8px 22px rgba(0,0,0,.16); font-size: 12px; font-weight: 500;
  line-height: 1.45; text-align: left; cursor: default;
}
.mod-tip:hover .mod-tip-box, .mod-tip:focus-within .mod-tip-box { display: block; }
/* the merged row message for a voided (deleted) bill — number + date stay,
   the rest of the row is one cell telling who deleted it and why */
.void-msg {
  color: var(--red); font-size: 13px;
  /* cont-136: NO row background change for a deleted bill — the red message
     text alone marks the row (owner request) */
  background: transparent;
}
.void-panel {
  border: 1px solid var(--red-bg, #f5c6c2); border-left: 4px solid var(--red);
  background: var(--red-bg, #fdf0ef); color: var(--red);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 10px;
  font-size: 13.5px;
}

/* ============ FORMS ============ */
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin: .6rem 0 .25rem; }
.sub-label { margin-top: 1rem; }
input, select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; font-size: 13.5px; background: var(--panel); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #f8c48f; border-color: var(--orange); }
.filters { display: flex; gap: .5rem; margin-bottom: .9rem; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 150px; flex: 0 1 auto; }
.form-row { display: flex; gap: .8rem; }
.form-row > div { flex: 1; min-width: 0; }
.check-line { display: flex; align-items: center; gap: .5rem; font-size: 13.5px; color: var(--text); margin-top: .8rem; }
.check-line input { width: auto; }

/* item groups page: section heading row per group type (Finished / Raw Materials) */
.type-head td { background: var(--bg); border-top: 2px solid var(--line); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .55rem .6rem; }
.check-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: .4rem; }
.check-list .check-line { margin: 0; padding: .35rem .5rem; border-radius: 6px; }
.check-list .check-line:hover { background: var(--gray-bg); }
.totals-bar {
  display: flex; justify-content: flex-end; gap: 1.5rem;
  padding: .6rem 0; margin-top: .8rem; font-size: 14px;
  border-top: 1px dashed var(--line);
}
/* ---- bill due strip: total due passed the credit limit (billing + approve) ---- */
#bm-due.over-limit {
  border: 1px solid var(--red); border-radius: var(--radius);
  background: var(--red-bg); padding: .6rem .8rem;
}
#bm-due.over-limit #bm-due-total { color: var(--red); }
#bm-due-warn { color: var(--red); border-color: var(--red); background: #fff; }
#bm-due.over-limit #bm-due-warn { background: var(--red); color: #fff; }

/* ---- bill VIEW modal credit strip — same "limit exceeds" message as the
   approve modal; separate ids because both modals live in the DOM ---- */
#bv-due {
  display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; align-items: center;
  margin-top: .8rem; padding: .55rem .8rem; font-size: 13.5px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--gray-bg);
}
#bv-due.over-limit {
  border: 1px solid var(--red); background: var(--red-bg);
}
#bv-due.over-limit #bv-due-total { color: var(--red); }
#bv-due-warn { color: var(--red); border-color: var(--red); background: #fff; }
#bv-due.over-limit #bv-due-warn { background: var(--red); color: #fff; }

/* queue row chip: this bill would cross the customer's credit limit */
.chip.over-chip { color: var(--red); border-color: var(--red); background: #fff; white-space: nowrap; }

/* ---- sales return modal: entry modes + bill lookup ---- */
.ret-modes { display: flex; gap: 1.2rem; margin: .2rem 0 .8rem; }
.ret-modes label { display: flex; align-items: center; gap: .4rem; font-size: 13.5px; cursor: pointer; }
.ret-billrow { display: flex; align-items: center; gap: .5rem; margin: .3rem 0 .8rem; }
.ret-prefix { font-weight: 600; padding: .45rem .6rem; background: var(--gray-bg); border: 1px solid var(--line); border-radius: var(--radius); }
table.ret-items { width: 100%; margin-top: .5rem; }
table.ret-items td, table.ret-items th { padding: .35rem .5rem; }

/* ============ BILL / RETURN LINE ROWS ============ */
.line { display: grid; grid-template-columns: 2.2fr .8fr .9fr 1fr 32px; gap: .45rem; align-items: center; margin-bottom: .45rem; }
.line .amt { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.line .btn { justify-self: center; }
/* cont-134: transport + cost lines on the bill form — purpose | amount | ✕ */
.cost-line { display: grid; grid-template-columns: 1fr 150px 32px; gap: .45rem; align-items: center; margin-bottom: .45rem; }
.cost-line .cl-purpose[readonly] { color: #444; background: #f6f7f9; }
.prod-mat { display: grid; grid-template-columns: 2.2fr .9fr 32px; gap: .45rem; align-items: center; margin-bottom: .45rem; }

/* ============ MODALS ============ */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 20, 30, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 1rem; overflow-y: auto;
}
.modal-box {
  background: var(--panel); border-radius: 14px; width: 560px; max-width: 100%;
  padding: 1.4rem 1.5rem; box-shadow: 0 24px 70px rgba(10,15,25,.25);
  margin-bottom: 4vh;
}
.modal-box.small { width: 420px; }
.modal-box.wide { width: 860px; }
.modal-box h3 { margin-bottom: .4rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; }

/* ============ PERMISSION MATRIX ============ */
.perm-groups { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem 1.2rem; margin-top: .6rem; }
.perm-group { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; }
.perm-group h4 { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; margin-bottom: .4rem; }
.perm-group .check-line { margin: 0 0 .2rem; }

/* ============ PAGER / TOAST ============ */
.pager { display: flex; align-items: center; gap: .8rem; justify-content: flex-end; padding: .7rem 0; font-size: 13px; }
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: .6rem 1.1rem; border-radius: 10px;
  font-size: 13.5px; z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  max-width: 90vw;
}
.toast.err { background: var(--red); }
.toast.warn { background: var(--amber); }
.report-head { padding: .8rem 0; }
.report-head h3 { margin-bottom: .2rem; }

/* ============ MOBILE ============ */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 56px; z-index: 70; margin-left: 0; box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .sidebar.collapsed { margin-left: calc(var(--side-w) * -1); }
  .side-backdrop.show {
    display: block; position: fixed; inset: 56px 0 0 0; z-index: 65; background: rgba(15,20,30,.35);
  }
  .form-row { flex-direction: column; gap: 0; }
  .perm-groups { grid-template-columns: 1fr; }
  .line { grid-template-columns: 1.6fr .7fr .8fr .9fr 32px; }
  .content { padding: 1rem; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  /* cont-193: long modal forms (the bill modal) scroll under a footer that
     never scrolls away — Save/Cancel stay reachable on tablets and phones */
  .modal { padding: 3vh .7rem .7rem; }
  .modal-box { padding: 1.1rem 1rem; }
  .modal-actions {
    position: sticky; bottom: 0; z-index: 5; background: var(--panel);
    border-top: 1px solid var(--line); padding-top: .7rem; margin-top: 1rem;
    box-shadow: 0 -10px 18px -12px rgba(15,23,42,.28);
  }
}

/* ============ MOBILE — phones (cont-193) ============
   Marketing bills and reads reports from a phone. NOT a separate site and
   not mobile-first: the desktop layout is untouched, these rules only relax
   fixed widths below 640px, stack the bill line rows, stop iOS auto-zoom
   and grow the tap targets. */
@media (max-width: 640px) {
  .content { padding: .8rem; }
  .page-head h2 { font-size: 18px; }
  /* the head action row owns a full line; fixed-width inputs (the dashboard's
     style="width:360px" search) shrink to it instead of overflowing */
  .head-actions { width: 100%; margin-left: 0; flex-wrap: wrap; }
  .head-actions input, .head-actions select { width: 100% !important; flex: 1 1 160px; min-width: 0; }
  /* iOS zooms any focused input whose font is smaller than 16px — 16 everywhere */
  input, select, textarea, .combo-input { font-size: 16px; }
  /* tighter cells so more columns fit before the sideways scroll starts */
  th, td { padding: .45rem .5rem; font-size: 13px; }
  th { font-size: 11px; }
  /* comfortable tap targets */
  .btn { padding: .5rem .85rem; }
  .btn.small { padding: .45rem .7rem; }
  .nav-item { padding: .65rem 1rem .65rem 1.25rem; }
  /* filter rows: every control takes a comfortable width and wraps */
  .filters input, .filters select, .filters .combo { flex: 1 1 150px; min-width: 130px; }
  /* the bill line stacks: the item picker owns row 1, qty · rate · amount · ✕
     share row 2 — no more 60px-wide selects on a 360px screen */
  .line { grid-template-columns: 1fr 1fr 1fr 32px; }
  .line > *:first-child { grid-column: 1 / -1; }
  .cost-line { grid-template-columns: 1fr 110px 32px; }
  .prod-mat { grid-template-columns: 1fr 1fr 32px; }
  /* the receive/production popups' fixed 130px qty column (page-scoped
     styles) — same stack: picker full row, qty + ✕ under it. The body
     prefix out-specifies the page-injected <style> blocks. */
  body #fr-modal .fr-line, body #mu-modal .mu-line,
  body #prod-modal .prod-line, body #sfr-modal .sfr-line { grid-template-columns: 1fr 110px 32px; }
  body #fr-modal .fr-line > *:first-child, body #mu-modal .mu-line > *:first-child,
  body #prod-modal .prod-line > *:first-child, body #sfr-modal .sfr-line > *:first-child { grid-column: 1 / -1; }
  body #fr-modal .fr-meta, body #mu-modal .mu-meta,
  body #prod-modal .prod-meta, body #sfr-modal .sfr-meta { grid-template-columns: 1fr; }
  .totals-bar { flex-wrap: wrap; gap: .5rem 1.2rem; }
  .combo-menu { max-width: min(92vw, 340px); }
  .cards { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
  .card-value { font-size: 19px; }
  /* slim topbar: the avatar carries the identity, the name text goes */
  #user-name { display: none; }
  /* toasts span the width instead of pinching in the middle */
  .toast { left: .6rem; right: .6rem; transform: none; max-width: none; text-align: center; }
}
/* ============================================================================
   A4 PRINT ENGINE — #print-area is filled by app.js, then window.print()
   ========================================================================== */
.print-only { display: none; }

@media print {
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  .print-only {
    display: block !important; position: static;
    width: 190mm; margin: 0 auto; color: #111; font-size: 12.5px;
  }
  /* cont-135: the cont-134 print forcing (0.5cm/0.9cm margins meant to push
     the printer's own header/footer off the sheet) did NOT work on the
     owner's setup — REMOVED; the engine is back to the standard A4 margins */
  @page { size: A4; margin: 12mm 10mm; }
}

.p-band {
  /* cont-198: back to the cont-196 geometry — the logo box + name+address
     block exactly as before (the box height follows the name+address block,
     no taller). The doc title + status/period chips OVERLAY the band from the
     right: position:absolute takes them out of the flow, so they can never
     squeeze the name+address column — the address keeps its single line (the
     original cont-197 goal, without the taller stacked band the owner found
     messy). The chip sits under the title like the old right zone did. */
  position: relative;
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 3px solid var(--orange); padding-bottom: 10px; margin-bottom: 14px;
  /* the name+address block's exact height: 21px name + 3px gap + 11.5px sub at
     the app's 1.5 line-height (if the header fonts ever change, update this
     one variable) */
  --plogo-h: calc(21px * 1.5 + 11.5px * 1.5 + 3px);
  /* cont-195: decent breathing room between the logo and its border */
  --plogo-pad: 5px;
}
.p-brand { display: flex; align-items: stretch; gap: 10px; }
.p-doc-float { position: absolute; top: 0; right: 0; text-align: right; }
.p-logo-box {
  flex: 0 0 auto; position: relative; overflow: hidden;
  height: var(--plogo-h);
  /* border-box width = padded image area (at the logo's own ratio) + 2×pad + borders */
  width: calc((var(--plogo-h) - 3px - 2 * var(--plogo-pad)) * 272 / 169 + 2 * var(--plogo-pad) + 3px);
  border: 1.5px solid #d9dde3; border-radius: 8px; background: #fff;
}
.p-logo-box img {
  position: absolute; inset: var(--plogo-pad);
  width: calc(100% - 2 * var(--plogo-pad)); height: calc(100% - 2 * var(--plogo-pad));
  object-fit: contain;
}
.p-company { font-size: 21px; font-weight: 800; letter-spacing: .2px; }
.p-company-sub { color: #444; font-size: 11.5px; margin-top: 3px; }
.p-doc-type {
  font-size: 15px; font-weight: 800; letter-spacing: .25em; text-transform: uppercase;
  text-align: right;
}
.p-chip {
  display: inline-block; margin-top: 5px; padding: 2px 10px;
  border: 1.5px solid var(--green); color: var(--green); border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em;
}
.p-meta { display: flex; gap: 26px; margin-bottom: 12px; }
.p-meta-item { font-size: 12px; }
.p-meta-item span { display: block; color: #666; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; }
.p-meta-item strong { font-size: 13px; }
.p-billto {
  border: 1px solid #e2e5ea; border-radius: 8px; padding: 10px 12px;
  margin-bottom: 14px; background: #fafbfc;
}
.p-billto-label { font-size: 10px; font-weight: 700; color: #888; letter-spacing: .12em; margin-bottom: 3px; }
.p-billto-name { font-size: 15px; font-weight: 700; }
.p-billto-line { font-size: 12px; color: #444; }
.p-duo { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.p-duo .p-billto { flex: 1; margin-bottom: 0; }
.p-dues { border: 1.5px solid #d9dde3; border-radius: 10px; padding: 10px 14px; min-width: 225px; background: #fafbfc; }
.p-dues h4 { margin: 0 0 6px; font-size: 10px; font-weight: 700; letter-spacing: .12em; color: #888; text-transform: uppercase; }
.p-due-row { display: flex; justify-content: space-between; gap: 20px; font-size: 12px; padding: 3px 0; }
.p-due-row.total { border-top: 1px solid #c9ced6; margin-top: 5px; padding-top: 6px; font-weight: 800; font-size: 13.5px; }
.p-group { margin-bottom: 12px; }
.p-group-title { font-size: 13px; font-weight: 800; margin: 8px 0 4px; }
.p-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.p-table th {
  background: #f2f3f5; border: 1px solid #d9dde3; padding: 6px 8px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; text-align: left;
}
.p-table td { border: 1px solid #e2e5ea; padding: 6px 8px; font-size: 12px; }
.p-center { text-align: center; }
.p-right { text-align: right; }
.p-words { font-size: 12px; padding: 6px 0; border-top: 1px dashed #cfd4db; }
.p-totals { margin-left: auto; width: 240px; font-size: 12.5px; }
.p-totals p { display: flex; justify-content: space-between; padding: 3px 0; }
.p-totals .p-net {
  border-top: 2px solid #111; margin-top: 4px; padding-top: 6px;
  font-weight: 800; font-size: 14px;
}
.p-notes { font-size: 11.5px; color: #444; margin-top: 8px; }
.p-sign { display: flex; justify-content: space-between; margin-top: 42px; }
.p-sign-box { width: 200px; text-align: center; font-size: 11px; color: #555; }
.p-sign-line { border-bottom: 1px solid #999; height: 26px; margin-bottom: 5px; }
.p-foot {
  margin-top: 22px; padding-top: 8px; border-top: 1px solid #e2e5ea;
  text-align: center; color: #777; font-size: 10.5px;
}
/* multi-page report pagination (cont-53): fixed-height page divs; every
   printed page ends with "Page x of y" bottom-right (print only).
   cont-67: break-after carries BOTH the modern property and the legacy
   page-break alias — some engines (older Safari, Android WebView) only
   honor the legacy one, and a missed break collapses every sheet onto one
   printed page. overflow is visible: if a sheet's content ever exceeds
   258mm it must spill visibly, never be silently swallowed (that once hid
   print rows and page numbers). */
.p-page {
  position: relative; height: 258mm; overflow: visible;
  break-after: page; page-break-after: always;
}
.p-page-last { height: auto; break-after: auto; page-break-after: auto; }
.p-pageno { position: absolute; bottom: 0; right: 0; font-size: 10.5px; color: #777; }
/* cont-201: the #build-tag stamp is gone (owner's call) — its rule removed */

.p-cont { font-size: 11px; color: #555; margin-bottom: 10px; }
.p-fixed { table-layout: fixed; }
.p-fixed td, .p-fixed th { padding-left: 4px; padding-right: 4px; }
.p-fixed td { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
/* statement/report print blocks */
.p-title { font-size: 17px; font-weight: 800; margin-bottom: 2px; }
.p-sub { color: #555; font-size: 11.5px; margin-bottom: 12px; }
.p-summary { display: flex; gap: 18px; margin: 10px 0; font-size: 12.5px; }
.p-summary div { border: 1px solid #e2e5ea; border-radius: 8px; padding: 8px 12px; background: #fafbfc; }
.p-summary span { display: block; color: #666; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; }
.p-summary strong { font-size: 14px; }

/* ================= PERMISSION MATRIX (pages/users.js) ================= */
.perm-toolbar{display:flex;gap:.6rem;align-items:center;margin-bottom:.6rem}
.perm-search{flex:1}
.perm-groups{max-height:52vh;overflow:auto;border:1px solid var(--line,#e5e7eb);border-radius:8px;padding:.35rem .75rem}
.perm-group{padding:.35rem 0}
.perm-group + .perm-group{border-top:1px dashed var(--line,#e5e7eb)}
.perm-group-head{display:flex;align-items:center;gap:.5rem;padding:.35rem 0}
.perm-group-head h4{margin:0;font-size:.8rem;text-transform:uppercase;letter-spacing:.04em}
.perm-mini{margin-left:auto;display:flex;gap:.25rem}
.btn.mini{padding:.1rem .45rem;font-size:.72rem;line-height:1.4}
.perm-row{display:flex;align-items:center;gap:.6rem;padding:.3rem .25rem;border-radius:6px;cursor:pointer}
.perm-row:hover{background:rgba(127,127,127,.07)}
.perm-row input[type=checkbox]{width:16px;height:16px;flex:none}
.perm-label{flex:1;display:flex;flex-direction:column;line-height:1.25}
.perm-desc{font-size:.75rem;color:#6b7280}
.perm-code{flex:none;font-size:.72rem;color:#9ca3af;background:rgba(127,127,127,.08);padding:.1rem .4rem;border-radius:4px}

/* ---------- searchable dropdowns (cont-152) ----------
   The wrapper keeps the original <select> (hidden — it stays the source of
   truth for options/value/rate data-* attributes); the input on top does the
   in-page type-to-filter, the menu lists the matches. */
.combo { position: relative; width: 100%; }
/* filter bars: the combo host takes over the sizing the old <select> had */
.filters .combo { width: auto; min-width: 150px; flex: 0 1 auto; }
.combo > select { display: none !important; }
.combo-input { width: 100%; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; }
.combo-input:focus { outline: none; border-color: #93b4f8; box-shadow: 0 0 0 2px rgba(37, 99, 235, .13); }
.combo-input:disabled { background: var(--bg); color: var(--muted); }
.combo-menu { display: none; position: absolute; top: 100%; left: 0; right: 0; min-width: 260px; max-height: 240px; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(20, 30, 60, .16); z-index: 90; }
.combo-menu.open { display: block; }
/* cont-153: full names always visible — rows wrap, no ellipsis */
.combo-menu .cm-row { padding: .45rem .6rem; cursor: pointer; font-size: 13px; line-height: 1.35; word-break: break-word; }
.combo-menu .cm-row.active, .combo-menu .cm-row:hover { background: #eef4ff; }
.combo-menu .cm-none { padding: .45rem .6rem; color: var(--muted); font-size: 13px; }

/* ==========================================================================
   SHELL UX — user hover menu, sidebar footer brand, hover-reveal, login,
   About popup (cont-179 … cont-182)
   ========================================================================== */

/* ---- topbar right: avatar + name, hover menu (cont-179) ---- */
.user-chip { position: relative; display: flex; align-items: center; gap: .5rem; cursor: pointer; outline: none; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #fbad41, var(--orange)); color: #fff;
  font-size: 12px; font-weight: 800; letter-spacing: .02em;
}
.user-menu {
  display: none; position: absolute; top: calc(100% + 10px); right: 0; z-index: 80;
  min-width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 18px 50px rgba(15,23,42,.18); padding: .45rem;
}
.user-chip:hover .user-menu, .user-chip:focus-within .user-menu { display: block; }
.user-menu-head { display: flex; flex-direction: column; gap: .1rem; padding: .55rem .7rem; border-bottom: 1px solid var(--line); margin-bottom: .35rem; }
.user-menu-head strong { font-size: 13.5px; }
.user-menu-item {
  display: flex; align-items: center; gap: .55rem; width: 100%;
  background: none; border: 0; font: inherit; font-size: 13.5px; color: var(--text);
  padding: .55rem .65rem; border-radius: 8px; cursor: pointer; text-align: left;
}
.user-menu-item:hover { background: var(--gray-bg); }
.user-menu-item.danger { color: #c0392b; }
.user-menu-item svg { opacity: .8; }

/* ---- sidebar footer = the software brand (name + version + About) ---- */
.side-brand { display: flex; align-items: center; gap: .45rem; margin-bottom: .3rem; flex-wrap: wrap; }
.side-brand-name { font-weight: 800; font-size: 14px; letter-spacing: -.01em; }
.ver-tag { font-size: 11.5px; font-weight: 700; color: var(--orange-dark); letter-spacing: .04em; }  /* cont-181: plain v1, no background */
.about-link {
  display: inline-flex; align-items: center; gap: .3rem; cursor: pointer;
  color: var(--muted); text-decoration: none; font-size: 12px; border-radius: 6px;
}
.about-link:hover { color: var(--orange-dark); text-decoration: underline; }

/* ---- hover-reveal overlay (desktop): a PURE overlay (cont-183) --------------
   The hidden sidebar is taken OUT of the page flow entirely — fixed and
   translated off-canvas — instead of the old in-flow negative margin (whose
   .18s transition re-flowed the page: on mouse-out the menu re-entered the
   flex row at full width and the content visibly squeezed left). Now showing
   or hiding the menu only ever SLIDES the same fixed box over the page; the
   content can never shift.                                                  */
#side-hotzone { position: fixed; left: 0; top: 56px; bottom: 0; width: 14px; z-index: 65; display: none; }
body.side-hidden #side-hotzone { display: block; }
@media (min-width: 901px) {
  body.side-hidden .sidebar {
    position: fixed; left: 0; top: 56px; bottom: 0; z-index: 70;
    margin-left: 0;                                    /* neutralize the old negative-margin hide */
    transform: translateX(calc(var(--side-w) * -1));   /* fully off-canvas — zero layout impact */
    box-shadow: none; transition: transform .18s ease; /* slide animation only, never layout */
  }
  body.side-hidden .sidebar.hover-reveal {
    transform: translateX(0);                          /* slides back OVER the page */
    box-shadow: 0 12px 44px rgba(15,23,42,.22);
  }
}
@media (max-width: 900px) {
  #side-hotzone { display: none !important; }   /* mobile keeps the backdrop flow */
  .sidebar.hover-reveal { position: fixed; }
}

/* ---- login card — logo slot on top, even vertical rhythm ---- */
.login-box { transition: box-shadow .25s ease, transform .25s ease; }
.login-box:hover { box-shadow: 0 18px 60px rgba(20,30,50,.13); transform: translateY(-2px); }
#login-logo { display: block; margin: 0 auto .5rem; max-height: 76px; max-width: 220px; object-fit: contain; }
#login-logo.hidden { display: none; }
.login-brand h1 { font-size: 21px; letter-spacing: -.01em; margin-top: .3rem; }
.login-brand .muted { margin-top: .25rem; font-size: 13px; }
#login-form label:first-child { margin-top: 0; }        /* first label hugs the brand block */
#login-form input { margin-bottom: .15rem; }
#login-form .form-error { margin: .7rem 0 0; }
#login-form .btn { margin-top: 1.15rem; }               /* clear separation before Sign in */
#login-form > .muted.center.small { margin-top: .9rem; }

/* ---- About popup — centered composition, no logo mark, no shadow (cont-182) ---- */
.about-card { position: relative; max-width: 440px; padding: 0 0 1.5rem; overflow: hidden; border-radius: 16px; box-shadow: none; }
.about-x {
  position: absolute; top: 12px; right: 12px; z-index: 2; border: 0; background: rgba(255,255,255,.75);
  font-size: 14px; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.about-x:hover { background: var(--gray-bg); color: var(--text); }
.about-hero {
  padding: 1.5rem 1.6rem 1.05rem; text-align: center; border-bottom: 1px solid var(--line);
  background:
    radial-gradient(440px 150px at 50% -50px, var(--orange-tint) 0%, transparent 72%),
    var(--panel);
}
.about-hero h2 { font-size: 20px; font-weight: 800; letter-spacing: -.01em; margin: 0; }
.about-body { padding: 1.15rem 1.7rem 0; text-align: center; }
.about-cap { font-size: 12.5px; color: var(--muted); margin: 0 0 .2rem; }   /* written as-is, no uppercase */
.about-co { font-size: 17px; font-weight: 800; margin: 0 0 .2rem; }
.about-line { font-size: 13.5px; margin: .15rem 0; }
.about-rule { border: 0; border-top: 1px solid var(--line); margin: .95rem auto; width: 60%; }
.about-dev { color: var(--orange-dark); font-weight: 700; text-decoration: none; border-bottom: 1.5px solid transparent; }
.about-dev:hover { border-bottom-color: var(--orange); }
.about-note {
  margin-top: .95rem; font-size: 12.5px; color: var(--muted); line-height: 1.55; text-align: left;
  background: var(--gray-bg); border: 1px solid var(--line); border-radius: 10px; padding: .65rem .8rem;
}

/* permission search dropdown (cont-187) */
.ps2-dd {
  position: absolute; left: 0; right: 0; top: calc(100% + 3px); z-index: 30;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
  max-height: 240px; overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.ps2-opt { padding: 7px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.ps2-opt:hover { background: rgba(127,127,127,.15); }
