/* ==========================================================================
   CivicPulse design system - "civic control room"
   ========================================================================== */

:root {
  --bg: #070b11;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #12324a 0%, transparent 55%),
             radial-gradient(900px 500px at 95% 0%, #1a2f2a 0%, transparent 50%),
             #070b11;
  --surface: #0d141d;
  --surface-2: #121b26;
  --surface-3: #182534;
  --border: #1e2c3c;
  --border-bright: #2b3f56;
  --text: #e8f0f8;
  --muted: #8aa0b6;
  --faint: #5c7186;

  --accent: #2ee6c5;
  --accent-2: #38bdf8;
  --accent-soft: rgba(46, 230, 197, .12);
  --lime: #a3e635;

  --sev-1: #64748b;
  --sev-2: #38bdf8;
  --sev-3: #f59e0b;
  --sev-4: #fb7185;
  --sev-5: #ef4444;

  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, .8);
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.015em; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.space-between { justify-content: space-between; }

/* ------------------------------------------------------------------ brand */

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  box-shadow: 0 0 26px -4px var(--accent);
  flex: none;
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-name { font-weight: 700; letter-spacing: -.02em; font-size: 17px; }
.brand-sub { font-size: 10.5px; text-transform: uppercase; letter-spacing: .16em; color: var(--faint); }

/* ------------------------------------------------------------------ shell */

.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }

.sidebar {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(13, 20, 29, .92), rgba(7, 11, 17, .92));
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em; color: var(--faint); padding: 10px 10px 5px; font-weight: 700; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; font-size: 13.5px;
  border: 1px solid transparent; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(46, 230, 197, .25); }
.nav a .badge { margin-left: auto; }

.main { padding: 22px 26px 60px; max-width: 1500px; width: 100%; }

.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding-bottom: 18px; margin-bottom: 20px; border-bottom: 1px solid var(--border);
}

.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(52, 211, 153, .6); animation: pulse 2.2s infinite; flex: none; }
.live-dot.off { background: var(--danger); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, .55); }
  70% { box-shadow: 0 0 0 9px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

/* ------------------------------------------------------------------ cards */

.card {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.split { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); align-items: start; }

.stat { padding: 15px 16px; }
.stat .value { font-size: 30px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; font-family: var(--mono); }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); font-weight: 700; margin-top: 4px; }
.stat .delta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.stat.accent .value { color: var(--accent); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }
.stat.ok .value { color: var(--ok); }

/* ----------------------------------------------------------------- inputs */

label.field { display: block; margin-bottom: 13px; }
label.field > span { display: block; font-size: 12px; font-weight: 650; color: var(--muted); margin-bottom: 6px; letter-spacing: .02em; }

input, select, textarea {
  width: 100%; padding: 10px 12px;
  background: var(--surface-3);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 14px; font-family: inherit;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 84px; }
select { cursor: pointer; }
input::placeholder, textarea::placeholder { color: var(--faint); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-bright); background: var(--surface-3);
  color: var(--text); font-weight: 600; font-size: 13.5px; font-family: inherit;
  cursor: pointer; transition: transform .08s, filter .15s, background .15s;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.16); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #04231f; font-weight: 700;
}
.btn.danger { background: rgba(248, 113, 113, .14); border-color: rgba(248, 113, 113, .4); color: #fca5a5; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }

/* ----------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  background: var(--surface-3); color: var(--muted); border: 1px solid var(--border-bright);
  white-space: nowrap;
}
.badge.ok { background: rgba(52, 211, 153, .13); color: var(--ok); border-color: rgba(52, 211, 153, .3); }
.badge.warn { background: rgba(251, 191, 36, .13); color: var(--warn); border-color: rgba(251, 191, 36, .3); }
.badge.danger { background: rgba(248, 113, 113, .14); color: var(--danger); border-color: rgba(248, 113, 113, .32); }
.badge.info { background: rgba(56, 189, 248, .13); color: var(--accent-2); border-color: rgba(56, 189, 248, .3); }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: rgba(46, 230, 197, .3); }

.sev { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 700; }
.sev i { width: 8px; height: 8px; border-radius: 2px; display: block; }
.sev-1 i { background: var(--sev-1); } .sev-1 { color: var(--sev-1); }
.sev-2 i { background: var(--sev-2); } .sev-2 { color: var(--sev-2); }
.sev-3 i { background: var(--sev-3); } .sev-3 { color: var(--sev-3); }
.sev-4 i { background: var(--sev-4); } .sev-4 { color: var(--sev-4); }
.sev-5 i { background: var(--sev-5); } .sev-5 { color: var(--sev-5); }

.status { font-family: var(--mono); font-size: 11px; letter-spacing: .05em; }

/* --------------------------------------------------------------- uploader */

.dropzone {
  border: 1.5px dashed var(--border-bright); border-radius: var(--radius);
  padding: 26px 18px; text-align: center; cursor: pointer;
  background: rgba(24, 37, 52, .4); transition: all .18s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 15px; font-weight: 650; margin-bottom: 4px; }

.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 13px; }
.thumb {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--border-bright); background: var(--surface-3);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .angle {
  position: absolute; left: 6px; top: 6px; font-size: 10px; font-weight: 700;
  background: rgba(7, 11, 17, .82); padding: 2px 7px; border-radius: 99px; letter-spacing: .06em;
}
.thumb .gps { position: absolute; right: 6px; top: 6px; font-size: 10px; background: rgba(46,230,197,.9); color:#04231f; padding: 2px 6px; border-radius: 99px; font-weight: 700; }
.thumb .rm {
  position: absolute; right: 5px; bottom: 5px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(7, 11, 17, .85); border: 1px solid var(--border-bright); color: var(--danger);
  cursor: pointer; display: grid; place-items: center; font-size: 13px; line-height: 1;
}

/* ------------------------------------------------------------------ lists */

.issue-list { display: flex; flex-direction: column; gap: 10px; }
.issue-card {
  display: grid; grid-template-columns: 78px 1fr auto; gap: 14px; align-items: center;
  padding: 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; transition: border-color .15s, transform .08s;
}
.issue-card:hover { border-color: var(--border-bright); transform: translateY(-1px); }
.issue-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }
.issue-card .shot { width: 78px; height: 62px; border-radius: 9px; object-fit: cover; background: var(--surface-3); border: 1px solid var(--border); }
.issue-card .title { font-weight: 640; font-size: 14px; }
.issue-card .meta { color: var(--muted); font-size: 12.3px; display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-top: 3px; }

.timeline { border-left: 2px solid var(--border-bright); margin-left: 8px; padding-left: 16px; display: flex; flex-direction: column; gap: 14px; }
.timeline .ev { position: relative; }
.timeline .ev::before {
  content: ''; position: absolute; left: -23px; top: 5px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent-2); border: 2px solid var(--bg);
}
.timeline .ev.sys::before { background: var(--faint); }
.timeline .ev .when { font-size: 11.5px; color: var(--faint); font-family: var(--mono); }

.alert-item {
  padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); border-left-width: 3px;
}
.alert-item.critical { border-left-color: var(--danger); }
.alert-item.warning { border-left-color: var(--warn); }
.alert-item.info { border-left-color: var(--accent-2); }
.alert-item.success { border-left-color: var(--ok); }
.alert-item.unread { background: var(--surface-2); }

/* --------------------------------------------------------------- AI panel */

.ai-panel {
  border: 1px solid rgba(46, 230, 197, .28);
  background: linear-gradient(160deg, rgba(46, 230, 197, .08), rgba(56, 189, 248, .04) 60%, transparent);
  border-radius: var(--radius); padding: 16px;
}
.ai-verdict { display: flex; align-items: center; gap: 13px; margin-bottom: 12px; }
.ai-verdict .cat { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }

.confidence { height: 7px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.confidence i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width .5s ease; }

.evidence-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px;
  background: var(--surface-3); border: 1px solid var(--border-bright);
  border-radius: 99px; font-size: 12px; margin: 3px 4px 0 0;
}
.evidence-chip b { color: var(--accent); font-family: var(--mono); font-size: 11.5px; }

.meter-row { display: grid; grid-template-columns: 1fr 62px 62px 54px; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.meter-row:last-child { border-bottom: none; }

/* ----------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); padding: 8px 10px; border-bottom: 1px solid var(--border-bright); font-weight: 700; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* -------------------------------------------------------------------- map */

#map, .map { height: 420px; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; z-index: 1; background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-bright); }
.leaflet-popup-content { margin: 11px 13px; font-family: var(--sans); font-size: 13px; }
.leaflet-container { background: #0b1219; }
/* Dark basemap without a vendor key: invert + hue-rotate standard OSM tiles. */
.leaflet-tile-pane { filter: invert(1) hue-rotate(185deg) brightness(.94) contrast(.86) saturate(.62); }
.leaflet-control-attribution { display: none; }

/* ------------------------------------------------------------------ modal */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 7, 11, .78); backdrop-filter: blur(5px);
  display: grid; place-items: center; padding: 22px; z-index: 900;
}
.modal {
  width: min(920px, 100%); max-height: 90vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border-bright); border-radius: 18px; padding: 22px;
  box-shadow: 0 40px 90px -30px #000;
}

/* ------------------------------------------------------------------ toast */

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 9px; z-index: 1000; max-width: 380px; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border-bright); border-left: 3px solid var(--accent);
  padding: 12px 15px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  animation: slide-in .28s cubic-bezier(.2, .9, .3, 1.2);
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast.ok { border-left-color: var(--ok); }
.toast .t { font-weight: 650; font-size: 13.5px; margin-bottom: 2px; }
.toast .m { font-size: 12.5px; color: var(--muted); }
@keyframes slide-in { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------- auth */

.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.auth-hero { padding: 54px 52px; display: flex; flex-direction: column; justify-content: space-between; border-right: 1px solid var(--border); }
.auth-form-side { display: grid; place-items: center; padding: 40px 30px; }
.auth-card { width: min(430px, 100%); }

.hero-title { font-size: 44px; line-height: 1.06; letter-spacing: -.035em; font-weight: 750; margin: 26px 0 16px; }
.hero-title em { font-style: normal; background: linear-gradient(120deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pipeline { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 22px; }
.pipeline span { font-size: 11.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; padding: 6px 11px; border: 1px solid var(--border-bright); border-radius: 99px; color: var(--muted); }
.pipeline span.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.demo-account {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; width: 100%;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  cursor: pointer; text-align: left; color: var(--text); font-family: inherit; font-size: 13px;
}
.demo-account:hover { border-color: var(--accent); background: var(--surface-2); }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-3); border-radius: var(--radius-sm); margin-bottom: 18px; }
.tabs button {
  flex: 1; padding: 8px; border: none; background: transparent; color: var(--muted);
  font-weight: 650; font-size: 13px; border-radius: 6px; cursor: pointer; font-family: inherit;
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.4); }

.err { color: #fca5a5; font-size: 13px; background: rgba(248, 113, 113, .1); border: 1px solid rgba(248, 113, 113, .28); padding: 9px 12px; border-radius: var(--radius-sm); margin-bottom: 12px; }

.spinner { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.25); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.scan { position: relative; overflow: hidden; }
.scan::after {
  content: ''; position: absolute; left: 0; right: 0; height: 42%;
  background: linear-gradient(180deg, transparent, rgba(46, 230, 197, .22), transparent);
  animation: scanmove 1.5s ease-in-out infinite;
}
@keyframes scanmove { 0% { top: -42%; } 100% { top: 100%; } }

.empty { text-align: center; padding: 40px 20px; color: var(--faint); }
.empty .big { font-size: 34px; margin-bottom: 8px; opacity: .5; }

.bar-track { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--accent-2); border-radius: 99px; }

.sparkline { display: flex; align-items: flex-end; gap: 3px; height: 54px; }
.sparkline i { flex: 1; background: linear-gradient(180deg, var(--accent), rgba(46,230,197,.18)); border-radius: 2px 2px 0 0; min-height: 2px; }

.ba-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ba-grid .side { border: 1px solid var(--border); border-radius: var(--radius); padding: 11px; }
.ba-grid img { width: 100%; border-radius: 8px; border: 1px solid var(--border); margin-top: 7px; display: block; }

@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.split, .grid.cols-3 { grid-template-columns: 1fr; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; gap: 12px; padding: 12px; }
  .sidebar .nav { flex-direction: row; }
  .nav-label, .sidebar .side-foot { display: none; }
  .main { padding: 16px; }
  .grid.cols-2, .grid.cols-4 { grid-template-columns: 1fr; }
  .thumbs { grid-template-columns: repeat(2, 1fr); }
  .ba-grid { grid-template-columns: 1fr; }
}
