/* IQ Execution System v6 — Myrava
 *
 * Brand custom properties come from /brand.css, which is generated from
 * v10_brand.py so this file and the .docx generators cannot drift apart.
 *
 * Touch target policy (Galaxy Tab A9+):
 *   Every interactive element resolves to at least var(--touch) = 44px in both
 *   dimensions. That includes native checkboxes, which are scaled rather than
 *   replaced so they keep their accessibility semantics.
 */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }


html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}

h1, h2, h3, .card-title, .sidenav-logo { font-family: var(--font-heading); }

.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

/* ── Navigation ─────────────────────────────────────────────────────────── */
.sidenav {
  width: 236px; flex-shrink: 0;
  background: var(--primary); color: #fff;
  display: flex; flex-direction: column;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.sidenav-logo {
  padding: 16px; font-weight: 700; font-size: 15px; line-height: 1.3;
  border-bottom: 1px solid rgba(255,255,255,.16);
}
.sidenav-logo span { display: block; font-size: 11px; opacity: .72; font-weight: 500; margin-top: 3px; }
/* Build fingerprint. Turns amber if the page is running from a stale cache. */
.build-stamp {
  display: block; margin-top: 4px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 10px; opacity: .55; letter-spacing: .02em;
}
.build-stamp.stale { color: var(--callout); opacity: 1; font-weight: 700; }
.nav-section {
  padding: 14px 16px 4px; font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; opacity: .55; font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: var(--touch);
  padding: 10px 16px;
  font: inherit; font-size: 14px; text-align: left;
  color: #fff; background: none; border: none;
  border-left: 3px solid transparent; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.10); }
.nav-item.active { background: rgba(255,255,255,.17); border-left-color: #fff; }
.nav-item.locked { opacity: .4; cursor: not-allowed; }
.nav-ico { font-size: 16px; line-height: 1; }
.gate-badge {
  margin-left: auto; font-size: 10px; font-weight: 700;
  background: rgba(255,255,255,.22); padding: 3px 7px; border-radius: 5px;
}
.gate-badge.open { background: var(--success); }
.sidenav-foot { margin-top: auto; padding: 14px 16px; }
.session-chip {
  background: rgba(255,255,255,.12); border-radius: 8px; padding: 8px 10px;
}
.session-label { display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: .08em; opacity: .7; }
.session-id { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 15px; font-weight: 700; letter-spacing: .06em; }

/* ── Main / topbar ──────────────────────────────────────────────────────── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--border);
}
.topbar h2 { font-size: 16px; font-weight: 700; color: var(--primary); }
.topbar .spacer { flex: 1; }
.topbar-info { font-size: 12px; color: var(--muted); }
.sync-state { font-size: 12px; color: var(--muted); min-width: 18px; text-align: center; }
.sync-state.saving { color: var(--callout); }
.sync-state.saved { color: var(--success); }
.sync-state.error { color: var(--danger); }
.icon-btn {
  display: none;
  min-width: var(--touch); min-height: var(--touch);
  border: none; background: none; font-size: 22px; color: var(--primary); cursor: pointer;
}

.panel { display: none; padding: 18px 16px 96px; max-width: 980px; width: 100%; }
.panel.active { display: block; }

/* ── Cards & fields ─────────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.card-inset { background: var(--bg); border-color: var(--border); margin: 12px 0; }
.card-slim { padding: 12px 14px; }
.card-title {
  font-size: 15px; font-weight: 700; color: var(--primary);
  margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.card-title.small { font-size: 13px; }
.card-note { font-size: 12px; font-weight: 400; color: var(--muted); }
.sub-title {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em; margin: 12px 0 6px;
}
.hint { font-size: 13px; color: var(--muted); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea,
.hazard-table input, .hazard-table textarea, #cal-tbody input {
  width: 100%; font: inherit; font-size: 15px; color: var(--ink);
  min-height: var(--touch);
  border: 1.5px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: var(--card);
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 3px solid var(--accent-soft); outline-offset: 1px; border-color: var(--accent);
}
.field input:read-only { background: var(--bg); color: var(--muted); }
.field-narrow { max-width: 320px; }
.field-btn { display: flex; align-items: flex-end; }
.req-label::after { content: " *"; color: var(--danger); }

.row-2, .row-3, .row-4 { display: grid; gap: 12px; }
.row-2 { grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: repeat(3, 1fr); }
.row-4 { grid-template-columns: repeat(4, 1fr); }
.span-all { grid-column: 1 / -1; justify-self: start; }

.rep-row { display: flex; align-items: center; gap: 6px; }
.rep-prefix { font-size: 15px; color: var(--muted); }
.rep-pro { width: 64px; text-align: center; }
.rep-suffix { width: 64px; text-align: center; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  min-height: var(--touch); min-width: var(--touch);
  padding: 10px 18px; border: none; border-radius: 8px;
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-outline { background: var(--card); border: 1.5px solid var(--border); color: var(--primary); }
.btn-lg { font-size: 16px; padding: 14px 24px; min-height: 52px; }
/* Compact buttons stay visually smaller but keep a 44px hit area. */
.btn-compact { font-size: 13px; padding: 6px 14px; min-height: var(--touch); }

.action-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.locked-badge { font-size: 13px; font-weight: 600; color: var(--success); }

/* ── Alerts ─────────────────────────────────────────────────────────────── */
.alert { padding: 12px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 12px; }
.alert-info    { background: var(--primary-tint); border: 1px solid var(--accent-soft); color: var(--primary); }
.alert-success { background: var(--success-soft); border: 1px solid var(--success); color: #0a5350; }
.alert-warn    { background: var(--warn-soft);    border: 1px solid var(--callout); color: #7a5310; }
.alert-danger  { background: var(--danger-soft);  border: 1px solid var(--danger);  color: var(--danger); }

.gate-locked-msg { text-align: center; padding: 48px 20px; color: var(--muted); }
.gate-icon { font-size: 46px; margin-bottom: 10px; }

/* ── Checkboxes & Yes/No controls ───────────────────────────────────────── */
input[type="checkbox"] {
  width: 26px; height: 26px; accent-color: var(--accent);
  flex-shrink: 0; cursor: pointer;
}
.toggle-row {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--touch); padding: 6px 0; cursor: pointer; font-size: 15px;
}
.toggle-row em { font-style: normal; color: var(--muted); font-size: 13px; }

.yn-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.yn-btn {
  min-height: var(--touch); padding: 8px 18px;
  border: 1.5px solid var(--border); border-radius: 8px; background: var(--card);
  font: inherit; font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.yn-btn.y.sel  { background: var(--success-soft); border-color: var(--success); color: #0a5350; }
.yn-btn.n.sel  { background: var(--danger-soft);  border-color: var(--danger);  color: var(--danger); }
.yn-btn.na.sel { background: var(--na-fill);      border-color: var(--secondary); color: var(--primary); }
.yn-vb { font-size: 12px; color: var(--muted); margin-top: 4px; }

.check-row {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--touch); padding: 6px 2px;
  border-bottom: 1px solid var(--border); font-size: 15px; cursor: pointer;
}
.check-row.form-tc { background: var(--bg); color: var(--muted); cursor: default; }
.check-row .doc-tag { margin-left: auto; font-size: 12px; color: var(--muted); }
.form-lock-badge {
  font-size: 11px; background: var(--na-fill); color: var(--primary);
  padding: 3px 8px; border-radius: 5px; margin-left: auto;
}
.validated-tag {
  font-size: 11px; font-weight: 700; color: var(--success);
  background: var(--success-soft); border-radius: 5px; padding: 2px 7px;
}

/* ── Item rows ──────────────────────────────────────────────────────────── */
.item-row { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.item-num { min-width: 26px; font-size: 14px; color: var(--muted); padding-top: 2px; }
.item-body { flex: 1; min-width: 0; }
.item-label { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.item-hint { font-size: 13px; color: var(--muted); }
.inline-field { margin-top: 10px; max-width: 260px; }
.inline-field label { font-size: 12px; }

.deviation-box {
  margin-top: 10px; padding: 12px;
  background: var(--danger-soft); border: 1px solid var(--danger); border-radius: 8px;
}
.deviation-box label { display: block; font-size: 13px; font-weight: 700; color: var(--danger); margin-bottom: 6px; }
.deviation-box textarea {
  width: 100%; min-height: 72px; font: inherit; font-size: 15px;
  border: 1px solid var(--danger); border-radius: 6px; padding: 8px;
}
.volt-warn {
  display: none; margin-top: 8px; padding: 8px 12px; border-radius: 6px; font-size: 13px;
  background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger);
}
.volt-warn.show { display: block; }

/* Shown while a justification still contains the unedited template. */
.template-warn {
  margin-top: 8px; font-size: 13px; font-weight: 600;
  color: var(--danger);
}

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--border); padding: 8px 10px; font-size: 14px; text-align: left; vertical-align: top; }
th { background: var(--primary-tint); font-weight: 700; color: var(--primary); }

/* Hazard header colours are fixed by the FM-014-04 template. */
.hazard-table th.h-task   { background: #8EAADB; color: #fff; }
.hazard-table th.h-hazard { background: #FF0000; color: #fff; }
.hazard-table th.h-cause  { background: #FFFF00; color: var(--ink); }
.hazard-table th.h-prev   { background: #00B050; color: #fff; }
.hazard-table textarea { min-height: 64px; font-size: 14px; padding: 8px; }
.hazard-table td { vertical-align: top; }
.row-del {
  min-width: var(--touch); min-height: var(--touch);
  border: none; background: none; color: var(--danger); font-size: 18px; cursor: pointer;
}

/* ── PPE grid ───────────────────────────────────────────────────────────── */
.ppe-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.ppe-item {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-height: 128px; padding: 12px 8px; cursor: pointer;
  border: 1.5px solid var(--border); border-radius: 10px; background: var(--card); text-align: center;
}
.ppe-item.sel { border-color: var(--success); background: var(--success-soft); }
.ppe-icon { font-size: 26px; line-height: 1; }
/* Pictograms carry their own captions, so they are sized for legibility and
 * the separate text label is not rendered. */
.ppe-icon-img { width: 100%; max-width: 92px; height: auto; object-fit: contain; }
.ppe-label { font-size: 12px; font-weight: 600; }

/* ── Test cases ─────────────────────────────────────────────────────────── */
.progress-row { display: flex; align-items: center; gap: 12px; }
.tc-counter { font-size: 13px; color: var(--muted); white-space: nowrap; }
.tc-progress { flex: 1; height: 10px; background: var(--na-fill); border-radius: 5px; overflow: hidden; }
.tc-progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 5px; transition: width .3s; }

.tc-card { background: var(--card); border: 2px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.tc-card.pass { border-color: var(--success); }
.tc-card.fail { border-color: var(--danger); }
.tc-card.skipped { border-color: var(--callout); }
.tc-card.na { border-color: var(--secondary); }
.tc-header { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.tc-num-badge { background: var(--primary); color: #fff; border-radius: 6px; padding: 4px 10px; font-size: 13px; font-weight: 700; }
.tc-title { font-size: 16px; font-weight: 700; color: var(--primary); }
.tc-status { margin-left: auto; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 6px; }
.tc-status.pass { background: var(--success-soft); color: #0a5350; }
.tc-status.fail { background: var(--danger-soft); color: var(--danger); }
.tc-status.skipped { background: var(--warn-soft); color: #7a5310; }
.tc-status.na { background: var(--na-fill); color: var(--primary); }
.tc-criteria { font-size: 14px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.tc-source-note { font-size: 13px; margin-bottom: 12px; }

.photo-zone {
  min-height: 72px; display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--border); border-radius: 8px; padding: 16px;
  text-align: center; font-size: 15px; color: var(--muted); cursor: pointer;
}
.photo-zone:hover { border-color: var(--accent); color: var(--accent); }
.photo-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.photo-thumb { position: relative; width: 96px; height: 96px; }
.photo-thumb img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.photo-thumb .del-btn {
  position: absolute; top: -10px; right: -10px;
  width: var(--touch); height: var(--touch); border-radius: 50%;
  border: 2px solid var(--card); background: var(--danger); color: #fff;
  font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.nozzle-input { width: 100px; }

/* Sticky Back / Skip / Next bar — always reachable with a thumb. */
.tc-nav {
  position: sticky; bottom: 0; z-index: 15;
  display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 10px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.tc-nav .btn { min-height: 52px; }

/* ── Report ─────────────────────────────────────────────────────────────── */
.completion-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 14px 0; }
.stat-box { text-align: center; padding: 16px 8px; border-radius: 10px; background: var(--bg); }
.stat-box .num { font-size: 28px; font-weight: 800; }
.stat-box .lbl { font-size: 12px; color: var(--muted); }
.stat-pass .num { color: var(--success); }
.stat-fail .num { color: var(--danger); }
.stat-skip .num { color: var(--callout); }
.stat-na   .num { color: var(--muted); }
.gen-status { margin-top: 12px; font-size: 14px; }

/* ── Handoff / QR ───────────────────────────────────────────────────────── */
.handoff-card { border: 2px solid var(--accent); }
.handoff-grid { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: start; }
/* The QR must stay inside its outlined box. The server renders the SVG at a
 * fixed module scale, so it carries intrinsic dimensions that overflow the
 * column unless they are overridden here. */
.qr-wrap {
  background: #fff; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border);
  width: 100%; max-width: 220px; overflow: hidden;
}
.qr-wrap img, .qr-wrap svg {
  display: block; width: 100%; height: auto; max-width: 100%;
}
.session-id-large {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 30px; font-weight: 700; letter-spacing: .1em; color: var(--primary);
}
.resume-url { display: block; word-break: break-all; font-size: 13px; color: var(--muted); }
.handoff-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(32,36,43,.6); padding: 16px;
}
.modal {
  background: var(--card); border-radius: 12px; padding: 24px;
  max-width: 620px; width: 100%; max-height: 86vh; overflow-y: auto;
  box-shadow: 0 16px 44px rgba(32,36,43,.28);
}
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.diff-block {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 13px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; margin: 10px 0; white-space: pre-wrap;
}

.cam-modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: #000;
}
.cam-modal video { max-width: 92vw; max-height: 62vh; border-radius: 10px; }
.cam-actions { display: flex; gap: 14px; }

/* ── Rotate overlay ─────────────────────────────────────────────────────── */
#rotate-overlay { display: none; }
.rotate-inner { text-align: center; color: #fff; padding: 24px; max-width: 420px; }
.rotate-icon { font-size: 56px; margin-bottom: 12px; }
.rotate-inner h2 { font-size: 22px; margin-bottom: 8px; }
.rotate-inner p { font-size: 15px; opacity: .82; margin-bottom: 20px; }

/* ── Responsive: tablet portrait is the primary execution target ─────────── */
@media (max-width: 1024px) {
  .icon-btn { display: inline-flex; }
  .shell { flex-direction: column; }
  .sidenav {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    width: 262px; transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidenav.open { transform: translateX(0); box-shadow: 0 0 40px rgba(32,36,43,.4); }
  .row-2, .row-3, .row-4 { grid-template-columns: 1fr; }
  .handoff-grid { grid-template-columns: 1fr; }
  .completion-grid { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: 16px 14px 110px; }
  body { font-size: 16px; }
}

@media (max-width: 1024px) and (orientation: landscape) {
  #rotate-overlay {
    display: flex; position: fixed; inset: 0; z-index: 300;
    align-items: center; justify-content: center; background: var(--primary);
  }
}

@media print {
  .sidenav, .topbar, .action-bar, #resume-card, .handoff-actions { display: none !important; }
  .panel { display: block !important; }
  .card { border: none; }
}

/* ── Hidden components ───────────────────────────────────────────────────────
 * MUST BE THE LAST RULE IN THIS FILE.
 *
 * The HTML `hidden` attribute is applied by the user-agent stylesheet as
 * [hidden] { display: none }, at specificity (0,1,0) — which any single class
 * selector ties or beats. Several components above set `display` on a class and
 * are toggled by `hidden` from app.js: .cam-modal, .modal-overlay, and the
 * .row-2 / .row-3 field groups. Without this rule the camera modal renders over
 * the entire page on first load, and the optional "add new operator / location"
 * field groups are permanently visible.
 *
 * !important covers specificity; last-in-file covers source order. Both are
 * needed — some CSS engines used in testing do not honour !important when
 * resolving computed styles, so relying on importance alone means the bug is
 * invisible to the DOM harness.
 *
 * Toggle visibility with the `hidden` attribute only. Never add a competing
 * display rule for these components.
 * ────────────────────────────────────────────────────────────────────────── */
[hidden] { display: none !important; }
