/* FAO SWALIM CDI Portal — Base Styles */
:root {
  --fao-blue: #2E8BC7;
  --fao-blue-dark: #2478B0;
  --fao-blue-darker: #1A6FA0;
  --fao-blue-light: #EBF5FB;
  --fao-blue-hover: #257AB5;
  --accent-gold: #F0C040;
  --teal: #0E6B5E;
  --cdi-extreme: #7B0000;
  --cdi-severe: #C04040;
  --cdi-moderate: #F4A460;
  --cdi-mild: #FFFF80;
  --cdi-normal: #00A000;
  --page-bg: #F0F2F5;
  --panel-bg: #FFFFFF;
  --prelim-red: #C84040;
  --final-green: #2A7A40;
  --text-primary: #1a1a2e;
  --text-secondary: #5a6270;
  --text-muted: #8b939e;
  --border: #dde1e6;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --header-h: 76px;
  --nav-h: 44px;
  --chrome-h: calc(var(--header-h) + var(--nav-h));
  --sidebar-w: 260px;
  --font: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 6px;
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--page-bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--fao-blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }

/* ── Site chrome wrapper ── */
.site-chrome {
  position: relative;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}

/* ── Header: logos left | title right (3 lines) ── */
.site-header {
  height: var(--header-h);
  background: linear-gradient(135deg, var(--fao-blue-dark) 0%, var(--fao-blue) 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: relative;
}

.header-logos-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logos-group img { height: 42px; width: auto; }

.logo-divider {
  width: 1px;
  height: 36px;
  background: rgba(255,255,255,0.35);
}

.header-app-title {
  text-align: right;
  line-height: 1.15;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 800;
}
.header-app-title .title-line1 {
  display: block;
  font-size: 0.72rem;
  color: rgba(255,255,255,0.9);
}
.header-app-title .title-line2,
.header-app-title .title-line3 {
  display: block;
  font-size: 0.95rem;
  color: var(--accent-gold);
}

.mobile-menu-btn {
  display: none;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius);
  margin-left: 12px;
}

/* ── Integrated navigation pills ── */
.site-nav {
  height: var(--nav-h);
  background: var(--fao-blue-darker);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  gap: 6px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.nav-list {
  display: flex;
  align-items: center;
  list-style: none;
  gap: 6px;
}

.nav-list a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 18px;
  color: rgba(255,255,255,0.85);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  border-radius: 20px;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

.nav-list a:hover {
  color: #fff;
  background: rgba(255,255,255,0.12);
  text-decoration: none;
}

.nav-list a.active {
  color: var(--fao-blue-darker);
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
}
.nav-icon .nav-svg { width: 15px; height: 15px; display: block; }
.nav-list a.active .nav-icon { opacity: 1; }

/* Hide old banner */
.prelim-banner { display: none !important; }

/* Subtle preliminary badge + info icon */
.prelim-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
}

.prelim-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: rgba(200,64,64,0.1);
  color: var(--prelim-red);
  border: 1px solid rgba(200,64,64,0.35);
  vertical-align: middle;
}

.prelim-info .info-tip-icon {
  background: rgba(200,64,64,0.12);
  color: var(--prelim-red);
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-prelim { background: rgba(200,64,64,0.12); color: var(--prelim-red); border: 1px solid rgba(200,64,64,0.3); }
.badge-final { background: var(--final-green); color: #fff; }
.badge-pending { background: #e8a020; color: #fff; }
.badge-approved { background: var(--final-green); color: #fff; }
.badge-rejected { background: var(--prelim-red); color: #fff; }
.badge-draft { background: #d4880a; color: #fff; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--fao-blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--fao-blue-hover); }
.btn-secondary { background: var(--fao-blue-dark); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text-primary); }
.btn-outline:hover:not(:disabled) { background: var(--page-bg); }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.btn-success { background: var(--final-green); color: #fff; }
.btn-danger { background: var(--prelim-red); color: #fff; }
.btn-block { width: 100%; }

.card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

.text-muted { color: var(--text-muted); }
.change-up { color: var(--final-green); font-weight: 600; }
.change-down { color: var(--prelim-red); font-weight: 600; }

.nav-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 999;
}
.nav-overlay.open { display: block; }

/* Info tooltip */
.info-tip {
  position: relative;
  display: inline-flex;
  cursor: help;
  z-index: 50;
}
.info-tip-icon {
  width: 17px; height: 17px;
  border-radius: 50%;
  background: var(--fao-blue-light);
  color: var(--fao-blue-dark);
  font-size: 0.62rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.info-tip-popup {
  display: none;
  position: fixed;
  background: #fff;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  width: 260px;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.45;
  box-shadow: var(--shadow-md);
  z-index: 11000;
  pointer-events: none;
}
.info-tip.is-open .info-tip-popup { display: block; }

#tooltip-portal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  pointer-events: none;
}
#tooltip-portal .info-tip-popup,
#tooltip-portal .action-tip-popup {
  pointer-events: auto;
  display: block;
}

.action-tip-popup {
  display: none;
  position: fixed;
  background: #fff;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 11px;
  max-width: 220px;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.4;
  box-shadow: var(--shadow-md);
  z-index: 12000;
  white-space: normal;
}

/* District breakdown & exposure details */
.bd-pct-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.bd-pct-chip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 0.62rem; color: var(--text-secondary);
  background: var(--page-bg); padding: 2px 6px;
  border-radius: 10px; border: 1px solid var(--border);
}
.bd-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 2px; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.1);
}
.bd-detail-block, .exposure-detail-block {
  margin-top: 8px; padding: 8px;
  background: var(--page-bg); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 0.72rem;
}
.bd-detail-title {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 6px;
}
.bd-detail-row {
  display: grid; grid-template-columns: 10px 1fr auto;
  align-items: center; gap: 6px; margin-bottom: 4px;
}
.bd-detail-label { font-weight: 600; font-size: 0.72rem; }
.bd-detail-pct { font-weight: 700; color: var(--fao-blue-dark); font-size: 0.72rem; }
.bd-detail-mini { grid-column: 2 / 4; height: 4px; background: #e8e8e8; border-radius: 2px; overflow: hidden; }
.bd-detail-mini span { display: block; height: 100%; border-radius: 2px; }
.district-detail-panel { margin-top: 6px; }
.exposure-mini-table { width: 100%; border-collapse: collapse; font-size: 0.65rem; }
.exposure-mini-table th, .exposure-mini-table td { padding: 4px 5px; border-bottom: 1px solid var(--border); text-align: left; }
.exposure-mini-table th { font-size: 0.6rem; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.exposure-report-box { max-width: 820px; width: 100%; }
.exposure-report-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.exposure-report-header h3 { font-size: 1rem; color: var(--fao-blue-dark); }
.exposure-report-body { max-height: 340px; overflow-y: auto; margin-bottom: 12px; }
.exposure-report-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.exposure-report-table th, .exposure-report-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.exposure-report-table th {
  background: var(--fao-blue-light); font-size: 0.68rem; text-transform: uppercase;
  color: var(--fao-blue-dark); position: sticky; top: 0;
}
.exposure-detail-panel { margin-bottom: 12px; padding: 12px; background: var(--page-bg); border: 1px solid var(--border); border-radius: var(--radius); }
.exposure-detail-panel[hidden] { display: none !important; }
.exposure-report-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn-link { background: none; border: none; color: var(--fao-blue); font-size: 0.72rem; font-weight: 600; cursor: pointer; font-family: var(--font); padding: 0; }
.btn-link:hover { text-decoration: underline; }
.detail-toggle { background: none; border: none; color: var(--fao-blue); font-size: 0.68rem; font-weight: 600; cursor: pointer; font-family: var(--font); padding: 0; }
.detail-toggle:hover { text-decoration: underline; }
.detail-toggle.is-open { color: var(--fao-blue-dark); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 5000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--panel-bg);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-md);
}

.modal-alert { text-align: center; max-width: 400px; }
.modal-alert-icon {
  width: 48px; height: 48px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: rgba(46, 139, 199, 0.12);
  color: var(--fao-blue-dark);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-alert h3 { font-size: 1.05rem; color: var(--fao-blue-dark); margin-bottom: 8px; }
.modal-alert p { font-size: 0.85rem; line-height: 1.5; margin-bottom: 8px; }
.modal-box h3 {
  font-size: 1rem;
  color: var(--fao-blue-dark);
  margin-bottom: 12px;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

@media (max-width: 900px) {
  :root { --header-h: 64px; }
  .header-logos-group img { height: 32px; }
  .header-app-title .title-line2,
  .header-app-title .title-line3 { font-size: 0.8rem; }
  .mobile-menu-btn { display: block; }
  .site-nav {
    position: fixed;
    top: var(--header-h);
    left: -300px;
    width: 300px;
    height: calc(100vh - var(--header-h));
    flex-direction: column;
    align-items: stretch;
    padding: 16px 12px;
    transition: left 0.3s ease;
    z-index: 1001;
  }
  .site-nav.open { left: 0; }
  .nav-list { flex-direction: column; align-items: stretch; }
  .nav-list a { border-radius: var(--radius); padding: 12px 16px; }
}
