/* ─────────────────────────────────────────────────────────────────────────
   Design tokens
   ───────────────────────────────────────────────────────────────────────── */
:root {
  --bg: #f8f8f4;
  --surface: #ffffff;
  --surface-alt: #f2f2ed;
  --text: #1a1a1a;
  --border: #d3d2cb;
  --accent: #1f7a64;
  --accent-strong: #0f5240;
  --danger: #a63333;
}

/* ─────────────────────────────────────────────────────────────────────────
   Reset / base
   ───────────────────────────────────────────────────────────────────────── */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #e8e4dc;
  color: var(--text);
  line-height: 1.5;
}

/* ─────────────────────────────────────────────────────────────────────────
   Layout
   ───────────────────────────────────────────────────────────────────────── */
.page-shell {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.app-header {
  display: grid;
  gap: 16px;
  padding: 18px 22px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.app-header h1 {
  margin: 0;
  font-size: 1.9rem;
}

.content {
  display: block;
}

/* ─────────────────────────────────────────────────────────────────────────
   Form card
   ───────────────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
}

/* ─────────────────────────────────────────────────────────────────────────
   Section rows (label + input pairs)
   ───────────────────────────────────────────────────────────────────────── */
.section-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin-bottom: 14px;
}

.section-row label {
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.section-row input,
.section-row select,
.section-row textarea {
  flex: 1 1 160px;
}

/* ─────────────────────────────────────────────────────────────────────────
   Inputs
   ───────────────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 1rem;
}

textarea {
  resize: vertical;
}

/* ─────────────────────────────────────────────────────────────────────────
   Fieldsets
   ───────────────────────────────────────────────────────────────────────── */
.field-group {
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfaf7;
}

.field-group legend {
  padding: 0 10px;
  font-weight: 700;
  color: var(--accent-strong);
}

/* ─────────────────────────────────────────────────────────────────────────
   Checkboxes
   ───────────────────────────────────────────────────────────────────────── */
.checkbox-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ─────────────────────────────────────────────────────────────────────────
   Radio buttons
   ───────────────────────────────────────────────────────────────────────── */
.radio-group {
  display: flex;
  gap: 24px;
  padding: 4px 0;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
}

.radio-item input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* ─────────────────────────────────────────────────────────────────────────
   Rescuers row
   ───────────────────────────────────────────────────────────────────────── */
.rescuers-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  align-items: center;
}

.slash {
  display: none; /* hidden on screen; shown in print */
}

/* ─────────────────────────────────────────────────────────────────────────
   Mobile layout fixes
   ───────────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .page-shell {
    padding: 12px;
  }

  .form-card {
    padding: 16px;
  }

  /* Stack each label + input as a aligned pair (fixes age/address row) */
  .section-row {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 10px;
    align-items: center;
  }

  .section-row label {
    justify-self: end;
    text-align: start;
  }

  .section-row input,
  .section-row select,
  .section-row textarea {
    flex: unset;
    width: 100%;
    min-width: 0;
  }

  /* 2×2 grid instead of 4 cramped columns */
  .rescuers-group {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .rescuers-group input[type="text"] {
    width: 100%;
    min-width: 0;
  }

  .field-group legend {
    margin-inline-start: 4px;
  }
}

/* ─────────────────────────────────────────────────────────────────────────
   Buttons
   ───────────────────────────────────────────────────────────────────────── */
.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 12px 22px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 1rem;
  transition: background 0.15s;
}

button:hover {
  background: var(--accent-strong);
}

button#resetBtn {
  background: #7a7a7a;
}

button#resetBtn:hover {
  background: #5c5c5c;
}

/* ─────────────────────────────────────────────────────────────────────────
   PDF header (hidden on screen, shown when printing)
   ───────────────────────────────────────────────────────────────────────── */
.pdf-header {
  display: none;
}

.pdf-header-top {
  display: flex;
  justify-content: flex-end;
  font-size: 0.85rem;
  color: #333;
  margin-bottom: 8px;
}

.pdf-header-left {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-weight: 600;
}

.pdf-header-title {
  text-align: center;
  margin-top: 8px;
}

.pdf-header-title h2 {
  margin: 0;
  font-size: 1.5rem;
  color: #1f7a64;
  font-weight: 700;
}

/* ─────────────────────────────────────────────────────────────────────────
   Admin panel (utility styles kept for compatibility)
   ───────────────────────────────────────────────────────────────────────── */
.admin-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.admin-header h2 {
  margin: 0;
}

.admin-control {
  margin-top: 14px;
  display: grid;
  gap: 12px;
}

.admin-editor {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f7f6f1;
}

.hidden {
  display: none;
}

.admin-status {
  margin-top: 8px;
  color: var(--accent-strong);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mobile PDF capture styles (.printing-pdf)
   Used by html2pdf on mobile — @media print rules do NOT apply to canvas.
   ═══════════════════════════════════════════════════════════════════════════ */
.printing-pdf {
  background: #fff !important;
  color: #000 !important;
  direction: rtl !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  font-size: 0.85rem !important;
}

.printing-pdf .actions-row {
  display: none !important;
}

.printing-pdf .pdf-header {
  display: block !important;
  margin-bottom: 12px !important;
  padding-bottom: 8px !important;
  border-bottom: 2px solid #1f7a64 !important;
}

.printing-pdf .pdf-header-title h2 {
  font-size: 1.4rem !important;
  color: #1f7a64 !important;
}

.printing-pdf .section-row {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: baseline !important;
  gap: 4px 10px !important;
  margin-bottom: 8px !important;
}

.printing-pdf .section-row label {
  font-weight: 700 !important;
  white-space: nowrap !important;
}

.printing-pdf .section-row input,
.printing-pdf .section-row select,
.printing-pdf .section-row textarea {
  flex: 1 1 80px !important;
  min-width: 60px !important;
  width: auto !important;
  border: none !important;
  border-bottom: 1px solid #666 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: #000 !important;
  box-shadow: none !important;
  padding: 2px 3px !important;
}

.printing-pdf textarea {
  width: 100% !important;
  border: 1px dashed #666 !important;
  min-height: 40px !important;
}

.printing-pdf .field-group {
  border: 1px solid #999 !important;
  border-radius: 5px !important;
  padding: 5px 10px 8px !important;
  margin-bottom: 8px !important;
  background: #fff !important;
}

.printing-pdf .field-group legend {
  font-weight: 700 !important;
  color: #1f7a64 !important;
}

.printing-pdf .checkbox-group {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 4px 12px !important;
}

.printing-pdf .radio-group {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 6px 20px !important;
}

.printing-pdf .rescuers-group {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  gap: 4px 6px !important;
}

.printing-pdf .rescuers-group input[type="text"] {
  flex: 1 1 80px !important;
  min-width: 60px !important;
  max-width: 140px !important;
}

.printing-pdf .slash {
  display: inline !important;
  font-weight: bold !important;
  color: #555 !important;
}

.printing-pdf input,
.printing-pdf select,
.printing-pdf textarea {
  color: #000 !important;
  -webkit-text-fill-color: #000 !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PRINT / PDF STYLES (desktop browser print via window.print)
   On mobile the app generates a PDF file instead — see app.js.
   ═══════════════════════════════════════════════════════════════════════════ */
@media print {
  /* ── Page setup ─────────────────────────────────────────────────────── */
  @page {
    size: A4 portrait;
    margin: 12mm 10mm;
  }

  /* Force light mode — prevents Windows dark-mode blank pages */
  :root,
  html {
    color-scheme: light only !important;
  }

  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif !important;
  }

  /* ── Hide screen-only chrome ────────────────────────────────────────── */
  .page-shell {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .app-header,
  .admin-panel,
  .admin-editor,
  .actions-row {
    display: none !important;
  }

  /* ── Form card fills the printable area ─────────────────────────────── */
  .content {
    display: block !important;
  }

  .form-card {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    direction: rtl !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* ── Show PDF header ─────────────────────────────────────────────────── */
  .pdf-header {
    display: block !important;
    margin-bottom: 12px !important;
    padding-bottom: 8px !important;
    border-bottom: 2px solid #1f7a64 !important;
  }

  .pdf-header-title h2 {
    font-size: 1.4rem !important;
    color: #1f7a64 !important;
  }

  /* ── Section rows ────────────────────────────────────────────────────── */
  .section-row {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: baseline !important;
    gap: 4px 10px !important;
    margin-bottom: 8px !important;
  }

  .section-row label {
    flex: 0 0 auto !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
    font-size: 0.85rem !important;
  }

  .section-row input,
  .section-row select {
    flex: 1 1 80px !important;
    min-width: 60px !important;
  }

  /* ── Fieldsets ───────────────────────────────────────────────────────── */
  .field-group {
    border: 1px solid #999 !important;
    border-radius: 5px !important;
    padding: 5px 10px 8px !important;
    margin-bottom: 8px !important;
    background: #fff !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .field-group legend {
    font-weight: 700 !important;
    font-size: 0.85rem !important;
    color: #1f7a64 !important;
    padding: 0 6px !important;
  }

  /* ── Checkboxes (2-column grid) ──────────────────────────────────────── */
  .checkbox-group {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 4px 12px !important;
  }

  .checkbox-item {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    font-size: 0.83rem !important;
  }

  /* ── Radio buttons ───────────────────────────────────────────────────── */
  .radio-group {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px 20px !important;
  }

  .radio-item {
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    font-size: 0.85rem !important;
  }

  /* ── Rescuers ────────────────────────────────────────────────────────── */
  .rescuers-group {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 4px 6px !important;
  }

  .rescuers-group input[type="text"] {
    flex: 1 1 80px !important;
    min-width: 60px !important;
    max-width: 140px !important;
  }

  .slash {
    display: inline !important;
    font-weight: bold !important;
    color: #555 !important;
  }

  /* ── All inputs / selects / textareas ───────────────────────────────── */
  input,
  select,
  textarea {
    border: none !important;
    border-bottom: 1px solid #666 !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: #000 !important;
    -webkit-text-fill-color: #000 !important;
    box-shadow: none !important;
    outline: none !important;
    padding: 2px 3px !important;
    font-size: 0.85rem !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    width: auto !important;
  }

  /* Textarea gets a box instead of just an underline */
  textarea {
    width: 100% !important;
    border: 1px dashed #666 !important;
    min-height: 40px !important;
  }
}
