:root {
  --bg: #f3f4f2;
  --surface: #ffffff;
  --border: #d7dad5;
  --text: #1e2321;
  --text-muted: #667069;
  --accent: #2f6f56;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --danger-tint: #f6dbd9;
  --clear-tint: #fbe9c8;
  --clear-border: #d9a441;
  /* Text specifically — #d9a441-on-#fbe9c8 (both light amber) measures
     1.88:1, well under WCAG AA's 4.5:1 minimum; this darker shade on the
     same tint measures ~5:1. --clear-border stays as-is for its original
     job (a border/background color, e.g. .btn-clear), which never put text
     directly on the tint. */
  --clear-text: #8a5a00;
  --nav-highlight: #3b5fa8;
  --nav-highlight-tint: #dde6f7;
  --radius: 4px;
}

:root[data-theme="dark"] {
  --bg: #14181a;
  --surface: #1b2120;
  --border: #333c3a;
  --text: #e6ece9;
  --text-muted: #93a19c;
  --accent: #4f9a7c;
  --accent-ink: #0d1211;
  --danger: #e3564a;
  --danger-tint: rgba(227, 86, 74, 0.16);
  --clear-tint: rgba(217, 164, 65, 0.16);
  --clear-border: #d9a441;
  --clear-text: #d9a441;
  --nav-highlight: #8fb3f0;
  --nav-highlight-tint: rgba(143, 179, 240, 0.16);
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font-family: ui-sans-serif, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Base link color — a plain, un-classed <a> (inline text links, "Show all"
   toggles, etc.) would otherwise fall back to the browser's default blue/
   visited-purple, which is unreadable on the dark theme. Every link that
   needs a different look (.btn, .topnav a, .brand, .report-link, ...) has
   its own class-based rule elsewhere, which wins on specificity regardless
   of source order, so this only ever affects links nobody styled. */
a { color: var(--accent); }
a:hover { text-decoration: underline; }

/* ---- Top bar ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  margin: 0 auto; padding: 0.7rem 1.5rem;
  display: flex; align-items: center; gap: 1.75rem;
}
.brand-block { display: flex; flex-direction: column; justify-content: center; line-height: 1.2; flex-shrink: 0; }
.brand-logo { display: flex; align-items: center; }
.brand-logo img { display: block; width: 190px; max-height: 42px; }
.brand { font-weight: 700; color: var(--accent); text-decoration: none; font-size: 1.05rem; }
.brand-company {
  font-size: 0.68rem; color: var(--text-muted); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 9rem;
}
.topnav { display: flex; align-items: center; gap: 1.1rem; flex: 1; }
.topnav a { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }
.topnav a:hover { color: var(--text); }
.topnav a.is-active { color: var(--accent); font-weight: 700; }

.nav-dropdown { position: relative; }
.nav-dropdown-toggle {
  background: none; border: none; padding: 0; font: inherit; cursor: pointer;
  color: var(--text-muted); font-size: 0.9rem; display: inline-flex; align-items: center; gap: 0.2rem;
}
.nav-dropdown-toggle:hover, .nav-dropdown-toggle.is-active { color: var(--accent); }
.nav-dropdown-toggle.is-active { font-weight: 700; }
.nav-caret { font-size: 0.65rem; }
.nav-dropdown-menu {
  display: none; position: absolute; top: calc(100% + 0.6rem); left: 0; min-width: 9rem; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(0,0,0,0.12); padding: 0.35rem;
}
.nav-dropdown-menu.is-open { display: flex; flex-direction: column; }
.nav-dropdown-menu a { padding: 0.4rem 0.6rem; border-radius: var(--radius); }
.nav-dropdown-menu a:hover { background: rgba(127,127,127,0.1); }
.nav-dropdown-menu a.is-active { color: var(--accent); font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; }
.user-role { text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.04em; color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px; padding: 0.1rem 0.5rem; }
/* Set apart from the icon toggles with a divider + extra gap, and given its
   own padded tap target — sitting right next to the theme toggle with the
   same small gap made it too easy to log out by mistake. */
.logout {
  color: var(--danger); text-decoration: none; margin-left: 0.5rem; padding-left: 0.9rem;
  border-left: 1px solid var(--border);
}
.nav-back-btn {
  background: none; border: 1px solid var(--border); border-radius: 999px;
  width: 1.9rem; height: 1.9rem; font-size: 1rem; line-height: 1; cursor: pointer; flex-shrink: 0;
  color: var(--text); display: inline-flex; align-items: center; justify-content: center;
}
.nav-back-btn:hover { background: var(--bg); }

.theme-toggle {
  background: none; border: 1px solid var(--border); border-radius: 999px;
  width: 1.9rem; height: 1.9rem; font-size: 0.95rem; line-height: 1; cursor: pointer;
  color: var(--text); display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--bg); }
/* Variant with a visible text label next to the icon (not just a title/
   aria-label tooltip) — used where the icon alone may not be obvious, e.g.
   a guest on a shared view who's never seen the app's icon-only convention. */
.theme-toggle-labeled { width: auto; height: auto; padding: 0.25rem 0.65rem; gap: 0.35rem; font-size: 0.78rem; }

.page { margin: 0 auto; padding: 1.5rem 1.5rem 3rem; }

/* ---- Login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2rem 2.25rem; width: 320px; display: flex; flex-direction: column; gap: 0.9rem;
}
.login-card h1 { margin: 0; font-size: 1.3rem; }
.login-logo { display: block; width: min(100%, 420px); height: auto; margin: 0 auto 0.4rem; }
.login-company { margin: 0; color: var(--accent); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.login-sub { margin: 0 0 0.5rem; color: var(--text-muted); font-size: 0.85rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-muted); }
.login-card input { padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.95rem; }
.login-card button {
  margin-top: 0.4rem; padding: 0.6rem; border: none; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer;
}
.form-error { color: var(--danger); font-size: 0.85rem; margin: 0; }

/* ---- Generic form / table helpers reused by later screens ---- */
/* Baseline color+background for every <select>, paired explicitly on
   <option> too — some mobile browsers render a select's native popup list
   using the select's own text color but a separate (often system-default)
   popup background, so without an explicit option-level pairing, dark-theme
   selects can show unreadable/invisible option text on a phone even though
   the closed select box itself looks fine. */
select { color: var(--text); background: var(--surface); }
select option { color: var(--text); background: var(--surface); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }
.btn { display: inline-block; padding: 0.45rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; font-size: 0.85rem; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
/* Every "Clear filters" button app-wide shares this class so it reads as
   "the thing that resets everything" at a glance, rather than blending in
   with every other plain action button — same amber used elsewhere for an
   active filter's outline (bar charts, table rows), so the color already
   reads as "filter-related" rather than introducing a new one. */
.btn-clear { background: var(--clear-tint); border-color: var(--clear-border); }
.badge { font-size: 0.72rem; padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); }
.badge-open { color: #a06a1e; border-color: #a06a1e; }
.badge-closed { color: var(--text-muted); }

/* ---- Dashboard ---- */
.dash-toolbar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.plant-filter { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--text-muted); }
.plant-filter select { padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }
.plant-filter .label-filter { margin: 0; }
.last-refreshed { margin-left: auto; font-size: 0.78rem; color: var(--text-muted); }
.empty-state { color: var(--text-muted); font-size: 0.85rem; padding: 0.75rem 0; }
.card h2 { margin: 0 0 0.75rem; font-size: 1rem; }
.section-head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }

/* Recency highlighting so operators spot "now" at a glance. Current-shift
   events get an accent left-stripe + tint; earlier-today a fainter tint. The
   stripe is on the first cell so it reads as a bar down the row's left edge. */
.shift-legend { display: flex; gap: 1rem; font-size: 0.72rem; color: var(--text-muted); }
.shift-legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.shift-swatch { width: 0.85rem; height: 0.85rem; border-radius: 3px; display: inline-block; }
.swatch-current { background: color-mix(in srgb, var(--accent) 22%, transparent); border-left: 3px solid var(--accent); }
.swatch-today { background: color-mix(in srgb, var(--accent) 8%, transparent); }
tr.row-current-shift > td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
tr.row-current-shift > td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tr.row-today > td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
#openTable tbody tr:hover, #historyTable tbody tr:hover { background: var(--bg); }
/* Standard click-to-select row highlighting for Maintenance Due/Maintenance
   Tasks (click selects just that row, Ctrl/Cmd+click adds/removes it from a
   multi-row selection) — same color-mix convention as the shift-schedule
   row highlights above, so it reads consistently in both themes. */
.lookup-list table tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); cursor: pointer; }
.lookup-list table tbody tr.row-selected { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.lookup-list table tbody tr.row-selected:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }
th.sortable { user-select: none; }
th.sortable:hover { color: var(--text); }
.sort-indicator { font-size: 0.65rem; color: var(--accent); margin-left: 0.2rem; }

/* ---- New Event modal ---- */
.event-modal {
  border: 1px solid var(--border); border-radius: 6px; padding: 1.5rem 1.75rem;
  width: min(720px, 92vw); background: var(--surface); color: var(--text);
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.event-modal::backdrop { background: rgba(10, 14, 12, 0.55); }
.event-modal h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.event-modal .event-form { max-width: none; }

/* ---- QR/barcode scanner modal ---- */
/* Anchored near the top of the viewport (not vertically centered) so the
   camera preview appears immediately rather than after the eye has to find
   it mid-screen — particularly helpful once an on-screen keyboard is up. */
.qr-scanner-modal {
  position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); margin: 0;
  border: 1px solid var(--border); border-radius: 6px; padding: 1.5rem;
  width: min(420px, 92vw); background: var(--surface); color: var(--text);
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.qr-scanner-modal::backdrop { background: rgba(10, 14, 12, 0.55); }
.qr-scanner-modal h2 { margin: 0 0 1rem; font-size: 1.05rem; }
.qr-scanner-video { width: 100%; border-radius: 4px; background: #000; aspect-ratio: 4 / 3; object-fit: cover; }
.qr-scanner-status { margin: 0.75rem 0 0; font-size: 0.85rem; color: var(--text-muted); min-height: 1.2em; }

/* ---- Phone-only dialog treatment: full-screen inline panel, no backdrop ---- */
dialog.dialog-inline {
  position: fixed; inset: 0; margin: 0; width: 100%; height: 100%;
  max-width: none; max-height: none; border: none; border-radius: 0;
  box-shadow: none; overflow-y: auto; z-index: 50; transform: none;
}

/* ---- Location/product code scan-or-type row, reused on New Event + Production ---- */
.code-scan-row { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1.1rem; }
.code-scan-row[hidden] { display: none; }
.code-scan-row input { flex: 1; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); font-family: ui-monospace, Consolas, monospace; }
.code-status { font-size: 0.8rem; margin: -0.6rem 0 1rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.code-status.ok { color: var(--accent); }
.code-status.err { color: var(--danger); }
.retry-btn { font-size: 0.72rem; padding: 0.15rem 0.5rem; border-color: var(--danger); color: var(--danger); }

.scan-photos { display: flex; gap: 0.5rem; margin: -0.6rem 0 1rem; flex-wrap: wrap; }
.scan-photo-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); cursor: pointer; }

/* ---- Feedback history (append-only event notes) ---- */
.feedback-list { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 0.75rem; }
.feedback-item { border-left: 2px solid var(--accent); padding: 0.2rem 0 0.2rem 0.75rem; }
.feedback-meta { display: flex; gap: 0.6rem; align-items: baseline; font-size: 0.75rem; color: var(--text-muted); }
.feedback-author { font-weight: 600; color: var(--text); }
.feedback-comment { margin: 0.2rem 0 0; white-space: pre-wrap; }
.feedback-form { display: flex; gap: 0.5rem; align-items: flex-end; margin-top: 0.75rem; }
.feedback-form input, .feedback-form textarea { flex: 1; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; resize: vertical; }

/* ---- Event / generic forms ---- */
.form-heading { font-size: 1.15rem; margin: 0 0 1rem; }
.notice { background: #fdf3e2; border: 1px solid #e8c27c; color: #7a5410; border-radius: var(--radius); padding: 0.6rem 0.9rem; font-size: 0.85rem; margin-bottom: 1rem; }
/* ---- Shared (no-login) view ---- */
.shared-banner {
  background: var(--accent); color: var(--accent-ink); padding: 0.6rem 1.25rem;
  font-size: 0.85rem; text-align: center;
}
/* .theme-toggle's default border/color (var(--text)/var(--border)) has poor
   contrast against the accent-colored banner — accent-ink is the color
   already chosen to read well on var(--accent) in both themes. */
.shared-banner .theme-toggle { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent-ink) 40%, transparent); vertical-align: middle; }
.shared-banner .theme-toggle:hover { background: color-mix(in srgb, var(--accent-ink) 15%, transparent); }
.shared-header { margin: 0 auto; padding: 1rem 1.5rem 0; }
.shared-header .brand { font-weight: 700; color: var(--accent); font-size: 1.05rem; }
.shared-header .brand-company { border-left: none; margin-left: 0.6rem; padding-left: 0; }
.event-form { max-width: 720px; }
#feedbackPanel { max-width: 720px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem 1.2rem; }
.form-grid label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; color: var(--text-muted); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid select, .form-grid input, .form-grid textarea {
  padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.92rem; color: var(--text); font-family: inherit; background: var(--surface);
}
.hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-muted); font-size: 0.75rem; }
/* Start/End sit side by side (stacked on mobile) with distinct tinted
   backgrounds so the two are easy to tell apart at a glance. */
.time-range-row { display: flex; gap: 1rem; }
.time-range-row > label { flex: 1; padding: 0.6rem 0.7rem; border-radius: var(--radius); }
.time-range-row > label.field-start { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.time-range-row > label.field-end { background: color-mix(in srgb, #d97706 16%, transparent); }
@media (max-width: 640px) { .time-range-row { flex-direction: column; gap: 0.9rem; } }
.time-quickpicks { display: flex; gap: 0.3rem; margin-top: 0.35rem; }
.time-quickpicks button {
  font-size: 0.72rem; padding: 0.2rem 0.5rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text-muted); cursor: pointer;
}
.time-quickpicks button:hover { background: var(--bg); color: var(--text); }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---- Lookups ---- */
.page-sub { color: var(--text-muted); font-size: 0.88rem; margin: -0.5rem 0 1.25rem; }
.page-sub-toggle {
  display: none; align-items: center; gap: 0.3rem; background: none; border: none;
  color: var(--text-muted); font-size: 0.82rem; padding: 0.2rem 0; margin: -0.3rem 0 0.6rem; cursor: pointer;
}
@media (max-width: 900px) {
  .page-sub-toggle { display: inline-flex; }
}
/* Each card sizes to its own content (flex default min-width:auto — never
   forced narrower than what's inside it) and wraps to the next line as a
   whole when a row runs out of room — no card's table ever needs to scroll
   or wrap its text sideways to fit a fixed column track. */
.lookup-grid { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; }
.lookup-grid > .lookup-section { flex: 0 1 auto; }
.lookup-section h2 { margin: 0 0 0.6rem; font-size: 0.95rem; }
.lookup-section label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.6rem; }
.lookup-section select { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }
.lookup-list { margin-bottom: 0.75rem; }
.lookup-list table { width: auto; }
.lookup-list th, .lookup-list td { white-space: nowrap; }
.lookup-list a { color: var(--accent); text-decoration: none; }
.lookup-list a:hover { text-decoration: underline; }
.lookup-add { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.lookup-add[hidden] { display: none; }
/* A .lookup-list squeezed into a narrow flex column (e.g. Downtime History's
   By Department table sitting next to its own bar charts) has no room for
   .lookup-list's normal nowrap-and-scroll behavior — it would just scroll
   sideways inside an already-narrow box. Shrinks to the column instead,
   wrapping long labels rather than scrolling. */
.stat-panel-table { overflow-x: visible; }
.stat-panel-table table { width: auto; max-width: 100%; table-layout: auto; }
.stat-panel-table th, .stat-panel-table td { white-space: normal; word-break: break-word; padding: 0.4rem 0.5rem; }
.stat-panel-table td:nth-child(1) { width: 1.6rem; }
/* Maintenance History's and Issues' tables have enough columns that forcing
   every cell to one line (the .lookup-list default) always overflows into a
   horizontal scrollbar, regardless of window width. Letting cells wrap
   instead lets the browser's normal table layout fit it to the card. */
#historyList table, #issuesList table, #assetMaintHistoryList table, #tasksList table, #assetsList table, #plansList table, #toolsList table { width: 100%; }
#historyList th, #historyList td, #issuesList th, #issuesList td, #assetMaintHistoryList th, #assetMaintHistoryList td, #tasksList th, #tasksList td, #assetsList th, #assetsList td, #plansList th, #plansList td, #toolsList th, #toolsList td { white-space: normal; }

/* Live-filtering search dropdown (asset pickers) — opens automatically as
   results come back, rather than needing a separate click to open a <select>. */
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20; margin-top: 0.25rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-height: 14rem; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.autocomplete-item { padding: 0.5rem 0.7rem; cursor: pointer; font-size: 0.9rem; color: var(--text); }
.autocomplete-item:hover, .autocomplete-item.is-active { background: var(--bg); }

/* "Fault finder" cause suggestion chips (New Event's Cause field) — same
   tint-pill treatment as other suggestion/quick-pick affordances, ranked
   left-to-right (most-likely cause first). */
.cause-suggestions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin-top: 0.4rem; }
.cause-suggestion-chip {
  padding: 0.2rem 0.6rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 0.78rem; cursor: pointer;
}
.cause-suggestion-chip:hover { border-color: var(--accent); color: var(--accent); }

/* Collapsible section headers (Compliance Summary, "x by Section" matrices,
   list panels, etc.) — padding + hover feedback here enlarges the click
   target beyond the bare text line and gives visible confirmation it's
   interactive, without touching the inline margin:0 each one already sets. */
.panel-header { padding: 0.4rem 0.3rem; border-radius: var(--radius); transition: background 0.12s ease; }
.panel-header:hover { background: rgba(127,127,127,0.1); }

/* Filter bar + "x by Section" panel side by side, instead of stacked —
   the section table starts collapsed so this keeps the common (collapsed)
   case compact; wraps to stacked below ~700px combined width. */
.filter-section-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.filter-section-row > .filter-col { flex: 1 1 320px; }
.filter-section-row > .section-col { flex: 2 1 420px; min-width: 0; }
.lookup-add input { flex: 1; min-width: 8rem; padding: 0.45rem 0.55rem; border: 1px solid var(--border); border-radius: var(--radius); }
.btn-edit { font-size: 0.75rem; padding: 0.25rem 0.6rem; }

/* ---- Reference photos (Equipment/Components/Products) ---- */
.photo-control { display: flex; align-items: center; gap: 0.4rem; }
.photo-icon-btn { font-size: 1.2rem; line-height: 1; background: none; border: none; padding: 0; cursor: pointer; }
.photo-upload-btn { font-size: 0.72rem; padding: 0.2rem 0.5rem; cursor: pointer; white-space: nowrap; }

/* ---- QR tag link (table-cell variant — see .hierarchy-tag-* for the tree-view one) ---- */
.tag-control { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.tag-control input { padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); max-width: 10rem; }

.lightbox-modal {
  /* <dialog> carries its own browser-default color (not just background),
     which otherwise wins over inheriting var(--text) — every other element
     just inherits, but dialog needs it stated explicitly here. */
  border: none; border-radius: 6px; padding: 0.75rem; background: var(--surface); color: var(--text);
  max-width: 90vw; max-height: 90vh;
}
.lightbox-modal::backdrop { background: rgba(0, 0, 0, 0.75); }
.lightbox-img { display: block; max-width: 100%; max-height: 75vh; border-radius: 4px; margin-bottom: 0.6rem; }
.lightbox-close { width: 100%; }
.dir-notes-text { max-width: 60vw; white-space: pre-wrap; margin: 0 0 0.6rem; }
.lookup-edit-modal {
  border: none; border-radius: 6px; padding: 1.25rem; background: var(--surface); color: var(--text);
  width: min(420px, 92vw); max-height: 90vh; box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.lookup-edit-modal::backdrop { background: rgba(0, 0, 0, 0.55); }
.lookup-edit-modal-title { margin: 0 0 1rem; font-size: 1.05rem; }
.lookup-edit-modal-fields { display: flex; flex-direction: column; gap: 0.75rem; }
.lookup-edit-modal-fields label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-muted); }
.lookup-edit-modal-fields input {
  padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.92rem; color: var(--text); font-family: inherit; background: var(--surface);
}

/* ---- Production form ---- */
.prod-add-form { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.8rem 1rem; align-items: end; margin-top: 1rem; }
.prod-add-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.78rem; color: var(--text-muted); }
.prod-add-form select, .prod-add-form input { padding: 0.45rem 0.55rem; border: 1px solid var(--border); border-radius: var(--radius); }
.prod-add-form .span-2 { grid-column: span 2; }
@media (max-width: 720px) { .prod-add-form { grid-template-columns: 1fr 1fr; } }
.value-with-uom { display: flex; align-items: center; gap: 0.5rem; }
.value-with-uom input { flex: 1; min-width: 0; }
.input-uom { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }

/* ---- Bulk production entry ---- */
.bulk-rows { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.9rem; }
.bulk-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 0.6rem; align-items: center;
  padding: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius);
}
.bulk-row select, .bulk-row input { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); width: 100%; }
.bulk-row-uom { flex-shrink: 0; }
@media (max-width: 720px) { .bulk-row { grid-template-columns: 1fr 1fr; } }

/* ---- Collapsible entry panel ---- */
.entry-panel summary {
  cursor: pointer; font-weight: 650; font-size: 0.95rem; list-style: none;
  display: flex; align-items: center; gap: 0.5rem;
}
.entry-panel summary::-webkit-details-marker { display: none; }
.entry-panel summary::before {
  content: '▸'; color: var(--accent); font-size: 0.75rem; transition: transform 0.15s ease;
}
.entry-panel[open] summary::before { transform: rotate(90deg); }
.entry-panel summary:hover { color: var(--accent); }
.entry-panel .prod-add-form { margin-top: 1rem; }
.entry-panel .form-error { margin-top: 0.75rem; }

/* ---- Plant hierarchy tree ---- */
.hierarchy-toggle { display: inline-flex; align-items: center; gap: 0.4rem; margin-bottom: 1rem; font-size: 0.85rem; color: var(--text-muted); }
.hierarchy-node { margin-bottom: 0.6rem; }
.hierarchy-area { padding: 0.6rem 0.8rem; }
.hierarchy-row {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.35rem 0; margin-left: 1.25rem; border-bottom: 1px solid var(--border);
}
.hierarchy-row:last-child { border-bottom: none; }
.hierarchy-components { margin-left: 1.25rem; }
.hierarchy-name-holder, .hierarchy-rename-row { display: inline-flex; align-items: center; gap: 0.4rem; }
.hierarchy-rename-row input { padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); }
.hierarchy-btn { font-size: 0.72rem; padding: 0.2rem 0.5rem; white-space: nowrap; }
.hierarchy-reorder { display: inline-flex; gap: 0.2rem; }
.hierarchy-move { display: inline-flex; align-items: center; gap: 0.3rem; }
.hierarchy-move-select { font-size: 0.8rem; padding: 0.25rem; border: 1px solid var(--border); border-radius: var(--radius); }

/* Deep-link landing: briefly flashes the row/panel a Directory "Edit" link
   pointed at, so it's obvious which item you were sent to find. */
@keyframes hierarchyFocusFlash {
  0%, 100% { background: transparent; }
  20%, 60% { background: var(--accent-soft, rgba(255, 200, 0, 0.25)); }
}
.hierarchy-focus-flash { animation: hierarchyFocusFlash 2.5s ease; border-radius: var(--radius); }

.hierarchy-tag-holder, .hierarchy-tag-row { display: inline-flex; align-items: center; gap: 0.4rem; }
.hierarchy-tag-row input { padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); }
.hierarchy-tag-status { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.hierarchy-tag-status.err { color: var(--danger); }

.hierarchy-plant-info { margin-left: 0; font-weight: 600; }

/* Process-unit node: nested one level inside its area's card. */
.hierarchy-unit { margin: 0.5rem 0 0.5rem 1.25rem; padding: 0.5rem 0.7rem; border-style: dashed; }
.hierarchy-unit.hierarchy-inactive > summary { color: var(--text-muted); }
.hierarchy-unit.hierarchy-inactive { opacity: 0.8; }
.hierarchy-unit-badge {
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 0.08rem 0.45rem;
}
.hierarchy-details-row { display: inline-flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.hierarchy-notes-input {
  padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: var(--radius);
  font: inherit; width: 220px; min-height: 2rem; resize: vertical;
}

.hierarchy-create { margin-left: 1.25rem; border-bottom: none; padding: 0.25rem 0; }
.hierarchy-create-nested { margin-left: 2.5rem; }
.hierarchy-create-holder, .hierarchy-create-row { display: inline-flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.hierarchy-create-row input { padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); }

/* ---- Printable labels ---- */
.labels-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.label-group { margin-top: 1.75rem; }
.label-group-title { font-size: 1rem; border-bottom: 2px solid var(--text); padding-bottom: 0.4rem; margin-bottom: 1rem; }
.label-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.9rem; }
.label-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.8rem; display: flex; gap: 0.7rem; align-items: flex-start;
}
.label-qr { width: 72px; height: 72px; flex-shrink: 0; background: #fff; border-radius: 3px; }
.label-text { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.label-kind { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.label-name { font-size: 0.95rem; font-weight: 700; white-space: normal; overflow-wrap: break-word; line-height: 1.25; }
.label-code { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; font-weight: 600; color: var(--accent); }

.label-filter { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 1rem 0 0.5rem; }
.label-filter-btn.is-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Downtime/Maintenance workspace switch — sits in the topnav's flex row
   alongside links that shrink/wrap under pressure (see .topnav), but the
   two tabs themselves must never wrap onto separate lines or fight the
   links for space, so this overrides .label-filter's flex-wrap and margin
   and reserves the switch its own fixed room. */
.workspace-switch { flex-wrap: nowrap; flex-shrink: 0; margin: 0; padding-right: 1.1rem; border-right: 1px solid var(--border); }
.workspace-switch .label-filter-btn { white-space: nowrap; padding: 0.35rem 0.7rem; font-size: 0.82rem; }
/* Whichever side is selected sits on the right — same two DOM elements,
   just reordered visually via flex order so the active workspace is always
   the one closest to its own menu, which immediately follows to its right. */
.workspace-switch a.is-active { order: 2; }
.workspace-switch a:not(.is-active) { order: 1; }
/* .topnav a.is-active (higher specificity: element + class beats these two
   classes) would otherwise win and repaint this text var(--accent) — the
   same colour as its own is-active background — making it invisible.
   Reasserted here at matching specificity to actually get --accent-ink. */
.topnav .workspace-switch a.is-active { color: var(--accent-ink); }

.label-card { position: relative; }
.label-card[hidden], .label-group[hidden] { display: none; }
.label-index {
  position: absolute; top: -0.5rem; left: -0.5rem; min-width: 1.4rem; height: 1.4rem;
  border-radius: 999px; background: var(--text); color: var(--bg);
  font-size: 0.7rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
  padding: 0 0.3rem; font-family: ui-monospace, Consolas, monospace;
}

@media print {
  /* Printing/Save-as-PDF must always come out light, regardless of the
     viewer's on-screen theme — dark mode's --surface/--border/--text etc.
     would otherwise cascade into every card/table/input that reads them
     (the body/.page override below only ever covered those two elements
     directly, not the variables everything else pulls from), producing a
     near-black printout. Re-declared here at matching specificity, later
     in the stylesheet than the :root[data-theme="dark"] block, so it wins
     in print regardless of which theme is active on screen. */
  :root[data-theme="dark"] {
    --bg: #f3f4f2; --surface: #ffffff; --border: #d7dad5; --text: #1e2321;
    --text-muted: #667069; --accent: #2f6f56; --accent-ink: #ffffff; --danger: #b3261e;
  }
  .topbar, .no-print { display: none !important; }
  body, .page { background: #fff; color: #000; }
  .label-group { break-inside: avoid; }

  /* Printed labels get stacked, larger text — this is going on a machine, not a screen. */
  .label-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.6rem; }
  .label-card {
    break-inside: avoid; border-color: #999;
    flex-direction: column; align-items: center; text-align: center; gap: 0.4rem; padding: 0.7rem 0.5rem;
  }
  .label-qr { width: 110px; height: 110px; }
  .label-text { align-items: center; width: 100%; }
  .label-kind { font-size: 0.7rem; }
  .label-name { font-size: 1.05rem; color: #000; }
  .label-code { font-size: 1rem; color: #000; }
  .label-index { background: #000; color: #fff; }

  /* Printing a modal (e.g. the event/task detail dialogs): standard "print
     just one element" technique — visibility:hidden (not display:none) on
     everything so ancestors of the dialog stay in the render tree instead of
     collapsing it too (the dialog is nested inside <main class="page">, not
     a direct child of <body>, so hiding ancestors by display:none had been
     hiding the dialog right along with them — a blank printout). Then make
     the dialog and everything inside it visible again and pull it out to
     the page origin, since it would otherwise still print at its normal
     (now-invisible-but-still-occupying-space) position partway down the page.
     visibility:hidden alone still leaves every hidden element's box height in
     the flow, though — on a page with a long table behind the dialog, that
     leftover height is tall enough to spill onto a second, entirely blank
     printed page. display:none on .page's own direct children (everything
     except the dialog) removes that height outright, while .page and body
     themselves stay un-hidden so the dialog inside can still render. */
  body.printing-modal * { visibility: hidden; }
  body.printing-modal dialog[open], body.printing-modal dialog[open] * { visibility: visible; }
  body.printing-modal main.page > *:not(dialog) { display: none; }
  body.printing-modal dialog[open] {
    position: absolute; left: 0; top: 0;
    display: block; width: 100%; max-width: 100%;
    box-shadow: none; border: none; margin: 0; padding: 0;
  }
}
/* ---- Blank QR tag sheets ---- */
.tags-toolbar-controls { display: flex; align-items: center; gap: 0.6rem; }
.tags-toolbar-controls label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--text-muted); }
.tags-toolbar-controls input { width: 4.5rem; padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }

.tags-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; margin-top: 1rem; }
.tag-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  position: relative; padding: 0.7rem; display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
}
.tag-brand {
  width: 100%; box-sizing: border-box; min-height: 1.32rem; padding: 0.28rem 0.35rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px; background: #123c32; color: #fff; white-space: nowrap;
  font-size: 0.66rem; font-weight: 800; line-height: 1; text-transform: uppercase; letter-spacing: 0.05em;
}
.tag-brand strong { font-size: 0.8rem; font-weight: 900; letter-spacing: 0.12em; }
.tag-qr-row {
  width: 100%; display: flex; align-items: center; justify-content: flex-start; gap: 0.4rem;
}
.tag-side-brand {
  writing-mode: vertical-rl; transform: rotate(180deg);
  color: #13795b; font-size: 0.56rem; font-weight: 900; line-height: 1;
  letter-spacing: 0.13em; text-align: center; text-transform: uppercase;
}
.tag-qr { width: 200px; max-width: 100%; height: auto; aspect-ratio: 1 / 1; background: #fff; border-radius: 3px; }
.tag-token { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; font-weight: 600; color: var(--accent); letter-spacing: 0.03em; }
.tag-fields { width: 100%; display: flex; flex-direction: column; gap: 0.55rem; margin-top: 0.3rem; }
.tag-field { display: flex; flex-direction: column; gap: 0.2rem; }
.tag-field-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.tag-field-line { border-bottom: 1px solid var(--text); height: 1.3rem; }

@media print {
  .tags-grid { grid-template-columns: repeat(3, 1fr); gap: 8mm; }
  .tag-card { break-inside: avoid; border-color: #999; padding: 5mm; gap: 3mm; }
  .tag-brand {
    color: #fff !important; background: #123c32 !important;
    print-color-adjust: exact; -webkit-print-color-adjust: exact;
  }
  .tag-side-brand { color: #13795b !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .tag-token { font-size: 0.85rem; color: #000; }
  .tag-field-label { color: #000; }
  .tag-field-line { border-bottom-color: #000; height: 8mm; }
}

/* ---- Plant directory (read-only report) ---- */
.directory-toolbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1rem 0; }
.dir-search { flex: 1; min-width: 14rem; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); }
/* Enough columns (13) that forcing every cell to one line always overflows
   into a horizontal scrollbar, regardless of window width. Letting cells
   wrap instead lets the browser's normal table layout fit it to the page. */
.dir-table { width: 100%; border-collapse: collapse; }
.dir-table th, .dir-table td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); white-space: normal; }
.dir-table td.dir-code { font-family: ui-monospace, Consolas, monospace; font-weight: 600; color: var(--accent); letter-spacing: 0.02em; }
.c-code, .item-code { font-family: ui-monospace, Consolas, monospace; font-weight: 600; color: var(--accent); letter-spacing: 0.02em; white-space: nowrap; }
.dir-table tbody tr:hover { background: rgba(127, 127, 127, 0.08); }
.dir-inactive { color: var(--text-muted); font-style: italic; }
.dir-new-badge {
  display: inline-block; font-size: 0.62rem; font-weight: 700; letter-spacing: 0.03em;
  background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0.1rem 0.4rem;
  vertical-align: middle;
}
.print-timestamp { display: none; }

@media print {
  /* @page has no selector to scope by — this is the one rule in effect for
     every printed page app-wide. Landscape suits the wide Directory/Dashboard
     tables; no other page currently needs a different orientation. */
  @page { size: A4 landscape; margin: 12mm; }
  body, .page { background: #fff; color: #000; }
  /* position:fixed anchors this to the printed page's own corner (not the
     document's normal flow), so it lands top-right on every printed page —
     including inside a printed modal, where the timestamp paragraph sits
     near the bottom of the dialog's markup but still needs to appear at the
     top of the printed sheet like every other report's timestamp does. */
  .print-timestamp { display: block; position: fixed; top: 0; right: 0; margin: 0; font-size: 0.75rem; color: #444; text-align: right; }
  /* Row separators default to a light theme-based grey (or a dark-mode
     tint) that some printers/PDF engines render as barely-there — force a
     dependable faint grey on paper regardless of which theme was active. */
  th, td { border-bottom: 1px solid #bbb; }
  .dir-table th:last-child, .dir-table td:last-child { display: none; }
  /* On screen, nowrap + a scrolling container keep the report tidy; paper
     can't scroll, so anything wider than the page just gets clipped off the
     edge. Force the table back to the page width and let cells wrap instead. */
  .table-scroll { overflow: visible; }
  .dir-table { table-layout: fixed; width: 100%; }
  .dir-table th, .dir-table td { color: #000; white-space: normal; word-break: break-word; font-size: 0.72rem; padding: 0.3rem 0.4rem; }
  /* The stat-panel bar charts (Downtime History's By Department/Symptoms
     Summary) fill each bar with an inline background-color, with the value
     printed in white text on top of it — if the browser's print dialog has
     "Background graphics" switched off (a per-print, often-default setting
     outside this app's control), that fill silently disappears and the
     white-on-nothing text goes with it, making the whole chart look empty.
     print-color-adjust:exact forces Chrome/Firefox to keep background colors
     regardless of that toggle, so the bars print reliably either way. */
  .bar-chart * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.inline-form { display: inline-block; margin: 0; }
.inline-form select { padding: 0.3rem 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); }
.table-scroll { overflow-x: auto; }
#sharedIssuesList table { width: 100%; }
.shared-issue-detail-link { border: 0; padding: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }
.shared-issue-detail-grid { display: flex; flex-wrap: wrap; gap: 1.25rem; margin-bottom: 0.75rem; }
.shared-issue-detail-field { margin-bottom: 0.75rem; overflow-wrap: anywhere; }
.shared-issue-detail-value { white-space: pre-wrap; }
.shared-issue-photos { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.shared-issue-photo-thumb { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.25rem; cursor: pointer; }
.shared-issue-photo-thumb img { display: block; width: 4.5rem; height: 4.5rem; object-fit: cover; border-radius: var(--radius); }
.shared-issue-photo-modal img { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto 1rem; object-fit: contain; }
#sharedIssueDetailModal h2, #sharedIssuePhotoModal h2 { margin: 0 0 0.75rem; }
#sharedIssueDetailRetry[hidden] { display: none !important; }
.shared-maintenance-table { width: 100%; }
.shared-maintenance-table td { white-space: pre-wrap; min-width: 4.5rem; }
.shared-maintenance-table th { white-space: normal; }
@media print {
  .shared-maintenance-table { table-layout: fixed; }
  .shared-maintenance-table th, .shared-maintenance-table td { min-width: 0; overflow-wrap: anywhere; font-size: 0.68rem; padding: 0.3rem; }
}
.shared-issue-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: 0.75rem; }
.shared-issue-filters label { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; font-size: 0.88rem; }
.shared-issue-filters select, .shared-issue-filters input { width: 100%; min-width: 0; min-height: 2.5rem; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; }
#sharedIssuesList th, #sharedIssuesList td { white-space: normal; }
#sharedIssuesList tbody tr:hover, #sharedIssueStats tbody tr:hover { cursor: default; }
@media print {
  #sharedIssuesList table { table-layout: fixed; }
  #sharedIssuesList th, #sharedIssuesList td { white-space: normal !important; overflow-wrap: anywhere !important; font-size: 0.68rem; padding: 0.3rem; }
}
.contact-form { display: flex; gap: 0.35rem; align-items: center; }
.contact-form input { padding: 0.3rem 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); width: 9rem; font-size: 0.85rem; }
.contact-form button { font-size: 0.75rem; padding: 0.25rem 0.6rem; }

/* ---- Nav hamburger toggle (hidden on desktop/tablet; see mobile block below) ---- */
.nav-toggle {
  display: none; width: 2.3rem; height: 2.3rem; flex-shrink: 0;
  align-items: center; justify-content: center; background: none;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 1.2rem; line-height: 1; color: var(--text); cursor: pointer;
}

/* Maintenance Due / Issues / Assets shortcuts, kept reachable without
   opening the hamburger — same links still live inside .topnav too, so this
   is a redundant fast-path, not a replacement. Sits as its own full-width
   row below the topbar (below the app name), not squeezed into the topbar
   row itself. Desktop/tablet already show the full nav inline, so this only
   needs to exist below the mobile breakpoint. */
.nav-quick-icons { display: none; gap: 0.4rem; padding: 0 0.8rem 0.6rem; }
.nav-quick-icon {
  display: flex; flex: 1; flex-direction: column; align-items: center; gap: 0.15rem;
  padding: 0.4rem 0.2rem; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 1.15rem; line-height: 1; text-decoration: none; color: var(--text-muted);
}
.nav-quick-icon span { font-size: 0.68rem; font-weight: 700; line-height: 1; white-space: nowrap; }
.nav-quick-icon.is-active { background: var(--nav-highlight-tint); border-color: var(--nav-highlight); color: var(--nav-highlight); }

/* Workspace switch gets its own colors, distinct from the generic nav
   highlight above and from the app's normal green accent buttons, so
   Downtime vs Maintenance reads at a glance instead of blending in. */
.nav-workspace-icons .nav-quick-icon-downtime.is-active { background: var(--danger-tint); border-color: var(--danger); color: var(--danger); }
.nav-workspace-icons .nav-quick-icon-maintenance.is-active { background: var(--clear-tint); border-color: var(--clear-border); color: var(--clear-border); }

/* ---- Small-screen fit (phones + narrow tablets) ---- */
@media (max-width: 900px) {
  .topbar-inner { padding: 0.6rem 0.8rem; gap: 0.9rem; flex-wrap: wrap; }
  .nav-toggle { display: inline-flex; }
  .nav-quick-icons { display: flex; }
  .topnav {
    display: none; flex-basis: 100%; flex-direction: column; align-items: stretch;
    gap: 0.15rem; margin-top: 0.5rem; padding-top: 0.6rem; border-top: 1px dashed var(--border);
  }
  .topnav.is-open { display: flex; }
  .topnav a, .nav-dropdown-toggle { white-space: normal; padding: 0.6rem 0.3rem; }
  .nav-dropdown-toggle { width: 100%; justify-content: space-between; }
  .nav-dropdown-menu {
    position: static; display: none; box-shadow: none; border: none;
    min-width: 0; padding-left: 0.9rem;
  }
  .nav-dropdown-menu.is-open { display: flex; }
  .page { padding: 1rem 0.8rem 2.5rem; }
  .brand-company { display: none; }
  /* Any bare table not already wrapped in .table-scroll gets its own
     horizontal scroll instead of blowing out the page width. */
  .card, .entry-panel { overflow-x: auto; }
}

/* ---- Quick Add ---- */
.quick-add-form { display: flex; flex-direction: column; gap: 0.6rem; align-items: flex-start; }
.quick-add-form input[type="text"] { width: 100%; max-width: 24rem; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; }
.quick-add-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

/* ---- Quick Add / Quick Tag ---- */
.quick-add-form { display: flex; flex-direction: column; gap: 0.6rem; max-width: 34rem; }
.quick-add-form input[type="text"] { padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; }
.quick-add-tagrow { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.quick-add-actions { display: flex; gap: 0.6rem; }
.qa-new-code { font-family: ui-monospace, Consolas, monospace; font-size: 1.25rem; letter-spacing: 0.08em; color: var(--accent); }
.qt-path { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0.6rem 1rem; }
.qt-path label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.78rem; color: var(--text-muted); }
.qt-path select { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }

/* ---- Selectable table rows (click = highlight one, Shift+click = range) ---- */
table.selectable-rows tbody tr { cursor: default; }
table.selectable-rows tbody tr.row-selected > td {
  background: color-mix(in srgb, var(--accent) 26%, transparent);
}
table.selectable-rows tbody tr.row-selected > td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

/* ---- Reports ---- */
.report-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.report-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1rem; margin-bottom: 1.25rem; }
.report-field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.78rem; color: var(--text-muted); }
.report-field select, .report-field input { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; color: var(--text); background: var(--surface); }
.report-extra { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1rem; }
.report-heading { font-size: 1.1rem; margin: 0.5rem 0 0.3rem; }
.report-chart { min-height: 60px; margin: 0.5rem 0 1.25rem; }
.report-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.report-table th, .report-table td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.report-table th { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }

/* Production Values' "Last 7 Days" grid — product rows x day columns, a bar
   per day (today highlighted) with a trend line drawn over the same bars,
   plus Trend and Today summary columns. See production.php's loadProd7d(). */
.prod7d-grid { display: grid; grid-template-columns: minmax(90px, 1.4fr) repeat(7, minmax(28px, 1fr)) minmax(52px, 0.9fr) minmax(52px, 0.9fr); width: 100%; }
.prod7d-grid .cell { padding: 6px 4px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.prod7d-grid .cell.head { color: var(--text-muted); font-size: 0.66rem; font-weight: 600; text-transform: uppercase; align-items: flex-end; justify-content: center; padding-bottom: 8px; }
.prod7d-grid .cell.head.label, .prod7d-grid .cell.head.trend, .prod7d-grid .cell.head.today { justify-content: flex-start; }
.prod7d-grid .cell.label { font-weight: 600; font-size: 0.85rem; }
/* .bar-cell isn't a .cell (it's a child of the .row-days cell, not a grid
   column itself) so it needs its own rule — without it, only the header cell
   picked up the tint and the "today" column looked highlighted for one row
   instead of running the full height of the table like every other row's
   .cell.today-col already does. */
.prod7d-grid .cell.today-col, .prod7d-grid .bar-cell.today-col { background: rgba(79, 154, 124, 0.1); }
.prod7d-grid .row-days { position: relative; grid-column: span 7; display: grid; grid-template-columns: repeat(7, 1fr); height: 44px; padding: 0; border: none; }
.prod7d-grid .row-days.with-nums { height: 60px; }
.prod7d-grid .row-days svg.prod7d-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.prod7d-grid .bar-cell { position: relative; display: flex; align-items: flex-end; justify-content: center; padding: 0 6px; }
.prod7d-grid .bar-fill { width: 100%; border-radius: 2px 2px 0 0; background: rgba(147, 161, 156, 0.35); }
.prod7d-grid .bar-num { position: absolute; bottom: -16px; left: 0; right: 0; text-align: center; font-size: 0.62rem; color: var(--text-muted); }
.prod7d-grid .total-row { border-top: 2px solid var(--border); border-bottom: none; font-weight: 700; }
.prod7d-grid .trend-badge { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; font-size: 0.82rem; }
.prod7d-grid .trend-badge.up { color: var(--accent); }
.prod7d-grid .trend-badge.down { color: #c0622a; }
/* The 7-day graph and the Period Totals table sit side by side on a wide
   screen; each is a plain flex item so they wrap to stacked automatically
   on a narrow one, no separate responsive rule needed. */
.prod-panels-row { display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: flex-start; margin-top: 1.25rem; }
#prod7dPlantLabel, #prodTotalsPlantLabel { color: var(--text-muted); font-size: 0.85rem; font-weight: 400; }
.prod-panels-row .card { flex: 1 1 480px; min-width: 0; margin-top: 0 !important; }
/* Squeezed into half the page width next to the 7-day graph — same
   content-fit reasoning as .stat-panel-table (Downtime History's By
   Department table): no forced nowrap-and-scroll, columns shrink to fit
   and long values wrap instead. */
#prodTotalsTable { table-layout: auto; width: 100%; }
#prodTotalsTable th, #prodTotalsTable td { text-align: right; white-space: normal; word-break: break-word; padding: 0.4rem 0.5rem; }
#prodTotalsTable th:first-child, #prodTotalsTable td:first-child { text-align: left; }
#prodTotalsTable tbody tr.total-row td { border-top: 2px solid var(--border); border-bottom: none; font-weight: 700; }
.report-table tbody tr:hover { background: rgba(127,127,127,0.08); }
.report-link { color: var(--accent); text-decoration: none; }
.report-link:hover { text-decoration: underline; }
.event-detail-link, .task-detail-link { color: var(--accent); font-weight: 600; text-decoration: none; }
.event-detail-link:hover, .task-detail-link:hover { text-decoration: underline; }
.report-single { font-size: 1rem; color: var(--text); }
/* ---- Tables that must fit the window width with no horizontal scroll ---- */
/* width:100% (not nowrap) lets the browser's normal table-layout algorithm
   shrink columns to fit — long content (Equipment/Component/Comment) wraps
   onto a second line instead of forcing the table wider than the viewport.
   Used by the Dashboard's Open/History tables and the shared (no-login)
   equivalent in shared_view.php. */
.fit-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.fit-table th, .fit-table td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); }
.fit-table th { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }

/* Stat tiles (Open vs Resolved) */
.stat-tiles { display: flex; flex-wrap: wrap; gap: 1rem; }
.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.5rem; display: flex; flex-direction: column; gap: 0.2rem; min-width: 8rem;
}
.stat-num { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-num.stat-warn { color: var(--safety, #a8631a); }
.stat-num.stat-ok { color: var(--accent); }
.stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

.report-untagged { margin-top: 1rem; }
.report-untagged h3 { font-size: 0.95rem; margin: 0 0 0.4rem; }
.report-untagged ul { margin: 0; padding-left: 1.2rem; font-size: 0.85rem; color: var(--text-muted); columns: 2; }

.company-switch-form { display: inline-flex; margin: 0; }
.company-edit-form { display: grid; grid-template-columns: minmax(9rem, 1fr) minmax(8rem, 0.8fr) auto; gap: 0.4rem; align-items: center; min-width: 25rem; }
.company-edit-form input { min-width: 0; padding: 0.42rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); background: var(--surface); }
@media (max-width: 700px) { .company-edit-form { grid-template-columns: 1fr; min-width: 12rem; } }

/* Public fault-reporting: "already reported" cards shown before submitting a
   duplicate. Colors match public_report_status.php's own STATUS_COLOR map,
   so a public reporter sees the same status color scheme whether they're
   about to submit or checking back later via their status link. */
.public-existing-item { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.public-existing-item:last-child { border-bottom: none; }
.public-status-badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.03em; padding: 0.15rem 0.55rem; border-radius: 999px; margin-bottom: 0.35rem;
  color: #fff;
}
.public-status-badge.reported { background: #b8860b; }
.public-status-badge.in-progress { background: #2f6f9e; }
.public-status-badge.active-downtime { background: var(--danger); }
.public-existing-description { font-weight: 600; }
.public-existing-comment, .public-existing-timing, .public-existing-expected, .public-existing-reference { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.15rem; }
.public-existing-update { margin-top: 0.55rem; padding: 0.55rem 0.65rem; border-left: 3px solid #2f6f9e; background: color-mix(in srgb, #2f6f9e 9%, var(--surface)); border-radius: 0 var(--radius) var(--radius) 0; white-space: pre-wrap; }
.public-existing-guidance { margin: 0 0 0.75rem; }

/* Asset document upload dialog */
.asset-document-form { min-width: 0; }
#assetDocumentModal { width: min(46rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto; }
.asset-document-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.85rem 1rem; }
.asset-document-grid > label { display: grid; gap: 0.35rem; min-width: 0; }
.asset-document-grid input, .asset-document-grid select, .asset-document-grid textarea { box-sizing: border-box; width: 100%; min-width: 0; }
.asset-document-grid textarea { resize: vertical; }
.asset-document-wide { grid-column: 1 / -1; }
.asset-document-file input[type="file"] { padding: 0.55rem; }
.asset-document-help, .asset-document-actions, #assetDocumentStatus { margin: 0; }
@media (max-width: 640px) {
  #assetDocumentModal { width: calc(100vw - 1rem); max-height: calc(100vh - 1rem); }
  .asset-document-grid { grid-template-columns: minmax(0, 1fr); }
}
