/* JPH Housekeeping — tokens from design-system/MASTER.md (light theme only) */
:root {
  color-scheme: light;
  --bg: #F4F7FB;
  --surface: #FFFFFF;
  --muted: #EEF3F9;
  --border: #DFE6EF;
  --border-strong: #C6D0DE;
  --text: #172033;
  --text-2: #4A5568;
  --primary: #253C8D;      /* JESA navy */
  --primary-press: #1B2D6B;
  --primary-soft: #EAF0FB;
  --cyan: #00BBED;         /* JESA cyan, fills only */
  --blue: #0483BA;         /* JESA blue */
  --tone: #00BBED;
  --accent: #C2410C;
  --danger: #B91C1C;
  --info: #0361AB;
  --sev-low-bg: #E2E8F0;  --sev-low-fg: #334155;
  --sev-medium-bg: #FEF3C7; --sev-medium-fg: #92400E;
  --sev-high-bg: #FFEDD5; --sev-high-fg: #9A3412;
  --sev-critical-bg: #FEE2E2; --sev-critical-fg: #991B1B;
  --r-sm: 10px; --r-md: 14px; --r-lg: 20px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.06);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --tap: 48px;
  --ease: 120ms ease-out;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 400 16px/1.5 Inter, "Noto Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; min-height: 100dvh;
}
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 600; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
p { margin: 0; }
a { color: var(--info); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.skip { position: absolute; inset-inline-start: 8px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: var(--r-sm); z-index: 1000; transform: translateY(-200%); }
.skip:focus { transform: none; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon .tone { fill: var(--tone); fill-opacity: .2; stroke: none; }
.btn.primary .icon .tone, .nav-new .icon .tone, .pin .icon .tone { fill: #fff; fill-opacity: .28; }
.muted { color: var(--text-2); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: var(--s2); }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: var(--s4); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s4); border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 600; text-decoration: none; transition: background var(--ease), border-color var(--ease);
}
.btn:hover { background: var(--muted); }
.btn:active { background: var(--border); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover, .btn.primary:active { background: var(--primary-press); }
.btn.danger { color: var(--danger); border-color: #FECACA; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--muted); }
.btn.block { width: 100%; }
.icon-btn { width: var(--tap); padding: 0; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Forms ─── */
.field { display: block; }
.field > .lbl { display: block; font-weight: 600; font-size: 14px; margin-bottom: var(--s1); }
.field .hint { font-size: 14px; color: var(--text-2); margin-top: var(--s1); }
.field .err { font-size: 14px; color: var(--danger); margin-top: var(--s1); }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface);
}
textarea.input { min-height: 96px; resize: vertical; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface); font-weight: 500; font-size: 15px; display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--ease), border-color var(--ease);
}
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-press); font-weight: 600; }
.chip[aria-pressed="true"]::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.seg { display: flex; background: var(--muted); border-radius: var(--r-sm); padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--text-2); white-space: nowrap; padding: 0 6px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ─── Layout ─── */
.topbar {
  position: sticky; top: 0; z-index: 1100; display: flex; align-items: center; gap: var(--s2);
  padding: calc(var(--s2) + var(--safe-t)) var(--s3) var(--s2); background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--border); backdrop-filter: saturate(1.2) blur(6px);
}
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 700; font-size: 16px; }
.brand-logo { height: 26px; width: auto; display: block; }
.brand-sep { width: 1px; height: 24px; background: var(--border-strong); }
.brand-name { font-size: 15px; color: #253C8D; white-space: nowrap; }
@media (max-width: 430px) { .brand-sep, .brand-name { display: none; } }
.login-brand { display: grid; justify-items: center; gap: 8px; text-align: center; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.login-brand img { width: 190px; height: auto; }
.login-brand h1 { color: #253C8D; font-size: 22px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.topbar select.input { min-height: 44px; width: auto; max-width: 46vw; font-weight: 600; padding: 6px 10px; }
.page { max-width: 760px; margin: 0 auto; padding: var(--s4) var(--s4) calc(var(--s7) + var(--safe-b)); }
.page.wide { max-width: 1100px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s4); box-shadow: var(--shadow); }
.menu { position: absolute; inset-inline-end: var(--s3); top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); min-width: 220px; padding: var(--s1); z-index: 50; }
.menu button, .menu a { width: 100%; justify-content: flex-start; }
.lang-row { display: flex; gap: 4px; padding: 4px; }
.lang-row .btn { flex: 1; min-height: 44px; padding: 0 8px; font-size: 14px; justify-content: center; }
.lang-row .btn[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary-press); }

/* ─── Login ─── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s4); }
.login .card { width: 100%; max-width: 400px; padding: var(--s5); }
.login .brand-mark { width: 48px; height: 48px; border-radius: 12px; }

/* ─── Map screen ─── */
.map-wrap { position: relative; }
#map { height: 48dvh; min-height: 280px; background: var(--muted); border-bottom: 1px solid var(--border); }
.map-overlay { position: absolute; top: var(--s3); left: var(--s3); right: var(--s3); z-index: 500; display: flex; justify-content: center; pointer-events: none; }
.map-overlay .seg { pointer-events: auto; background: rgba(255,255,255,.95); box-shadow: var(--shadow); width: 100%; max-width: 420px; }
.list { padding: var(--s3) var(--s4) calc(96px + var(--safe-b)); max-width: 760px; margin: 0 auto; }
.list-head { display: flex; justify-content: space-between; align-items: baseline; margin: var(--s2) 0 var(--s3); }
.obs { display: flex; gap: var(--s3); width: 100%; text-align: start; padding: var(--s3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: var(--s2); transition: background var(--ease); }
.obs:hover { background: var(--muted); }
.obs img, .obs .ph { width: 72px; height: 72px; border-radius: var(--r-sm); object-fit: cover; background: var(--muted); flex: none; }
.obs .t { font-weight: 600; }
.obs .meta { font-size: 14px; color: var(--text-2); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--muted); color: var(--text-2); white-space: nowrap; }
.sev-low { background: var(--sev-low-bg); color: var(--sev-low-fg); }
.sev-medium { background: var(--sev-medium-bg); color: var(--sev-medium-fg); }
.sev-high { background: var(--sev-high-bg); color: var(--sev-high-fg); }
.sev-critical { background: var(--sev-critical-bg); color: var(--sev-critical-fg); }
.st-open { background: #E0F2FE; color: #075985; }
.st-closed { background: #E3F6EA; color: #166534; }
.fab {
  position: fixed; inset-inline-end: var(--s4); bottom: calc(var(--s4) + var(--safe-b)); z-index: 600;
  min-height: 56px; padding: 0 var(--s5); border-radius: 999px; box-shadow: 0 6px 18px rgba(4,120,87,.28);
}
.empty { text-align: center; color: var(--text-2); padding: var(--s6) var(--s4); }

/* Map pins: severity letter + colour (never colour alone) */
.pin { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(15,23,42,.35); display: grid; place-items: center; }
.pin span { transform: rotate(45deg); font: 700 12px/1 Inter, sans-serif; }
.pin.low { background: #CBD5E1; color: #1E293B; }
.pin.medium { background: #FCD34D; color: #78350F; }
.pin.high { background: #FB923C; color: #431407; }
.pin.critical { background: #F87171; color: #450A0A; }
.pin.closed { background: #A7F3D0; color: #064E3B; }
.pin.draft { background: var(--primary); color: #fff; }
.leaflet-container { font-family: inherit; }

/* ─── New observation / detail ─── */
.photo-box { position: relative; aspect-ratio: 4 / 3; border: 2px dashed var(--border-strong); border-radius: var(--r-md); background: var(--surface); display: grid; place-items: center; overflow: hidden; }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-box .btn { position: absolute; bottom: var(--s3); left: 50%; transform: translateX(-50%); box-shadow: var(--shadow); }
.photo-empty { display: grid; justify-items: center; gap: var(--s2); color: var(--text-2); }
.photo-empty .icon { width: 40px; height: 40px; }
#pickmap { height: 220px; border-radius: var(--r-md); border: 1px solid var(--border); }
.gps { font-size: 14px; padding: var(--s2) var(--s3); border-radius: var(--r-sm); background: var(--muted); color: var(--text-2); }
.gps.ok { background: var(--primary-soft); color: var(--primary-press); }
.gps.warn { background: #FFF7ED; color: #9A3412; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 70%, rgba(248,250,252,0)); padding: var(--s4) 0 calc(var(--s2) + var(--safe-b)); display: flex; gap: var(--s2); }
.sticky-actions .btn { flex: 1; }
.detail-photo { width: 100%; border-radius: var(--r-md); background: var(--muted); aspect-ratio: 4 / 3; object-fit: cover; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px var(--s4); font-size: 15px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ─── Admin ─── */
.tabs { display: flex; gap: var(--s1); overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: var(--s4); scrollbar-width: none; }
.tabs button { min-height: var(--tap); padding: 0 var(--s4); border: 0; background: none; font-weight: 600; color: var(--text-2); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--primary-press); border-bottom-color: var(--primary); }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td { text-align: start; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 13px; color: var(--text-2); font-weight: 600; }
.form-grid { display: grid; gap: var(--s3); }
@media (min-width: 640px) { .form-grid.two { grid-template-columns: 1fr 1fr; } }
.check { display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }
#adminmap { height: 440px; border-radius: var(--r-md); border: 1px solid var(--border); }

/* ─── Toast & banner ─── */
#toast { position: fixed; z-index: 1200; left: 50%; bottom: calc(88px + var(--safe-b)); transform: translateX(-50%); display: grid; gap: var(--s2); width: min(92vw, 420px); }
.toast { background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--primary); box-shadow: var(--shadow); border-radius: var(--r-sm); padding: var(--s3) var(--s4); font-weight: 500; }
.toast.err { border-inline-start-color: var(--danger); }
.banner { background: #FFF7ED; color: #9A3412; padding: var(--s2) var(--s4); font-size: 14px; text-align: center; }

@media (min-width: 900px) {
  .map-layout { display: grid; grid-template-columns: 1fr 420px; height: calc(100dvh - 61px); }
  .map-layout #map { height: 100%; border-bottom: 0; border-right: 1px solid var(--border); }
  .map-layout .list { overflow-y: auto; max-width: none; padding-bottom: 120px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 0.01ms !important; }
}

/* Right-to-left (Arabic) */
[dir="rtl"] .icon { transform: none; }
[dir="rtl"] a[aria-label] .icon, [dir="rtl"] .topbar > a .icon { transform: scaleX(-1); } /* back arrow points right */
[dir="rtl"] .leaflet-container { direction: ltr; }

/* Bottom navigation (icons + labels) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100; display: flex; justify-content: space-around; align-items: stretch;
  background: rgba(255,255,255,.98); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + var(--safe-b));
  box-shadow: 0 -2px 10px rgba(15,23,42,.05);
}
.nav-item {
  flex: 1; min-width: 56px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--text-2); text-decoration: none; font: inherit; border-radius: 12px; transition: background var(--ease), color var(--ease);
}
.nav-item:active { background: var(--muted); }
.nav-ic { display: grid; place-items: center; width: 44px; height: 30px; border-radius: 15px; transition: background var(--ease); }
.nav-lbl { font-size: 12px; font-weight: 600; line-height: 1.2; white-space: nowrap; }
.nav-item[aria-current="page"] { color: var(--primary-press); }
.nav-item[aria-current="page"] .nav-ic { background: var(--primary-soft); }
.nav-new .nav-ic { width: 52px; height: 36px; border-radius: 18px; background: var(--primary); color: #fff; }
.nav-new { color: var(--primary-press); }
.tabs button { display: inline-flex; align-items: center; gap: 6px; }
.tabs button .icon { width: 18px; height: 18px; }
/* leave room for the bottom bar */
.list { padding-bottom: calc(96px + var(--safe-b)); }
.page { padding-bottom: calc(110px + var(--safe-b)); }
#toast { bottom: calc(96px + var(--safe-b)); }
@media (min-width: 900px) { .map-layout { height: calc(100dvh - 61px - 70px); } }

/* ── Design refresh: JESA look, two-tone icons ── */
.topbar { background: rgba(255,255,255,.97); }
.card { border-radius: 16px; box-shadow: 0 1px 2px rgba(23,32,51,.04), 0 6px 18px rgba(37,60,141,.06); }
.obs { border-radius: 16px; }
.btn { border-radius: 12px; }
.btn.primary { box-shadow: 0 4px 12px rgba(37,60,141,.22); }
h1, h2 { color: var(--primary); }
.list-head h2 { color: var(--primary); }
.badge.cat { background: #EAF6FC; color: #0B4F6C; gap: 5px; }
.badge .icon { width: 15px; height: 15px; }
.cat-chip { gap: 8px; padding-inline: 12px 16px; }
.cat-chip .icon { width: 22px; height: 22px; color: var(--primary); }
.cat-chip:has(.icon)::before { display: none !important; }
.cat-chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.cat-chip[aria-pressed="true"] .icon { color: #fff; }
.cat-chip[aria-pressed="true"] .icon .tone { fill: #fff; fill-opacity: .28; }
.chip[aria-pressed="true"]::before { background: var(--primary); }
.seg button[aria-pressed="true"] { color: var(--primary); }
.gps.ok { background: #E6F6FC; color: #0B4F6C; }
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--cyan); }
.nav-item[aria-current="page"] { color: var(--primary); }
.nav-item[aria-current="page"] .nav-ic { background: var(--primary-soft); }
.nav-new .nav-ic { background: var(--primary); box-shadow: 0 0 0 3px #D9F3FC; }
.nav-new { color: var(--primary); }
.nav-ic .icon { width: 24px; height: 24px; }
/* Login on the JESA wave */
.login { background: #EEF5F8 url(brand/bg.jpg) center / cover no-repeat; }
.login .card { background: rgba(255,255,255,.93); backdrop-filter: blur(6px); border-color: rgba(255,255,255,.7); }
.login-brand h1 { color: var(--primary); }

/* ── Statistics ── */
.stats-filters { display: grid; gap: 10px; }
@media (min-width: 640px) { .stats-filters { grid-template-columns: 240px 1fr; align-items: center; } }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; display: grid; gap: 2px; box-shadow: 0 1px 2px rgba(23,32,51,.04); }
.kpi-n { font-size: 28px; font-weight: 700; color: var(--primary); line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-l { font-size: 14px; color: var(--text-2); }
.kpi-warn { border-color: #FBD5C0; background: #FFF8F3; }
.kpi-warn .kpi-n { color: #9A3412; }
.kpi-inline { font-size: 20px; color: var(--primary); }
.st-h { font-size: 16px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.vbars { display: flex; align-items: flex-end; gap: 4px; height: 170px; padding-top: 18px; border-bottom: 1px solid var(--border); }
.vbar { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.vbar-fill { width: 70%; max-width: 26px; min-height: 0; background: var(--blue); border-radius: 4px 4px 0 0; transition: background var(--ease); }
.vbar:hover .vbar-fill { background: var(--primary); }
.vbar-n { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.vbar-k { position: absolute; bottom: -22px; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.vbars + * { margin-top: 26px; }
section.card:has(.vbars) { padding-bottom: 34px; }
.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.hbars li { display: grid; grid-template-columns: minmax(110px, 40%) 1fr 36px; align-items: center; gap: 10px; }
.hb-label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-label .icon { width: 20px; height: 20px; color: var(--primary); }
.hb-track { height: 12px; background: var(--muted); border-radius: 6px; overflow: hidden; }
.hb-fill { display: block; height: 100%; background: var(--blue); border-radius: 6px; }
.hb-n { text-align: end; font-weight: 600; font-variant-numeric: tabular-nums; }
.sevfill-low { background: #94A3B8; } .sevfill-medium { background: #F59E0B; } .sevfill-high { background: #EA580C; } .sevfill-critical { background: #DC2626; }

/* Manual reports */
.req-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.req-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); font-size: 14px; }
.req-links { display: flex; flex-wrap: wrap; gap: 4px 12px; width: 100%; }
.req-res a { font-weight: 600; }
.nowrap { white-space: nowrap; }

.photo-box .btn { white-space: nowrap; }

/* Drive viewer (admins) */
#viewer { position: fixed; inset: 0; z-index: 1300; background: #F4F7FB; display: flex; flex-direction: column; }
.viewer-bar { display: flex; justify-content: flex-start; padding: calc(10px + var(--safe-t)) 12px 10px; border-bottom: 1px solid var(--border); background: #fff; }
.viewer-body { flex: 1; overflow: auto; padding: 16px; display: grid; align-content: start; justify-items: center; gap: 12px; }
.viewer-body img { max-width: 100%; max-height: calc(100dvh - 140px); border-radius: 12px; box-shadow: var(--shadow); }
.drive-list { list-style: none; margin: 0; padding: 0; width: min(760px, 100%); display: grid; gap: 6px; }
.drive-list a { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: #fff; border: 1px solid var(--border); border-radius: 12px; color: var(--text); text-decoration: none; min-height: 48px; }
.drive-list a:hover { background: var(--muted); }

/* Password reset requests */
.badge.warn { background: #FFF4E0; color: #8A4B00; }
.count-dot { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-inline-start: 4px; border-radius: 10px; background: #FFE3B3; color: #8A4B00; font-size: 12px; font-weight: 700; }
