:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:
    ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Courier New", monospace;
  --navy: #1b3a5c;
  --navy2: #2c5282;
  --red: #a93226;
  --red-bg: #fdecea;
  --red-bg2: #f5c6c2;
  --amber: #a07000;
  --org-bg: #fdf8ec;
  --green: #1e6b3c;
  --alt: #eef3f8;
  --dark: #111111;
  --mid: #444444;
  --lgray: #aaaaaa;
  --brand-red: #6b1212;
  --mob-blue: #1a7fc4;
  --insurer: #4a0970;
  --mob-bg: #eaf2f8;
  --mob-bg2: #d6eaf8;
  --white: #ffffff;
  --input-bg: #f0f6ff;
  --input-bdr: #a8c4e0;
  --ui-bg: #f4f7fa;
  --ui-border: #d0dbe8;
  --inp-font: var(--font-mono);
  --inp-size: 13px;
  --inp-pad: 7px 10px;
  --inp-border: 1.5px solid var(--input-bdr);
  --inp-radius: 4px;
  --inp-bg: var(--input-bg);
  --inp-color: var(--dark);
  --inp-focus-color: var(--navy2);
  --inp-focus-shadow: 0 0 0 3px rgba(44, 82, 130, 0.15);
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}
input,
textarea {
  user-select: text;
}
body {
  font-family: var(--font-sans);
  background: var(--ui-bg);
  color: var(--dark);
}

.sticky-header {
  position: sticky;
  top: 0;
  z-index: 100;
}
.editor {
  background: var(--navy);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.editor h1 {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  color: #a8c4e0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  margin: 0;
  display: flex;
  align-items: center;
}
.editor h1 .title-text {
  color: #a8c4e0;
}
.editor h1 .title-text span,
.editor h1 .title-short span {
  color: white;
}
.editor h1 .title-short {
  display: none;
  color: #a8c4e0;
}

.save-load-bar {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  max-width: calc(794px * 1.5);
  width: 100%;
  margin-bottom: 8px;
}
.action-bar {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.print-btn {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  background: var(--amber);
  color: white;
  border: none;
  border-radius: 5px;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.print-btn {
  gap: 7px;
}
.print-btn:hover {
  background: #a85b14;
}
.print-btn.sec {
  background: var(--navy2);
}
.print-btn.sec:hover {
  background: #1e3a6e;
}

.lang-btns {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.lang-btn {
  font-size: 22px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 6px;
  line-height: 1;
  opacity: 0.5;
  transition:
    opacity 0.15s,
    background 0.15s;
}
.lang-btn:hover {
  opacity: 0.85;
}
.lang-btn.active {
  background: white;
  opacity: 1;
}

.fields-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 8px;
  background: var(--ui-bg);
}
.fields-grid {
  display: flex;
  flex-direction: column;
  background: white;
  border: 1.5px solid var(--ui-border);
  border-radius: 8px;
  overflow: hidden;
  max-width: calc(794px * 1.5);
  width: 100%;
}
.editor-section {
  padding: 12px 24px 14px;
  border-bottom: 1px solid var(--ui-border);
}
.editor-section:last-child {
  border-bottom: none;
}
.editor-section-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--navy);
  margin-bottom: 10px;
  padding-bottom: 5px;
  border-bottom: 1.5px solid var(--alt);
}

.fields-row {
  display: grid;
  gap: 10px 16px;
}
.fields-row.r2 {
  grid-template-columns: 1fr 1fr;
}
.fields-row.r3 {
  grid-template-columns: 1fr 1fr 1fr;
}
.fields-row.r4 {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field-group label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--navy2);
}
.inp {
  font-family: var(--inp-font);
  font-size: var(--inp-size);
  padding: var(--inp-pad);
  border: var(--inp-border);
  border-radius: var(--inp-radius);
  background: var(--inp-bg);
  color: var(--inp-color);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
.inp:focus {
  border-color: var(--inp-focus-color);
  box-shadow: var(--inp-focus-shadow);
}
.inp-wrap .inp:focus {
  box-shadow: none;
}
.inp-wrap {
  display: flex;
  align-items: stretch;
  border-radius: var(--inp-radius);
  transition: box-shadow 0.15s;
}
.inp-wrap:focus-within {
  box-shadow: var(--inp-focus-shadow);
}
.inp-wrap:focus-within .inp,
.inp-wrap:focus-within .inp-badge {
  border-color: var(--inp-focus-color);
}
.inp-wrap--m .inp {
  border-right: none;
  border-radius: var(--inp-radius) 0 0 var(--inp-radius);
}
.inp-badge {
  font-family: var(--inp-font);
  font-size: 12px;
  color: var(--mid);
  background: var(--ui-border);
  border: var(--inp-border);
  border-left: none;
  border-radius: 0 var(--inp-radius) var(--inp-radius) 0;
  padding: 0 8px;
  display: flex;
  align-items: center;
  transition: border-color 0.15s;
}
.inp-wrap--phone .dial-sel {
  flex: none;
  width: 90px;
  border-right: none;
  border-radius: var(--inp-radius) 0 0 var(--inp-radius);
  padding: 6px 5px;
  cursor: pointer;
}
.inp-wrap--phone .inp:not(.dial-sel) {
  flex: 1;
  min-width: 0;
  border-left: none;
  border-radius: 0 var(--inp-radius) var(--inp-radius) 0;
}

.contact-rows {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 8px;
}
.contact-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.add-btn {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  color: var(--navy2);
  background: var(--alt);
  border: 1.5px solid var(--input-bdr);
  border-radius: 4px;
  padding: 5px 12px;
  cursor: pointer;
}
.add-btn:hover:not(:disabled) {
  background: #d6e4f5;
}
.add-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.del-btn {
  font-size: 14px;
  color: var(--lgray);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.del-btn:hover {
  color: var(--red);
}

.preview-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--lgray);
  text-align: center;
  padding: 10px 0 6px;
}

.a4-wrap {
  display: flex;
  justify-content: center;
  padding: 0 16px 32px;
}
.a4-wrap.scaled .emergency-card {
  width: 794px;
  max-width: none;
}
.emergency-card {
  width: 794px;
  max-width: 100%;
  background: white;
  border: 2px solid var(--navy);
  border-radius: 6px;
  padding: 10px;
  font-family: var(--font-sans);
  font-size: 10.5px;
  line-height: 1.3;
  display: flex;
  flex-direction: column;
  height: 1123px;
}

.title-bar {
  background: var(--navy);
  border-radius: 4px;
  padding: 5px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
  min-height: 34px;
}
.title-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
#vessel-name {
  font-size: 13px;
  font-weight: 700;
  color: white;
  line-height: 1.2;
}
.title-bar h2 {
  font-size: 8.5px;
  font-weight: 600;
  color: #a8c4e0;
  letter-spacing: 0.06em;
  line-height: 1.2;
}
.title-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
  flex-shrink: 0;
  max-width: 260px;
}
.title-right small {
  font-size: 8.5px;
  color: #a8c4e0;
  line-height: 1.2;
}

.sec-hdr {
  background: var(--navy);
  border-radius: 3px 3px 0 0;
  padding: 0 7px;
  height: 21px;
  display: flex;
  align-items: center;
  font-size: 9px;
  font-weight: 700;
  color: white;
  letter-spacing: 0.03em;
}
.sec-hdr.green {
  background: var(--insurer);
}
.sec-hdr.red {
  background: var(--red);
}
.sec-hdr.brand {
  background: var(--brand-red);
}
.sec-hdr.mob {
  background: var(--mob-blue);
}
.sec-hdr.navy2 {
  background: var(--navy2);
}

.cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.right-col {
  display: flex;
  flex-direction: column;
}
.right-col .verz-block {
  margin-top: auto;
}

.dtable {
  width: 100%;
  border-collapse: collapse;
}
.dtable tr:nth-child(odd) td {
  background: var(--alt);
}
.dtable tr:nth-child(even) td {
  background: white;
}
.dtable td {
  padding: 0 6px;
  height: 26px;
  font-size: 10.5px;
  vertical-align: middle;
}
.dtable .sub-hdr td {
  background: var(--navy2) !important;
  color: white !important;
  font-weight: 700;
  font-size: 9.5px;
}
.dtable td.lbl {
  width: 42%;
}
.dtable td.val {
  font-weight: 700;
}
.dtable td.c25 {
  width: 25%;
}
.dtable td.c30 {
  width: 30%;
}
.dtable td.c40 {
  width: 40%;
}
.dtable td.c45 {
  width: 45%;
}
.dtable td.right {
  text-align: right;
  font-weight: 700;
  font-size: 10px;
}
.calls-lang-note {
  font-size: 7.5px;
  font-weight: 400;
  font-style: normal;
  opacity: 0.75;
  margin-left: 8px;
  text-transform: uppercase;
}
.oproepen-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid #bbbbbb;
}
.oproep:first-child {
  border-right: 1px solid #bbbbbb;
}
.oproep-hdr {
  padding: 0 8px;
  height: 24px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.oproep-hdr.mayday {
  background: var(--red);
}
.oproep-hdr.panpan {
  background: var(--amber);
}

.oproep-hdr .sein-lbl {
  font-size: 12px;
  font-weight: 700;
  color: white;
}
.oproep-hdr .when-lbl {
  font-size: 9px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
}
.oproep-body {
  padding: 8px 10px;
  font-size: 9.5px;
  line-height: 1.7;
}
.oproep-body.mayday-bg {
  background: var(--red-bg);
}
.oproep-body.panpan-bg {
  background: var(--org-bg);
}
.call-line {
  color: var(--dark);
}
.call-hint {
  font-style: italic;
}
.call-line.bold-red {
  font-weight: 700;
  color: var(--red);
  font-size: 10px;
}
.call-line.bold-orange {
  font-weight: 700;
  color: var(--amber);
  font-size: 10px;
}
.oproep-note {
  font-size: 8.5px;
  font-weight: 600;
  color: var(--dark);
  text-align: center;
  padding: 9px 12px;
  background: var(--alt);
  border-top: 1px solid #bbbbbb;
}

.proto-rows {
  width: 100%;
  border-collapse: collapse;
}
.proto-rows tr:nth-child(odd) td {
  background: var(--red-bg);
}
.proto-rows tr:nth-child(even) td {
  background: var(--red-bg2);
}
.proto-rows.mob tr:nth-child(odd) td {
  background: var(--mob-bg);
}
.proto-rows.mob tr:nth-child(even) td {
  background: var(--mob-bg2);
}
.proto-rows td {
  height: 26px;
  padding: 0 6px;
  font-size: 9.5px;
  vertical-align: middle;
}
.nr-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--brand-red);
  color: white;
  font-size: 8.5px;
  font-weight: 700;
  border-radius: 2px;
  margin-right: 6px;
  flex-shrink: 0;
}
.nr-badge.mob {
  background: var(--mob-blue);
}
.step-cell {
  display: flex;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
  font-size: 7px;
  font-weight: 700;
  color: white;
  padding: 1px 5px;
  min-width: 34px;
  margin-right: 5px;
}

.gelu-hdr {
  background: var(--navy2);
  border-radius: 3px 3px 0 0;
  padding: 0 7px;
  height: 21px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  font-weight: 700;
  color: white;
}
.gelu-hdr .leg-item {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.gelu-hdr .sep {
  color: rgba(255, 255, 255, 0.35);
}
.sym-diamond {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: white;
  transform: rotate(45deg);
  flex-shrink: 0;
}
.sym-circle {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: white;
  flex-shrink: 0;
}
.sym-bar {
  display: inline-block;
  width: 15px;
  height: 5px;
  background: white;
  flex-shrink: 0;
}
.gelu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 8px;
}
.gelu-row {
  display: flex;
  align-items: center;
  height: 19px;
  padding: 0 6px;
  font-size: 9px;
  gap: 4px;
}
.gelu-row.alt {
  background: var(--alt);
}
.gelu-row.wht {
  background: white;
}
.gelu-pat {
  display: flex;
  align-items: center;
  gap: 3px;
  width: 104px;
  flex-shrink: 0;
}
.g-L {
  display: inline-block;
  width: 14px;
  height: 5px;
  background: var(--navy);
  flex-shrink: 0;
}
.g-S {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--navy);
  flex-shrink: 0;
}
.g-XS {
  display: inline-block;
  width: 5px;
  height: 5px;
  background: var(--navy);
  transform: rotate(45deg);
  flex-shrink: 0;
}
.gelu-desc {
  color: var(--dark);
  white-space: nowrap;
}
.card-footer {
  font-size: 7px;
  font-style: italic;
  color: var(--mid);
  text-align: center;
  margin-top: 7px;
}

.crew-inp {
  flex: 1;
  min-width: 0;
}

@media (max-width: 480px) {
  .save-load-bar,
  .action-bar {
    flex-direction: column;
  }
  .save-load-bar .print-btn,
  .save-load-bar label.print-btn,
  .action-bar .print-btn {
    flex: none;
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 650px) {
  .save-load-bar .print-btn,
  .save-load-bar label.print-btn,
  .action-bar .print-btn {
    flex: 1;
    justify-content: center;
  }
  .editor {
    padding: 10px 14px;
    gap: 8px;
  }
  .editor h1 {
    font-size: 18px;
  }
  .fields-wrap {
    padding: 12px 10px 6px;
  }
  .editor-section {
    padding: 10px 14px 12px;
  }
  .fields-row.r3,
  .fields-row.r4 {
    grid-template-columns: 1fr 1fr;
  }
  .fields-row.r3 > :last-child {
    grid-column: 1 / -1;
  }
  .inp {
    font-size: 16px;
  }
  .contact-row {
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .contact-row .crew-inp:first-child {
    min-width: 100%;
  }
  .contact-row .inp-wrap--phone {
    flex: 1;
    min-width: 0;
  }
  .contact-row .dial-sel {
    width: 82px;
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .editor h1 .title-text {
    display: none;
  }
  .editor h1 .title-short {
    display: inline;
  }
  .lang-btns {
    margin-left: auto;
  }
}

@media (max-width: 520px) {
  .fields-row.r2,
  .fields-row.r3,
  .fields-row.r4 {
    grid-template-columns: 1fr;
  }
  .fields-row.r3 > :last-child {
    grid-column: auto;
  }
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  html,
  body {
    width: 210mm;
    margin: 0;
    padding: 0;
    background: white;
  }
  .editor,
  .sticky-header,
  .fields-wrap,
  .preview-label,
  .info-block,
  .modal-overlay,
  .site-footer,
  #version-warning {
    display: none !important;
  }
  .a4-wrap {
    display: block !important;
    width: 210mm !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }
  .emergency-card {
    width: 210mm !important;
    height: 297mm !important;
    overflow: hidden !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 10px !important;
    box-shadow: none !important;
    transform: none !important;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  body.printing-ios .emergency-card {
    zoom: 0.92 !important;
  }
  @page {
    size: A4 portrait;
    margin: 0;
  }
}

/* ── INFO BUTTON ──────────────────────────────────────────────── */
.info-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  line-height: 1;
  padding: 0;
}
.info-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

/* ── LABEL ROW (label + tip button side by side) ─────────────── */
.label-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* ── TIP BUTTON (? badge) ─────────────────────────────────────── */
.tip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: rgba(44, 82, 130, 0.08);
  border: 1px solid rgba(44, 82, 130, 0.35);
  color: var(--navy2);
  font-family: var(--font-sans);
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
  transition:
    background 0.15s,
    border-color 0.15s;
}
.tip-btn:hover,
.tip-btn.open {
  background: rgba(44, 82, 130, 0.16);
  border-color: rgba(44, 82, 130, 0.55);
}
.save-load-bar .tip-btn,
.action-bar .tip-btn {
  align-self: center;
  margin-right: 4px;
}

/* ── TOOLTIP POPUP ────────────────────────────────────────────── */
#tip-popup {
  display: none;
  position: fixed;
  z-index: 300;
  background: var(--dark);
  color: white;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
  padding: 7px 10px;
  border-radius: 5px;
  width: 210px;
  white-space: normal;
  text-align: left;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
#tip-popup.visible {
  display: block;
}
#tip-popup::before {
  content: "";
  position: absolute;
  left: var(--arrow-x, 50%);
  transform: translateX(-50%);
  border: 5px solid transparent;
}
#tip-popup.above::before {
  top: 100%;
  border-top-color: var(--dark);
}
#tip-popup.below::before {
  bottom: 100%;
  border-bottom-color: var(--dark);
}

/* ── MODAL ────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 15, 35, 0.8);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open {
  display: flex;
}
.modal-panel {
  background: var(--navy);
  border-radius: 10px;
  max-width: 760px;
  width: 100%;
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}
.modal-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--navy);
  border-radius: 10px 10px 0 0;
  position: sticky;
  top: 0;
}
.modal-hdr-title {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #a8c4e0;
  line-height: 1;
}
.modal-hdr-title span {
  color: white;
}
.modal-close-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.45);
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.1s;
}
.modal-close-btn:hover {
  color: white;
}
.modal-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 12px 24px 24px;
  background: var(--navy);
  border-radius: 0 0 10px 10px;
}
.modal-section {
  padding: 20px 24px;
  background: var(--navy2);
  border-radius: 8px;
}
.modal-section--warn {
  border: 2px solid rgba(169, 50, 38, 0.75);
}
.modal-section-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #a8c4e0;
  margin-bottom: 7px;
}
.modal-section--warn .modal-section-title {
  color: #f1948a;
}
.modal-section-body {
  font-family: var(--font-sans);
  font-size: 13px;
  color: white;
  line-height: 1.6;
}
.modal-section--warn .modal-section-body {
  color: rgba(255, 255, 255, 0.85);
}
.hl {
  color: #fbd38d;
}
@media (max-width: 540px) {
  .modal-body {
    grid-template-columns: 1fr;
  }
}

#numeric-warn {
  position: fixed;
  background: var(--navy2);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 9999;
  white-space: nowrap;
}
#numeric-warn.visible {
  opacity: 1;
}
