/* ============================================================
   SUN Environmental CRM — shared design system (app.css)
   Dark theme + #E8621A orange, mirrors the field-form template.
   This is the ONLY stylesheet for all CRM pages.
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --orange: #E8621A;
  --dark: #1A1A1A;
  --gray: #2D2D2D;
  --border: #3A3A3A;
  --field: #252525;
  --text: #F0F0F0;
  --muted: #888;
  --label: #AAAAAA;
  --green: #4CAF50;
  --amber: #FFB300;
  --red: #E53935;
  --touch: 52px;
}

html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--dark);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
}
a { color: var(--orange); }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.right { text-align: right; }
.w-full { width: 100%; }
.mt8 { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.mb8 { margin-bottom: 8px; }
.mb16 { margin-bottom: 16px; }
[hidden] { display: none !important; }

/* ---------- Fields & inputs (template-identical) ---------- */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.lbl {
  display: block; font-size: 11px; font-weight: 600; letter-spacing: .6px;
  text-transform: uppercase; color: var(--label); margin-bottom: 6px;
}
input[type=text], input[type=date], input[type=time], input[type=number],
input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: var(--touch); background: var(--field);
  border: 1.5px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 16px; padding: 0 14px;
  appearance: none; -webkit-appearance: none; outline: none;
  font-family: inherit; transition: border-color .15s;
}
input[type=date], input[type=time] { padding: 14px; color-scheme: dark; }
textarea { padding: 14px; min-height: 90px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--orange); }
input::placeholder, textarea::placeholder { color: #666; }

/* Read-only fields — a permission downgrade (e.g. customer.view without
   customer.edit) leaves the record legible but not editable. Without this they
   are pixel-identical to editable inputs: they take focus, show the orange
   focus ring and a caret, then silently swallow typing, which reads as a bug
   rather than as a deliberate restriction.
   NOTE: `[readonly]` (the attribute, set by the `.readOnly` IDL property) and
   NOT `:read-only`, which also matches checkboxes, radios and buttons. */
input[readonly], textarea[readonly] {
  background: transparent; border-color: var(--border);
  color: var(--label); cursor: default;
}
input[readonly]:focus, textarea[readonly]:focus {
  border-color: var(--border); box-shadow: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6,9 12,15 18,9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px;
}
input[type=checkbox].cb { width: 20px; height: 20px; min-height: 0; accent-color: var(--orange); cursor: pointer; }
.check-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--label); font-weight: 600; cursor: pointer; min-height: 44px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }
/* Grid children default to min-width:auto and inflate their track to the
   intrinsic width of inputs / nowrap rows, overflowing 390px viewports
   (SPEC §18). Let them shrink instead. */
.row2 > .field, .row2 > .field input, .row2 > .field select { min-width: 0; }
.grid2 > * { min-width: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn-pri, .btn-sec, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); padding: 0 22px; border-radius: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer; text-decoration: none;
  font-family: inherit; transition: opacity .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn-pri { background: var(--orange); border: none; color: #fff; }
.btn-pri:hover { opacity: .92; }
.btn-pri:active { opacity: .85; }
.btn-sec { background: transparent; border: 1.5px solid var(--border); color: var(--label); font-weight: 600; }
.btn-sec:hover { border-color: #4d4d4d; color: var(--text); }
.btn-danger { background: transparent; border: 1.5px solid rgba(229,57,53,.5); color: var(--red); font-weight: 600; }
.btn-danger:hover { border-color: var(--red); }
.btn-pri:disabled, .btn-sec:disabled, .btn-danger:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { min-height: 44px; padding: 0 14px; font-size: 13px; border-radius: 9px; } /* ≥44px touch target (SPEC §18) */
.btn-block { width: 100%; }
.btn-pri svg, .btn-sec svg, .btn-danger svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* Dashed add-row button (template) */
.add-btn {
  width: 100%; min-height: 48px; background: rgba(232,98,26,.07);
  border: 1.5px dashed rgba(232,98,26,.4); border-radius: 10px; color: var(--orange);
  font-size: 14px; font-weight: 600; cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 8px; transition: background .15s; font-family: inherit; margin-top: 10px;
}
.add-btn:hover, .add-btn:active { background: rgba(232,98,26,.15); }
.add-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; }

/* ---------- Cards ---------- */
.card {
  background: var(--field); border: 1.5px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 14px;
}
.card-title {
  font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--label); margin-bottom: 14px; display: flex; align-items: center; gap: 10px;
}
.card-title svg { width: 15px; height: 15px; stroke: var(--orange); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* row-card header (edit mode / dynamic rows, template style) */
.card-hdr { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-num { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--orange); }
.rm-btn {
  position: relative; width: 32px; height: 32px; background: rgba(255,255,255,.05); border: none; border-radius: 6px;
  color: var(--muted); font-size: 20px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; line-height: 1; font-family: inherit; flex-shrink: 0;
}
/* Invisible hit-area extension: 32px visual, 44px touch target (SPEC §18). */
.rm-btn::after { content: ''; position: absolute; inset: -6px; }
.rm-btn:hover { color: var(--red); background: rgba(229,57,53,.12); }
.card .card, .row-card { background: var(--dark); }
.total-box {
  background: rgba(232,98,26,.1); border: 1.5px solid rgba(232,98,26,.3); border-radius: 10px;
  min-height: 46px; display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: var(--orange); padding: 0 14px;
}
.time-row { display: grid; grid-template-columns: 1fr 1fr 104px 60px; gap: 8px; align-items: end; }
.time-row .field { margin-bottom: 0; }
/* Time inputs must shrink below their intrinsic width or the row overflows
   390px viewports in edit mode (form.html carries the same rule). */
.time-row .field, .time-row .field input, .time-row .field select { min-width: 0; }
/* The break select's value must never clip ('30 min', not '30 mi'): narrower
   chevron gutter than the 38px global select rule. */
.time-row select { padding-right: 30px; background-position: right 8px center; }
/* Small phones: 4 columns squeeze the IN/OUT values to a letter ('A|').
   Wrap to 2×2 — times on the first row, BREAK/TOTAL on the second
   (form.html carries the same rule for the field form). */
@media (max-width: 479px) {
  .time-row { grid-template-columns: 1fr 1fr; }
}

/* ---------- Toggle group + checkbox tiles (template) ---------- */
.toggle-group { display: flex; gap: 10px; }
.tog { flex: 1; position: relative; }
.tog input[type=radio] { position: absolute; opacity: 0; width: 0; height: 0; min-height: 0; }
.tog label {
  display: flex; align-items: center; justify-content: center; min-height: var(--touch);
  background: var(--field); border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 15px; font-weight: 600; color: var(--muted); cursor: pointer; transition: all .15s;
}
.tog input:checked + label { background: rgba(232,98,26,.14); border-color: var(--orange); color: var(--orange); }
.tog.yes input:checked + label { background: rgba(76,175,80,.12); border-color: var(--green); color: var(--green); }
.tog input:focus-visible + label { outline: 2px solid var(--orange); outline-offset: 2px; }
.chk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chk { position: relative; }
.chk input[type=checkbox] { position: absolute; opacity: 0; width: 0; height: 0; min-height: 0; }
.chk label {
  display: flex; align-items: center; gap: 10px; background: var(--field);
  border: 1.5px solid var(--border); border-radius: 10px; padding: 13px 12px;
  font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer;
  transition: all .15s; min-height: 50px;
}
.chk-box {
  width: 20px; height: 20px; border: 2px solid var(--border); border-radius: 5px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.chk-box svg { width: 11px; height: 11px; stroke: #fff; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity .1s; }
.chk input:checked + label { border-color: var(--orange); background: rgba(232,98,26,.1); }
.chk input:checked + label .chk-box { background: var(--orange); border-color: var(--orange); }
.chk input:checked + label .chk-box svg { opacity: 1; }
.chk input:focus-visible + label { outline: 2px solid var(--orange); outline-offset: 2px; }
.chk-list { display: flex; flex-direction: column; gap: 10px; }
.chk-list .chk label { font-size: 13px; min-height: 44px; }

/* ---------- Badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px;
  border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .3px;
  border: 1.5px solid transparent; white-space: nowrap; line-height: 1.4;
}
.badge-pending  { color: var(--orange); background: rgba(232,98,26,.12);  border-color: rgba(232,98,26,.35); }
.badge-partial  { color: var(--amber);  background: rgba(255,179,0,.1);   border-color: rgba(255,179,0,.3); }
.badge-approved { color: var(--green);  background: rgba(76,175,80,.12);  border-color: rgba(76,175,80,.35); }
.badge-guest    { color: var(--label);  background: rgba(255,255,255,.06); border-color: var(--border); }
.badge-muted    { color: var(--muted);  background: rgba(255,255,255,.04); border-color: var(--border); }

.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px;
  border-radius: 999px; border: 1.5px solid var(--border); background: var(--field);
  font-size: 12px; font-weight: 600; color: var(--label); white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.chip-on  { color: var(--green); border-color: rgba(76,175,80,.35); }
.chip-on .dot { background: var(--green); }
.chip-off { color: var(--muted); }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--dark); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 9px; font-size: 13px; letter-spacing: 1.5px; color: var(--text);
}

/* ---------- Stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 820px) { .stat-grid { grid-template-columns: 1fr 1fr; } }
.stat-tile { background: var(--field); border: 1.5px solid var(--border); border-radius: 12px; padding: 14px 16px; min-height: 84px; }
.stat-label { font-size: 11px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--label); }
.stat-value { font-size: 27px; font-weight: 800; color: var(--text); margin-top: 6px; line-height: 1.15; }
.stat-value .unit { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Tables ---------- */
.table-wrap {
  border: 1.5px solid var(--border); border-radius: 12px; background: var(--field);
  overflow-x: auto; margin-bottom: 14px;
}
.card .table-wrap { border: none; border-radius: 0; background: transparent; margin-bottom: 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--label); padding: 11px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tfoot td { border-top: 1px solid var(--border); border-bottom: none; font-weight: 700; color: var(--label); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl th.num { text-align: right; }
.tbl tr.rowlink { cursor: pointer; }
.tbl tr.rowlink:hover td { background: rgba(255,255,255,.03); }
.tbl .cell-strong { font-weight: 700; }
.tbl .cell-sub { font-size: 12px; color: var(--muted); }
/* Short values that must never break onto two lines (dates, people names) —
   the DFR list looked ragged with 'Jul 18,' / '2026' wrapping on every row. */
.tbl .cell-nowrap { white-space: nowrap; }

/* Mobile: tables collapse to stacked cards (unless .tbl-keep). Cells need data-label. */
@media (max-width: 699px) {
  .tbl:not(.tbl-keep) thead { display: none; }
  .tbl:not(.tbl-keep), .tbl:not(.tbl-keep) tbody, .tbl:not(.tbl-keep) tfoot,
  .tbl:not(.tbl-keep) tr, .tbl:not(.tbl-keep) td { display: block; width: 100%; }
  .tbl:not(.tbl-keep) tr { border-bottom: 1px solid var(--border); padding: 10px 14px; }
  .tbl:not(.tbl-keep) tbody tr:last-child { border-bottom: none; }
  .tbl:not(.tbl-keep) td { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 4px 0; border: none; text-align: right; }
  .tbl:not(.tbl-keep) td.num { text-align: right; }
  .tbl:not(.tbl-keep) td[data-label]::before {
    content: attr(data-label); color: var(--label); font-size: 11px; font-weight: 600;
    letter-spacing: .5px; text-transform: uppercase; text-align: left; flex-shrink: 0; padding-top: 2px;
  }
  .tbl:not(.tbl-keep) tr.rowlink:hover td { background: none; }
  .tbl:not(.tbl-keep) tr.rowlink:hover { background: rgba(255,255,255,.03); }
  /* Footer Total rows: one 'Total … amount' line — no per-column labels and
     no orphaned empty label rows (reads as broken data otherwise). */
  .tbl:not(.tbl-keep) tfoot tr { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; }
  .tbl:not(.tbl-keep) tfoot td { display: block; width: auto; padding: 4px 0; }
  .tbl:not(.tbl-keep) tfoot td:empty { display: none; }
  .tbl:not(.tbl-keep) tfoot td[data-label]::before { content: none; }
}

/* ---------- Toolbar (filters / actions row) ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.toolbar .field { margin-bottom: 0; flex: 1 1 150px; min-width: 130px; }
.toolbar .field-grow { flex: 2 1 220px; }
.toolbar .btn-pri, .toolbar .btn-sec, .toolbar .btn-danger { flex: 0 0 auto; }
.toolbar-spacer { flex: 1; }
.result-count { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-title { font-size: 22px; font-weight: 800; letter-spacing: .2px; flex: 1 1 auto; min-width: 0; }
.page-sub { flex-basis: 100%; font-size: 13px; color: var(--muted); margin-top: -8px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none; margin-bottom: 12px; min-height: 44px; }
.back-link:hover { color: var(--text); }
.section-title {
  font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--label); margin: 22px 0 12px;
}

/* ---------- App shell ---------- */
/* Content container (SPEC §11): every shell page's <main class="main"> is
   capped at 1160px and centered in the area right of the sidebar (the body's
   padding-left shifts the centering box), so big monitors never get
   edge-to-edge content or unreadable table line lengths. Side padding steps
   up on wide screens. No full-bleed exceptions. */
body.has-shell .main { max-width: 1160px; margin: 0 auto; padding: 20px 16px 110px; }
@media (min-width: 900px) {
  body.has-shell { padding-left: 230px; }
  body.has-shell .main { padding: 28px 32px 48px; }
}
@media (min-width: 1600px) {
  body.has-shell .main { padding: 36px 48px 56px; }
}

/* Desktop sidebar */
.sidebar {
  display: none; position: fixed; top: 0; left: 0; bottom: 0; width: 230px;
  background: var(--gray); border-right: 1px solid var(--border);
  flex-direction: column; z-index: 50;
}
@media (min-width: 900px) { .sidebar { display: flex; } }
.side-logo { background: #fff; padding: 12px 16px; display: flex; align-items: center; border-bottom: 2px solid var(--orange); }
.side-logo img { height: 44px; width: auto; max-width: 100%; }
.side-nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.side-link {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px;
  color: var(--label); font-size: 14px; font-weight: 600; text-decoration: none; min-height: 44px;
}
.side-link svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.side-link:hover { background: rgba(255,255,255,.04); color: var(--text); }
.side-link.active { background: rgba(232,98,26,.12); color: var(--orange); }
.side-foot { padding: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 4px 10px; min-width: 0; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: rgba(232,98,26,.18);
  color: var(--orange); font-weight: 700; font-size: 13px; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.signout-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px;
  background: transparent; border: 1.5px solid var(--border); border-radius: 10px;
  color: var(--label); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0 12px;
}
.signout-btn:hover { border-color: #4d4d4d; color: var(--text); }
.signout-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Mobile top bar (white logo band, like the form) */
.topbar {
  position: sticky; top: 0; z-index: 40; background: #fff; padding: 8px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 2px solid var(--orange);
}
.topbar img { height: 38px; width: auto; }
.topbar-title {
  font-size: 11px; font-weight: 700; color: #555; letter-spacing: .5px;
  text-transform: uppercase; text-align: right; line-height: 1.5;
}
@media (min-width: 900px) { .topbar { display: none; } }

/* Mobile bottom tab bar */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--gray); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: stretch;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
@media (min-width: 900px) { .bottombar { display: none; } }
.bb-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  gap: 3px; padding: 4px 2px; color: var(--muted); font-size: 10px; font-weight: 600;
  text-decoration: none; min-height: 48px; background: none; border: none; cursor: pointer;
}
.bb-item svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bb-item.active { color: var(--orange); }
.bb-new-circle {
  width: 48px; height: 48px; border-radius: 50%; background: var(--orange);
  display: flex; align-items: center; justify-content: center; margin-top: -22px;
  box-shadow: 0 4px 14px rgba(232,98,26,.45); border: 3px solid var(--dark);
}
.bb-new-circle svg { stroke: #fff; width: 24px; height: 24px; }

/* "More" bottom sheet */
.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; border: none; padding: 0; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; background: var(--gray);
  border-radius: 16px 16px 0 0; border-top: 1px solid var(--border);
  padding: 10px 14px calc(16px + env(safe-area-inset-bottom));
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 10px; }
.sheet-link {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px;
  border-radius: 10px; color: var(--text); font-size: 15px; font-weight: 600;
  text-decoration: none; background: none; border: none; cursor: pointer; min-height: 52px;
}
.sheet-link:hover { background: rgba(255,255,255,.05); }
.sheet-link svg { width: 20px; height: 20px; stroke: var(--label); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Toasts ---------- */
.toast-wrap {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
@media (max-width: 899px) { body.has-shell .toast-wrap { bottom: 90px; } }
.toast {
  background: var(--gray); border: 1px solid var(--border); border-left: 4px solid var(--orange);
  border-radius: 10px; padding: 12px 18px; color: var(--text); font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); max-width: 100%; animation: toast-in .2s ease;
}
.toast-err { border-left-color: var(--red); }
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Empty / loading states ---------- */
.empty {
  padding: 44px 20px; text-align: center; color: var(--muted); font-size: 14px;
  display: flex; flex-direction: column; gap: 16px; align-items: center;
}
.empty-title { font-size: 16px; font-weight: 700; color: var(--label); }
.spinner {
  width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--orange);
  border-radius: 50%; animation: spin .8s linear infinite; margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }
.pg-info { font-size: 13px; color: var(--muted); }

/* ---------- Dashboard ---------- */
.greeting { font-size: 24px; font-weight: 800; }
.greeting-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.dash-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.dash-head .greet-wrap { flex: 1 1 auto; min-width: 0; }
.chart-box { position: relative; min-height: 200px; }
.chart-svg { display: block; width: 100%; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--gray);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.5); transform: translate(-50%, -100%);
}
.list-rows { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 6px; min-height: 56px;
  border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); border-radius: 6px;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: rgba(255,255,255,.03); }
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.list-side { text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; flex-shrink: 0; }
.list-side .hrs { font-size: 13px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Login page ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 18px; }
.login-card {
  width: 100%; max-width: 430px; background: var(--gray); border: 1px solid var(--border);
  border-radius: 16px; overflow: hidden;
}
.logo-band { background: #fff; padding: 18px; display: flex; align-items: center; justify-content: center; border-bottom: 2px solid var(--orange); }
.logo-band img { height: 56px; width: auto; max-width: 90%; }
.login-body { padding: 24px 22px 26px; }
.login-title { font-size: 13px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--label); text-align: center; margin-bottom: 20px; }
.code-input {
  text-transform: uppercase; text-align: center; font-size: 21px; font-weight: 700;
  letter-spacing: 3px; min-height: 58px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.code-input::placeholder { letter-spacing: 2px; font-size: 17px; color: #555; font-family: inherit; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; margin: 22px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.ms-btn {
  width: 100%; min-height: var(--touch); background: var(--field); border: 1.5px solid var(--border);
  border-radius: 12px; color: var(--text); font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 11px; cursor: pointer;
  transition: border-color .15s;
}
.ms-btn:hover { border-color: #4d4d4d; }
.ms-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.guest-link {
  display: block; width: 100%; text-align: center; color: var(--muted); font-size: 14px;
  margin-top: 20px; text-decoration: underline; background: none; border: none;
  cursor: pointer; font-family: inherit; min-height: 44px;
}
.guest-link:hover { color: var(--text); }
.form-err {
  background: rgba(229,57,53,.1); border: 1.5px solid rgba(229,57,53,.4); color: #ff8a80;
  border-radius: 10px; padding: 11px 14px; font-size: 14px; font-weight: 600; margin-bottom: 16px;
}

/* ---------- DFR detail ---------- */
.detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 6px; }
.detail-head h1 { font-size: 22px; font-weight: 800; letter-spacing: .3px; }
.detail-sub { flex-basis: 100%; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.action-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.guest-banner {
  background: rgba(255,179,0,.08); border: 1.5px solid rgba(255,179,0,.35); border-radius: 12px;
  padding: 13px 16px; color: var(--amber); font-size: 14px; font-weight: 600;
  margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start;
}
.guest-banner svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; margin-top: 1px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px 20px; }
.kv .k { font-size: 11px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; color: var(--label); margin-bottom: 3px; }
.kv .v { font-size: 15px; font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.desc-block { font-size: 14px; line-height: 1.6; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 12px; }
.approve-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
@media (max-width: 700px) { .approve-grid { grid-template-columns: 1fr; } }
.approve-box {
  background: var(--field); border: 1.5px solid var(--border); border-radius: 12px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 8px;
}
.approve-box.stamped { border-color: rgba(76,175,80,.4); background: rgba(76,175,80,.06); }
.approve-kind { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--label); }
.approve-stamp { color: var(--green); font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.approve-stamp svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.approve-wait { color: var(--muted); font-size: 14px; }
.method-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.check-list-view { display: flex; flex-direction: column; gap: 9px; }
.check-item { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; line-height: 1.45; }
.check-item .ck {
  width: 20px; height: 20px; border-radius: 5px; flex-shrink: 0; display: flex;
  align-items: center; justify-content: center; font-size: 12px; font-weight: 800; margin-top: 1px;
}
.check-item.yes .ck { background: var(--green); color: #fff; }
.check-item.no .ck { border: 2px solid var(--border); color: var(--muted); }
.check-item.yes { color: var(--text); }
.check-item.no { color: var(--muted); }
.sig-view { font-size: 17px; font-style: italic; font-weight: 600; color: var(--text); }

/* ---------- Modals (customers/users pages etc.) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 80;
  display: flex; align-items: center; justify-content: center; padding: 18px; overflow-y: auto;
}
.modal {
  background: var(--gray); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; width: 100%; max-width: 500px; max-height: 92vh; overflow-y: auto;
}
.modal-hdr { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-title { font-size: 16px; font-weight: 800; }
.modal-close {
  position: relative; width: 36px; height: 36px; background: rgba(255,255,255,.05); border: none; border-radius: 8px;
  color: var(--muted); font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.modal-close::after { content: ''; position: absolute; inset: -4px; } /* 44px touch target */
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Users page: capacity meter + integrations ---------- */
.meter-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--label); font-weight: 600; margin-bottom: 7px; }
.meter-row .meter-count { color: var(--text); font-weight: 800; }
.meter { height: 10px; background: var(--dark); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--orange); border-radius: 999px; transition: width .3s; min-width: 2px; }
.meter-fill.full { background: var(--red); }
.integration-chips { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- Reports (billing) page ---------- */
.report-note { font-size: 13px; color: var(--muted); margin: -8px 0 16px; }
.report-head-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin: 18px 0 10px; }
.report-range { font-size: 13px; color: var(--muted); }

/* ============================================================
   ROLES & PERMISSIONS (permissions.html) — SPEC §19
   Desktop: a real matrix table with a sticky header row and a sticky
   permission column. Mobile (<900px): a role selector + that role's
   toggle list — a squashed 5-column table is unusable at 390px.
   ============================================================ */

/* Page-head action buttons (sit right of the title, wrap on narrow screens). */
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Roles card ---------- */
.pm-role-row { align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.pm-role-row .list-title { white-space: normal; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pm-role-desc { white-space: normal; overflow: visible; text-overflow: clip; }
.pm-role-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex-shrink: 0; }
/* Narrow screens: the chips + Rename/Delete cannot shrink, so drop them onto
   their own full-width line instead of letting them push past the card edge. */
@media (max-width: 899px) {
  .pm-role-actions { flex-basis: 100%; flex-shrink: 1; margin-top: 10px; }
}
.pm-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; font-weight: 600; color: var(--muted);
  background: rgba(255,255,255,.05); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 6px;
}
.badge-locked { color: var(--orange); background: rgba(232,98,26,.12); border-color: rgba(232,98,26,.35); }
/* A staged, not-yet-saved permission count — reads as pending, not as truth. */
.badge-pending { color: var(--orange); background: rgba(232,98,26,.10); border-color: rgba(232,98,26,.45); }

/* ---------- Shared permission label block ---------- */
.pm-perm { min-width: 0; }
.pm-perm-label {
  font-size: 13.5px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 6px; line-height: 1.3;
}
.pm-perm-desc { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.pm-danger { color: var(--amber); font-size: 12px; cursor: help; }
.pm-lock { font-size: 11px; }

/* ---------- Desktop matrix ---------- */
.pm-wrap { display: none; }
@media (min-width: 900px) {
  .pm-wrap {
    display: block;
    background: var(--field); border: 1.5px solid var(--border); border-radius: 12px;
    /* Own scroll box so the sticky header/column have something to stick to
       and a wide role list never scrolls the page body sideways. */
    overflow: auto; max-height: calc(100vh - 260px);
  }
}
.pm-matrix { width: 100%; border-collapse: separate; border-spacing: 0; }
.pm-matrix th, .pm-matrix td { background: var(--field); }

/* Permission column — sticky left, holds the label + description. */
.pm-matrix .pm-permcol {
  position: sticky; left: 0; z-index: 2;
  text-align: left; vertical-align: middle;
  padding: 12px 16px; min-width: 300px; max-width: 380px;
  border-bottom: 1px solid var(--border); border-right: 1.5px solid var(--border);
  font-weight: 400;
}
/* Role columns — sticky header row. */
.pm-matrix thead th {
  position: sticky; top: 0; z-index: 3;
  padding: 12px 14px; border-bottom: 1.5px solid var(--border);
  vertical-align: bottom;
}
.pm-matrix thead .pm-corner {
  z-index: 4; /* above both sticky axes */
  font-size: 11px; font-weight: 700; letter-spacing: .6px;
  text-transform: uppercase; color: var(--label);
}
.pm-rolecol { text-align: center; min-width: 132px; }
.pm-role-name { font-size: 14px; font-weight: 800; color: var(--text); }
.pm-role-sub { display: flex; align-items: center; justify-content: center; gap: 5px; margin-top: 4px; }
.pm-usercount {
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  background: rgba(255,255,255,.05); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 8px; white-space: nowrap;
}

/* Group header rows. */
.pm-matrix .pm-groupcell {
  position: sticky; left: 0;
  text-align: left; padding: 14px 16px 8px;
  background: var(--field); border-bottom: 1px solid var(--border);
}
.pm-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--orange);
}
.pm-group-desc { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 10px; }

/* Checkbox cells — generous hit target, no zebra striping (SPEC brief). */
.pm-cell {
  text-align: center; border-bottom: 1px solid var(--border);
  padding: 0; vertical-align: middle;
}
.pm-check {
  display: flex; align-items: center; justify-content: center;
  min-height: 48px; width: 100%; cursor: pointer;
}
.pm-cb { width: 22px; height: 22px; }
.pm-matrix tbody tr:hover .pm-permcol,
.pm-matrix tbody tr:hover .pm-cell { background: rgba(255,255,255,.03); }

/* Locked admin column. The tint must COMPOSITE over the opaque cell background
   rather than replace it: `.pm-matrix .pm-locked` (0-2-0) outranks
   `.pm-matrix th, .pm-matrix td` (0-1-1), so a plain `background: rgba(…)` left
   the sticky Admin header translucent and tbody rows scrolled through it. */
.pm-matrix .pm-locked {
  background-color: var(--field);
  background-image: linear-gradient(rgba(232,98,26,.06), rgba(232,98,26,.06));
}
.pm-matrix tbody tr:hover .pm-locked {
  background-color: var(--field);
  background-image: linear-gradient(rgba(232,98,26,.09), rgba(232,98,26,.09));
}
.pm-locked .pm-check { cursor: not-allowed; }
.pm-cb:disabled { opacity: .75; }

/* Staged (unsaved) cells. */
.pm-changed { box-shadow: inset 0 0 0 2px rgba(232,98,26,.55); }

/* ---------- Mobile role view ---------- */
.pm-roletabs { display: none; }
@media (max-width: 899px) {
  .pm-roletabs {
    display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px;
    margin-bottom: 12px; scrollbar-width: none;
  }
  .pm-roletabs::-webkit-scrollbar { display: none; }
}
.pm-roletab {
  display: inline-flex; align-items: center; gap: 7px; flex-shrink: 0;
  min-height: 44px; padding: 0 14px; border-radius: 999px;
  background: var(--field); border: 1.5px solid var(--border);
  color: var(--label); font-family: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer; white-space: nowrap;
}
.pm-roletab.active { border-color: var(--orange); color: var(--orange); background: rgba(232,98,26,.1); }
.pm-roletab-count {
  font-size: 11px; font-weight: 700; color: var(--muted);
  background: rgba(255,255,255,.07); border-radius: 999px; padding: 1px 7px;
}
.pm-roletab.active .pm-roletab-count { color: var(--orange); background: rgba(232,98,26,.18); }

.pm-panel { display: none; }
@media (max-width: 899px) {
  .pm-panel {
    display: block; background: var(--field);
    border: 1.5px solid var(--border); border-radius: 12px; padding: 4px 14px 10px;
  }
}
.pm-panel-head { padding: 14px 0 12px; border-bottom: 1px solid var(--border); }
.pm-panel-title { font-size: 17px; font-weight: 800; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pm-panel-sub { font-size: 12.5px; color: var(--muted); margin-top: 5px; line-height: 1.45; }
.pm-panel-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pm-locked-note {
  font-size: 12.5px; color: var(--orange); background: rgba(232,98,26,.08);
  border: 1px solid rgba(232,98,26,.3); border-radius: 9px;
  padding: 10px 12px; margin-top: 12px; line-height: 1.45;
}
.pm-mgroup {
  font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--orange); padding: 18px 0 6px;
}
.pm-toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  min-height: 56px; padding: 10px 10px 10px 0; margin: 0 -10px 0 0;
  border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 8px;
}
.pm-toggle-row:last-child { border-bottom: none; }
.pm-toggle-row .pm-cb { flex-shrink: 0; margin-right: 10px; }
.pm-toggle-row.pm-locked { cursor: not-allowed; opacity: .75; }
.pm-toggle-row.pm-changed { background: rgba(232,98,26,.09); padding-left: 10px; margin-left: -10px; }

/* ---------- Legend ---------- */
.pm-legend { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 8px; }
.pm-legend-item {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 12.5px; color: var(--muted); line-height: 1.45;
}

/* ---------- Sticky dirty bar ---------- */
.pm-dirtybar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  background: var(--gray); border-top: 2px solid var(--orange);
  padding: 12px 16px; box-shadow: 0 -6px 24px rgba(0,0,0,.45);
}
@media (min-width: 900px) { .pm-dirtybar { left: 230px; padding: 12px 32px; } }
/* Above the mobile tab bar, and pad the page so the bar never covers content. */
@media (max-width: 899px) { .pm-dirtybar { bottom: 64px; } }
body.pm-has-dirtybar .main { padding-bottom: 96px; }
@media (max-width: 899px) { body.pm-has-dirtybar .main { padding-bottom: 160px; } }
/* Toasts must clear the dirty bar — both live bottom-centre. */
body.pm-has-dirtybar .toast-wrap { bottom: 92px; }
@media (max-width: 899px) { body.pm-has-dirtybar.has-shell .toast-wrap { bottom: 156px; } }
.pm-dirty-msg { min-width: 0; font-size: 13px; color: var(--label); }
.pm-dirty-msg strong { display: block; font-size: 14px; color: var(--text); }
.pm-dirty-roles {
  display: block; font-size: 12px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw;
}
.pm-dirty-actions { display: flex; gap: 10px; flex-shrink: 0; }
.pm-modal-text { font-size: 13.5px; color: var(--label); line-height: 1.55; margin-bottom: 12px; }

/* ============================================================
   PRINT PAGE (print.html) — light theme via .print-page on body
   ============================================================ */
body.print-page { background: #fff; color: #111; font-size: 13px; }
.print-page .print-wrap { max-width: 820px; margin: 0 auto; padding: 26px 24px 40px; }
.print-page .print-head {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  border-bottom: 3px solid var(--orange); padding-bottom: 14px; margin-bottom: 18px;
}
.print-page .print-head img { height: 54px; width: auto; }
.print-page .print-title { font-size: 20px; font-weight: 800; letter-spacing: 1.5px; color: #111; }
.print-page .print-meta { font-size: 12px; color: #444; text-align: right; line-height: 1.6; }
.print-page .print-sec { margin-bottom: 16px; break-inside: avoid; }
.print-page .print-sec-title {
  font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: #333; border-bottom: 1.5px solid #bbb; padding-bottom: 4px; margin-bottom: 8px;
}
.print-page .print-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.print-page .print-table th {
  text-align: left; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .4px; color: #555; border-bottom: 1px solid #999; padding: 4px 6px;
}
.print-page .print-table td { padding: 4px 6px; border-bottom: 1px solid #ddd; color: #111; }
.print-page .print-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.print-page .print-table tfoot td { border-top: 1.5px solid #999; border-bottom: none; font-weight: 700; }
.print-page .print-kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 18px; font-size: 12px; }
.print-page .print-kv .k { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: #666; }
.print-page .print-kv .v { color: #111; font-weight: 500; }
.print-page .sig-row { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-top: 22px; }
.print-page .sig-line { border-bottom: 1px solid #333; min-height: 30px; display: flex; align-items: flex-end; padding-bottom: 3px; font-size: 13px; }
.print-page .sig-caption { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: #666; margin-top: 4px; }
.print-page .print-foot { margin-top: 28px; font-size: 10px; color: #888; text-align: center; border-top: 1px solid #ddd; padding-top: 10px; }
.print-page .badge { border-width: 1px; }
.print-page .badge-pending  { color: #B84D12; background: rgba(232,98,26,.1);  border-color: rgba(232,98,26,.5); }
.print-page .badge-partial  { color: #8a6100; background: rgba(255,179,0,.12); border-color: rgba(255,179,0,.55); }
.print-page .badge-approved { color: #2e7d32; background: rgba(76,175,80,.12); border-color: rgba(76,175,80,.5); }
.print-page .print-actions { display: flex; justify-content: center; margin: 18px 0; }

@media print {
  .no-print { display: none !important; }
  body, body.print-page { background: #fff !important; }
  .print-page .print-wrap { padding: 0; max-width: none; }
}

/* ============================================================
   SHARED FOUNDATION (SPEC §20/§21/§22) — job-site photos,
   lightbox, signature capture, printable QR card, form site
   prefill banner, and the site-access admin page. Consumed BY
   CLASS NAME by the DFR-detail / form / site-links feature
   pages. Dark theme + #E8621A, ≥44px touch targets, usable at
   390px. NB: none of these rules touch existing selectors.
   ============================================================ */

/* ---------- Photo capture grid + thumbnail tiles (§20) ---------- */
/* Layout: a responsive grid of square tiles; the last cell is the dashed
   "add photo" tile. At 390px this lands 3 tiles across. Use in both the form
   (capture) and DFR-detail edit mode. */
.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 10px;
}
.photo-tile {
  position: relative; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden;
  background: var(--dark); border: 1.5px solid var(--border);
}
.photo-tile > img, .photo-thumb {
  width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in;
}
/* The × remove control. 28px visual, ≥44px hit area via the ::after inset. */
.photo-remove {
  position: absolute; top: 5px; right: 5px; width: 28px; height: 28px; border: none;
  border-radius: 50%; background: rgba(0,0,0,.62); color: #fff; font-size: 17px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 2;
}
.photo-remove::after { content: ''; position: absolute; inset: -9px; } /* ≥44px touch */
.photo-remove:hover { background: rgba(229,57,53,.85); }
/* Caption shown over the bottom of a tile (read view). */
.photo-cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 5px;
  font-size: 11px; color: #fff; line-height: 1.25;
  background: linear-gradient(to top, rgba(0,0,0,.72), rgba(0,0,0,0));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
/* Editable caption input placed under a tile (edit mode). */
.photo-cap-input { min-height: 44px; font-size: 13px; padding: 0 10px; margin-top: 6px; }
/* "Add photo" tile — dashed orange, matches the template's add-row affordance. */
.photo-add {
  position: relative; aspect-ratio: 1 / 1; border: 1.5px dashed rgba(232,98,26,.5);
  border-radius: 10px; background: rgba(232,98,26,.07); color: var(--orange);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; cursor: pointer; font-size: 12px; font-weight: 700; text-align: center;
  transition: background .15s; font-family: inherit;
}
.photo-add:hover { background: rgba(232,98,26,.15); }
.photo-add svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.photo-add input[type=file] { display: none; }
.photo-add.is-disabled { opacity: .4; pointer-events: none; }
.photo-count { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------- Lightbox (full-screen photo viewer) ---------- */
body.lightbox-open { overflow: hidden; }
.lightbox {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: lb-fade .18s ease;
}
.lightbox-figure { max-width: 100%; max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.lightbox-img {
  max-width: 100%; max-height: calc(100vh - 96px); object-fit: contain;
  border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.6); animation: lb-zoom .18s ease;
}
.lightbox-caption { color: #eee; font-size: 14px; text-align: center; max-width: 640px; overflow-wrap: anywhere; }
.lightbox-close {
  position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border: none;
  border-radius: 50%; background: rgba(255,255,255,.12); color: #fff; font-size: 26px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.lightbox-close:hover { background: rgba(255,255,255,.24); }
@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes lb-zoom { from { transform: scale(.96); } to { transform: none; } }
.lightbox.no-anim, .lightbox.no-anim .lightbox-img { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .lightbox, .lightbox-img { animation: none !important; }
}

/* ---------- Signature capture (§21) ---------- */
.signoff { display: flex; flex-direction: column; gap: 14px; }
/* White drawing surface framed like a form input, so the dark ink reads (and
   the exported PNG looks right on both the dark UI and on white paper). */
.sig-pad-frame {
  position: relative; border: 1.5px solid var(--border); border-radius: 10px;
  background: #fff; overflow: hidden;
}
.sig-pad-frame:focus-within { border-color: var(--orange); }
.sig-pad { display: block; width: 100%; height: 172px; background: #fff; touch-action: none; cursor: crosshair; }
/* Baseline "sign above" guide + hint, drawn over the canvas (non-interactive). */
.sig-pad-baseline { position: absolute; left: 18px; right: 18px; bottom: 34px; border-bottom: 1.5px dashed #c7c7c7; pointer-events: none; }
.sig-pad-hint { position: absolute; left: 18px; bottom: 11px; font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: #a0a0a0; pointer-events: none; }
.sig-pad-clear {
  position: absolute; top: 8px; right: 8px; min-height: 34px; padding: 0 12px; border-radius: 8px;
  background: rgba(0,0,0,.06); border: 1px solid #ddd; color: #444; font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 6px; z-index: 2;
}
.sig-pad-clear:hover { background: rgba(229,57,53,.1); border-color: rgba(229,57,53,.4); color: var(--red); }
/* Printed name + title fields under the pad. */
.signoff-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .signoff-fields { grid-template-columns: 1fr; } }
.signoff-fields > .field { min-width: 0; }
/* Read-only rendering of a captured signature on the DFR detail page. */
.signoff-view { display: flex; flex-direction: column; gap: 10px; }
.signoff-sig-img { background: #fff; border: 1.5px solid var(--border); border-radius: 10px; padding: 8px; max-width: 320px; }
.signoff-sig-img img { display: block; width: 100%; height: auto; }
.signoff-meta { font-size: 14px; color: var(--text); }
.signoff-meta .signoff-name { font-weight: 700; }
.signoff-meta .signoff-title, .signoff-meta .signoff-when { color: var(--muted); font-size: 13px; }

/* ---------- Printable QR job-site card (§22) ---------- */
/* Always a white card (a physical poster to print & post at the site), like
   the login logo band. Big centered QR + headline + monospace URL + label. */
.qr-card {
  background: #fff; color: #111; border: 1px solid #e3e3e3; border-radius: 16px;
  padding: 26px 22px 24px; max-width: 430px; margin: 0 auto; text-align: center;
}
.qr-card-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.qr-card-logo img { height: 42px; width: auto; }
.qr-card-head { font-size: 19px; font-weight: 800; color: #141414; line-height: 1.25; margin-bottom: 18px; }
.qr-code { width: min(280px, 72vw); height: min(280px, 72vw); margin: 0 auto 18px; }
.qr-code svg, .qr-code canvas, .qr-code img { display: block; width: 100%; height: 100%; }
.qr-card-label { font-size: 15px; font-weight: 700; color: #222; margin-bottom: 6px; overflow-wrap: anywhere; }
.qr-card-url { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: #555; word-break: break-all; line-height: 1.5; }
.qr-card-foot { margin-top: 16px; font-size: 11px; color: #999; }
/* Print: strip the app shell + any opted-out chrome so a poster prints clean.
   Scoped to body.qr-print-mode (feature page toggles it before window.print),
   so no other page's print output changes. */
@media print {
  body.qr-print-mode .sidebar,
  body.qr-print-mode .topbar,
  body.qr-print-mode .bottombar,
  body.qr-print-mode .no-print { display: none !important; }
  body.qr-print-mode.has-shell { padding-left: 0 !important; }
  body.qr-print-mode .qr-card { border: none; max-width: none; margin: 0 auto; }
}

/* ---------- Job-site prefill banner (form.html, §22) ---------- */
.site-banner {
  display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px;
  background: rgba(232,98,26,.1); border: 1.5px solid rgba(232,98,26,.4);
  border-radius: 12px; padding: 13px 16px;
}
.site-banner svg { width: 20px; height: 20px; stroke: var(--orange); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; margin-top: 1px; }
.site-banner-body { min-width: 0; }
.site-banner-label { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--orange); }
.site-banner-text { font-size: 15px; font-weight: 700; color: var(--text); margin-top: 2px; overflow-wrap: anywhere; }
.site-banner-sub { font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }

/* ============================================================
   IN-PRODUCT HELP (help brief §3) — Help & guide panel (C1),
   shell affordances (C2), per-page ? buttons (C3), captions and
   teaching empty states (C5–C8). Dark theme + #E8621A, ≥44px
   targets, flawless at 390px. No existing selector is changed.
   ============================================================ */

/* ? button — 44×44 circular icon button, border style of .btn-sec. */
.help-btn {
  width: 44px; height: 44px; flex-shrink: 0; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1.5px solid var(--border); border-radius: 50%;
  color: var(--label); cursor: pointer; font-family: inherit;
  transition: border-color .15s, color .15s;
}
.help-btn:hover { border-color: #4d4d4d; color: var(--text); }
.help-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* Beside the <h1>, as a SIBLING — never nested inside it, which would pollute
   the heading's accessible name with the button label. `.has-help` (set by the
   page JS that inserts the ?) stops the title's flex-grow, and margin-right:
   auto on the ? takes over the growing so the right-edge action buttons stay
   pinned right instead of collapsing toward the title. */
.page-head .page-title.has-help { flex: 0 1 auto; }
.page-head .help-btn { margin-right: auto; }
.detail-head .help-btn { margin-left: 2px; }

/* ---------- Help & guide panel ---------- */
/* Overlay z 90, panel 91 — below toasts (100). */
.help-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 90; border: none; padding: 0; cursor: pointer; }
body.help-open { overflow: hidden; }
/* Mobile <900px: full-screen sheet sliding up (More-sheet motion grammar). */
.help-panel {
  position: fixed; inset: 0; z-index: 91; background: var(--gray);
  border-top: 3px solid var(--orange);
  display: flex; flex-direction: column; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  animation: help-up .22s ease;
}
/* Desktop ≥900px: right slide-over, 400px, full height. */
@media (min-width: 900px) {
  .help-panel {
    left: auto; width: 400px; max-width: 100vw;
    border-left: 1px solid var(--border);
    box-shadow: -12px 0 40px rgba(0,0,0,.45);
    animation: help-in .18s ease;
  }
}
@keyframes help-up { from { transform: translateY(48px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes help-in { from { transform: translateX(48px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .help-panel { animation: none !important; } }

.help-panel-head {
  position: sticky; top: 0; z-index: 2; background: var(--gray);
  padding: 12px 16px 12px; border-bottom: 1px solid var(--border);
}
.help-panel-titlebar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.help-panel-title { font-size: 17px; font-weight: 800; }
.help-close {
  width: 44px; height: 44px; flex-shrink: 0; background: rgba(255,255,255,.05);
  border: none; border-radius: 10px; color: var(--muted); font-size: 24px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center; font-family: inherit;
}
.help-close:hover { color: var(--text); }
/* ≥16px font so iOS never zooms the panel on focus. */
.help-search { margin-top: 10px; min-height: 44px; font-size: 16px; }

.help-body { padding: 2px 16px calc(28px + env(safe-area-inset-bottom)); }
.help-section { margin-top: 18px; scroll-margin-top: 132px; }
.help-section-title {
  font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--orange); margin-bottom: 2px;
}
.help-entry { border-bottom: 1px solid var(--border); }
.help-entry:last-child { border-bottom: none; }
.help-entry-q {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 52px; padding: 13px 2px; background: none; border: none;
  color: var(--text); font-size: 15px; font-weight: 600; line-height: 1.35;
  text-align: left; cursor: pointer; font-family: inherit;
}
.help-entry-q .chev { display: inline-flex; color: var(--muted); flex-shrink: 0; transition: transform .15s; }
.help-entry.open .help-entry-q .chev { transform: rotate(180deg); }
.help-entry-body { padding: 0 2px 14px; }
.help-entry-body p { font-size: 16px; line-height: 1.5; color: var(--label); margin: 0 0 10px; }
.help-entry-body p:last-child { margin-bottom: 0; }
.help-empty { padding: 36px 10px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- Shell affordances (C2) ---------- */
/* Sidebar "Help" row — styled like .side-link, sits in .side-foot above the
   user chip. */
.side-help {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px;
  padding: 12px 14px; margin-bottom: 6px; border-radius: 10px; background: none; border: none;
  color: var(--label); font-size: 14px; font-weight: 600; cursor: pointer;
  text-align: left; font-family: inherit;
}
.side-help svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.side-help:hover { background: rgba(255,255,255,.04); color: var(--text); }

/* ---------- Micro-hint components (shared with the form's own copies) ---------- */
.field-hint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.help-inline-warn {
  margin-top: 8px; padding: 7px 10px; border-left: 3px solid var(--amber);
  background: rgba(255,179,0,.08); border-radius: 0 8px 8px 0;
  font-size: 13px; line-height: 1.4; color: var(--text);
}
/* Modifier is `.fade` — the class form.js flashAdded() actually adds (and the
   name form.html's own copy uses). Keep the two copies in lockstep. */
.microhint-flash { font-size: 12px; font-weight: 700; color: var(--green); transition: opacity .5s; }
.microhint-flash.fade { opacity: 0; }

/* ---------- Page captions & teaching states (C5–C8) ---------- */
.help-note { font-size: 13px; color: var(--muted); line-height: 1.45; margin: 2px 0 14px; }
/* C5 sits inside the approve grid — span both columns, no extra margin. */
.approve-grid .help-note { grid-column: 1 / -1; margin: 0; }
.empty-teach { gap: 10px; }
.empty-hint { font-size: 13.5px; color: var(--muted); line-height: 1.5; max-width: 480px; }
/* C7 — dashboard list-cap note: muted footer line, orange ≥44px link. */
.list-cap-note {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px;
  border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px;
  font-size: 13px; color: var(--muted);
}
.list-cap-note a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px;
  color: var(--orange); font-weight: 600; text-decoration: none;
}
.list-cap-note a:hover { text-decoration: underline; }

/* C4 — "Need help signing in?" centered under the login card. */
.login-wrap { flex-direction: column; }
.login-help-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; margin-top: 14px; padding: 0 18px;
  background: none; border: none; color: var(--muted); font-size: 14px;
  text-decoration: underline; cursor: pointer; font-family: inherit;
}
.login-help-link:hover { color: var(--text); }

/* ---------- Site-access admin page (list + create, §22) ---------- */
.sitelink-list { display: flex; flex-direction: column; gap: 12px; }
.sitelink {
  display: flex; gap: 14px; align-items: center; background: var(--field);
  border: 1.5px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.sitelink-qr { width: 66px; height: 66px; flex-shrink: 0; background: #fff; border-radius: 8px; padding: 5px; }
.sitelink-qr svg, .sitelink-qr canvas, .sitelink-qr img { display: block; width: 100%; height: 100%; cursor: zoom-in; }
.sitelink-main { flex: 1; min-width: 0; }
.sitelink-label { font-size: 15px; font-weight: 700; color: var(--text); }
.sitelink-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
.sitelink-url { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--label); margin-top: 6px; word-break: break-all; }
.sitelink-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (max-width: 620px) {
  .sitelink { flex-wrap: wrap; }
  .sitelink-actions { width: 100%; }
  .sitelink-actions > * { flex: 1; }
}
