/* GRA Operations Tracker — design system (ported verbatim from design/mockups).
   Modern light SaaS: Inter type, indigo accent, soft shadows, light sidebar.
   Class names match the mock so templates map 1:1. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e7e8ec;
  --border-soft: #f0f1f4;
  --text: #18181f;
  --text-soft: #5d6069;
  --text-faint: #9095a1;
  --accent: #4f46e5;        /* actions, links, active nav */
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #e11d48;
  --bad-soft: #ffe4e6;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 18, 28, .04);
  --shadow-md: 0 1px 3px rgba(16, 18, 28, .06), 0 4px 12px rgba(16, 18, 28, .05);
  --sidebar-w: 216px;
  font-size: 13px;
}

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

body {
  font-family: Inter, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: #fbfbfc;
  color: var(--text-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  color: var(--text);
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: -.01em;
}
.sidebar .brand .brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex: 0 0 auto;
  box-shadow: var(--shadow-sm);
}
.sidebar .brand .brand-text { min-width: 0; }
.sidebar .brand small { display: block; color: var(--text-faint); font-weight: 450; font-size: 11px; margin-top: 1px; }
.sidebar nav { padding: 4px 8px; flex: 1; }
.sidebar nav .section {
  padding: 14px 10px 5px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-faint);
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  margin: 1px 0;
  color: var(--text-soft);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: var(--radius-sm);
}
.sidebar nav a:hover { background: #f0f1f4; color: var(--text); }
.sidebar nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.sidebar nav a .ico { width: 16px; text-align: center; opacity: .75; }
.sidebar .user {
  margin: 8px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.sidebar .user .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
}
.sidebar .user .meta { color: var(--text); font-weight: 600; }
.sidebar .user .meta small { display: block; color: var(--text-faint); font-size: 10.5px; font-weight: 450; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.topbar .crumbs { color: var(--text-faint); font-size: 12px; }
.topbar .crumbs a { color: var(--text-soft); text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .global-search {
  width: 300px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-family: inherit;
  background: var(--bg);
}
.topbar .global-search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.content { padding: 20px 24px; flex: 1; }

/* ---------- Generic components ---------- */
.row { display: flex; gap: 14px; }
.col { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card .card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card .card-head h2 { font-size: 13px; font-weight: 600; letter-spacing: -.01em; }
.card .card-head .hint { color: var(--text-faint); font-size: 11.5px; }
.card .card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.card .card-body { padding: 16px; }
.card .card-body.flush { padding: 0; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
}
.kpi .label { color: var(--text-faint); font-size: 11px; font-weight: 550; text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 11.5px; font-weight: 500; margin-top: 3px; }
.kpi .delta.up { color: var(--ok); }
.kpi .delta.down { color: var(--bad); }
.kpi .delta.flat { color: var(--text-faint); }

/* Tables */
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th {
  text-align: left;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
  font-weight: 550;
  font-size: 11.5px;
  white-space: nowrap;
}
table.data td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fafafc; }
table.data td.num, table.data th.num { text-align: right; }
table.data a { color: var(--accent); font-weight: 500; text-decoration: none; }
table.data a:hover { text-decoration: underline; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.muted { background: #f0f1f4; color: var(--text-soft); }

/* Buttons & inputs */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f6f6f8; }
.btn.primary {
  background: linear-gradient(180deg, #5b52f0, var(--accent));
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.sm { padding: 5px 10px; font-size: 11.5px; }
.btn.danger { color: var(--bad); border-color: #fecdd3; }

select, input[type="text"], input[type="search"], input[type="date"], input[type="email"],
input[type="password"], input[type="number"], textarea {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.filterbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filterbar .count { margin-left: auto; color: var(--text-faint); font-size: 12px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a {
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-soft);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { color: var(--text); }

/* Pagination */
.pager {
  display: flex;
  gap: 4px;
  padding: 11px 14px;
  align-items: center;
  font-size: 12px;
  color: var(--text-soft);
}
.pager .pg {
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-soft);
  font-weight: 500;
  cursor: pointer;
}
.pager .pg:hover { background: #f6f6f8; }
.pager .pg.cur { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Charts (rendered server-side as relative-height bars) */
.chart { display: flex; align-items: flex-end; gap: 7px; height: 150px; padding: 4px 2px 0; }
.chart .bar {
  flex: 1;
  background: linear-gradient(180deg, #c7d2fe, #a5b4fc);
  border-radius: 6px 6px 2px 2px;
  min-width: 10px;
}
.chart .bar.hi { background: linear-gradient(180deg, #6366f1, var(--accent)); }
.chart-x { display: flex; gap: 7px; margin-top: 8px; }
.chart-x span { flex: 1; text-align: center; font-size: 10.5px; color: var(--text-faint); }

.sparkline { height: 32px; display: flex; align-items: flex-end; gap: 2px; }
.sparkline i { flex: 1; background: #c7d2fe; border-radius: 2px; }

/* Progress / coverage bars */
.meter { background: #eef0f4; border-radius: 999px; height: 7px; overflow: hidden; min-width: 80px; }
.meter i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #6366f1, var(--accent)); }
.meter.ok i { background: linear-gradient(90deg, #10b981, var(--ok)); }
.meter.warn i { background: linear-gradient(90deg, #f59e0b, #d97706); }

/* Map: shell = left sidebar + map area */
.map-wrap { position: relative; display: flex; background: #e3e9f0; overflow: hidden; }
.map-area { position: relative; flex: 1; min-width: 0; }
.map-canvas { width: 100%; height: 100%; display: block; }

/* Map: small inline locator on the taxpayer detail page */
.taxpayer-map {
  height: 200px; width: 100%; margin-top: 12px;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.map-panel {
  position: absolute;
  z-index: 1;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 12px 14px;
  font-size: 12px;
}
.map-panel strong { font-size: 12px; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.legend-square { border-radius: 2px; }

/* "My location" (GeolocateControl): bright blue dot, matching the mobile app. */
.maplibregl-user-location-dot,
.maplibregl-user-location-dot::before { background-color: #1e88e5; }

/* Map: blocking loading overlay shown while filtered data reloads */
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  cursor: progress;
}
.map-loading[hidden] { display: none; }
.map-loading-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-soft);
}
.map-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-soft);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .map-spinner { animation-duration: 1.6s; }
  .map-loading { -webkit-backdrop-filter: none; backdrop-filter: none; }
}

/* Map: control sidebar (drill selectors + layer toggles + stats card) */
.map-sidebar {
  flex: 0 0 272px;
  width: 272px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.map-drill { display: flex; flex-direction: column; gap: 10px; }
.map-field { display: flex; flex-direction: column; gap: 4px; }
.map-field > span {
  font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-faint);
}
.map-select {
  width: 100%;
  padding: 7px 8px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}
.map-select:disabled { background: #f6f7f9; color: var(--text-faint); cursor: not-allowed; }

.map-layers { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.map-side-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); margin-bottom: 6px;
}
.layer-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; font-size: 12.5px; cursor: pointer;
}
.layer-row input { accent-color: var(--accent); }

.map-stats { margin: 0; }
/* Selected-area stats: label on top, value below; numbers in a 2-col grid. */
.map-stats-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin: 0; }
.map-stats-kv > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.map-stats-kv .span-2 { grid-column: 1 / -1; }
.map-stats-kv dt { font-size: 12.5px; color: var(--text-faint); }
.map-stats-kv dd { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.map-note { font-size: 11px; line-height: 1.45; margin: auto 0 0; }

/* Map: floating panels (back button, legend) */
.map-back { font-weight: 600; color: var(--accent); text-decoration: none; }
.map-back:hover { text-decoration: underline; }
.map-legend { line-height: 1.75; }

/* Map: popups */
.maplibregl-popup-content { padding: 10px 12px; font-size: 12px; border-radius: var(--radius-sm); }
.map-pop strong { display: block; margin-bottom: 4px; }
.map-pop a { display: inline-block; margin-top: 6px; color: var(--accent); text-decoration: none; font-weight: 600; }
.map-pop a:hover { text-decoration: underline; }

/* Modal (HTMX-loaded into #modal-host) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(17,21,28,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(17,21,28,.30);
  width: min(560px, 100%);
  max-height: 85vh;
  overflow: auto;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0 0 2px; font-size: 17px; }
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); }
.modal-close { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-faint); padding: 0 4px; }
.modal-close:hover { color: var(--text); }

/* Key-value lists */
.kv { display: grid; grid-template-columns: 130px 1fr; row-gap: 8px; font-size: 12.5px; }
.kv dt { color: var(--text-faint); }
.kv dd { font-weight: 500; }

/* Misc */
.muted { color: var(--text-faint); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.right { text-align: right; }
.mt { margin-top: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.w-2 { grid-column: span 2; }

.note {
  background: var(--warn-soft);
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 9px 13px;
  font-size: 12px;
  color: #92400e;
}

/* ===== Web-app additions (beyond the static mock) ===== */

/* Sortable datatable headers */
table.data th.sortable a {
  color: var(--text-faint);
  text-decoration: none;
  font-weight: 550;
  cursor: pointer;
  display: inline-flex;
  gap: 4px;
}
table.data th.sortable a:hover { color: var(--text); }
table.data th.sortable .arrow { color: var(--accent); }
.dt-empty { padding: 28px 14px; text-align: center; color: var(--text-faint); }
.htmx-request .dt-busy { opacity: .55; transition: opacity .12s; }

/* Auth / login */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.auth-card { width: 360px; }
.auth-card .auth-head {
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 16px 16px;
  text-align: center;
}
.auth-card .auth-head .auth-logo {
  width: 48px;
  height: 48px;
  border-radius: 11px;
  box-shadow: var(--shadow-md);
  margin-bottom: 4px;
}
.auth-card .card-body { padding: 22px; }
.auth-card label { display: block; font-size: 11.5px; color: var(--text-faint); font-weight: 550; margin: 10px 0 4px; }
.auth-card input { width: 100%; }
.auth-error { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius-sm); padding: 8px 11px; font-size: 12px; font-weight: 500; }
.full-w { width: 100%; justify-content: center; margin-top: 16px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: block; font-size: 11.5px; color: var(--text-faint); font-weight: 550; margin-bottom: 4px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
.field-full { grid-column: span 2; }

/* Page size selector */
.page-size { margin-left: auto; display: flex; align-items: center; gap: 6px; color: var(--text-faint); }
.page-size .pg.cur { background: var(--accent); border-color: var(--accent); color: #fff; }
