/* HQ Tanzania Dashboard — Shared Styles (Mobile-First, MD3) */
:root {
  /* Brand / MD3 color tokens — Refined for HQ Tanzania Premium */
  --primary:    #003425; /* Deep Forest Green */
  --accent:     #C5A059; /* Gold Accent */
  --secondary:  #075985; /* Soft Navy Blue */
  --on-primary: #ffffff;
  --green:      #1B5E20; /* Semantic Success */
  --amber:      #B45309; /* Semantic Warning */
  --red:        #991B1B; /* Semantic Danger */
  --blue:       #075985; /* Semantic Info */
  --surface-1:  #ffffff;
  --surface-2:  #F4F7F5; /* Brand Tinted Background */
  --surface-3:  #E8EDEA; /* Deeper Tinted Neutral */
  --on-surface: #1A1C1A; /* Accessible Dark Text */
  --muted:      #526058; /* accessible Muted Text */
  --faint:      #8FA397; /* High contrast faint text */
  --border:     #D1D9D4; /* Subtle brand border */

  /* Legacy aliases (keep pages that reference these working) */
  --navy: #003425;
  --bg:   #F4F7F5;

  /* Typography scale */
  --font-display:  32px;
  --font-headline: 24px;
  --font-title-lg: 22px;
  --font-title:    20px;
  --font-body-lg:  19px;
  --font-body:     18px;
  --font-label-lg: 17px;
  --font-label:    16px;
  --font-caption:  15px;
  --font-micro:    14px;

  /* Spacing */
  --page-gutter: 16px;
  --section-gap: 12px;
  --card-pad:    16px;

  /* Shape */
  --radius-card:  16px;
  --radius-btn:   24px;
  --radius-input: 12px;
  --radius-badge: 999px;

  /* Elevation */
  --shadow-card:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-sheet: 0 -4px 32px rgba(0,0,0,.18);
  --shadow-nav:   0 -1px 0 #e2e8f0;
  --shadow-fab:   0 4px 12px rgba(0,0,0,.15);
}

/* ── Base ── */
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--surface-2);
  color: var(--on-surface);
}

/* ── Injected header wrapper ── */
#hq-injected-header { background: #fff; border-bottom: 1px solid var(--border); }

/* ── Mobile top app bar ── */
.top-app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--page-gutter);
  background: #fff;
  min-height: 56px;
}
.top-app-bar .tab-logo-group { display: flex; align-items: center; gap: 10px; }
.top-app-bar .tab-title {
  font-size: var(--font-body-lg);
  font-weight: 700;
  color: var(--on-surface);
  line-height: 1.2;
}
.top-app-bar .tab-subtitle {
  font-size: var(--font-caption);
  color: var(--faint);
  line-height: 1.2;
}
.top-app-bar .tab-icons { display: flex; gap: 2px; }
.top-app-bar .icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: background .15s;
}
.top-app-bar .icon-btn:hover { background: var(--surface-3); }

/* ── Desktop header ── */
.hq-desktop-header {
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* ── Desktop nav bar ── */
.hq-desktop-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
  border-top: 1px solid var(--border);
}
.hq-desktop-nav::-webkit-scrollbar { display: none; }

.nav-link {
  min-width: fit-content;
  padding: 10px 14px;
  border-radius: 2px 2px 0 0;
  text-decoration: none;
  font-size: var(--font-label);
  font-weight: 500;
  color: var(--muted);
  transition: background .15s, color .15s;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.nav-link:hover { background: var(--surface-3); color: var(--primary); }
.nav-link.active { color: var(--primary); font-weight: 700; border-bottom: 2px solid var(--primary); }

/* ── Bottom navigation bar ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  box-shadow: var(--shadow-nav);
  display: none; /* shown via media query */
  align-items: stretch;
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bn-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 8px 4px;
  position: relative;
  color: var(--faint);
  font-size: 11px;
  font-weight: 500;
  transition: color .15s;
  min-height: 64px;
  text-decoration: none;
}
.bn-tab:active { background: var(--surface-3); }
.bn-tab svg { width: 24px; height: 24px; }
.bn-tab span { font-size: 11px; font-weight: 500; }
.bn-tab.active { color: var(--primary); }
.bn-tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 3px 3px;
}

/* ── More Drawer ── */
.more-drawer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 9000;
  align-items: flex-end;
}
.more-drawer.open { display: flex; }
.more-drawer-panel {
  background: #fff;
  width: 100%;
  max-height: 85vh;
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  animation: sheetIn .25s cubic-bezier(.32,1,.23,1) both;
}
.more-drawer-handle {
  width: 36px;
  height: 4px;
  background: #d1d5db;
  border-radius: 2px;
  margin: 12px auto 4px;
}
.more-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.more-drawer-title {
  font-size: var(--font-title);
  font-weight: 700;
  color: var(--on-surface);
}
.more-drawer-close {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--surface-3);
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.more-drawer-section-title {
  font-size: var(--font-caption);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--faint);
  padding: 14px 20px 6px;
}
.more-drawer-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 20px;
  text-decoration: none;
  color: var(--on-surface);
  font-size: var(--font-body-lg);
  font-weight: 500;
  transition: background .15s;
  min-height: 52px;
}
.more-drawer-item:hover,
.more-drawer-item:active { background: var(--surface-3); }
.more-drawer-item svg { width: 22px; height: 22px; color: var(--muted); flex-shrink: 0; }
.more-drawer-item.active { color: var(--primary); font-weight: 700; }
.more-drawer-item.active svg { color: var(--primary); }

/* ── Cards ── */
.card {
  background: var(--surface-1);
  border-radius: var(--radius-card);
  padding: var(--card-pad);
  box-shadow: var(--shadow-card);
  border: none;
}

.kpi-card {
  background: var(--surface-1);
  border-radius: var(--radius-card);
  padding: var(--card-pad);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: box-shadow .2s;
  border: none;
}
.kpi-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.12); }

/* ── Item cards (mobile card list rows) ── */
.item-card {
  background: var(--surface-1);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  transition: box-shadow .15s;
  min-height: 48px;
}
.item-card:active { box-shadow: 0 2px 8px rgba(0,0,0,.12); background: var(--surface-2); }
.item-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.item-card-primary {
  font-size: var(--font-title);
  font-weight: 600;
  color: var(--on-surface);
  flex: 1;
  min-width: 0;
}
.item-card-secondary {
  font-size: var(--font-body);
  color: var(--muted);
  margin-top: 4px;
}
.item-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* Card list show/hide */
.card-list         { display: none; flex-direction: column; gap: 8px; }
.desktop-table-wrap { display: block; }
table th {font-size: 13px}
table td {font-size: 15px}

/* ── Buttons ── */
.btn {
  padding: 0 20px;
  height: 48px;
  min-height: 48px;
  border-radius: var(--radius-btn);
  border: none;
  cursor: pointer;
  font-size: var(--font-label-lg);
  font-weight: 600;
  transition: opacity .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover  { opacity: .85; }
.btn:active { opacity: .75; }

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-blue      { background: var(--secondary); color: #fff; }
.btn-green     { background: var(--green);     color: #fff; }
.btn-amber     { background: var(--amber);     color: #1e293b; }
.btn-red       { background: var(--red);       color: #fff; }
.btn-ghost     { background: var(--surface-3); color: var(--muted); }
.btn-ghost:hover { background: var(--border); opacity: 1; }
.btn-outline   { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }

/* Small button — 36px */
.btn-sm {
  height: 36px;
  min-height: 36px;
  padding: 0 14px;
  font-size: var(--font-label);
  border-radius: 8px;
}

/* ── Badges ── */
.badge {
  font-size: var(--font-micro);
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--radius-badge);
  display: inline-block;
  white-space: nowrap;
}
.badge-red     { background: #FEF2F2; color: var(--red); }
.badge-amber   { background: #FFFBEB; color: var(--amber); }
.badge-green   { background: #F0FDF4; color: var(--green); }
.badge-blue    { background: #F0F9FF; color: var(--blue); }
.badge-gray    { background: var(--surface-3); color: var(--muted); }
.badge-darkred { background: var(--red); color: #fff; }

/* ── Form inputs ── */
input[type=text],
input[type=date],
input[type=number],
input[type=email],
input[type=password],
select {
  width: 100%;
  height: 52px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  padding: 0 14px;
  font-size: var(--font-body-lg);
  color: var(--on-surface);
  background: var(--surface-1);
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
  margin-top: 0;
}
textarea {
  width: 100%;
  min-height: 100px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-input);
  padding: 14px;
  font-size: var(--font-body-lg);
  color: var(--on-surface);
  background: var(--surface-1);
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
  resize: vertical;
  margin-top: 0;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--secondary);
  /* box-shadow: 0 0 0 3px rgba(0,86,179,.12); */
}
label {
  font-size: var(--font-label-lg);
  font-weight: 600;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

/* ── Modals / Bottom Sheets ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 16px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  padding: 24px;
}

/* Fullscreen modal (maps) — never converted to sheet */
.modal-fullscreen .modal-box {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  max-height: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
}

/* ── Search bar ── */
#globalSearch {
  border: 1.5px solid var(--border);
  border-radius: 8px;
}

/* ── Animations ── */
@keyframes sheetIn {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* ═══════════════════════════════════════
   MOBILE  ≤ 767px
   ═══════════════════════════════════════ */
@media (max-width: 767px) {
  body {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  /* Navigation */
  .hq-desktop-nav    { display: none !important; }
  .hq-desktop-header { display: none !important; }
  .bottom-nav        { display: flex; }

  /* Card list vs table */
  .desktop-table-wrap { display: none !important; }
  .card-list          { display: flex; }

  /* Page padding */
  .p-6 { padding: var(--page-gutter) !important; }

  /* Modals → bottom sheets */
  .modal-overlay:not(.modal-fullscreen) {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal-overlay:not(.modal-fullscreen) .modal-box {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    padding: 8px 20px calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    animation: sheetIn .25s cubic-bezier(.32,1,.23,1) both;
  }
  .modal-overlay:not(.modal-fullscreen) .modal-box::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 0 auto 16px;
  }

  /* 2-col KPI grids */
  .kpi-grid-auto {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Management insight 3-col → 1-col */
  .insight-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* Charts single column */
  .charts-grid {
    grid-template-columns: 1fr !important;
  }

  /* Horizontal scroll strips */
  .scroll-x-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
  }
  .scroll-x-mobile::-webkit-scrollbar { display: none; }
}

/* ═══════════════════════════════════════
   DESKTOP  ≥ 768px
   ═══════════════════════════════════════ */
@media (min-width: 768px) {
  .bottom-nav     { display: none !important; }
  .top-app-bar    { display: none !important; }
  .more-drawer    { display: none !important; }
  .hq-desktop-header { display: flex; }
  .hq-desktop-nav    { display: flex; }
  .card-list          { display: none !important; }
  .desktop-table-wrap { display: block !important; }
}
