/* ===== SAR POD Calculator v2 — PSAR Branded Styles ===== */

/* ---- Light mode (default) ---- */

:root {
  --bg: #f0ebe3;
  --surface: #ffffff;
  --text: #183859;
  --muted: #4e5d6c;
  --primary: #f57c00;
  --primary-soft: #fff3e0;
  --primary-hover: #e06800;
  --danger: #c62828;
  --border: #c4bdb2;
  --accent: #6e8f4e;
  --surface-alt: #e8e1d6;
  --input-bg: #ffffff;
  --selected: #183859;
  --selected-soft: #dce6f0;
}

/* ---- Dark mode ---- */

[data-theme="dark"] {
  --bg: #1a1e24;
  --surface: #242a32;
  --text: #e6e8ea;
  --muted: #8a8f94;
  --primary: #f57c00;
  --primary-soft: #3d2e10;
  --primary-hover: #ff9100;
  --danger: #ef5350;
  --border: #3a4450;
  --accent: #6e8f4e;
  --surface-alt: #2e343c;
  --input-bg: #1a1e24;
  --selected: #6fb2cf;
  --selected-soft: #1a2a38;
}

/* ---- Smooth theme transition ---- */

*, *::before, *::after {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* Exclude inputs and explicit animations from theme transition */
input, select, textarea,
.toast, .chip span,
[class*="animate"], [class*="transition"] {
  transition: none;
}

/* Re-apply only theme transitions on inputs (not user-typing related) */
input, select, textarea {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---- App shell ---- */

.app-shell {
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 0 12px calc(12px + env(safe-area-inset-bottom, 0px));
  padding-top: env(safe-area-inset-top, 0px);
}

/* ---- Header ---- */

.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  margin: 10px 0 16px;
}

.logo {
  width: 62px;
  height: 62px;
  background: transparent;
  border: none;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-qr {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  flex-shrink: 0;
  cursor: pointer;
}

/* QR code fullscreen overlay */
#qr-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#qr-overlay img {
  width: min(80vw, 80vh);
  height: auto;
  border-radius: 12px;
  background: var(--surface);
  padding: 16px;
}

.app-header h1 { font-size: 1.45rem; margin: 0; }

.subtle { font-size: 0.9rem; color: var(--muted); margin: 2px 0 0; }

/* ---- Header controls group ---- */

.header-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

/* ---- Theme toggle ---- */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1;
}
.theme-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ---- About overlay ---- */

#about-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.about-panel {
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
}
.about-panel h2 { margin: 0 0 12px; font-size: 1.15rem; }
.about-panel ul { margin: 0; padding-left: 1.3em; }
.about-panel li { margin: 6px 0; font-size: 0.9rem; line-height: 1.4; }
.about-close { margin-top: 16px; width: 100%; }

/* ---- Connectivity bar (above content) ---- */

.connectivity-bar {
  margin-bottom: 10px;
}
.connectivity-pill {
  display: inline-block;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  white-space: nowrap;
}
.connectivity-pill.online {
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--accent);
}
.connectivity-pill.offline {
  color: var(--danger);
  background: var(--surface);
  border: 1px solid var(--danger);
}
.offline-hint {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.35;
}

/* ---- Panel (card) ---- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

/* ---- Typography ---- */

h2 { margin-top: 0; }
h3 { margin: 10px 0 6px; }

/* ---- Labels & inputs ---- */

label {
  display: block;
  font-weight: 600;
  margin: 10px 0;
}

.hint {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}
.hint-list p { margin: 0; }
.hint-list ul { margin: 2px 0; padding-left: 1.3em; }
.hint-list li { margin: 1px 0; }

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  min-height: 44px;
}

textarea { min-height: 90px; resize: vertical; }

/* ---- Disabled / read-only inputs ---- */

.input-disabled,
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--surface-alt);
  color: var(--muted);
}

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #ffffff;
}
.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--surface);
}
.btn-danger:hover {
  background: var(--danger);
  color: #ffffff;
}

/* ---- Layout utilities ---- */

.row { display: flex; }
.between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-sm { gap: 8px; }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

/* ---- Segment list & card ---- */

.segment-list { display: grid; gap: 10px; }

.segment-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.segment-row .segment-card { flex: 1; min-width: 0; }
.segment-action-btn {
  flex-shrink: 0;
  width: 36px;
  padding: 0;
  font-size: 1.1rem;
  border-radius: 10px;
}
.segment-duplicate {
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface);
}
.segment-duplicate:hover {
  background: var(--muted);
  color: #ffffff;
}

.segment-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: var(--surface);
  cursor: pointer;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
}
.segment-card:hover { border-color: var(--primary); }

.segment-meta { font-size: 0.88rem; color: var(--muted); }

.pod-badge {
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  padding: 4px 10px;
  font-size: 0.9rem;
  white-space: nowrap;
}

/* Upload status badges */
.upload-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.upload-none   { background: var(--border); color: var(--muted); }
.upload-ok     { background: #e8f5e9; color: #2e7d32; }
.upload-warn   { background: #fff3e0; color: #e65100; }
.upload-fail   { background: #ffebee; color: #c62828; }
[data-theme="dark"] .upload-ok   { background: #1b3a1b; color: #66bb6a; }
[data-theme="dark"] .upload-warn { background: #3e2700; color: #ffb74d; }
[data-theme="dark"] .upload-fail { background: #3b1010; color: #ef9a9a; }
[data-theme="dark"] .upload-none { background: var(--border); color: var(--muted); }

/* ---- Chip radios / checkboxes ---- */

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.chip-row .chip { margin: 0; }
.chip-col { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 10px; }
.chip-col .chip { margin: 0; }
.chip-col-tight { display: flex; flex-direction: column; gap: 10px; margin: 3px 0 8px; }
.chip-col-tight .chip { margin: 0; }
.chip-col-tight .chip span { padding: 4px 12px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip input:checked + span {
  background: var(--selected-soft);
  border-color: var(--selected);
  color: var(--selected);
}
.chip-disabled {
  cursor: default;
  opacity: 0.5;
  pointer-events: none;
}
.chip-coming-soon {
  font-size: 0.75rem;
  font-weight: 400;
  font-style: italic;
}

/* ---- Segment note toggle ---- */

.note-section { margin: 2px 0 4px; }
.btn-note-toggle {
  font-size: 0.82rem;
  padding: 4px 10px;
  min-height: auto;
  border-radius: 8px;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-note-toggle:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}
.note-input { margin-top: 4px; }
.note-input textarea {
  min-height: 60px;
  font-size: 0.88rem;
}

/* ---- Report note sub-line ---- */

.report-note {
  margin-left: 1.5em;
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ---- Search-level survey ---- */

.survey-group {
  border-top: 1px solid var(--border);
  margin-top: 14px;
  padding-top: 10px;
}

/* Hide auditory/visual response section for non-missing-person search types */
#search-survey:not([data-search-type="missing_person"]) .missing-person-only { display: none; }

/* ---- Sticky POD result ---- */

.sticky-result {
  position: sticky;
  bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-top: 12px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .sticky-result {
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}

.pod-large {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  margin: 0;
}

.pod-average {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 4px 0 0;
}

.pod-detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 0.88rem;
  margin-top: 8px;
}
.pod-detail-list dt { font-weight: 600; }
.pod-detail-list dd { margin: 0; }

/* ---- Report ---- */

.report-panel article h2 {
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.report-segment {
  border-bottom: 1px dashed var(--border);
  margin-bottom: 16px;
  padding-bottom: 16px;
}
.report-segment:last-child { border-bottom: none; }

.report-avg-pod {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 2px 0 0;
}

.report-list { margin-top: 4px; }

.report-detail pre {
  white-space: pre-wrap;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text);
}

/* ---- Config error (concise inline) ---- */

.config-error {
  background: var(--surface);
  border: 1px solid var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.88rem;
  color: var(--danger);
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 900;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Computed output ---- */

.computed-output {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  margin-top: 4px;
}

/* ---- Report segment cards ---- */

.report-seg-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
}

.report-seg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* ---- Coefficient impact badges ---- */

.impact-positive {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
}

.impact-negative {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--danger);
}

.impact-neutral {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

/* ---- Spacing helpers (estimated spacing for target POD) ---- */

.spacing-helpers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

/* ---- Reference image button ---- */

.chip-with-ref {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chip-with-ref .chip { flex: 1; min-width: 0; }

.btn-ref-images {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-ref-images:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ---- Reference image viewer overlay ---- */

.ref-image-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
}

.ref-image-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex-shrink: 0;
}

.ref-image-title {
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
}

.ref-image-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  flex-shrink: 0;
}
.ref-image-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.ref-image-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ref-image-figure {
  margin: 0;
}

.ref-image-figure img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
}

.ref-image-figure figcaption {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 6px;
}

/* ---- Utility ---- */

.hidden { display: none; }

.build-stamp {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 8px 0 4px;
  opacity: 0.6;
}

/* ---- Responsive ---- */

@media (max-width: 640px) {
  .action-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .report-seg-actions {
    flex-wrap: nowrap;
    gap: 4px;
  }
  .report-seg-actions .btn-sm {
    padding: 4px 6px;
    font-size: 0.75rem;
    min-height: 32px;
    flex: 1 1 0;
  }
}

@media (max-width: 480px) {
  .app-header { grid-template-columns: auto 1fr; gap: 4px 10px; }
  .app-header h1 { font-size: 1.15rem; }
  .logo { width: 88px; height: 88px; grid-row: 1 / 3; align-self: center; }
  .header-title { align-self: end; }
  .header-controls {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    grid-column: 2;
    justify-content: flex-start;
    align-self: start;
  }
}

@media print {
  .app-header, .btn, .action-grid, .toast, .sticky-result, .theme-toggle { display: none; }
  .panel { border: none; box-shadow: none; }
  .app-shell { width: 100%; padding: 0; }
  /* Auto-expand all calculation details for print */
  .report-detail { display: block; }
  .report-detail > summary { display: none; }
  .report-detail > pre { display: block; }
}
