/* assets/css/app.css — shared responsive + accessible layout for every module.
   Loaded after Tailwind/Bootstrap so it can override consistently. */

:root {
  --nfr-navy-1: #1a2c5b;
  --nfr-navy-2: #1f3872;
  --nfr-blue: #2563eb;
  --nfr-link: #b0c4de;
  --nfr-ink: #1e293b;
  --nfr-muted: #64748b;
  --nfr-line: #e2e8f0;
  --nfr-danger: #dc2626;
  --nfr-sidebar-w: 264px;
  --nfr-header-h: 60px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--nfr-ink);
  background: linear-gradient(135deg, #edf2f9 0%, #f1f5f9 50%, #e2e8f0 100%);
  min-height: 100vh;
}

/* ---------- Skip link (accessibility) ---------- */
.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 3000;
  background: var(--nfr-blue);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 8px 8px;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: top .18s ease;
}
.skip-link:focus { top: 0; }

/* Visible focus for keyboard users, everywhere */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #38bdf8;
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
  width: var(--nfr-sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--nfr-navy-1) 0%, var(--nfr-navy-2) 100%);
  color: var(--nfr-link);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 1000;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 16px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo {
  width: 42px; height: 42px; background: #fff; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; padding: 5px; flex-shrink: 0;
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.sidebar-brand-text strong { color: #fff; font-size: 15px; }
.sidebar-brand-text span { color: #7ea6d8; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.drawer-close { display: none; margin-left: auto; background: none; border: 0; color: #cbd5e1; font-size: 20px; cursor: pointer; }

.sidebar-nav { flex: 1; padding: 10px 0; }
.sidebar-group {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: #7ea6d8; font-weight: 700; padding: 16px 20px 6px; margin: 0;
}
.sidebar-link {
  display: flex; align-items: center; gap: 12px;
  color: var(--nfr-link); text-decoration: none;
  padding: 10px 14px; margin: 3px 12px; border-radius: 8px;
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-link.active { background: var(--nfr-blue); color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(37,99,235,.35); }
.sidebar-link.danger { color: #fca5a5; }
.sidebar-link.danger:hover { background: rgba(220,38,38,.18); color: #fecaca; }
.sidebar-link i:first-child { width: 18px; text-align: center; }
.sidebar-caret { margin-left: auto; font-size: 11px; transition: transform .2s ease; }

.sidebar-module summary { list-style: none; }
.sidebar-module summary::-webkit-details-marker { display: none; }
.sidebar-module[open] .sidebar-caret { transform: rotate(180deg); }
.sidebar-subnav { padding: 2px 0 6px; }
.sidebar-sublink {
  display: flex; align-items: center; gap: 10px;
  color: #93a9c9; text-decoration: none; font-size: 12.5px;
  padding: 8px 14px 8px 44px; margin: 1px 12px; border-radius: 8px;
}
.sidebar-sublink:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-sublink.active { background: rgba(37,99,235,.28); color: #fff; font-weight: 600; }
.sidebar-sublink i { width: 16px; text-align: center; }

.sidebar-quit { margin-top: 16px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 10px; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding: 8px 0 14px; margin-top: auto; }
.sidebar-copy { text-align: center; font-size: 10px; color: #94a3b8; opacity: .8; padding: 8px 12px 0; margin: 0; }

/* ---------- Body / header / main ---------- */
.app-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.app-header {
  position: sticky; top: 0; z-index: 900;
  height: var(--nfr-header-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--nfr-line); box-shadow: 0 1px 3px rgba(15,23,42,.05);
}
.drawer-toggle {
  display: none; background: none; border: 0; color: #334155;
  font-size: 20px; cursor: pointer; padding: 6px 8px; border-radius: 8px;
}
.drawer-toggle:hover { background: #f1f5f9; }
.app-header-titles { min-width: 0; flex: 1; }
.app-header-title { font-size: 15px; font-weight: 700; margin: 0; color: #0f172a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb-trail { list-style: none; display: flex; gap: 6px; margin: 2px 0 0; padding: 0; font-size: 11px; color: var(--nfr-muted); flex-wrap: wrap; }
.breadcrumb-trail li + li::before { content: '/'; margin-right: 6px; color: #cbd5e1; }
.breadcrumb-trail a { color: var(--nfr-blue); text-decoration: none; }
.breadcrumb-trail a:hover { text-decoration: underline; }

.app-header-user { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: baseline; gap: 6px; font-size: 12px; background: #f1f5f9; border: 1px solid var(--nfr-line); padding: 6px 12px; border-radius: 999px; }
.user-chip i { color: var(--nfr-blue); }
.user-chip-name { font-weight: 600; color: #0f172a; }
.user-chip-role { color: var(--nfr-muted); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.btn-logout { display: inline-flex; align-items: center; gap: 6px; background: var(--nfr-danger); color: #fff; text-decoration: none; font-size: 12px; font-weight: 600; padding: 8px 14px; border-radius: 8px; }
.btn-logout:hover { background: #b91c1c; }

.app-main { flex: 1; padding: 22px; width: 100%; max-width: 1400px; margin: 0 auto; }
/* Wrapper used by the module dashboard/report pages: the shell already pads. */
.dash-wrap { width: 100%; }

/* ---------- Alerts ---------- */
.nfr-alert { display: flex; align-items: center; gap: 10px; border-radius: 10px; padding: 12px 16px; font-size: 13.5px; font-weight: 500; margin-bottom: 16px; border: 1px solid transparent; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-danger  { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; background: #fff; border: 1px solid var(--nfr-line); border-radius: 12px; scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table caption { text-align: left; padding: 12px 16px; font-weight: 700; color: #0f172a; caption-side: top; }
.data-table th, .data-table td { padding: 8px 8px; text-align: left; border-bottom: 1px solid var(--nfr-line); vertical-align: top; overflow-wrap: break-word; }
.data-table thead th { background: #f8fafc; font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--nfr-muted); position: sticky; top: 0; white-space: nowrap; }
.data-table tbody tr:nth-child(even) { background: #fbfcfe; }
.data-table tbody tr:hover { background: #f1f6ff; }
.data-table tbody tr:last-child td { border-bottom: 0; }

.row-actions { display: flex; gap: 5px; align-items: center; }
.inline-form { display: inline; margin: 0; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 29px; height: 29px; border-radius: 8px; border: 1px solid transparent;
  background: #f1f5f9; color: #475569; cursor: pointer; text-decoration: none; font-size: 12px;
  transition: background .13s ease, color .13s ease, border-color .13s ease;
}
.btn-icon.view   { background: #e0edff; color: #1d4ed8; border-color: #bfdbfe; }
.btn-icon.view:hover   { background: var(--nfr-blue); color: #fff; border-color: var(--nfr-blue); }
.btn-icon.edit   { background: #fef3c7; color: #b45309; border-color: #fcd34d; }
.btn-icon.edit:hover   { background: #d97706; color: #fff; border-color: #d97706; }
.btn-icon.danger { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.btn-icon.danger:hover { background: var(--nfr-danger); color: #fff; border-color: var(--nfr-danger); }

.empty-state { text-align: center; padding: 48px 20px; color: var(--nfr-muted); }
.empty-state i { font-size: 34px; display: block; margin-bottom: 10px; color: #cbd5e1; }

/* ---------- Chart data-table alternative ---------- */
.chart-table { margin-top: 10px; font-size: 13px; }
.chart-table summary { cursor: pointer; color: var(--nfr-blue); font-weight: 600; }
.chart-table .data-table { margin-top: 10px; min-width: 0; }

/* ---------- Screen-reader live region ---------- */
.sr-live { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Overlay ---------- */
.app-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.6); backdrop-filter: blur(3px); z-index: 999; }
.app-overlay[hidden] { display: none; }

/* ---------- Cards ---------- */
.nfr-card { background:#fff; border:1px solid var(--nfr-line); border-radius:14px; box-shadow:0 1px 3px rgba(15,23,42,.06); margin-bottom:18px; }
.nfr-card-head { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:12px; padding:14px 18px; border-bottom:1px solid var(--nfr-line); }
.nfr-card-head h2 { display:flex; align-items:center; gap:9px; margin:0; font-size:15px; font-weight:700; color:#0f172a; }
.nfr-card-head h2 i { color:var(--nfr-blue); font-size:14px; }
.nfr-card-tools { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
.nfr-card-body { padding:16px 18px; }
.nfr-card-body .table-wrap { border:0; box-shadow:none; }

/* ---------- Filter bar ---------- */
.filter-bar { background:#fff; border:1px solid var(--nfr-line); border-radius:12px; margin:0 0 16px; box-shadow:0 1px 3px rgba(15,23,42,.05); }
.filter-fieldset { border:0; margin:0; padding:14px 16px; }
.filter-fieldset legend { font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.06em; color:var(--nfr-muted); padding:0 6px; }
.filter-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(148px, 1fr)); gap:11px 12px; align-items:end; }
.filter-cell label, .form-cell label { display:block; font-size:11px; font-weight:600; color:#475569; margin-bottom:4px; }
.filter-actions { display:flex; flex-wrap:wrap; gap:8px; align-items:end; justify-content:flex-end; grid-column:1 / -1; }

/* ---------- Forms ---------- */
.form-input, .form-select, .form-textarea {
  width:100%; font:inherit; font-size:13px; color:var(--nfr-ink);
  background:#fff; border:1px solid #cbd5e1; border-radius:8px; padding:8px 10px; min-height:38px;
}
.form-textarea { min-height:84px; resize:vertical; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color:var(--nfr-blue); }
.form-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(230px, 1fr)); gap:14px 16px; }
.form-actions { display:flex; flex-wrap:wrap; gap:10px; margin-top:16px; }

/* ---------- Buttons ---------- */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  border:1px solid transparent; border-radius:8px; padding:9px 14px;
  font:inherit; font-size:13px; font-weight:600; text-decoration:none; cursor:pointer;
}
.btn-blue { background:var(--nfr-blue); color:#fff; }
.btn-blue:hover { background:#1d4ed8; color:#fff; }
.btn-green { background:#059669; color:#fff; }
.btn-green:hover { background:#047857; color:#fff; }
.btn-gray { background:#f1f5f9; color:#334155; border-color:var(--nfr-line); }
.btn-gray:hover { background:#e2e8f0; color:#0f172a; }

/* ---------- Table extras ---------- */
.asset-link { color:var(--nfr-blue); font-weight:600; text-decoration:none; }
.asset-link:hover { text-decoration:underline; }
.muted { color:#94a3b8; }
.col-action { width:1%; white-space:nowrap; }
.btn-icon.is-frozen { background:#f8fafc; color:#cbd5e1; border:1px dashed #e2e8f0; cursor:not-allowed; }
.result-count { font-size:12px; color:var(--nfr-muted); margin:0 0 10px; }

/* ---------- View page ---------- */
.detail-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:1px; background:var(--nfr-line); border:1px solid var(--nfr-line); border-radius:12px; overflow:hidden; }
.detail-item { background:#fff; padding:10px 14px; margin:0; }
.detail-item dt { font-size:10.5px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--nfr-muted); }
.detail-item dd { margin:3px 0 0; font-size:13.5px; color:var(--nfr-ink); word-break:break-word; }

/* ---------- Lift / escalator and record-type tabs ---------- */
.kind-tabs { display:flex; flex-wrap:wrap; gap:6px; margin:0 0 14px; }
.kind-tabs a { font-size:12.5px; font-weight:600; text-decoration:none; color:#475569; background:#fff; border:1px solid var(--nfr-line); border-radius:999px; padding:7px 14px; }
.kind-tabs a:hover { border-color:var(--nfr-blue); color:var(--nfr-blue); }
.kind-tabs a.active { background:var(--nfr-blue); color:#fff; border-color:var(--nfr-blue); }

/* ---------- Shared module pages (core/module_pages.php) ---------- */
.card-tools { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin:0 0 14px; }
.form-block-head { font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--nfr-muted); margin:18px 0 10px; }
.pagination { display:flex; flex-wrap:wrap; gap:6px; margin:0 0 12px; }
.pagination .page { min-width:34px; text-align:center; font-size:12.5px; font-weight:600; padding:7px 10px; border:1px solid var(--nfr-line); border-radius:8px; background:#fff; color:#334155; text-decoration:none; }
.pagination .page:hover { border-color:var(--nfr-blue); color:var(--nfr-blue); }
.pagination .is-current { background:var(--nfr-blue); border-color:var(--nfr-blue); color:#fff; }
.batch-row { border:1px dashed #cbd5e1; border-radius:12px; padding:12px 14px; margin:0 0 12px; background:#fcfdff; }
.batch-row-head { display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:10px; font-size:12px; font-weight:700; color:var(--nfr-muted); }
.btn-sm { padding:5px 9px; min-height:28px; font-size:12px; }
.checklist-table { margin-top:10px; }
.chk-note { padding:14px; font-size:13px; font-style:italic; color:var(--nfr-muted); text-align:center; }
.chk-cat td { background:#dbeafe; color:#1e3a8a; font-weight:700; font-size:11.5px; padding:8px 12px; }
.chk-item td { padding:8px 12px; border-top:1px solid #f1f5f9; font-size:13px; vertical-align:top; }
.chk-status { white-space:nowrap; }
.chk-status label { display:inline-flex; align-items:center; gap:4px; margin-right:12px; font-size:12.5px; font-weight:700; cursor:pointer; }
.print-page { max-width:1200px; margin:0 auto; padding:24px; background:#fff; }
.print-head { display:flex; justify-content:space-between; align-items:flex-start; gap:16px; border-bottom:2px solid #0f172a; padding-bottom:10px; margin-bottom:14px; }
.print-head h1 { font-size:17px; margin:0 0 4px; }
.print-sub { font-size:12px; color:#475569; margin:2px 0; }

/* ---------- Super-admin access control (nfrehq/delete_access.php) ---------- */
.btn-red { background:var(--nfr-danger); color:#fff; }
.btn-red:hover { background:#b91c1c; color:#fff; }
.btn-amber { background:#d97706; color:#fff; }
.btn-amber:hover { background:#b45309; color:#fff; }
.page-intro { font-size:13.5px; color:#475569; margin:0 0 16px; max-width:78ch; }
.stat-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:12px; margin:0 0 18px; }
.stat-card { display:block; background:#fff; border:1px solid var(--nfr-line); border-left:4px solid var(--nfr-blue); border-radius:12px; padding:13px 15px; }
.stat-card .stat-label { display:block; font-size:10.5px; font-weight:700; letter-spacing:.05em; text-transform:uppercase; color:var(--nfr-muted); }
.stat-card .stat-value { display:block; font-size:19px; font-weight:800; color:#0f172a; margin:4px 0 2px; }
.stat-card .stat-value.ok { color:#047857; }
.stat-card .stat-value.warn { color:#b45309; }
.stat-card .stat-value.danger { color:var(--nfr-danger); }
.stat-card .stat-note { display:block; font-size:11.5px; color:var(--nfr-muted); }
.btn-row { display:flex; flex-wrap:wrap; align-items:center; gap:10px; }
.field-inline { display:inline-flex; align-items:center; gap:7px; font-size:13px; color:#334155; }
.field-hint { font-size:12px; color:var(--nfr-muted); margin:12px 0 0; }
.input-mins { width:64px; display:inline-block; padding:6px 8px; text-align:center; }
.inline-filter { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
.inline-filter .form-select, .inline-filter .form-input { width:auto; min-width:130px; padding:6px 9px; font-size:12.5px; }
.inline-post { display:inline-flex; margin:0; }
.grant-form .filter-cell { min-width:0; }

/* ---------- Top bar communication links (core/layout.php, index.php) ---------- */
.topbar-links { display:flex; align-items:center; gap:6px; }
.topbar-link {
  display:inline-flex; align-items:center; gap:6px; text-decoration:none;
  font-size:12.5px; font-weight:600; color:#334155;
  background:#f1f5f9; border:1px solid var(--nfr-line); border-radius:999px; padding:7px 12px;
}
.topbar-link:hover { border-color:var(--nfr-blue); color:var(--nfr-blue); background:#eff6ff; }
.topbar-link.active { background:var(--nfr-blue); border-color:var(--nfr-blue); color:#fff; }
.topbar-link .topbar-count {
  font-size:10.5px; font-weight:700; background:var(--nfr-danger); color:#fff;
  border-radius:999px; padding:1px 6px;
}

/* ---------- Broadcast board & chat rooms (broadcast.php, chat.php) ---------- */
.nfr-msg { border:1px solid var(--nfr-line); border-radius:12px; background:#fff; padding:11px 13px; margin:0 0 10px; }
.nfr-msg:nth-of-type(even) { background:#fbfdff; }
.nfr-msg-head { display:flex; flex-wrap:wrap; align-items:baseline; gap:6px 8px; margin-bottom:6px; }
.nfr-msg-who { font-size:13px; font-weight:700; color:#0f172a; }
.nfr-msg-role { font-size:10.5px; font-weight:700; text-transform:uppercase; letter-spacing:.04em; color:#1e40af; background:#dbeafe; border-radius:999px; padding:2px 8px; }
.nfr-msg-tag { font-size:10.5px; font-weight:700; color:#92400e; background:#fef3c7; border-radius:999px; padding:2px 8px; }

/* Small state chip: "Found in place", "Pending Signature", "Never Inspected" ...
   Used by the record lists and by media_check.php. */
.badge { display:inline-block; font-size:10.5px; font-weight:700; line-height:1.6;
  border-radius:999px; padding:2px 9px; border:1px solid transparent; white-space:nowrap; }
.badge-ok   { color:#065f46; background:#ecfdf5; border-color:#a7f3d0; }
.badge-warn { color:#92400e; background:#fffbeb; border-color:#fde68a; }
.badge-bad  { color:#991b1b; background:#fef2f2; border-color:#fecaca; }
.badge-info { color:#1e40af; background:#eff6ff; border-color:#bfdbfe; }
.badge-mute { color:#475569; background:#f1f5f9; border-color:#e2e8f0; }
.nfr-msg-when { font-size:11.5px; color:var(--nfr-muted); margin-left:auto; white-space:nowrap; }
.nfr-msg-body { font-size:13.5px; line-height:1.55; color:var(--nfr-ink); word-break:break-word; white-space:normal; }
.nfr-msg-body a { color:var(--nfr-blue); }
.nfr-msg-attach { margin-top:9px; }
.nfr-msg-media { display:block; max-width:100%; width:auto; max-height:420px; border-radius:10px; border:1px solid var(--nfr-line); background:#0f172a; }
.nfr-msg-file { display:inline-flex; align-items:center; gap:7px; font-size:12.5px; font-weight:600;
  color:#0f172a; text-decoration:none; background:#f1f5f9; border:1px solid var(--nfr-line);
  border-radius:8px; padding:8px 12px; word-break:break-all; }
.nfr-msg-file:hover { border-color:var(--nfr-blue); color:var(--nfr-blue); }
.nfr-msg-file i { color:var(--nfr-blue); }
.nfr-msg-form { margin:0; }
.nfr-msg-form .form-textarea { min-height:110px; }
.nfr-emoji { display:flex; flex-wrap:wrap; gap:4px; margin-top:8px; }
.nfr-emoji-btn { font-size:16px; line-height:1; background:#fff; border:1px solid var(--nfr-line);
  border-radius:8px; padding:6px 9px; cursor:pointer; }
.nfr-emoji-btn:hover { border-color:var(--nfr-blue); background:#eff6ff; }
.chat-list { max-height:60vh; overflow-y:auto; padding-right:2px; overscroll-behavior:contain; }
.room-note { font-size:12.5px; color:var(--nfr-muted); margin:0 0 12px; }
.msg-fresh { border-color:var(--nfr-blue); box-shadow:0 0 0 2px rgba(37,99,235,.12); }

/* ---------- Legacy sidebar pages (earthing module, old HQ screens) ----------
   These print `body.flex > aside.sidebar` themselves: a 256px column locked
   beside the content with the page height fixed to the viewport. On a phone
   that left about 130px for the actual content and the page could not scroll,
   so the menu becomes an off-canvas drawer exactly like the shared shell.

   app.js adds the toggle button and the backdrop (there is nowhere in their
   own markup to put one) and marks <body> with .has-legacy-sidebar. */
.legacy-drawer-toggle,
.legacy-drawer-backdrop { display: none; }

@media (max-width: 860px) {
  body.has-legacy-sidebar {
    display: block !important;          /* stop aside + main sitting side by side */
    height: auto !important;
    /* The page itself no longer locks its height. overflow-x stays hidden
       because the old markup uses "overflow-hidden" on <body> to clip
       decorative blobs — overriding it to `visible` let those blobs widen the
       page, and every card's text then ran off the right edge. A wide table
       still scrolls, inside its own .table-wrap. */
    overflow-x: hidden !important;
    overflow-y: visible !important;
  }
  body.has-legacy-sidebar > aside.sidebar {
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    width: min(84vw, 300px) !important;
    height: 100dvh !important;
    max-width: none;
    z-index: 1000;
    overflow-y: auto !important;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
  }
  body.has-legacy-sidebar > aside.sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
  }
  /* The module nav is a vertical list again inside the drawer. */
  body.has-legacy-sidebar > aside.sidebar nav {
    display: block;
    padding: 6px 0;
    flex-wrap: nowrap;
  }
  body.has-legacy-sidebar > aside.sidebar .nav-group-label { padding: 12px 16px 4px; }
  body.has-legacy-sidebar > aside.sidebar .nav-item { border-radius: 0; padding: 11px 16px !important; }

  body.has-legacy-sidebar .legacy-drawer-toggle {
    display: inline-flex !important;
    align-items: center; justify-content: center;
    position: fixed; top: 10px; left: 10px;
    width: 42px; height: 42px;
    z-index: 950;
    background: #1a2c5b; color: #fff;
    border: 0; border-radius: 10px;
    font-size: 18px; cursor: pointer;
    box-shadow: 0 2px 8px rgba(15,23,42,.25);
  }
  body.has-legacy-sidebar .legacy-drawer-backdrop {
    display: block; position: fixed; inset: 0;
    background: rgba(15,23,42,.6); z-index: 990;
  }
  body.has-legacy-sidebar .legacy-drawer-backdrop[hidden] { display: none !important; }
  body.has-legacy-sidebar.legacy-nav-open { overflow: hidden !important; }

  /* Main content takes the full width now, and leaves room for the floating
     button. Only the vertical overflow is freed — letting the horizontal one
     through as well would push the whole page sideways on a phone. */
  body.has-legacy-sidebar > main,
  body.has-legacy-sidebar > div {
    width: 100% !important;
    max-width: 100%;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    min-width: 0;
  }
  body.has-legacy-sidebar > main { padding-top: 62px !important; }
  body.has-legacy-sidebar > main > header.sticky { position: static !important; }

  /* Wide tables scroll inside their own box rather than widening the page. */
  body.has-legacy-sidebar .table-wrap { -webkit-overflow-scrolling: touch; }
}

/* Older markup with no .has-legacy-sidebar marker still needs this much. */
@media (max-width: 860px) {
  body.flex { display:block !important; height:auto !important; overflow:visible !important; }
  body > aside.sidebar { width:auto !important; height:auto !important; flex:0 0 auto !important; overflow:visible !important; }
  body > aside.sidebar nav { display:flex; flex-wrap:wrap; gap:2px; padding:4px 8px 8px; }
  body > aside.sidebar .nav-group-label { flex:1 0 100%; padding:8px 8px 0; }
  body > aside.sidebar .nav-item { border-radius:8px; padding:7px 10px !important; }
  body > aside.sidebar > div { padding-left:12px !important; padding-right:12px !important; }
  /* Free the vertical overflow only; a wide table must not push the page sideways.
     The table itself scrolls inside .table-wrap. */
  main { overflow-x: hidden !important; overflow-y: visible !important; min-width:0; }
  main > header.sticky { position:static !important; }
}

/* A few of the older screens put a row of buttons in their top bar with fixed
   horizontal padding and no wrapping, so the row came out wider than the phone.
   Let the bar wrap and the button group drop onto its own line. */
@media (max-width: 860px) {
  body.has-legacy-sidebar > div > header,
  body.has-legacy-sidebar > main > header {
    display: flex !important; flex-wrap: wrap !important;
    gap: 8px !important; align-items: center !important;
  }
  body.has-legacy-sidebar > div > header > div,
  body.has-legacy-sidebar > main > header > div {
    flex-wrap: wrap; max-width: 100%;
  }
}

@media print {
  body > aside.sidebar, body .skip-link { display:none !important; }
  body.flex { display:block !important; height:auto !important; overflow:visible !important; }
}

/* ---------- Responsive: tablet ---------- */
@media (max-width: 992px) {
  .user-chip-role { display: none; }
  .app-main { padding: 16px; }
}

/* ---------- Responsive: mobile drawer ---------- */
@media (max-width: 768px) {
  /* The top bar carries the menu button, the welcome block and four actions.
     On a phone they cannot share one line — the welcome text was being drawn
     over the buttons. Make it two rows, titles first and actions underneath,
     and let the header grow instead of clipping to a fixed height. */
  .app-header {
    flex-wrap: wrap;
    height: auto;
    min-height: 0;
    row-gap: 8px;
    padding: 8px 12px;
    gap: 8px;
  }
  .app-header-titles { order: 1; flex: 1 1 auto; }
  .app-header-user {
    order: 2; flex: 1 1 100%; flex-wrap: wrap;
    justify-content: flex-start; gap: 6px;
  }
  .app-welcome { font-size: 13.5px; line-height: 1.3; }
  .app-welcome-sub { font-size: 10.5px; }
  /* Every action keeps a 40px touch target once its label is hidden. */
  .app-header-user .hdr-btn,
  .app-header-user .btn-logout {
    min-width: 40px; min-height: 38px;
    justify-content: center; padding: 7px 11px;
  }
  .drawer-toggle {
    display: inline-flex; order: 0;
    min-width: 40px; min-height: 40px; justify-content: center;
  }
  .drawer-close { display: inline-flex; }

  /* Off-canvas menu. position:fixed must also cancel the desktop
     `position: sticky; height: 100vh` rules, and the shell must stop being a
     side-by-side flex row so the closed menu does not reserve a column. */
  .app-shell { display: block; }
  .app-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100dvh;
    width: min(84vw, 300px);
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
  }
  .app-sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.25); }
  .app-header-title { font-size: 14px; }
  .btn-logout span { display: none; }
  .btn-logout { padding: 8px 10px; }
  .user-chip { padding: 5px 10px; }
  .app-main { padding: 12px; }
  .nfr-card-head { padding: 12px 14px; }
  .nfr-card-body { padding: 12px; }
  .filter-bar .btn { flex: 1 1 auto; }

  /* Lists become cards so a phone user never scrolls sideways.
     Two kinds of table need this:
       - table[data-cards], marked by build/label_tables.php, with a data-label
         on every cell (the earthing module and the older HQ screens); and
       - .data-table, which nfr_table() in core/layout.php generates together
         with its own data-label attributes.
     A table with neither keeps its normal shape and scrolls inside .table-wrap.
     The :has() on the wrapper only removes the border; it degrades harmlessly
     where it is unsupported. */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap:has(table[data-cards]) { overflow: visible; border: 0; background: transparent; }
  table[data-cards],
  .data-table { min-width: 0; }
  table[data-cards] caption,
  .data-table caption { padding: 6px 2px 10px; }
  table[data-cards] thead,
  .data-table thead { display: none; }
  table[data-cards] tbody tr,
  .data-table tbody tr {
    display: block; background: #fff; border: 1px solid var(--nfr-line);
    border-radius: 12px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(15,23,42,.05);
  }
  table[data-cards] tbody td,
  .data-table tbody td {
    display: flex; justify-content: space-between; gap: 12px; text-align: right;
    padding: 9px 14px; border-bottom: 1px solid #f1f5f9; font-size: 13px;
    min-width: 0; overflow-wrap: anywhere;
  }
  table[data-cards] tbody tr:last-child td,
  .data-table tbody tr:last-child td { border-bottom: 1px solid #f1f5f9; }
  table[data-cards] tbody td:last-child,
  .data-table tbody td:last-child { border-bottom: 0; }
  table[data-cards] tbody td::before,
  .data-table tbody td::before {
    content: attr(data-label); flex: 0 0 42%; text-align: left;
    font-size: 10.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .04em; color: var(--nfr-muted);
    overflow-wrap: break-word;
  }
  table[data-cards] tbody td.col-action,
  .data-table tbody td.col-action {
    /* A block, not a flex row: the button group is wider than the 1%-wide
       desktop column, and as a flex item it spilled out of the card on the left. */
    display: block; width: auto; text-align: right;
  }
  table[data-cards] tbody td.col-action::before,
  .data-table tbody td.col-action::before { display: none; }
  table[data-cards] tbody td.col-action .row-actions,
  .data-table tbody td.col-action .row-actions {
    display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end;
  }
  table[data-cards] tbody td.col-action .btn-icon,
  .data-table tbody td.col-action .btn-icon { min-height: 34px; padding: 0 12px; }
  /* A colspan cell (the "nothing found" row) needs no label column. */
  table[data-cards] tbody td[colspan],
  .data-table tbody td[colspan] { display: block; text-align: left; }
  table[data-cards] tbody td[colspan]::before,
  .data-table tbody td[colspan]::before { display: none; }
  .data-table tbody td .empty-state { width: 100%; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .topbar-link { padding: 7px 9px; }
  .topbar-link .topbar-text { display: none; }
  .chat-list { max-height: none; overflow: visible; }
  .nfr-msg-when { margin-left: 0; flex: 1 0 100%; }
  .nfr-msg-media { max-height: 300px; }
}

@media (max-width: 430px) {
  .filter-grid { grid-template-columns: 1fr; }
  .app-header-user .user-chip-name { display: none; }
  .nfr-msg { padding: 10px 11px; }
}

/* ---------- Stop a stray wide element from scrolling the whole page ----------
   On a phone, one oversized box must not drag the entire page sideways. Some of
   the older dashboards paint decorative blobs and absolutely positioned badges
   that are meant to be clipped by an ancestor's overflow:hidden — and that
   ancestor is exactly what the drawer fix has to switch off. Tables are the one
   thing that legitimately needs to be wide, and they scroll inside .table-wrap,
   so clipping here costs nothing. */
@media (max-width: 860px) {
  /* A flex row cannot shrink below the longest word of its content unless its
     items are allowed to. Several dashboard panels are a flex row holding an
     icon plus a paragraph, with the icon marked flex-shrink-0; the paragraph
     then forces the panel wider than the phone and its text runs off the edge.
     Letting the items shrink and the words break keeps the text readable. */
  .flex > * { min-width: 0; }
  .flex > p, .flex > div { overflow-wrap: break-word; }

  /* No page-level overflow guard: two attempts at one (on <body>, then on <html>)
     each made things worse, because the document itself then became the
     horizontal clipper and a wide table's overflow was cut off at the wrong edge
     — card text disappeared down the right of every page.
     Instead the content column is the clipper, which is where a wide table's
     overflow actually lands. A table still scrolls on its own, in .table-wrap. */
  .app-main,
  body.has-legacy-sidebar > main {
    overflow-x: hidden;
    /* The column must be exactly as wide as the screen minus its own padding.
       Without the clamp a flex or grid item further down can push it wider, and
       then the clipper cuts card text instead of the wide table. */
    width: 100%;
    max-width: 100%;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .app-sidebar { transition: none; }
}

/* ---------- Print ---------- */
@media print {
  @page { size: landscape; margin: 12mm; }
  body { background: #fff; }
  .app-sidebar, .app-header, .drawer-toggle, .skip-link, .app-overlay,
  .no-print, .filter-actions, .row-actions, .btn-icon, .btn, .kind-tabs,
  .pagination, .card-tools, .result-count { display: none !important; }
  .app-shell { display: block; }
  .app-main { max-width: none; padding: 0; }
  .nfr-card { border: 0; box-shadow: none; margin: 0 0 12px; break-inside: avoid; }
  .nfr-card-body { padding: 0; }
  .table-wrap { border: 0; overflow: visible; background: transparent; }
  .data-table { font-size: 11px; min-width: 0; }
  .data-table thead { display: table-header-group; }
  .data-table th, .data-table td { padding: 5px 7px; border-color: #cbd5e1; }
  .data-table tbody tr { break-inside: avoid; }
  .nfr-alert { border-color: #cbd5e1; }
  .nfr-msg { break-inside: avoid; border-color: #cbd5e1; }
  .chat-list { max-height: none; overflow: visible; }
  .nfr-msg-media { max-height: 220px; }
  a { color: #000; text-decoration: none; }
}

/* message notifications + delete (also in theme-old.css) */
.nfr-badge { display:inline-block; min-width:18px; padding:1px 6px; margin-left:6px; border-radius:999px; background:#dc2626; color:#fff; font-size:11px; font-weight:700; line-height:16px; text-align:center; }
.nfr-badge[hidden] { display:none; }
.nfr-toast { position:fixed; right:16px; bottom:16px; z-index:6000; max-width:320px; background:#1e3a8a; color:#fff; padding:12px 16px; border-radius:10px; box-shadow:0 6px 18px rgba(0,0,0,.25); font-size:13px; cursor:pointer; }
.nfr-msg-del { margin-left:auto; display:inline; }
.nfr-msg-del-btn { background:none; border:0; color:#b91c1c; cursor:pointer; padding:2px 6px; font-size:13px; }

.nfr-unread-banner { margin:0 0 14px; padding:11px 16px; border-radius:10px; background:#fef3c7; border:1px solid #fcd34d; color:#92400e; font-size:13.5px; font-weight:600; }
.nfr-unread-banner a { color:#b45309; text-decoration:underline; }
.nfr-unread-banner i { margin-right:6px; }
.sidebar-link .nfr-badge { margin-left:auto; }

/* Pop-up shown for a few seconds when a frozen delete button is pressed (assets/js/app.js). */
.nfr-pop { position:fixed; left:50%; bottom:24px; z-index:7000; display:flex; align-items:flex-start; gap:10px;
  width:max-content; max-width:min(92vw, 460px); padding:12px 16px; border-radius:12px; background:#0f172a; color:#fff;
  font-size:13.5px; font-weight:600; line-height:1.45; box-shadow:0 10px 30px rgba(15,23,42,.35); cursor:pointer;
  opacity:0; visibility:hidden; transform:translate(-50%, 12px); transition:opacity .2s ease, transform .2s ease, visibility 0s linear .2s; }
.nfr-pop.show { opacity:1; visibility:visible; transform:translate(-50%, 0); transition:opacity .2s ease, transform .2s ease; }
.nfr-pop i { color:#fbbf24; margin-top:2px; }
[data-frozen], .is-frozen { cursor:pointer; }
@media (prefers-reduced-motion: reduce) { .nfr-pop, .nfr-pop.show { transition:none; } }
@media print { .nfr-pop { display:none !important; } }

/* ---------- area bar (Nov 2026): one area for the whole module, kept while moving between pages ---------- */
.nfr-areabar { display:flex; flex-wrap:wrap; align-items:center; gap:10px 16px; background:#fff; border:1.5px solid #bcd0fb; border-radius:14px; padding:10px 16px; margin:0 0 16px; box-shadow:0 1px 3px rgba(15,23,42,.06); }
.nfr-areabar .ab-pin { width:40px; height:40px; border-radius:50%; background:#1f3872; color:#fff; display:flex; align-items:center; justify-content:center; font-size:17px; flex:none; }
/* Nov 2026 (update 14b): the text keeps a fixed width and the boxes start right after it, so choosing a division
   adds a box to the right instead of moving the others; Show all stays at the right end. */
.nfr-areabar .ab-text { min-width:0; flex:0 1 250px; }
.nfr-areabar .ab-text small { display:block; font-size:10.5px; letter-spacing:.09em; text-transform:uppercase; color:#64748b; font-weight:700; }
.nfr-areabar .ab-text strong { display:block; font-size:17px; line-height:1.3; color:#1a2c5b; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.nfr-areabar .ab-text em { display:block; font-style:normal; font-size:13px; line-height:1.3; color:#475569; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.nfr-areabar .ab-sel { display:flex; flex-wrap:wrap; gap:10px; align-items:flex-end; }
.nfr-areabar label { display:flex; flex-direction:column; gap:3px; font-size:11px; font-weight:700; color:#64748b; margin:0; }
.nfr-areabar select { width:180px; height:38px; padding:0 10px; border:1.5px solid #cbd5e1; border-radius:10px; font-size:14px; color:#1e293b; background:#fff; }
.nfr-areabar .ab-all { display:inline-flex; align-items:center; gap:6px; height:38px; padding:0 14px; border-radius:10px; background:#eef2ff; color:#1f3872; font-weight:700; font-size:13.5px; text-decoration:none; border:1.5px solid #c7d2fe; white-space:nowrap; align-self:flex-end; margin-left:auto; }
.nfr-areabar .ab-all:hover, .nfr-areabar .ab-all:focus-visible { background:#e0e7ff; color:#1f3872; text-decoration:none; }
.nfr-areabar .ab-all.is-on { opacity:.55; pointer-events:none; }
.ab-side { margin:8px 14px 2px; padding:7px 10px; border-radius:10px; background:rgba(255,255,255,.12); color:#fff; font-size:12.5px; font-weight:600; display:flex; gap:8px; align-items:center; line-height:1.3; }
/* narrower computers: the text on the first line, the boxes and Show all on the second, at every area */
@media (max-width:1320px) { .nfr-areabar .ab-text { flex:1 1 calc(100% - 60px); } }
/* tablets beside the menu: three equal boxes on one line, Show all on the next */
@media (min-width:769px) and (max-width:960px) {
  .nfr-areabar .ab-sel { flex:1 1 100%; display:grid; grid-template-columns:repeat(3, minmax(0, 1fr)); }
  .nfr-areabar .ab-sel select { width:100%; }
}
@media (max-width:768px) {
  .nfr-areabar { padding:10px 12px; gap:10px; }
  .nfr-areabar .ab-sel, .nfr-areabar .ab-sel label { width:100%; }
  .nfr-areabar select { width:100%; min-width:0; height:44px; }
  .nfr-areabar .ab-all { width:100%; justify-content:center; height:42px; }
}
@media print { .nfr-areabar { display:none !important; } }
