:root {
  --ink: #17212b;
  --muted: #64717d;
  --line: #d9e0e5;
  --surface: #ffffff;
  --canvas: #f4f6f7;
  --green: #18794e;
  --green-dark: #105c3a;
  --blue: #2463a7;
  --orange: #b65e09;
  --red: #b42318;
  --radius: 6px;
}
* { box-sizing: border-box; }
html { font-family: Inter, "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-width: 320px; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
.topbar { min-height: 58px; background: #162b24; color: white; display: flex; align-items: center; flex-wrap: wrap; gap: 0 12px; padding: 0 24px; position: relative; z-index: 40; }
.brand { color: white; display: flex; align-items: center; gap: 10px; font-weight: 700; flex-shrink: 0; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 4px; background: #f0b429; color: #162b24; font-weight: 800; }
.brand-mark.large { width: 46px; height: 46px; font-size: 18px; }
.top-actions { display: flex; align-items: center; gap: 14px; font-size: 14px; margin-left: auto; flex-shrink: 0; }
.report-menu { flex: 1 1 auto; min-width: 0; }
.report-menu-bar { display: flex; flex-wrap: wrap; list-style: none; margin: 0; padding: 0; }
.report-menu-group { position: relative; margin: 0; }
.report-menu-label {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 0 14px;
  border: 0;
  background: none;
  color: #dbe6e0;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.report-menu-label::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.75;
}
.report-menu-label:hover,
.report-menu-group.open .report-menu-label {
  color: white;
  background: #1e3d32;
  text-decoration: none;
}
.report-menu-group.current .report-menu-label {
  color: white;
  border-bottom-color: #f0b429;
}
.report-menu-group.open .report-menu-label::after {
  transform: rotate(180deg);
}
.report-menu-panel {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 50;
  min-width: 240px;
  max-width: min(360px, calc(100vw - 24px));
  margin: 0;
  padding: 8px 0;
  list-style: none;
  background: white;
  border: 1px solid #c5d4cc;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 12px 28px rgba(22, 43, 36, 0.22);
  max-height: min(70vh, 480px);
  overflow-y: auto;
}
.report-menu-group.open .report-menu-panel:not([hidden]) { display: flex; flex-direction: column; }
.report-menu-panel a {
  display: block;
  padding: 10px 16px;
  color: #3f4d58;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.report-menu-panel a:hover {
  background: #f4f8f6;
  color: var(--green);
  text-decoration: none;
}
.report-menu-panel a.active {
  color: var(--green);
  background: #eef5f2;
}
.language-switch { display: flex; border: 1px solid #6f827a; border-radius: 4px; overflow: hidden; }
.language-switch a { color: #dbe6e0; padding: 5px 8px; }
.language-switch a.active { color: #152a23; background: white; font-weight: 700; }
.link-button { border: 0; background: none; color: white; cursor: pointer; padding: 5px; }
.nav { height: 44px; display: flex; align-items: stretch; gap: 4px; background: white; border-bottom: 1px solid var(--line); padding: 0 24px; }
.nav a { color: #34434f; display: flex; align-items: center; padding: 0 14px; border-bottom: 3px solid transparent; font-size: 14px; font-weight: 600; }
.nav a:hover { text-decoration: none; background: #f7f9fa; }
.nav a.active { color: var(--green); border-bottom-color: var(--green); }
.page { max-width: 1440px; margin: 0 auto; padding: 24px; }
.page-header { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 20px; }
h1, h2, p { margin-top: 0; }
h1 { font-size: 26px; margin-bottom: 5px; }
h2 { font-size: 17px; margin-bottom: 0; }
.page-header p { color: var(--muted); margin-bottom: 0; font-size: 14px; }
.eyebrow { color: var(--muted); text-transform: uppercase; font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius); padding: 8px 14px; border: 1px solid transparent; font-weight: 700; font-size: 14px; cursor: pointer; }
.button:hover { text-decoration: none; }
.button.primary { color: white; background: var(--green); }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { color: var(--ink); border-color: #acb7bf; background: white; }
.button.full { width: 100%; }
.command-row { display: flex; gap: 8px; flex-wrap: wrap; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 22px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid #77838c; border-radius: var(--radius); padding: 15px; min-height: 90px; display: flex; flex-direction: column; justify-content: space-between; }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { font-size: 28px; }
.metric.success { border-left-color: var(--green); }
.metric.warning { border-left-color: var(--orange); }
.metric.info { border-left-color: var(--blue); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(230px, 1fr); gap: 18px; }
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.section-header { min-height: 50px; padding: 13px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.district-summary ul { list-style: none; padding: 0; margin: 0; }
.district-summary li { display: flex; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.report-filters { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); align-items: end; }
.compact-button { padding: 6px 9px; min-height: 0; }
.table-pagination { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.table-pagination > div { display: flex; gap: 6px; }
.pagination-button { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); font-weight: 700; }
.pagination-button.disabled { color: var(--muted); background: #f4f6f7; }
.report-filters .date-filter { min-width: 0; }
.report-metrics { grid-template-columns: repeat(6, minmax(120px, 1fr)); }
.report-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 18px; margin-bottom: 18px; }
.reports-page .section { min-width: 0; }
.report-section { margin-bottom: 18px; }
.method-bars { padding: 8px 16px; }
.method-row { display: grid; grid-template-columns: 110px minmax(100px, 1fr) 42px 52px; gap: 10px; align-items: center; min-height: 40px; border-bottom: 1px solid var(--line); font-size: 13px; }
.method-row small { color: var(--muted); text-align: right; }
.bar-track { height: 8px; background: #e5eaed; border-radius: 4px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--green); }
.compact-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: #53616c; background: #f7f9fa; font-size: 12px; text-transform: uppercase; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: #fafcfc; }
td small { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.filterbar { display: flex; gap: 10px; align-items: end; background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.field[hidden] { display: none !important; }
.field.grow { flex: 1; min-width: 220px; }
.field label { font-size: 12px; color: #46545f; font-weight: 700; }
.control, .login-panel input { min-height: 40px; width: 100%; border: 1px solid #abb6be; border-radius: 4px; background: white; color: var(--ink); padding: 8px 10px; }
textarea.control { min-height: 90px; resize: vertical; }
.control:focus, .login-panel input:focus { border-color: var(--blue); outline: 2px solid #d9e9f8; }
.filter-submit { margin-bottom: 0; }
.registry-table { background: white; border: 1px solid var(--line); border-radius: var(--radius); }
.status { display: inline-flex; padding: 3px 7px; border-radius: 4px; background: #e8edf0; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status.active { background: #dff3e8; color: #12623e; }
.status.out { background: #fde8e6; color: var(--red); }
.status.review { background: #fff0d9; color: #8a4b08; }
.record-form { max-width: 1180px; }
.record-form.compact { max-width: 850px; }
fieldset { background: white; border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 16px; padding: 18px; }
legend { padding: 0 8px; font-weight: 800; color: #293944; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.form-grid .field { grid-column: span 4; min-width: 0; }
.form-grid .field-book_wra_code,
.form-grid .field-age_years,
.form-grid .field-method_satisfied,
.form-grid .field-is_pregnant,
.form-grid .field-pregnancy_planned,
.form-grid .field-living_children { grid-column: span 2; }
.form-grid .field-full_name,
.form-grid .field-home_address { grid-column: span 6; }
.form-grid .field-chw,
.form-grid .field-current_method,
.form-grid .field-current_method_other,
.form-grid .field-non_use_reason,
.form-grid .field-non_use_reason_other,
.form-grid .field-out_project_reason,
.form-grid .field-method_switch { grid-column: span 4; }
.form-grid .field-book_id { grid-column: span 4; }
.form-grid .field-district,
.form-grid .field-health_center,
.form-grid .field-cell,
.form-grid .field-village,
.form-grid .field-national_id,
.form-grid .field-mobile,
.form-grid .field-date_of_birth,
.form-grid .field-baseline_date,
.form-grid .field-last_refill_date,
.form-grid .field-lmp_or_delivery_date,
.form-grid .field-youngest_child_category { grid-column: span 3; }
.field-error { color: var(--red); font-size: 12px; }
/* D-083: the referral follow-up hint under the visit outcome. Muted, wraps
   without ever scrolling sideways at 360 px. */
.field-hint {
  color: #4a5a64;
  display: block;
  font-size: 12px;
  line-height: 1.35;
  margin: 2px 0 0;
  max-width: 46ch;
  overflow-wrap: anywhere;
}
.field-hint[hidden] { display: none !important; }
.inline-field-error {
  color: var(--red);
  display: block;
  font-size: 12px;
  margin-top: 5px;
}
.field.has-error .control {
  border-color: var(--red);
  box-shadow: 0 0 0 1px var(--red);
}
.control:disabled {
  background: #edf0f1;
  color: #667174;
  cursor: not-allowed;
}
.form-alert { border-left: 4px solid var(--red); background: #fff0ef; padding: 12px; margin-bottom: 14px; }
.form-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 12px 0; background: var(--canvas); }
/* D-069: the CIC registration form keeps Save at the bottom of the page. */
.form-actions.form-actions-static { position: static; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.details-list { margin: 0; }
.details-list div { display: grid; grid-template-columns: 160px 1fr; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.details-list dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.details-list dd { margin: 0; overflow-wrap: anywhere; }
.complete-detail-grid .section:last-child { grid-column: 1 / -1; }
.visits-section { margin-top: 18px; }
.visits-section table { min-width: 1100px; }
.messages { margin-bottom: 14px; }
.message { background: #dff3e8; color: #125a3b; border-left: 4px solid var(--green); padding: 10px 12px; }
.login-page { min-height: calc(100vh - 58px); display: grid; place-items: center; }
.login-panel { width: min(420px, 100%); background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; }
.login-heading { display: flex; gap: 13px; align-items: center; margin-bottom: 24px; }
.login-logo { width: 72px; height: 56px; object-fit: contain; background: white; }
.login-heading h1 { font-size: 22px; margin-bottom: 2px; }
.login-heading p { color: var(--muted); margin: 0; }
.stack-form { display: flex; flex-direction: column; gap: 8px; }
.stack-form label { margin-top: 6px; font-size: 13px; font-weight: 700; }
.stack-form .button { margin-top: 12px; }
@media (max-width: 900px) {
  /* D-099: the nav now carries the password links, so it must wrap on a
     phone instead of forcing a horizontal scroll at 360 px. */
  .nav { height: auto; flex-wrap: wrap; padding: 0 12px; }
  .nav a { padding: 10px 10px; font-size: 13px; }
  .report-menu { flex: 1 0 100%; order: 3; border-top: 1px solid #2a473c; }
  .report-menu-label { min-height: 44px; font-size: 13px; padding: 0 12px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .form-grid .field { grid-column: span 3; }
  .form-grid .field-book_wra_code,
  .form-grid .field-age_years,
  .form-grid .field-method_satisfied,
  .form-grid .field-is_pregnant,
  .form-grid .field-pregnancy_planned,
  .form-grid .field-living_children { grid-column: span 2; }
  .form-grid .field-full_name,
  .form-grid .field-home_address { grid-column: span 6; }
  .filterbar { flex-wrap: wrap; }
  .report-filters { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
  .report-metrics { grid-template-columns: repeat(3, 1fr); }
  .report-grid { grid-template-columns: 1fr; }
  .filterbar .field { flex: 1 1 180px; }
}
@media (max-width: 620px) {
  .topbar { padding: 0 12px; }
  .user-name { display: none; }
  .nav { padding: 0 8px; overflow-x: auto; }
  .nav a { padding: 0 10px; white-space: nowrap; }
  .page { padding: 16px 12px; }
  .page-header { flex-direction: column; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 8px; }
  .report-filters { grid-template-columns: 1fr; }
  .report-metrics { grid-template-columns: 1fr 1fr; }
  .method-row { grid-template-columns: 90px minmax(70px, 1fr) 34px; }
  .method-row small { display: none; }
  .metric { min-height: 82px; padding: 12px; }
  .metric strong { font-size: 24px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .field { grid-column: auto; }
  fieldset { padding: 14px 12px; }
  .details-list div { grid-template-columns: 120px 1fr; }
}
.training-banner { background: #b3261e; color: #fff; text-align: center; font-weight: 700; font-size: 14px; padding: 8px 12px; letter-spacing: 0.2px; }
