/* SIRUJAK PONO — Public Referral Form Stylesheet (Konsisten dengan Workstation Admin) */
:root {
  --bg: #f0f3ef;
  --bg-subtle: #e5ebe3;
  --card: #ffffff;
  --text: #132018;
  --muted: #596a5e;
  --line: #d8e0d6;
  --line-strong: #c0ccc0;

  --accent: #256633;
  --accent-hover: #1c5027;
  --accent-soft: #e5f2e7;
  --brand-lime: #c6df6a;

  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;

  --shadow-xs: 0 1px 2px rgba(16, 32, 20, 0.04);
  --shadow-sm: 0 1px 3px rgba(16, 32, 20, 0.06);
  --shadow-md: 0 6px 18px rgba(16, 32, 20, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 32, 20, 0.14);

  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b100c;
    --bg-subtle: #131c15;
    --card: #162018;
    --text: #edf2ee;
    --muted: #88998d;
    --line: #223025;
    --line-strong: #2c3e30;
    --accent: #52b761;
    --accent-hover: #67ca76;
    --accent-soft: #142a18;
    --warn: #fbbf24;
    --warn-soft: #30240d;
    --danger: #f87171;
    --danger-soft: #331616;
    --ok: #4ade80;
    --ok-soft: #142b1b;
    --shadow-xs: none;
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.5;
  min-height: 100dvh; -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

h1, h2, h3, h4 { margin: 0; font-weight: 700; color: var(--text); letter-spacing: -0.015em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

/* Top Navigation Bar Konsisten dengan Admin */
.app-nav {
  position: sticky; top: 0; z-index: 30; background: var(--card);
  border-bottom: 1px solid var(--line); box-shadow: var(--shadow-xs);
}
.app-nav-inner {
  max-width: 680px; margin: 0 auto; height: 46px; padding: 0 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.nav-brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: inherit; }
.nav-brand img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.brand-text { display: flex; align-items: baseline; gap: 8px; }
.brand-text h1 { font-size: 1.05rem; line-height: 1; }
.brand-text p { font-size: 12px; color: var(--muted); font-weight: 500; }
@media (max-width: 440px) {
  .brand-text p { display: none; }
}

.nav-tools { display: flex; align-items: center; gap: 8px; }
.live-badge {
  font-size: 12px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-subtle); padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line);
}
.live-badge.off { color: var(--warn); border-color: var(--warn); }
.pulse-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
.live-badge.off .pulse-dot { background: var(--warn); animation: none; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.3; } 100% { opacity: 1; } }

.admin-link-btn {
  font-size: 12px; font-weight: 700; color: var(--accent); text-decoration: none;
  padding: 4px 9px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg-subtle); transition: all 0.12s;
}
.admin-link-btn:hover { background: var(--card); border-color: var(--accent); }

/* Progress bar kelengkapan */
.progress-wrap { height: 3px; background: var(--line); width: 100%; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width 0.3s ease; }

/* Main Wrapper */
.wrap {
  max-width: 680px; margin: 0 auto; padding: 14px 14px calc(90px + env(safe-area-inset-bottom));
}

/* Banner & Hero */
.banner-card {
  border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--line);
  background: var(--card); box-shadow: var(--shadow-sm); margin-bottom: 12px;
}
.banner-img {
  display: block; width: 100%; aspect-ratio: 794 / 193; object-fit: cover; background: var(--brand-lime);
}
.hero-content {
  padding: 14px 16px;
}
.hero-content h2 { font-size: 1.25rem; margin-bottom: 4px; color: var(--text); }
.hero-content .desc { font-size: 13.5px; color: var(--muted); white-space: pre-line; line-height: 1.45; }

/* Kapasitas Bed Chips */
.info-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.info-chip {
  background: var(--bg-subtle); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 5px 11px; font-size: 13px; color: var(--muted); font-weight: 600; display: inline-flex; align-items: center; gap: 5px;
}
.info-chip b { color: var(--text); font-weight: 800; font-size: 13.5px; }
.info-chip.full {
  background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); color: var(--danger);
}
.info-chip.full b { color: var(--danger); }

/* Card & Field */
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow-xs); border: 1px solid var(--line);
}
.stack > * + * { margin-top: 10px; }

/* Section Header (Kategori Pertanyaan Klinis Konsisten) */
.section-title {
  margin-top: 16px; margin-bottom: 4px; padding: 7px 12px;
  background: var(--bg-subtle); border-left: 3.5px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-top: 1px solid var(--line);
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.section-title h2 {
  font-size: 0.92rem; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: 0.04em;
}
.section-title .help { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Input Field Card */
.field {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow-xs); transition: border-color 0.15s, box-shadow 0.15s;
}
.field.invalid { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.field label.lbl { display: block; font-weight: 700; font-size: 14px; color: var(--text); margin-bottom: 5px; }
.field .req { color: var(--danger); font-weight: bold; margin-left: 3px; }
.field .help { color: var(--muted); font-size: 12.5px; margin-bottom: 8px; line-height: 1.35; }
.field .err { color: var(--danger); font-size: 12.5px; font-weight: 600; margin-top: 6px; display: none; }
.field.invalid .err { display: block; }

/* Form Controls */
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=date], input[type=time],
input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 14.5px; color: var(--text); background: var(--bg-subtle);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 11px; min-height: 42px;
  outline: none; transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
  appearance: none; -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); background: var(--card); box-shadow: 0 0 0 2px var(--accent-soft);
}
textarea { min-height: 85px; resize: vertical; line-height: 1.4; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px;
}

/* Grup Tanggal Lahir & Usia Otomatis */
.dob-age-group {
  margin-top: 4px;
}
.dob-age-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.dob-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dob-sublbl {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.dob-sublbl b {
  color: var(--accent);
  font-weight: 700;
}
.dob-age.auto-filled {
  animation: dobFlash 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes dobFlash {
  0% { background: var(--accent-soft); border-color: var(--accent); }
  50% { background: var(--accent-soft); border-color: var(--accent); }
  100% { background: var(--bg-subtle); border-color: var(--line); }
}
@media (max-width: 500px) {
  .dob-age-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

/* Choices (Radio & Checkbox) */
.choices { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; min-height: 40px; border-radius: var(--radius-sm);
  background: var(--bg-subtle); border: 1px solid var(--line); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all 0.12s ease;
}
.choice span::before {
  content: ""; flex: none; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted);
  background: var(--card); transition: all 0.12s;
}
.choice input[type=checkbox] + span::before { border-radius: 4px; }
.choice input:checked + span {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.choice input:checked + span::before {
  border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--card);
}
/* Opsi "Yang lain:" dengan input teks mandiri */
.choice-other-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: all 0.12s ease;
  min-height: 42px;
}
.choice-other-wrap:focus-within,
.choice-other-wrap.checked {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.choice-other-trigger {
  flex: none;
  margin: 0;
}
.choice-other-trigger span {
  background: transparent !important;
  border: none !important;
  padding: 6px 8px;
  min-height: 32px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.choice-other-wrap.checked .choice-other-trigger span {
  color: var(--accent);
  font-weight: 700;
}
.choice-other-input-wrap {
  flex: 1;
  min-width: 140px;
}
.other-text-input {
  width: 100% !important;
  min-height: 34px !important;
  height: 34px !important;
  padding: 5px 10px !important;
  font-size: 13.5px !important;
  background: var(--card) !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text) !important;
  outline: none !important;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.other-text-input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent-soft) !important;
  background: #ffffff !important;
}
@media (max-width: 520px) {
  .choice-other-wrap {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 6px 8px 8px;
  }
  .choice-other-trigger span {
    padding: 4px 2px;
    min-height: 28px;
  }
  .other-text-input {
    min-height: 38px !important;
    height: 38px !important;
    font-size: 14px !important;
  }
}
.choice.other span { flex-wrap: nowrap; gap: 8px; }
.choice .other-text {
  flex: 1; min-width: 0; min-height: 32px; padding: 4px 8px; background: var(--card);
  border-radius: var(--radius-sm); font-size: 13.5px; border: 1px solid var(--line);
}

/* Scale (1-5) */
.scale { display: flex; gap: 6px; margin-top: 6px; }
.scale .choice { flex: 1; }
.scale .choice span { justify-content: center; padding: 8px 0; font-weight: 700; min-height: 38px; }
.scale .choice span::before { display: none; }
.scale-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }

/* File Uploader (USG, Partograf, Lab) */
.files { display: grid; gap: 6px; margin: 6px 0 8px; }
.files:empty { margin: 0; }
.file-chip {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--bg-subtle); border: 1px solid var(--line);
}
.file-thumb {
  flex: none; width: 40px; height: 40px; border-radius: 4px; overflow: hidden; background: var(--line);
  display: grid; place-items: center; text-decoration: none;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-ico { font-size: 11px; font-weight: 800; color: var(--danger); }
.file-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.file-btn { width: 100%; min-height: 38px; cursor: pointer; border-radius: var(--radius-sm); font-size: 13.5px; }
.file-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.readonly-files .file-btn, .readonly-files .file-note { display: none; }

/* Buttons */
.btn {
  font: inherit; font-size: 14px; font-weight: 600; border: 0; border-radius: var(--radius-sm);
  padding: 8px 16px; min-height: 38px; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; text-decoration: none; transition: all 0.12s ease;
  background: var(--accent); color: #fff; line-height: 1; white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg-subtle); border-color: var(--line-strong); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.icon { width: 32px; min-height: 32px; padding: 0; border-radius: var(--radius-sm); }
.btn.wa { background: #25d366; color: #fff; }
.btn.wa:hover { background: #20bd5a; }

/* Bottom Action Bar */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); box-shadow: 0 -2px 10px rgba(0,0,0,0.04);
}
.bottombar-inner { max-width: 680px; margin: 0 auto; display: flex; gap: 8px; align-items: center; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(75px + env(safe-area-inset-bottom)); transform: translate(-50%, 15px);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: var(--radius-sm); font-size: 13.5px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: all 0.2s ease; z-index: 60;
  max-width: calc(100% - 28px); box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Success Done View */
.done { text-align: center; padding: 32px 10px 20px; }
.done .check {
  width: 64px; height: 64px; border-radius: 50%; background: var(--ok-soft); color: var(--ok);
  display: grid; place-items: center; margin: 0 auto 14px; box-shadow: var(--shadow-sm);
}

.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

/* Memory & Autocomplete Faskes Perujuk */
.perujuk-memory-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.perujuk-memory-chip b {
  color: var(--accent);
}
.perujuk-memory-chip button {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 2px;
  text-decoration: underline;
}

/* Kartu Deteksi Pasien Rujukan Berulang */
.patient-repeat-box {
  margin-top: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--accent) 7%, var(--card));
  border: 1.5px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: var(--radius-sm);
  animation: fadeIn 0.2s ease;
}
.patient-repeat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.patient-repeat-header span {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-close-repeat {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  padding: 0 4px;
}
.patient-repeat-desc {
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text);
  margin-bottom: 8px;
}
.btn-apply-repeat {
  width: 100%;
  font-size: 12.5px !important;
  font-weight: 700 !important;
  padding: 7px 10px !important;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #ffffff !important;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s ease;
}
.btn-apply-repeat:hover {
  opacity: 0.9;
}

