:root {
  --bg: #050b12;
  --panel: #0a1522;
  --panel-border: rgba(203, 221, 235, 0.16);
  --ink: #eaf1f6;
  --muted: #93aabd;
  --accent: #e03131;
  --accent-hover: #c92a2a;
  --amber: #d97706;
  --ok: #38d9a9;
  --warn: #ffa94d;
  --sheet-bg: #ffffff;
  --sheet-ink: #0b1726;
  --sheet-muted: #3d4f63;
  --sheet-line: #cbd5e1;
  --mayday-red: #b91c1c;
  --mayday-soft: #fef2f2;
  --panpan-amber: #b45309;
  --panpan-soft: #fffbeb;
}

body.night-mode {
  --bg: #050000;
  --panel: #110202;
  --panel-border: rgba(255, 60, 60, 0.28);
  --ink: #ff4d4d;
  --muted: #b83232;
  --sheet-bg: #0c0101;
  --sheet-ink: #ff4d4d;
  --sheet-muted: #cc3b3b;
  --sheet-line: #4d1010;
  --mayday-red: #ff3333;
  --mayday-soft: #1a0303;
  --panpan-amber: #d9480f;
  --panpan-soft: #140501;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Header */
.app-header {
  border-bottom: 1px solid var(--panel-border);
  background: rgba(10, 21, 34, 0.92);
  padding: 14px 20px;
}

.header-main {
  max-width: 1480px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.kicker {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f87171;
}

.app-header h1 {
  margin: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(20px, 2.2vw, 26px);
  font-weight: 700;
  line-height: 1.2;
}

.lede {
  margin: 4px 0 0;
  font-size: 13.5px;
  color: var(--muted);
  max-width: 72ch;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

select,
input[type="text"] {
  background: rgba(4, 10, 18, 0.85);
  color: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 11px;
  font-family: inherit;
  font-size: 14px;
}

select:focus,
input[type="text"]:focus {
  outline: 2px solid #f87171;
  outline-offset: 1px;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 13px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary[aria-pressed="true"] {
  background: rgba(224, 49, 49, 0.25);
  border-color: #ff4d4d;
  color: #ff8787;
}

/* Main Workspace */
.workspace {
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 410px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

/* Editor Panel */
.editor-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 18px;
  position: sticky;
  top: 16px;
}

.editor-card-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.privacy-badge {
  margin: 4px 0 12px;
  font-size: 12px;
  color: var(--ok);
}

.presets-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--panel-border);
}

.presets-label {
  font-size: 11.5px;
  color: var(--muted);
  margin-inline-end: 4px;
}

.chip {
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
}

.chip:hover {
  background: rgba(255, 255, 255, 0.12);
}

.field-grid {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.field-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.field-hint {
  font-size: 11px;
  color: var(--muted);
  min-height: 14px;
}

.field-hint.valid {
  color: var(--ok);
}

.field-hint.invalid {
  color: var(--warn);
}

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink);
  padding-top: 4px;
  cursor: pointer;
}

.checkbox-field input {
  margin-top: 2px;
}

.editor-footer-actions {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.full-width {
  width: 100%;
}

.secondary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.fairhelm-pill {
  font-size: 12px;
  font-weight: 600;
  color: #93c5fd;
  text-decoration: none;
}

.fairhelm-pill:hover {
  text-decoration: underline;
}

.copy-status {
  margin: 0;
  font-size: 12px;
  color: var(--ok);
}

/* A4 Sheet Stage & Printable Card */
.sheet-stage {
  display: flex;
  justify-content: center;
  overflow-x: auto;
}

.a4-sheet {
  width: 210mm;
  min-height: 296mm;
  background: var(--sheet-bg);
  color: var(--sheet-ink);
  border-radius: 6px;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.55);
  padding: 7mm 8mm;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 3mm;
}

/* Punch Hole Marks for Cockpit Lamination / Ring Binder */
.punch-marks {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 18mm 1mm;
  color: var(--sheet-muted);
  font-size: 8pt;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.punch-hole {
  width: 4.5mm;
  height: 4.5mm;
  border: 1.2px dashed #94a3b8;
  border-radius: 50%;
  display: inline-block;
}

/* Top Protocol Bar */
.sheet-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0f172a;
  color: #ffffff;
  padding: 2mm 3.5mm;
  border-radius: 3px;
  font-size: 8.5pt;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.sheet-top-port {
  font-family: "JetBrains Mono", monospace;
  color: #fde68a;
  font-size: 8.5pt;
}

/* Vessel ID Grid */
.vessel-id-grid {
  display: grid;
  grid-template-columns: 1.15fr 1.25fr 1.05fr 1.35fr;
  gap: 2.2mm;
}

.id-cell {
  border: 1.5px solid #0f172a;
  border-radius: 3px;
  padding: 2mm 2.5mm;
  background: #f8fafc;
}

body.night-mode .id-cell {
  background: #140202;
  border-color: #ff4d4d;
}

.id-label {
  font-size: 6.8pt;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sheet-muted);
  margin-bottom: 0.8mm;
}

.id-value-xl {
  font-size: 13.5pt;
  font-weight: 800;
  line-height: 1.1;
  color: var(--sheet-ink);
  word-break: break-word;
}

.mmsi-highlight {
  color: var(--mayday-red);
  letter-spacing: 0.03em;
}

.id-phonetic {
  margin-top: 0.8mm;
  font-size: 7.2pt;
  line-height: 1.2;
  color: var(--sheet-muted);
}

.id-phonetic-bold {
  margin-top: 0.8mm;
  font-size: 7.8pt;
  font-weight: 700;
  line-height: 1.2;
  color: var(--sheet-ink);
}

.id-spec-line {
  font-size: 8.2pt;
  line-height: 1.25;
}

.id-spec-epirb {
  margin-top: 0.8mm;
  font-size: 7.5pt;
  font-weight: 600;
  color: var(--sheet-muted);
}

/* Distress Boxes */
.distress-box {
  border-radius: 4px;
  overflow: hidden;
}

.mayday-box {
  border: 2.6px solid var(--mayday-red);
  background: #ffffff;
}

body.night-mode .mayday-box {
  background: #0d0101;
}

.box-banner {
  padding: 2mm 3mm;
  display: flex;
  align-items: center;
  gap: 3mm;
  color: #ffffff;
}

.mayday-banner {
  background: var(--mayday-red);
}

.panpan-banner {
  background: var(--panpan-amber);
}

.box-badge {
  font-size: 11pt;
  font-weight: 900;
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding: 0.6mm 2mm;
  background: rgba(0, 0, 0, 0.24);
  border-radius: 2px;
}

.box-when {
  font-size: 7.6pt;
  font-weight: 600;
  line-height: 1.2;
}

/* Action Steps Row */
.action-steps-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.5mm;
  padding: 2.2mm 3mm;
  background: var(--mayday-soft);
  border-bottom: 1.5px solid var(--mayday-red);
}

.step-title {
  font-size: 8.2pt;
  font-weight: 800;
  color: var(--mayday-red);
  margin-bottom: 0.5mm;
}

.step-body {
  font-size: 7.8pt;
  line-height: 1.25;
}

.spoken-script-title {
  padding: 1.4mm 3mm;
  background: #1e293b;
  color: #ffffff;
  font-size: 8pt;
  font-weight: 800;
  letter-spacing: 0.05em;
}

/* Script Table */
.script-table {
  display: flex;
  flex-direction: column;
}

.script-row {
  display: grid;
  grid-template-columns: 46mm 1fr;
  border-bottom: 1px solid var(--sheet-line);
}

.script-row-last {
  border-bottom: none;
}

.script-cue {
  padding: 1.8mm 2.5mm;
  background: #f8fafc;
  border-inline-end: 1px solid var(--sheet-line);
  font-size: 7.5pt;
  font-weight: 700;
  color: var(--sheet-muted);
  display: flex;
  align-items: center;
}

body.night-mode .script-cue {
  background: #140202;
}

.script-spoken {
  padding: 1.8mm 3mm;
  font-size: 9.2pt;
  line-height: 1.28;
}

.say-red {
  font-size: 11pt;
  font-weight: 900;
  color: var(--mayday-red);
  letter-spacing: 0.02em;
}

.say-amber {
  font-weight: 900;
  color: var(--panpan-amber);
}

.say-lead {
  font-weight: 700;
}

.say-vessel {
  font-size: 10.2pt;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.say-sub {
  font-size: 8.6pt;
}

.write-in-coords {
  display: inline-block;
  padding: 0.6mm 2mm;
  border: 1px dashed #64748b;
  background: #f8fafc;
  border-radius: 2px;
  font-size: 8.4pt;
  font-weight: 700;
}

body.night-mode .write-in-coords {
  background: #1a0303;
  border-color: #ff4d4d;
}

.over-hint {
  font-size: 8pt;
  font-weight: 600;
  color: var(--sheet-muted);
  margin-inline-start: 2mm;
}

/* PAN-PAN Box */
.panpan-box {
  border: 2px solid var(--panpan-amber);
  background: var(--panpan-soft);
}

.panpan-body {
  padding: 2mm 3mm;
}

.panpan-step {
  font-size: 7.6pt;
  font-weight: 800;
  color: var(--panpan-amber);
  margin-bottom: 0.8mm;
}

.panpan-script {
  font-size: 8.5pt;
  line-height: 1.3;
}

.panpan-placeholder {
  font-weight: 700;
  text-decoration: underline;
}

/* Bottom Reference Grid */
.bottom-reference-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 2.5mm;
}

.cancel-box,
.nato-box {
  border: 1.2px solid #334155;
  border-radius: 3px;
  padding: 2mm 2.5mm;
  background: #f8fafc;
}

body.night-mode .cancel-box,
body.night-mode .nato-box {
  background: #140202;
  border-color: #ff4d4d;
}

.ref-title {
  font-size: 7.2pt;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #0f172a;
  margin-bottom: 1mm;
}

body.night-mode .ref-title {
  color: #ff6b6b;
}

.cancel-text {
  margin: 0 0 1.2mm;
  font-size: 7.1pt;
  line-height: 1.25;
}

.keywords-strip {
  padding-top: 1mm;
  border-top: 1px solid var(--sheet-line);
  font-size: 6.9pt;
  line-height: 1.25;
}

.nato-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.6mm 1.5mm;
  font-size: 7pt;
  line-height: 1.22;
}

.nato-grid b {
  font-family: "JetBrains Mono", monospace;
  color: var(--mayday-red);
}

/* Sheet Footer with Vector QR */
.sheet-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4mm;
  border-top: 1.5px solid #0f172a;
  padding-top: 2mm;
}

.qr-block {
  display: flex;
  align-items: center;
  gap: 2.8mm;
}

.qr-svg-wrap {
  width: 17mm;
  height: 17mm;
  flex-shrink: 0;
  border: 1px solid #cbd5e1;
  border-radius: 2px;
  overflow: hidden;
  background: #ffffff;
}

.qr-svg-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
}

.qr-title {
  font-size: 8pt;
  font-weight: 800;
}

.qr-body {
  font-size: 7.1pt;
  color: var(--sheet-muted);
}

.sheet-meta-right {
  text-align: end;
  display: flex;
  flex-direction: column;
  gap: 0.8mm;
}

.sheet-meta-right a {
  font-family: "JetBrains Mono", monospace;
  font-size: 8pt;
  font-weight: 800;
  color: #0f172a;
  text-decoration: none;
}

body.night-mode .sheet-meta-right a {
  color: #ff6b6b;
}

.sheet-standard {
  font-size: 6.8pt;
  color: var(--sheet-muted);
}

/* PRINT STYLES (Exact Single-Sheet A4 Lamination Output) */
@page {
  size: A4 portrait;
  margin: 6mm;
}

@media print {
  html, body {
    background: #ffffff !important;
    color: #0b1726 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .screen-only {
    display: none !important;
  }

  .workspace {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
  }

  .sheet-stage {
    display: block !important;
    overflow: visible !important;
  }

  .a4-sheet {
    width: 100% !important;
    min-height: 284mm !important;
    max-height: 285mm !important;
    margin: 0 !important;
    padding: 2mm 3mm !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    page-break-inside: avoid;
    break-inside: avoid;
  }
}
