:root {
  --navy: #17324d;
  --navy-2: #24567c;
  --ink: #1f2b38;
  --muted: #667487;
  --line: #d7dfe7;
  --surface: #ffffff;
  --background: #f3f5f8;
  --blue-soft: #eaf2f8;
  --green: #247047;
  --green-soft: #eaf7ef;
  --red: #a33d37;
  --red-soft: #fbeeed;
  --amber: #8b5b18;
  --amber-soft: #fff4df;
  --shadow: 0 12px 28px rgba(28, 48, 67, .09);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body { min-width: 320px; min-height: 100%; margin: 0; background: var(--background); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 16px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; min-height: 74px; align-items: center; justify-content: space-between; gap: 20px; padding: 10px max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left)); border-bottom: 1px solid rgba(255,255,255,.12); background: var(--navy); color: white; }
.brand { display: flex; min-width: 0; align-items: center; gap: 12px; }
.brand-mark { display: inline-flex; width: 48px; height: 48px; flex: 0 0 auto; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.32); border-radius: 14px; background: rgba(255,255,255,.1); font-size: .95rem; font-weight: 900; letter-spacing: .02em; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 1rem; }
.brand > div > span { margin-top: 2px; color: rgba(255,255,255,.7); font-size: .75rem; }
.status-stack { display: flex; min-width: 0; align-items: flex-end; flex-direction: column; gap: 4px; text-align: right; }
.status-badge { display: inline-flex; max-width: 220px; align-items: center; padding: 5px 9px; border-radius: 999px; background: rgba(255,255,255,.1); font-size: .72rem; font-weight: 750; }
.status-badge.online { background: rgba(94, 210, 141, .19); color: #d8f6e4; }
.status-badge.offline { background: rgba(255, 193, 92, .19); color: #fff0cc; }
.save-status { color: rgba(255,255,255,.65); font-size: .69rem; }

.app-shell { width: min(920px, 100%); margin: 0 auto; padding: 28px 18px 70px; }
.screen { display: none; }
.screen.is-active { display: block; }
.hero { max-width: 720px; padding: 28px 0 12px; }
.hero h1, .screen-heading h1 { margin: 6px 0 10px; color: var(--navy); font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1.08; letter-spacing: -.035em; }
.hero p:not(.eyebrow), .screen-heading > p:not(.eyebrow) { max-width: 710px; margin: 0; color: var(--muted); line-height: 1.55; }
.screen-heading { margin-bottom: 22px; }
.screen-heading .text-button { margin-bottom: 0; }
.summary-nav { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.eyebrow { margin: 0 0 6px; color: var(--navy-2); font-size: .76rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }

.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 24px; }
.action-card { display: flex; min-height: 128px; align-items: center; gap: 16px; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink); text-align: left; box-shadow: 0 4px 16px rgba(20,40,59,.04); transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease; }
.action-card:hover { transform: translateY(-1px); border-color: #9eb0c1; box-shadow: var(--shadow); }
.action-icon { display: inline-flex; width: 62px; height: 62px; flex: 0 0 auto; align-items: center; justify-content: center; border-radius: 17px; background: var(--blue-soft); color: var(--navy); font-size: .86rem; font-weight: 950; letter-spacing: -.02em; }
.action-card strong, .action-card small { display: block; }
.action-card strong { color: var(--navy); font-size: 1.04rem; }
.action-card small { margin-top: 5px; color: var(--muted); line-height: 1.4; }
.info-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 28px; }
.info-grid article { padding: 18px; border-top: 3px solid #aebdca; background: transparent; }
.info-grid h2 { margin: 0 0 6px; color: var(--navy); font-size: .95rem; }
.info-grid p { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.5; }

.resume-panel { margin-top: 20px; padding: 18px; border: 1px solid #c8d8e5; border-radius: 18px; background: var(--blue-soft); }
.resume-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.resume-heading strong { color: var(--navy); }
.resume-heading p { margin: 4px 0 0; color: var(--muted); font-size: .86rem; }
.resume-list { display: grid; gap: 9px; margin-top: 14px; }
.resume-item { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 12px; border: 1px solid rgba(99, 126, 149, .28); border-radius: 13px; background: rgba(255,255,255,.74); }
.resume-item strong, .resume-item small { display: block; }
.resume-item strong { color: var(--navy); font-size: .92rem; }
.resume-item small { margin-top: 3px; color: var(--muted); }
.resume-cancel { display: inline-flex; width: 38px; height: 38px; align-items: center; justify-content: center; border: 1px solid #d9b4b1; border-radius: 10px; background: white; color: var(--red); font-size: 1.2rem; font-weight: 900; line-height: 1; }

.form-card, .question-card, .send-panel, .report-preview { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: 0 8px 24px rgba(22,43,62,.05); }
.form-card { padding: clamp(20px, 4vw, 34px); }
.form-card > label, .form-section > label, .form-grid label { display: block; margin: 17px 0 8px; color: var(--navy); font-weight: 760; }
.form-card > label:first-child { margin-top: 0; }
.form-section { padding: 4px 0 24px; border-bottom: 1px solid var(--line); }
.form-section + .form-section { padding-top: 25px; }
.form-section:last-of-type { border-bottom: 0; }
.form-section h2 { margin: 3px 0; color: var(--navy); font-size: 1.2rem; }
.form-grid { display: grid; gap: 0 14px; }
fieldset { min-width: 0; margin: 18px 0 4px; padding: 0; border: 0; }
legend { margin-bottom: 9px; color: var(--navy); font-weight: 760; }
input[type="text"], input[type="date"], input[type="time"], select, textarea { width: 100%; min-width: 0; border: 1px solid #bac5d2; border-radius: 12px; background: white; color: var(--ink); padding: 13px 14px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(36,79,114,.13); }
textarea { resize: vertical; line-height: 1.45; }
.date-wrapper { display: block; width: 100%; min-width: 0; }
.field-help, .optional, .small-note { color: var(--muted); font-size: .82rem; font-weight: 500; }
.field-help { margin: -5px 0 5px; }
.choice-grid { display: grid; gap: 10px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice-tile, .answer-button { position: relative; display: flex; align-items: center; min-height: 72px; border: 1px solid var(--line); border-radius: 14px; background: #fff; cursor: pointer; }
.choice-tile { padding: 14px; gap: 10px; }
.choice-tile input { accent-color: var(--navy); }
.choice-tile strong, .choice-tile small { display: block; }
.choice-tile small { margin-top: 3px; color: var(--muted); font-weight: 500; }
.choice-tile:has(input:checked) { border-color: var(--navy-2); background: var(--blue-soft); }

.button { display: inline-flex; min-height: 46px; align-items: center; justify-content: center; padding: 11px 18px; border: 1px solid transparent; border-radius: 12px; font-weight: 800; text-decoration: none; }
.button-primary { background: var(--navy); color: white; }
.button-primary:hover { background: #10273d; }
.button-secondary { border-color: #b9c5d1; background: white; color: var(--navy); }
.button-secondary:hover { background: #f7f9fb; }
.button-danger { border-color: #a33d37; background: #a33d37; color: white; }
.button-danger:hover { background: #812f2a; }
.button-full { width: 100%; margin-top: 20px; }
.text-button { padding: 0; border: 0; background: transparent; color: var(--navy-2); font-weight: 800; }
.error-message { margin-top: 15px; padding: 12px 14px; border: 1px solid #e1b8b5; border-radius: 12px; background: var(--red-soft); color: #7f2f2f; font-weight: 650; line-height: 1.4; }
.is-hidden { display: none !important; }

.question-topline { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.counter { color: var(--muted); font-size: .86rem; font-weight: 700; white-space: nowrap; }
.progress-track { height: 9px; margin: 12px 0 18px; overflow: hidden; border-radius: 999px; background: #dfe6ec; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--navy-2); transition: width .2s ease; }
.question-card { padding: clamp(20px, 4vw, 34px); }
.question-card h1 { margin: 14px 0 0; color: var(--navy); font-size: clamp(1.55rem, 5vw, 2.35rem); line-height: 1.22; letter-spacing: -.025em; }
.category-chip { display: inline-flex; padding: 6px 10px; border-radius: 999px; background: var(--blue-soft); color: var(--navy); font-size: .78rem; font-weight: 800; }
.answer-fieldset { margin-top: 28px; }
.answer-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.answer-button { justify-content: center; min-height: 64px; padding: 10px; font-size: 1.05rem; }
.answer-button input { position: absolute; opacity: 0; pointer-events: none; }
.answer-button:has(input:checked) { border-width: 2px; }
.answer-yes:has(input:checked) { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.answer-no:has(input:checked) { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.answer-na:has(input:checked) { border-color: #687386; background: #f0f2f4; color: #4e5966; }
.deviation-panel { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--line); }
.deviation-heading, .photo-heading, .section-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.deviation-heading h2 { margin: 2px 0; color: var(--navy); }
.priority-check { display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid #e2c190; border-radius: 999px; background: var(--amber-soft); color: var(--amber); font-size: .84rem; }
.priority-check input { accent-color: var(--amber); }
.deviation-panel > label { display: block; margin: 16px 0 8px; color: var(--navy); font-weight: 760; }
.character-line { text-align: right; color: var(--muted); font-size: .75rem; }
.photo-section { margin-top: 20px; padding: 16px; border: 1px dashed #b8c5d2; border-radius: 14px; background: #f9fbfc; }
.photo-heading strong, .photo-heading small { display: block; }
.photo-heading small { margin-top: 3px; color: var(--muted); }
.file-button { position: relative; overflow: hidden; white-space: nowrap; }
.file-button input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.photo-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.photo-item { position: relative; overflow: hidden; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; background: #e8edf1; }
.photo-item img { display: block; width: 100%; height: 100%; object-fit: cover; }
.photo-remove { position: absolute; top: 5px; right: 5px; width: 30px; height: 30px; border: 0; border-radius: 50%; background: rgba(15,31,45,.82); color: white; font-weight: 900; }
.navigation-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; }
.navigation-row .button { min-width: 120px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 24px; }
.metric { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.metric span, .metric strong { display: block; }
.metric span { color: var(--muted); font-size: .8rem; }
.metric strong { margin-top: 5px; overflow-wrap: anywhere; color: var(--navy); font-size: 1.35rem; }
.section-block { margin: 28px 0; }
.section-title-row { margin-bottom: 12px; }
.section-title-row h2 { margin: 0; color: var(--navy); }
.deviation-list { display: grid; gap: 12px; }
.deviation-item, .report-section { padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.deviation-item-header { display: flex; justify-content: space-between; gap: 12px; }
.deviation-item h3, .report-section h2 { margin: 4px 0 8px; color: var(--navy); font-size: 1rem; }
.deviation-item p, .report-section p { margin: 6px 0; color: #3f4b59; line-height: 1.5; white-space: pre-wrap; }
.deviation-number { color: var(--muted); font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.urgent-badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: var(--amber-soft); color: var(--amber); font-size: .75rem; font-weight: 800; }
.thumb-strip { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.thumb-strip img { width: 72px; height: 72px; object-fit: cover; border: 1px solid var(--line); border-radius: 8px; }
.empty-state { padding: 24px; border: 1px solid #bad8c7; border-radius: 15px; background: var(--green-soft); color: #345d45; }
.send-panel { display: grid; gap: 16px; padding: 20px; }
.send-panel h2 { margin: 0 0 4px; color: var(--navy); }
.send-panel p { margin: 0; color: var(--muted); line-height: 1.5; }
.send-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.send-status { padding: 13px 14px; border-radius: 12px; background: var(--blue-soft); color: var(--navy); font-weight: 650; }
.send-status.success { background: var(--green-soft); color: var(--green); }
.send-status.warning { background: var(--amber-soft); color: var(--amber); }
.send-status.error { background: var(--red-soft); color: var(--red); }
.report-preview { display: grid; gap: 12px; margin-bottom: 24px; padding: 20px; }
.report-meta { display: grid; grid-template-columns: 150px 1fr; gap: 7px 14px; margin: 0; }
.report-meta dt { color: var(--muted); }
.report-meta dd { margin: 0; font-weight: 700; }

.history-tools { display: grid; grid-template-columns: minmax(0, 250px); gap: 7px; margin-bottom: 16px; }
.history-tools label { color: var(--navy); font-weight: 760; }
.history-list { display: grid; gap: 12px; }
.history-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.history-item h2 { margin: 0; color: var(--navy); font-size: 1rem; }
.history-item p { margin: 5px 0 0; color: var(--muted); font-size: .85rem; }
.history-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.mini-button { min-height: 38px; padding: 8px 11px; border: 1px solid #b9c5d1; border-radius: 10px; background: white; color: var(--navy); font-weight: 750; }
.mini-button.danger { border-color: #dfb6b3; color: var(--red); }
.state-pill, .type-pill { display: inline-flex; margin-left: 6px; padding: 3px 7px; border-radius: 999px; background: var(--blue-soft); color: var(--navy); font-size: .7rem; font-weight: 800; }
.type-pill.stopthink { background: var(--amber-soft); color: var(--amber); }
.type-pill.nearmiss { background: var(--red-soft); color: var(--red); }

.confirm-dialog { width: min(520px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: white; color: var(--ink); box-shadow: 0 24px 60px rgba(14, 32, 48, .28); }
.confirm-dialog::backdrop { background: rgba(12, 26, 39, .58); backdrop-filter: blur(2px); }
.confirm-dialog-content { display: grid; grid-template-columns: auto 1fr; gap: 14px; padding: 24px 24px 12px; }
.confirm-dialog-content h2 { margin: 0; color: var(--navy); font-size: 1.25rem; }
.confirm-dialog-content p { margin: 8px 0 0; color: var(--muted); line-height: 1.5; }
.confirm-icon { display: inline-flex; width: 42px; height: 42px; align-items: center; justify-content: center; border-radius: 50%; background: var(--amber-soft); color: var(--amber); font-weight: 900; }
.confirm-dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 12px 24px 24px; }

.toast { position: fixed; left: 50%; bottom: 22px; z-index: 50; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px; background: #122538; color: white; box-shadow: 0 12px 28px rgba(0,0,0,.22); transform: translate(-50%, 24px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 720px) {
  .topbar { min-height: 64px; padding-top: max(10px, env(safe-area-inset-top)); }
  .brand > div > span { display: none; }
  .brand-mark { width: 42px; height: 42px; }
  .app-shell { padding: 18px 14px 50px; }
  .hero { padding-top: 18px; }
  .action-grid, .info-grid, .metric-grid { grid-template-columns: 1fr 1fr; }
  .info-grid article:last-child { grid-column: 1 / -1; }
  .photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .status-stack .save-status { display: none; }
  .status-badge { font-size: .69rem; }
  .action-grid, .two-columns, .three-columns, .answer-grid, .metric-grid { grid-template-columns: 1fr; }
  .action-card { min-height: 104px; }
  .answer-grid { gap: 8px; }
  .answer-button { min-height: 56px; }
  .question-topline { align-items: flex-start; }
  .question-topline .text-button { max-width: 64%; text-align: left; }
  .deviation-heading, .photo-heading, .section-title-row { flex-direction: column; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .navigation-row .button { min-width: 0; flex: 1; }
  .history-item { grid-template-columns: 1fr; }
  .history-actions { justify-content: flex-start; }
  .resume-item { grid-template-columns: 1fr auto; }
  .resume-item .button { grid-column: 1 / -1; grid-row: 2; width: 100%; }
  .summary-nav { align-items: flex-start; flex-direction: column; gap: 10px; }
  .confirm-dialog-actions .button { width: 100%; }
  .report-meta { grid-template-columns: 1fr; gap: 2px; }
  .report-meta dd { margin-bottom: 8px; }
}

@media print {
  .topbar, .text-button, .send-panel, .button, .history-tools { display: none !important; }
  body { background: white; }
  .app-shell { width: 100%; padding: 0; }
  .screen { display: none !important; }
  #checklistSummaryScreen.is-active, #nearMissSummaryScreen.is-active { display: block !important; }
  .metric, .deviation-item, .report-section { break-inside: avoid; box-shadow: none; }
}
