/* ============================================
   Health Facility Assessment System
   Design: Clinical clarity meets field usability
   Palette: Deep teal + warm white + alert amber
   ============================================ */

:root {
  --teal-900: #0f3d3e;
  --teal-700: #1a5c5d;
  --teal-500: #2a8a8c;
  --teal-200: #b2e0e1;
  --teal-50:  #f0fafb;
  --amber:    #e8960c;
  --amber-bg: #fff8e6;
  --red:      #c0392b;
  --red-bg:   #fdf2f0;
  --green:    #1e8a4a;
  --green-bg: #f0faf4;
  --ink:      #1a1f2e;
  --ink-60:   #6b7280;
  --ink-30:   #d1d5db;
  --white:    #ffffff;
  --surface:  #f8fafb;
  --shadow-sm: 0 1px 3px rgba(15,61,62,0.08);
  --shadow-md: 0 4px 12px rgba(15,61,62,0.12);
  --radius:   8px;
  --radius-sm: 4px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Top Navigation ── */
.topbar {
  background: var(--teal-900);
  color: var(--white);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar-brand .brand-icon {
  width: 32px; height: 32px;
  background: var(--teal-500);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}

.topbar-brand .brand-sub {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--teal-200);
  display: block;
  line-height: 1.1;
}

.topbar-nav {
  display: flex;
  gap: 0.25rem;
}

.topbar-nav a {
  color: var(--teal-200);
  text-decoration: none;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.topbar-nav a:hover { background: rgba(255,255,255,0.1); color: var(--white); }
.topbar-nav a.active { background: var(--teal-500); color: var(--white); }

/* ── Page Layout ── */
.page {
  max-width: 820px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 2px solid var(--teal-200);
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--teal-900);
  line-height: 1.25;
}

.page-header p {
  color: var(--ink-60);
  font-size: 0.875rem;
  margin-top: 0.35rem;
}

/* ── Section Cards ── */
.section-card {
  background: var(--white);
  border: 1px solid var(--ink-30);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.section-header {
  background: var(--teal-50);
  border-bottom: 1px solid var(--teal-200);
  padding: 0.875rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.section-header .section-num {
  width: 24px; height: 24px;
  background: var(--teal-700);
  color: var(--white);
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.section-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--teal-900);
  letter-spacing: 0.01em;
}

.section-body { padding: 1.25rem; }

/* ── Form Fields ── */
.field-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

.field-grid-2 { grid-template-columns: 1fr 1fr; }
.field-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 600px) {
  .field-grid-2, .field-grid-3 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 0.35rem; }

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.field label .req { color: var(--red); margin-left: 2px; }

.field input,
.field select,
.field textarea {
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--ink-30);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  font-family: inherit;
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(42,138,140,0.15);
}

.field textarea { resize: vertical; min-height: 90px; line-height: 1.5; }

.field input.error, .field select.error, .field textarea.error {
  border-color: var(--red);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--ink-60);
  margin-top: -0.2rem;
}

/* ── Radio Groups ── */
.radio-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.radio-group input[type=radio] { display: none; }

.radio-group label {
  padding: 0.45rem 1rem;
  border: 1.5px solid var(--ink-30);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink-60);
  transition: all 0.15s;
  text-transform: none;
  letter-spacing: 0;
  user-select: none;
}

.radio-group input[type=radio]:checked + label {
  background: var(--teal-700);
  border-color: var(--teal-700);
  color: var(--white);
}

/* ── Conditional Panel ── */
.conditional-panel {
  background: var(--amber-bg);
  border: 1px solid #f5c842;
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-top: 0.75rem;
  display: none;
}

.conditional-panel.visible { display: block; }

/* ── Dynamic HR Tables ── */
.hr-section { margin-bottom: 1.5rem; }
.hr-section:last-child { margin-bottom: 0; }

.hr-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--teal-900);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.hr-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--teal-200);
}

.hr-table { width: 100%; border-collapse: collapse; }

.hr-table thead th {
  background: var(--teal-50);
  border: 1px solid var(--teal-200);
  padding: 0.45rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--teal-700);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hr-table tbody td {
  border: 1px solid var(--ink-30);
  padding: 0.35rem 0.4rem;
  vertical-align: middle;
}

.hr-table tbody tr:hover { background: var(--teal-50); }

.hr-table input[type=text],
.hr-table input[type=number] {
  width: 100%;
  border: none;
  background: transparent;
  padding: 0.25rem 0.3rem;
  font-size: 0.875rem;
  color: var(--ink);
  font-family: inherit;
}

.hr-table input[type=number] { text-align: center; max-width: 70px; }

.hr-table input:focus {
  outline: 2px solid var(--teal-500);
  border-radius: 3px;
  background: var(--white);
}

.hr-table .col-name { min-width: 150px; }
.hr-table .col-num  { width: 80px; text-align: center; }
.hr-table .col-del  { width: 40px; text-align: center; }

.gdmo-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--teal-50);
  border: 1px solid var(--teal-200);
  border-radius: var(--radius-sm);
}

.gdmo-row .field label { font-size: 0.72rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
}

.btn-primary {
  background: var(--teal-700);
  color: var(--white);
  border-color: var(--teal-700);
}
.btn-primary:hover { background: var(--teal-900); border-color: var(--teal-900); }

.btn-ghost {
  background: transparent;
  color: var(--teal-700);
  border-color: var(--teal-200);
}
.btn-ghost:hover { background: var(--teal-50); border-color: var(--teal-500); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: transparent;
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
}
.btn-danger:hover { background: var(--red-bg); }

.btn-add {
  font-size: 0.8rem;
  padding: 0.35rem 0.8rem;
  margin-top: 0.5rem;
}

.btn-submit {
  width: 100%;
  padding: 0.875rem;
  font-size: 1rem;
  justify-content: center;
  border-radius: var(--radius);
  margin-top: 1.5rem;
  letter-spacing: 0.02em;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Submit Zone ── */
.submit-zone {
  background: var(--white);
  border: 1px solid var(--ink-30);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.submit-zone p {
  font-size: 0.8rem;
  color: var(--ink-60);
  margin-top: 0.75rem;
}

/* ── Toast / Success ── */
.toast {
  position: fixed;
  top: 70px;
  right: 1rem;
  max-width: 380px;
  background: var(--white);
  border: 1px solid var(--ink-30);
  border-left: 4px solid var(--green);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  transform: translateX(110%);
  transition: transform 0.3s ease;
}

.toast.visible { transform: translateX(0); }
.toast.error { border-left-color: var(--red); }

.toast-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
}

.toast-code {
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--teal-700);
  background: var(--teal-50);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  margin: 0.4rem 0;
  display: inline-block;
  letter-spacing: 0.05em;
}

.toast-sub { font-size: 0.8rem; color: var(--ink-60); margin-top: 0.25rem; }

/* ── Admin Page ── */
.admin-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1.5rem;
  background: var(--white);
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--ink-30);
  box-shadow: var(--shadow-sm);
}

.admin-controls .field { flex: 1; min-width: 160px; }

.records-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.records-count {
  font-size: 0.8rem;
  color: var(--ink-60);
  background: var(--teal-50);
  padding: 0.25rem 0.6rem;
  border-radius: 12px;
  font-weight: 600;
}

.records-table-wrap { overflow-x: auto; }

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.records-table th {
  background: var(--teal-900);
  color: var(--white);
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.records-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--ink-30);
  color: var(--ink);
  vertical-align: middle;
}

.records-table tr:hover td { background: var(--teal-50); }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: #7a5100; }

.link-btn {
  color: var(--teal-500);
  font-weight: 600;
  text-decoration: none;
  font-size: 0.8rem;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}
.link-btn:hover { color: var(--teal-900); text-decoration: underline; }

/* ── Detail Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,61,62,0.4);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.modal-head {
  background: var(--teal-900);
  color: var(--white);
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky; top: 0;
}

.modal-head h3 { font-size: 1rem; font-weight: 700; }
.modal-body { padding: 1.5rem; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 1rem; }
.detail-item { display: flex; flex-direction: column; gap: 0.2rem; }
.detail-label { font-size: 0.7rem; font-weight: 700; color: var(--ink-60); text-transform: uppercase; letter-spacing: 0.06em; }
.detail-value { font-size: 0.9rem; color: var(--ink); }

.detail-section { margin-top: 1rem; }
.detail-section h4 { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--teal-700); margin-bottom: 0.5rem; border-bottom: 1px solid var(--teal-200); padding-bottom: 0.35rem; }

/* ── Empty State ── */
.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--ink-60);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty p { font-size: 0.9rem; }

/* ── Loading spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--teal-200);
  border-top-color: var(--teal-700);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Validation banner ── */
.validation-banner {
  background: var(--red-bg);
  border: 1px solid #f5c6c6;
  border-left: 4px solid var(--red);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--red);
  margin-bottom: 1rem;
  display: none;
}
.validation-banner.visible { display: block; }

/* ── Utilities ── */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.items-center { align-items: center; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--ink-60); }

@media print {
  .topbar, .btn, .admin-controls { display: none !important; }
}
