/* ============================================================
   piping.css - VaneInsight Piping, styled to match VaneInsight
   Reports: steel-blue tokens, white banner header with module name,
   pill tabs, card panels, compact report list and toasts.
   ============================================================ */

:root {
  --color-ink: #16212b;
  --color-steel-900: #1f4e78;
  --color-steel-800: #1a3d5c;
  --color-steel-700: #2e6da4;
  --color-steel-100: #d5e8f0;
  --color-steel-50: #f0f5fa;
  --color-border: #c4d0db;
  --color-surface: #ffffff;
  --color-bg: #e6edf4;
  --color-amber: #c97a1a;
  --color-success: #1f7a4d;
  --color-danger: #b3261e;
  --color-muted: #5b6b76;
  --font-body: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 20px;
  --shadow-card: 0 4px 20px rgba(22, 33, 43, 0.09), 0 1px 4px rgba(22, 33, 43, 0.05);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: var(--font-body);
  color: var(--color-ink);
  background:
    radial-gradient(ellipse 900px 600px at 0% 0%, rgba(31, 78, 120, 0.09) 0%, transparent 100%),
    radial-gradient(ellipse 700px 500px at 100% 100%, rgba(46, 109, 164, 0.07) 0%, transparent 100%),
    var(--color-bg);
  background-attachment: fixed;
  line-height: 1.5;
  font-size: 13px;
}

h1, h2, h3 { margin: 0 0 var(--space-3); font-weight: 700; color: var(--color-steel-900); }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; border-bottom: 2px solid var(--color-steel-100); padding-bottom: var(--space-2); }
h3 { font-size: 1rem; }
a { color: var(--color-steel-700); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--color-amber);
  outline-offset: 2px;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ----------------------------- Header ----------------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  background: #fff;
  padding: var(--space-2) var(--space-5);
  border-bottom: 4px solid #34495e;
  box-shadow: 0 3px 18px rgba(26, 61, 92, 0.18);
}
.app-header__title { display: flex; align-items: center; gap: var(--space-3); min-width: 0; text-decoration: none; }
.app-header__banner { display: block; height: 110px; width: auto; max-width: 100%; }
.module-name {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-left: 3px solid var(--color-amber);
  background: var(--color-steel-50);
  color: #244e70;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.3;
}
.app-nav { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.nav-link {
  color: var(--color-steel-900);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  font: 600 0.9rem var(--font-body);
  text-decoration: none;
  padding: var(--space-2) 0;
  cursor: pointer;
}
.nav-link:hover, .nav-link--active { color: var(--color-steel-700); border-bottom-color: var(--color-amber); }
.nav-user { color: var(--color-muted); font-size: 0.8rem; }

.local-app-banner {
  background: #fff8e6;
  border-bottom: 1px solid #f3d999;
  color: #7a5a10;
  padding: 6px var(--space-5);
  font-size: 0.8rem;
}

.app-main { padding: var(--space-4) var(--space-5) var(--space-6); }

@media (max-width: 720px) {
  .app-header { flex-direction: column; gap: var(--space-2); padding: var(--space-2) var(--space-4); }
  .app-header__banner { height: 80px; }
  .module-name { font-size: 0.95rem; padding: 6px 10px; }
  .app-main { padding: var(--space-3) var(--space-4) var(--space-6); }
}

/* ----------------------------- Buttons ----------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 34px;
  padding: var(--space-2) var(--space-5);
  font: 700 0.82rem var(--font-body);
  letter-spacing: 0.01em;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn:hover:not(:disabled) { box-shadow: 0 2px 8px rgba(22, 33, 43, 0.14); transform: translateY(-1px); }
.btn--primary {
  background: linear-gradient(135deg, var(--color-steel-900) 0%, var(--color-steel-700) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(31, 78, 120, 0.30);
}
.btn--primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--color-steel-800) 0%, var(--color-steel-900) 100%); }
.btn--secondary { background: #fff; color: var(--color-steel-900); border-color: var(--color-border); }
.btn--secondary:hover:not(:disabled) { background: var(--color-steel-50); border-color: #aebdc8; }
.btn--danger { background: #fff; color: var(--color-danger); border-color: #efc8c4; }
.btn--danger:hover:not(:disabled) { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn--icon { width: 36px; padding: 0; }
.btn svg { width: 18px; height: 18px; }

/* ----------------------------- Forms ----------------------------- */

label, .field-label {
  display: block;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  margin-bottom: var(--space-1);
}
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], textarea, select {
  width: 100%;
  padding: 6px 9px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font: 0.85rem var(--font-body);
  background: var(--color-surface);
  color: var(--color-ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-steel-700);
  box-shadow: 0 0 0 3px rgba(46, 109, 164, 0.18);
}
input:disabled, textarea:disabled, select:disabled { background: var(--color-steel-50); color: var(--color-ink); }
textarea { resize: vertical; min-height: 34px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: var(--space-3) var(--space-4); }
.minimum-thickness-grid, .design-field-grid { align-items: end; }
.pressure-design-warning {
  margin: var(--space-2) 0;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--color-danger);
  background: #fff3f2;
  color: var(--color-danger);
  font-weight: 600;
}
.factor-references summary { cursor: pointer; font-weight: 600; }
.factor-references__tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: var(--space-4); margin-top: var(--space-3); }
.factor-references table { min-width: 0; }
.factor-references caption { text-align: left; font-weight: 600; padding-bottom: var(--space-1); }
.remaining-life-table input, .remaining-life-table select { min-width: 100px; }
.remaining-life-table [data-rl-status] { min-width: 180px; }
.general-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.piping-identification-table { overflow-x: auto; }
.piping-identification-table table { width: 100%; min-width: 650px; border-collapse: collapse; }
.piping-identification-table th, .piping-identification-table td { padding: var(--space-1); text-align: left; }
.piping-identification-table .remaining-life-summary-table { min-width: 0; margin-bottom: var(--space-2); }
.remaining-life-summary-table :is(th, td) { vertical-align: top; border: 1px solid var(--color-border); }
.remaining-life-summary-table th { width: 12rem; }
.remaining-life-summary-table td input { max-width: 12rem; }
.remaining-life-summary-table td p:last-child { margin-bottom: 0; }
.inspection-entry-table td { vertical-align: top; }
.inspection-entry-table textarea { min-width: 240px; }
.piping-identification-table [data-inspection-table="findings"] { table-layout: fixed; min-width: 59rem; }
[data-inspection-table="findings"] thead th { white-space: nowrap; }
[data-inspection-table="findings"] thead th:nth-child(1) { width: 2.5rem; }
[data-inspection-table="findings"] thead th:nth-child(2) { width: 10.5rem; }
[data-inspection-table="findings"] thead th:nth-child(4) { width: 11.5rem; }
[data-inspection-table="findings"] thead th:nth-child(5) { width: 7.5rem; }
[data-inspection-table="findings"] thead th:nth-child(6) { width: 7.25rem; }
.piping-identification-table [data-inspection-table="findings"] :is(th, td):nth-child(6) { text-align: center; }
[data-inspection-table="findings"] thead th:nth-child(7) { width: 4.25rem; }
[data-inspection-table="recommendations"] { table-layout: fixed; }
[data-inspection-table="recommendations"] thead th:nth-child(1) { width: 2.5rem; }
[data-inspection-table="recommendations"] thead th:nth-child(3) { width: 7.5rem; }
[data-inspection-table="recommendations"] thead th:nth-child(4) { width: 4.25rem; }
.inspection-entry-table textarea[data-inspection-field="observation"] {
  display: block;
  width: 100%;
  min-height: 0;
  overflow-y: hidden;
  resize: none;
}
.inspection-entry-table input[type="checkbox"] { width: auto; }
.inspection-entry-table select { min-width: 110px; }
.inspection-entry-table .inspection-component { width: 10.5rem; }
.inspection-entry-table .inspection-component select { width: 10rem; }
.inspection-entry-table [data-inspection-field="location"] { width: 11rem; }
.inspection-entry-table [data-inspection-field="severity"] { width: 7rem; }
.inspection-row-actions { display: flex; align-items: center; gap: var(--space-1); white-space: nowrap; }
.finding-row-actions { flex-wrap: wrap; margin-top: var(--space-1); }
.finding-row-actions label { margin: 0; text-transform: none; }
.finding-draft-dialog { width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: auto; padding: var(--space-4); border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-surface); color: var(--color-ink); }
.finding-draft-dialog::backdrop { background: rgba(18, 31, 43, 0.55); }
.finding-draft-dialog h2 { margin-top: 0; }
.finding-draft-dialog fieldset { margin: var(--space-2) 0; border: 1px solid var(--color-border); border-radius: 6px; }
.finding-draft-dialog .photo-actions { flex-wrap: wrap; margin-top: var(--space-2); }
.finding-draft-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: var(--space-2); max-height: 190px; overflow: auto; }
.finding-draft-photos label { display: grid; justify-items: start; gap: var(--space-1); margin: 0; text-transform: none; overflow-wrap: anywhere; }
.finding-draft-photos input { width: auto; }
.finding-draft-photos img { width: 100%; height: 72px; object-fit: cover; border-radius: 4px; }
.report-signoff + .report-signoff, .report-photo-group + .report-photo-group { margin-top: var(--space-4); }
.report-photo-group .photo-actions { margin-top: var(--space-2); }
.report-camera-dialog { width: min(700px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; padding: var(--space-3); border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface); color: var(--color-ink); }
.report-camera-dialog::backdrop { background: rgba(18, 31, 43, 0.55); }
.report-camera-dialog h2 { margin-top: 0; }
.report-camera-dialog video { display: block; width: 100%; max-height: 65vh; border-radius: 6px; background: #17222d; }
.report-camera-dialog .photo-actions { flex-wrap: wrap; }
.sigpad-tabs { display: flex; gap: var(--space-2); overflow-x: auto; margin-bottom: var(--space-3); }
.sigpad { padding: var(--space-3); border: 1px solid var(--color-border); border-radius: 8px; background: #fff; }
.sigpad__canvas { display: block; width: 100%; height: 200px; border: 1px dashed var(--color-border); border-radius: var(--radius-sm); touch-action: none; }
.sigpad__actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-3); }
.sigpad__status { color: var(--color-muted); font-size: 0.85rem; font-weight: 700; }
.add-piping-row { margin-top: var(--space-3); }
.thickness-toolbar { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.piping-identification-table .thickness-table { min-width: 1440px; }
.thickness-table th { white-space: nowrap; }
.thickness-spot-column { width: 1%; }
.thickness-table input[data-thickness-spot] { width: 5.5rem; }
.thickness-comment-column { width: 28%; }
.thickness-table textarea { min-width: 140px; }
.thickness-actions { display: flex; gap: var(--space-1); white-space: nowrap; }
.thickness-photo-section { margin-top: var(--space-4); }
.thickness-actions .action-btn:disabled { cursor: not-allowed; }
.corrosion-visuals {
  display: grid;
  grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
  gap: var(--space-3);
  margin: var(--space-4) 0;
}
.corrosion-visual {
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}
.corrosion-visual h3 { margin: 0 0 var(--space-2); }
.thickness-gauge { --gauge-bar-width: clamp(64px, 24%, 94px); padding: 24px 0; max-width: 400px; }
.thickness-gauge-scale { position: relative; }
.thickness-gauge-bar { display: flex; flex-direction: column; width: var(--gauge-bar-width); height: 100%; border-radius: 6px; overflow: hidden; }
.thickness-zone { display: grid; place-items: center; flex-basis: 0; min-height: 0; overflow: hidden; text-align: center; font-size: 0.73rem; font-weight: 700; }
.thickness-gauge-marker { color: #526778; }
.thickness-gauge-tick, .thickness-gauge-leader, .thickness-gauge-label { position: absolute; }
.thickness-gauge-tick { top: var(--level); left: 0; width: calc(var(--gauge-bar-width) + 8px); border-top: 1px dashed currentColor; }
.thickness-gauge-leader { left: calc(var(--gauge-bar-width) + 7px); top: min(var(--level), var(--label)); width: 9px; height: calc(max(var(--level), var(--label)) - min(var(--level), var(--label))); border-left: 1px solid currentColor; }
.thickness-gauge-label { top: var(--label); left: calc(var(--gauge-bar-width) + 16px); right: 0; transform: translateY(-50%); display: grid; gap: 2px; font-size: 0.75rem; line-height: 1.1; }
.thickness-gauge-label::before { content: ''; position: absolute; width: 9px; border-top: 1px solid currentColor; left: -9px; top: 50%; }
.thickness-gauge-label strong { color: var(--color-ink); font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.thickness-gauge-marker.is-actual, .thickness-gauge-marker.is-actual strong { color: #185a9a; }
.thickness-gauge-marker.is-actual .thickness-gauge-tick { border-top: 2px solid currentColor; }
.thickness-gauge-fallback { display: grid; grid-template-columns: 1fr auto; gap: var(--space-1) var(--space-2); }
.thickness-gauge-fallback dd { margin: 0; font-weight: 700; }
.thickness-zone--normal { background: #d6efde; color: #145b2e; }
.thickness-zone--alert { background: #fff0b7; color: #684700; }
.thickness-zone--critical { background: #c52a35; color: #fff; }
.thickness-zone--structural { background: #a71929; color: #fff; box-shadow: inset 0 1px #ffd6d8; }
.thickness-zone--pressure { background: #761120; color: #fff; box-shadow: inset 0 2px #ffd6d8; }
@media (max-width: 850px) {
  .corrosion-visuals { grid-template-columns: minmax(0, 1fr); }
}
.corrosion-projection-values { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.corrosion-projection-values > div { flex: 1 1 180px; padding: var(--space-2); border: 1px solid var(--color-border); border-radius: 6px; }
.corrosion-projection-values strong { display: block; font-size: 1.25rem; }
.corrosion-projection canvas { display: block; width: 100%; max-width: 1000px; height: auto; }
.corrosion-chart-legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); list-style: none; padding: 0; }
.corrosion-chart-legend li::before { display: inline-block; width: 0.8em; height: 3px; margin-right: 0.4em; vertical-align: middle; content: ''; background: var(--series-color); }
.corrosion-chart-legend [data-series="projection"] { --series-color: #216fc5; }
.corrosion-chart-legend [data-series="alert"] { --series-color: #267841; }
.corrosion-chart-legend [data-series="structural"] { --series-color: #a94e11; }
.corrosion-chart-legend [data-series="required"] { --series-color: #ad2b37; }
.inspection-interval-reference { max-width: 950px; }
.inspection-interval-reference caption { text-align: left; font-weight: 700; padding: var(--space-2) var(--space-1); }
.inspection-interval-reference th, .inspection-interval-reference td { border-bottom: 1px solid var(--color-border); }
.pressure-input { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); }
.general-grid .report-field--owner { grid-column: 1; }
.general-grid .report-field--client_address { grid-column: 1 / -1; }
.inspection-types { border: 1px solid var(--color-border); border-radius: 8px; }
.inspection-types summary { padding: 10px 12px; cursor: pointer; }
.inspection-types__options { display: grid; gap: 6px; padding: 0 12px 10px; }
.inspection-types__options label { margin: 0; text-transform: none; cursor: pointer; }
@media (max-width: 600px) {
  .general-grid { grid-template-columns: minmax(0, 1fr); }
}
.field-group { margin-bottom: var(--space-4); }
.form-error { color: var(--color-danger); font-weight: 600; min-height: 1.2em; }

/* ----------------------------- Cards and panels ----------------------------- */

.card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(196, 208, 219, 0.70);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

/* ----------------------------- Toasts ----------------------------- */

#toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 1000;
  max-width: calc(100vw - 2 * var(--space-4));
}
.toast {
  background: var(--color-steel-900);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(22, 33, 43, 0.2);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  font-size: 0.9rem;
  max-width: 380px;
  cursor: pointer;
}
.toast--visible { opacity: 1; transform: translateY(0); }
.toast--success { background: var(--color-success); }
.toast--error { background: var(--color-danger); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ----------------------------- Report list ----------------------------- */

.dashboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.search-box { flex: 1; min-width: 220px; }
.search-box input {
  padding: 7px var(--space-4);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 1px 4px rgba(22, 33, 43, 0.08);
}
.records-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.96);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(196, 208, 219, 0.6);
}
.records-table thead { background: linear-gradient(135deg, rgba(31, 78, 120, 0.08) 0%, rgba(46, 109, 164, 0.06) 100%); }
.records-table th {
  text-align: left;
  padding: 8px var(--space-3);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-steel-900);
  border-bottom: 1px solid var(--color-border);
}
.records-table td {
  padding: 4px var(--space-3);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.78rem;
  vertical-align: middle;
  height: 34px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.records-table tbody tr { transition: background 0.12s ease; }
.records-table tbody tr:hover { background: var(--color-steel-50); }
.records-table tbody tr:last-child td { border-bottom: none; }
.records-table__report-id { width: 170px; }
.records-table__date { width: 95px; white-space: nowrap; }
.records-table__status { width: 100px; }
.records-table__detail { display: block; color: var(--color-muted); font-size: 0.72rem; }
.records-table__link { color: var(--color-steel-900); font-weight: 700; text-decoration: none; }
.records-table__link:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--color-steel-50);
  color: var(--color-steel-900);
  border: 1px solid var(--color-steel-100);
}
.badge--draft { background: #fff8e6; color: #8a5a00; border-color: #f3d999; }
.badge--in-progress { background: #eaf2fb; color: var(--color-steel-700); border-color: #c4daf0; }
.badge--completed { background: #e7f4ed; color: var(--color-success); border-color: #bfe0cd; }

.record-actions { display: flex; gap: var(--space-1); align-items: center; }
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--color-border);
  background: #fff;
  color: var(--color-ink);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}
.action-btn svg { width: 16px; height: 16px; }
.action-btn:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(22, 33, 43, 0.12); }
.action-btn--view { color: var(--color-steel-700); border-color: var(--color-steel-700); }
.action-btn--view:hover { background: var(--color-steel-700); color: #fff; }
.action-btn--edit { color: var(--color-amber); border-color: var(--color-amber); }
.action-btn--edit:hover { background: var(--color-amber); color: #fff; }
.action-btn--delete { color: var(--color-danger); border-color: var(--color-danger); }
.action-btn--delete:hover { background: var(--color-danger); color: #fff; }
.action-btn:disabled { opacity: 0.5; cursor: wait; transform: none; }

.empty-state {
  text-align: center;
  padding: var(--space-6);
  color: var(--color-muted);
  background: #fff;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
}
.empty-state h3 { color: var(--color-ink); margin-bottom: var(--space-2); }

@media (min-width: 721px) {
  .records-table th:last-child, .records-table .actions-cell { width: 160px; }
}
@media (max-width: 720px) {
  .records-table thead { display: none; }
  .records-table, .records-table tbody, .records-table tr, .records-table td { display: block; width: 100%; }
  .records-table tr { border-bottom: 4px solid var(--color-bg); padding: var(--space-3) 0; }
  .records-table td { border-bottom: none; padding: var(--space-1) var(--space-4); height: auto; }
  .records-table td::before { content: attr(data-label); display: block; font-weight: 700; font-size: 0.72rem; color: var(--color-muted); }
  .action-btn { width: 40px; height: 40px; }
}

/* ----------------------------- Report editor ----------------------------- */

.editor-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-2) var(--space-5);
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 2px 8px rgba(22, 33, 43, 0.06);
}
.editor-bar__title { flex: 1; min-width: 180px; font-weight: 700; color: var(--color-steel-900); font-size: 1rem; overflow-wrap: anywhere; }
.save-status { color: var(--color-muted); font-size: 0.8rem; }
.save-status[data-state="dirty"] { color: var(--color-amber); font-weight: 600; }
.save-status[data-state="error"] { color: var(--color-danger); font-weight: 600; }

.tabnav {
  position: sticky;
  top: 52px;
  z-index: 35;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px var(--space-5);
  background: rgba(230, 237, 244, 0.97);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
  scrollbar-width: thin;
}
.tabnav__btn {
  flex: 0 0 auto;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.80);
  color: var(--color-muted);
  font: 700 0.74rem var(--font-body);
  min-height: 28px;
  padding: 4px 13px;
  cursor: pointer;
  white-space: nowrap;
}
.tabnav__btn:hover { border-color: var(--color-steel-700); color: var(--color-steel-900); background: #fff; }
.tabnav__btn.is-active {
  background: linear-gradient(135deg, var(--color-steel-900) 0%, var(--color-steel-700) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(31, 78, 120, 0.28);
}

.panel { display: none; }
.panel.is-active { display: block; }
.panel__heading { display: flex; align-items: center; gap: var(--space-2); }
.tab-applicability { display: inline-flex; align-items: center; gap: var(--space-2); margin: var(--space-2) 0; text-transform: none; }
.tab-applicability input { width: auto; margin: 0; }
.panel__num {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-steel-900) 0%, var(--color-steel-700) 100%);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
}
.panel-nav { display: flex; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-4); }

.checklist-table { width: 100%; border-collapse: collapse; }
.checklist-table th {
  text-align: left;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-steel-900);
  padding: 6px var(--space-2);
  border-bottom: 2px solid var(--color-steel-100);
}
.checklist-table td { padding: 6px var(--space-2); border-bottom: 1px solid var(--color-border); vertical-align: top; }
.checklist-table tbody tr:hover { background: var(--color-steel-50); }
.checklist-table .col-no { width: 44px; color: var(--color-muted); }
.checklist-table .col-choice { width: 56px; text-align: center; }
.checklist-table .col-comments { width: 34%; }
.checklist-table input[type="radio"], .checklist-table input[type="checkbox"] { width: 18px; height: 18px; margin: 2px 0 0; cursor: pointer; }
.checklist-table textarea { min-height: 30px; }

@media (max-width: 720px) {
  .editor-bar { padding: var(--space-2) var(--space-4); }
  .tabnav { padding: 8px var(--space-4); top: 92px; }
  .checklist-table thead { display: none; }
  .checklist-table, .checklist-table tbody, .checklist-table tr { display: block; }
  .checklist-table tr { padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); }
  .checklist-table td { display: inline-block; border: 0; }
  .checklist-table .col-item { display: block; }
  .checklist-table .col-choice { width: auto; }
  .checklist-table .col-choice::before { content: attr(data-label) " "; font-weight: 700; color: var(--color-muted); }
  .checklist-table .col-comments { display: block; width: 100%; }
}

/* ----------------------------- Sign-in and account ----------------------------- */

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: var(--space-4); }
.auth-card { width: min(420px, 100%); }
.auth-card__brand { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); }
.auth-card__brand img { width: 100%; max-width: 320px; height: auto; }
.auth-card form { display: grid; gap: var(--space-3); }
.hint { color: var(--color-muted); font-size: 0.8rem; margin: 0; }

.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { text-align: left; padding: 6px var(--space-2); border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.users-table th { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-steel-900); }
.users-table select { width: auto; }
.inline-form { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: end; }
.inline-form > div { flex: 1; min-width: 180px; }
.setup-link { display: flex; gap: var(--space-2); margin-top: var(--space-3); }
.setup-link input { font-family: Consolas, monospace; font-size: 0.75rem; }

/* ----------------------------- PSV details and photographs ----------------------------- */

.psv-list { display: grid; gap: var(--space-4); margin-bottom: var(--space-4); }
.psv-card {
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-amber);
  border-radius: var(--radius-md);
  background: #fff;
  padding: var(--space-4);
}
.psv-card__header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.psv-card__title { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.field-wide { grid-column: 1 / -1; }
.psv-photos { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-4); margin-top: var(--space-4); }
.photo-group { background: var(--color-steel-50); border: 1px solid var(--color-steel-100); border-radius: var(--radius-md); padding: var(--space-3); }
.photo-group h4 { margin: 0 0 var(--space-2); color: var(--color-steel-900); font-size: 0.85rem; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-2); margin-bottom: var(--space-2); }
.photo-thumb { margin: 0; background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-sm); overflow: hidden; display: flex; flex-direction: column; }
.photo-thumb img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #f4f6f8; }
.photo-thumb figcaption { padding: 4px 6px; font-size: 0.72rem; font-weight: 600; color: var(--color-steel-900); overflow-wrap: anywhere; }
.photo-thumb__actions { display: flex; gap: 4px; flex-wrap: wrap; padding: 0 6px 6px; }
.photo-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
/* Upload / Camera are <label>s wrapping a file input: keep button styling, not field-label styling. */
.photo-actions label.btn { padding-inline: var(--space-4); margin: 0; text-transform: none; letter-spacing: 0.01em; font-size: 0.82rem; color: var(--color-steel-900); }
.btn--small { min-height: 26px; padding: 2px 8px; font-size: 0.7rem; }

.psv-section__heading { margin: var(--space-5) 0 var(--space-2); padding-top: var(--space-3); border-top: 2px solid var(--color-steel-100); }
/* Fields just filled from a tag photograph, until the page is reloaded. */
.is-ai-filled { border-color: var(--color-success); background: #f1f9f4; }

/* ----------------------------- Account: AI settings ----------------------------- */

.ai-status { margin: 0 0 var(--space-3); font-weight: 600; }
.ai-status[data-state="on"] { color: var(--color-success); }
.ai-status[data-state="off"] { color: var(--color-muted); }
