/* CPF Patrol System — tokens and components from docs/DESIGN_SPEC.md section 4.
   Dark, low-glare, night-patrol UI. Keep token names; don't invent colours. */
:root {
  --navy:        #0B1D35;
  --navy-mid:    #132840;
  --navy-light:  #1E3A52;
  --navy-border: #2A4A65;
  --teal:        #00C9A7;
  --teal-dim:    #00956F;
  --amber:       #F5A623;
  --red:         #E8402A;
  --red-dim:     #C03020;
  --green:       #2ECC71;
  --blue:        #3B9EDB;
  --text-primary:   #F0F4F8;
  --text-secondary: #8FA8BF;
  --text-muted:     #6E86A0; /* spec #556B82 lifted for 4.5:1 on navy-mid */
  --sidebar-w: 220px;
  --topbar-h: 52px;
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--navy);
  color: var(--text-primary);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
.muted { color: var(--text-secondary); }
.faint { color: var(--text-muted); }
.small { font-size: 11px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.c-teal { color: var(--teal); } .c-amber { color: var(--amber); } .c-red { color: var(--red); }
.c-green { color: var(--green); } .c-blue { color: var(--blue); }

/* ------------------------------------------------------------ app shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--navy-mid); border-right: 1px solid var(--navy-border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--navy-border); min-height: var(--topbar-h); }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--teal); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 20px; height: 20px; }
.brand-text { min-width: 0; }
.brand-text b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text span { font-size: 11px; color: var(--text-secondary); }
.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-height: 44px;
  border-radius: 8px; color: var(--text-secondary); font-size: 13px; text-decoration: none; border: 1px solid transparent;
}
.nav a:hover { background: var(--navy-light); color: var(--text-primary); }
.nav a.on { background: rgba(0, 201, 167, .1); color: var(--teal); border-color: rgba(0, 201, 167, .25); }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a.sos-link svg { color: var(--red); }
.nav .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 10px; font-size: 10px; font-weight: 700; padding: 1px 6px; min-width: 18px; text-align: center; }
.nav-sep { height: 1px; background: var(--navy-border); margin: 6px 4px; }
.side-foot { padding: 10px; border-top: 1px solid var(--navy-border); }
.duty-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px solid var(--navy-border); border-radius: 10px; background: var(--navy); }
.duty-box b { font-size: 13px; }
.duty-sub { font-size: 11px; color: var(--text-muted); text-align: center; margin-top: 6px; }
.duty-sub .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); margin-right: 4px; vertical-align: middle; }
.duty-sub.on .dot { background: var(--green); }
.side-links { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 11px; }
.side-links form { margin: 0; }
.linkish { background: none; border: 0; color: var(--text-secondary); font: inherit; cursor: pointer; padding: 6px 0; }
.linkish:hover { color: var(--text-primary); text-decoration: underline; }
.credit { font-size: 10.5px; color: var(--text-muted); text-align: center; margin-top: 8px; }
.credit a { color: var(--text-secondary); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 20px;
  background: var(--navy-mid); border-bottom: 1px solid var(--navy-border); position: sticky; top: 0; z-index: 15;
}
.topbar h1 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.duty-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; border: 1px solid var(--navy-border); color: var(--text-secondary); }
.duty-badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.duty-badge.on { color: var(--green); border-color: rgba(46, 204, 113, .4); background: rgba(46, 204, 113, .1); }
.duty-badge.on::before { background: var(--green); }
.conn { font-size: 11px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 5px; }
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }
.conn.ok::before { background: var(--teal); }
.conn.bad { color: var(--amber); }
.conn.bad::before { background: var(--amber); }
.clock { font-variant-numeric: tabular-nums; color: var(--text-secondary); font-size: 12px; }
.content { padding: 20px; flex: 1; }
.content.narrow { max-width: 680px; }
.content.mid { max-width: 1000px; }

/* --------------------------------------------------------------- SOS banner */
.sos-banner {
  position: sticky; top: 0; z-index: 50; background: var(--red); color: #fff;
  display: flex; align-items: center; gap: 12px; padding: 10px 20px; font-weight: 700;
}
.sos-banner .grow { flex: 1; min-width: 0; }
.sos-banner small { font-weight: 400; opacity: .9; display: block; }
.sos-banner + .sos-banner { border-top: 1px solid rgba(255, 255, 255, .3); }
.sos-banner .btn { background: #fff; color: var(--red-dim); border-color: #fff; }
.sos-banner .btn.ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .6); }
.sos-banner.acked { background: var(--red-dim); }

/* ------------------------------------------------------------------ cards */
.card { background: var(--navy-mid); border: 1px solid var(--navy-border); border-radius: 10px; padding: 14px 16px; }
.card + .card, .stack > * + * { margin-top: 14px; }
.label, .card-title {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-secondary); margin: 0 0 10px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head .card-title { margin: 0; }
.grid-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.grid-stats.three { grid-template-columns: repeat(3, 1fr); }
.stat .value { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat .value small { font-size: 14px; }
.stat .sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; align-items: start; }
.side-stack > * + * { margin-top: 14px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
  padding: 2px 7px; border-radius: 4px; white-space: nowrap; line-height: 1.5;
  background: rgba(143, 168, 191, .15); color: var(--text-secondary);
}
.b-teal { background: rgba(0, 201, 167, .15); color: var(--teal); }
.b-green { background: rgba(46, 204, 113, .15); color: var(--green); }
.b-amber { background: rgba(245, 166, 35, .15); color: var(--amber); }
.b-red { background: rgba(232, 64, 42, .18); color: #FF6B55; }
.b-blue { background: rgba(59, 158, 219, .15); color: var(--blue); }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--teal);
  background: var(--teal); color: var(--navy); font: 700 13px var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--teal-dim); border-color: var(--teal-dim); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: var(--navy-border); color: var(--text-secondary); font-weight: 600; }
.btn.ghost:hover { background: var(--navy-light); color: var(--text-primary); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { background: var(--red-dim); border-color: var(--red-dim); }
.btn.warn { background: var(--amber); border-color: var(--amber); color: var(--navy); }
.btn.sm { min-height: 28px; padding: 3px 10px; font-size: 12px; }
.btn.lg { min-height: 50px; font-size: 15px; width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ----------------------------------------------------------------- forms */
.field { margin-bottom: 14px; }
.field > label, .field-label { display: block; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-secondary); margin-bottom: 6px; }
.field .hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], input[type=time],
input[type=number], input[type=search], select, textarea {
  width: 100%; background: var(--navy); color: var(--text-primary); border: 1px solid var(--navy-border);
  border-radius: 8px; padding: 10px 12px; font: 13px var(--font); min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 2px rgba(0, 201, 167, .2); }
input[readonly] { color: var(--teal); }
::placeholder { color: var(--text-muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.check { display: flex; gap: 8px; align-items: center; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--teal); }

.toggle { position: relative; width: 38px; height: 22px; flex: none; display: inline-block; }
.toggle input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.toggle span { position: absolute; inset: 0; background: var(--navy-border); border-radius: 22px; transition: .2s; }
.toggle span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; }
.toggle input:checked + span { background: var(--teal); }
.toggle input:checked + span::after { transform: translateX(16px); }
.toggle input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 2px; }

/* --------------------------------------------------------------- flashes */
.flashes { margin-bottom: 14px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; border: 1px solid; font-size: 13px; }
.flash.ok { border-color: rgba(0, 201, 167, .4); background: rgba(0, 201, 167, .1); }
.flash.error { border-color: rgba(232, 64, 42, .5); background: rgba(232, 64, 42, .12); }
.flash.info { border-color: var(--navy-border); background: var(--navy-light); }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); }
.toast {
  background: var(--navy-light); border: 1px solid var(--navy-border); border-left: 4px solid var(--teal);
  padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .35); animation: slide-up .25s ease-out;
}
.toast.error, .toast.sos { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
.toast.info { border-left-color: var(--blue); }
@keyframes slide-up { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------- login screen */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 440px; background: var(--navy-mid); border: 1px solid var(--navy-border); border-radius: 16px; padding: 36px 28px 22px; }
.login-card .logo { width: 72px; height: 72px; border-radius: 16px; background: var(--teal); display: grid; place-items: center; margin: 0 auto 18px; }
.login-card .logo svg { width: 38px; height: 38px; }
.login-card h1 { text-align: center; font-size: 22px; }
.login-card .tagline { text-align: center; color: var(--text-secondary); margin: 6px 0 24px; }
.role-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 22px; }
.role-tabs label { position: relative; }
.role-tabs input { position: absolute; opacity: 0; }
.role-tabs span {
  display: grid; place-items: center; min-height: 46px; border: 1px solid var(--navy-border); border-radius: 8px;
  color: var(--text-secondary); font-weight: 700; cursor: pointer; text-align: center; padding: 4px;
}
.role-tabs input:checked + span { background: var(--teal); color: var(--navy); border-color: var(--teal); }
.role-tabs input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 2px; }
.login-foot { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 18px; }
.login-credit { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 14px; }
.login-credit a { color: var(--text-secondary); }
.otp-input { font-size: 22px !important; letter-spacing: 6px; text-align: center; }

/* ------------------------------------------------------------------- map */
.map-card { padding: 0; overflow: hidden; position: relative; }
.map { height: calc(100vh - 230px); min-height: 380px; background: var(--navy-light); }
.map.tall { height: calc(100vh - 120px); }
.leaflet-container { background: var(--navy-light); font: 12px var(--font); }
.leaflet-tile-pane { filter: invert(1) hue-rotate(185deg) brightness(.82) contrast(.9) saturate(.5); }
.leaflet-control-zoom a, .leaflet-bar a { background: var(--navy-mid) !important; color: var(--text-primary) !important; border-color: var(--navy-border) !important; }
.leaflet-control-attribution { background: rgba(11, 29, 53, .75) !important; color: var(--text-muted) !important; }
.leaflet-control-attribution a { color: var(--text-secondary) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--navy-mid); color: var(--text-primary); border: 1px solid var(--navy-border); }
.leaflet-popup-content { margin: 10px 12px; font-size: 12px; }
.map-legend {
  position: absolute; left: 12px; top: 12px; z-index: 500; background: rgba(19, 40, 64, .92); border: 1px solid var(--navy-border);
  border-radius: 8px; padding: 8px 10px; font-size: 11px; line-height: 1.8;
}
.map-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.map-tools { position: absolute; right: 12px; top: 12px; z-index: 500; display: flex; flex-direction: column; gap: 6px; }
.map-tools button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--navy-border); background: var(--navy-mid); color: var(--text-primary); font-size: 16px; cursor: pointer; }
.unit-pin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255,255,255,.85); box-shadow: 0 0 0 2px rgba(0,0,0,.3); }
.unit-pin.active { background: var(--green); }
.unit-pin.stationary, .unit-pin.nosignal { background: var(--amber); }
.unit-pin.sos { background: var(--red); animation: pulse 1s infinite; }
.unit-pin.me { background: var(--teal); width: 22px; height: 22px; box-shadow: 0 0 0 6px rgba(0, 201, 167, .3); }
.unit-label { color: var(--text-primary); font-weight: 700; font-size: 12px; text-shadow: 0 1px 2px #000, 0 0 4px #000; white-space: nowrap; }
.inc-pin { width: 0; height: 0; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 18px solid var(--amber); }
.inc-pin.high, .inc-pin.crime_scene { border-bottom-color: var(--red); }
.inc-pin.medical { border-bottom-color: var(--blue); }
.inc-pin.low { border-bottom-color: var(--green); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(232, 64, 42, .8); } 100% { box-shadow: 0 0 0 18px rgba(232, 64, 42, 0); } }

/* -------------------------------------------------------- lists / feeds */
.rows > * + * { border-top: 1px solid var(--navy-border); }
.unit-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.avatar { width: 34px; height: 34px; border-radius: 8px; background: var(--navy-light); color: var(--teal); display: grid; place-items: center; font-weight: 700; font-size: 11px; flex: none; }
.unit-row .who { flex: 1; min-width: 0; }
.unit-row .who b { display: block; }
.unit-row .who span { font-size: 11px; color: var(--text-muted); }
.inc-item { padding: 10px 0; }
.inc-item .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.inc-item p { margin: 6px 0 2px; }
.inc-item .where { font-size: 11px; color: var(--text-muted); }
.feed-card { display: flex; gap: 14px; align-items: flex-start; }
.feed-card + .feed-card { margin-top: 10px; }
.feed-card .body { flex: 1; min-width: 0; }
.feed-card h3 { font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.feed-card p { margin: 4px 0; color: var(--text-secondary); }
.feed-card .actions { display: flex; flex-direction: column; gap: 6px; min-width: 90px; }
.feed-card.sos-row { border-color: rgba(232, 64, 42, .5); }
.sos-strip { margin-top: 10px; padding: 8px 12px; border-radius: 6px; background: rgba(232, 64, 42, .12); border: 1px solid rgba(232, 64, 42, .4); color: #FF6B55; font-weight: 700; font-size: 12px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.seg a, .seg button {
  padding: 7px 14px; min-height: 36px; border-radius: 8px; border: 1px solid var(--navy-border); background: transparent;
  color: var(--text-secondary); font: 600 13px var(--font); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
}
.seg a.on, .seg button.on { border-color: var(--teal); color: var(--teal); background: rgba(0, 201, 167, .08); }
.empty { color: var(--text-muted); padding: 18px 0; text-align: center; }

/* ----------------------------------------------------------- list tables */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input[type=search], .filters input[type=text] { width: 220px; min-height: 36px; padding: 6px 10px; }
.filters select, .filters input[type=date] { width: auto; min-height: 36px; padding: 6px 10px; }
.filters .btn { min-height: 36px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--navy-border); border-radius: 10px; background: var(--navy-mid); }
table.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th, .data-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--navy-border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.data-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-secondary); background: var(--navy-mid); font-weight: 700; }
.data-table tbody tr:hover { background: var(--navy-light); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .ref-cell { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.data-table .title-cell a { color: var(--text-primary); font-weight: 600; }
.data-table .sub { color: var(--text-muted); }
.data-table .empty-row td { text-align: center; color: var(--text-muted); padding: 20px; }
.sort-link { color: inherit; text-decoration: none; }
.sort-link.on { color: var(--teal); }
.sort-arrow { font-size: 9px; margin-left: 4px; }
.list-foot { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.list-controls { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.pager { display: flex; gap: 4px; align-items: center; }
.pager a, .pager span { padding: 4px 9px; border-radius: 6px; border: 1px solid transparent; min-width: 30px; text-align: center; }
.pager a { color: var(--text-secondary); border-color: var(--navy-border); }
.pager a:hover { color: var(--text-primary); text-decoration: none; background: var(--navy-light); }
.pager .on { background: var(--teal); color: var(--navy); font-weight: 700; }
.pager .off { color: var(--text-muted); }
.per-pick a { padding: 2px 6px; color: var(--text-secondary); }
.per-pick a.on { color: var(--teal); font-weight: 700; }

/* ---------------------------------------------------------------- roster */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.day { border: 1px solid var(--navy-border); border-radius: 8px; padding: 10px 4px; text-align: center; background: var(--navy); min-height: 76px; }
.day .d { font-size: 11px; color: var(--text-secondary); }
.day .t { margin-top: 4px; color: var(--text-muted); font-weight: 600; }
.day.on { border-color: var(--teal); background: rgba(0, 201, 167, .08); }
.day.on .t { color: var(--teal); font-weight: 700; }
.day.today { box-shadow: inset 0 0 0 1px var(--text-secondary); }
table.grid { width: 100%; border-collapse: separate; border-spacing: 3px; table-layout: fixed; }
.grid th { font-size: 11px; color: var(--text-secondary); padding: 6px 4px; background: var(--navy); border-radius: 4px; }
.grid th.rowh { text-align: left; padding-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid td { text-align: center; padding: 0; border-radius: 4px; background: var(--navy); color: var(--text-muted); font-size: 11.5px; height: 30px; }
.grid td.yes { background: rgba(0, 201, 167, .2); color: var(--teal); font-weight: 700; }
.grid td.gap { background: rgba(245, 166, 35, .1); color: var(--amber); }
.grid td.today-col { box-shadow: inset 0 0 0 1px var(--text-secondary); }
.grid td button.cell { width: 100%; height: 30px; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; border-radius: 4px; }
.grid td button.cell:hover { background: var(--navy-light); color: var(--text-primary); }
dialog { background: var(--navy-mid); color: var(--text-primary); border: 1px solid var(--navy-border); border-radius: 12px; padding: 18px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin-bottom: 12px; }

/* ------------------------------------------------------------ sectors */
.sector-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sector-card .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.bar { height: 5px; border-radius: 3px; background: var(--navy-light); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--teal); }
.bar.mid > i { background: var(--amber); }
.bar.low > i { background: var(--red); }

/* ---------------------------------------------------------------- comms */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chat-log { min-height: 220px; max-height: 46vh; overflow-y: auto; padding: 4px 2px; display: flex; flex-direction: column; gap: 2px; }
.msg { max-width: 78%; align-self: flex-start; }
.msg .from { font-size: 11px; color: var(--text-muted); margin: 6px 0 3px; }
.msg .bubble { background: var(--navy-light); padding: 9px 12px; border-radius: 10px; word-wrap: break-word; }
.msg .at { font-size: 10.5px; color: var(--text-muted); margin-top: 3px; }
.msg.me { align-self: flex-end; text-align: right; }
.msg.me .bubble { background: rgba(0, 201, 167, .18); text-align: left; }
.msg.joc .bubble { border-left: 3px solid var(--blue); }
.msg audio { height: 34px; max-width: 100%; }
.chat-form { display: flex; gap: 8px; margin-top: 12px; }
.chat-form input { flex: 1; }
.channels { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.ptt-wrap { text-align: center; padding: 10px 0 4px; }
.ptt {
  width: 96px; height: 96px; border-radius: 50%; border: 0; background: var(--blue); color: #fff; font: 800 13px var(--font);
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none;
}
.ptt.rec { background: var(--red); animation: pulse 1s infinite; }
.ptt-note { margin-top: 10px; color: var(--text-secondary); }

/* ------------------------------------------------------------------ SOS */
.sos-card { text-align: center; padding: 28px 16px; }
.panic {
  width: 140px; height: 140px; border-radius: 50%; border: 0; background: var(--red); color: #fff; margin: 16px auto;
  font: 800 26px var(--font); letter-spacing: 1px; cursor: pointer; display: grid; place-items: center; position: relative;
  box-shadow: 0 0 0 10px rgba(232, 64, 42, .15); animation: idle-pulse 2.4s infinite;
  user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none;
}
.panic.holding { animation: pulse .5s infinite; }
.panic.sent { background: var(--red-dim); animation: pulse .9s infinite; }
.panic svg.ring { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); transform: rotate(-90deg); pointer-events: none; }
.panic svg.ring circle { fill: none; stroke: #fff; stroke-width: 5; stroke-dasharray: 465; stroke-dashoffset: 465; }
@keyframes idle-pulse { 0%, 100% { box-shadow: 0 0 0 8px rgba(232, 64, 42, .15); } 50% { box-shadow: 0 0 0 16px rgba(232, 64, 42, .06); } }
.sos-states { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.sos-states span { padding: 5px 10px; border-radius: 16px; border: 1px solid var(--navy-border); font-size: 12px; color: var(--text-muted); }
.sos-states span.done { border-color: var(--teal); color: var(--teal); }
.sos-states span.now { border-color: var(--red); color: #fff; background: var(--red); }
.kv { width: 100%; border-collapse: collapse; }
.kv th, .kv td { text-align: left; padding: 9px 0; border-bottom: 1px solid var(--navy-border); vertical-align: top; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: 0; }
.kv th { color: var(--text-secondary); font-weight: 400; width: 38%; }
.kv td { font-weight: 600; }
.contact { display: flex; justify-content: space-between; padding: 10px 0; font-weight: 700; min-height: 44px; align-items: center; }
.contact a { font-size: 15px; }

/* ----------------------------------------------------- patroller screens */
.quick-types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.quick-types button {
  min-height: 48px; border-radius: 8px; border: 1px solid var(--navy-border); background: transparent; color: var(--text-primary);
  font: 600 13px var(--font); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px;
}
.quick-types button.on { border-color: var(--teal); background: rgba(0, 201, 167, .1); color: var(--teal); }
.quick-types svg { width: 18px; height: 18px; }
.section-title { display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 700; margin: 0 0 12px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--navy-border); }
.attach-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.attach-row label.btn, .attach-row button { position: relative; }
.attach-row input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--navy-border); }
.pos-big { text-align: center; font-size: 22px; font-weight: 700; color: var(--teal); line-height: 1.5; font-variant-numeric: tabular-nums; }
.queue-note { padding: 8px 12px; border-radius: 8px; background: rgba(245, 166, 35, .12); border: 1px solid rgba(245, 166, 35, .4); color: var(--amber); margin-bottom: 12px; font-size: 12px; }
.panel { display: none; }
.panel.on { display: block; }

/* --------------------------------------------------------------- misc */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h2 { font-size: 17px; }
.dl { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; }
.dl dt { color: var(--text-secondary); }
.dl dd { margin: 0; }
.danger-zone { border-color: rgba(232, 64, 42, .45); }
.cred { font-size: 22px; font-weight: 700; color: var(--teal); padding: 14px; border: 1px dashed var(--teal); border-radius: 8px; text-align: center; letter-spacing: .5px; margin: 12px 0; user-select: all; }
.error-page { text-align: center; padding: 60px 16px; }
.error-page .code { font-size: 54px; font-weight: 800; color: var(--text-muted); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--navy-border); font-size: 12px; }
.timeline li:last-child { border-bottom: 0; }
.media-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.media-grid img { max-width: 220px; max-height: 180px; border-radius: 8px; border: 1px solid var(--navy-border); }
.qr { background: #F0F4F8; padding: 10px; border-radius: 10px; display: inline-block; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 900px) {
  .grid-stats, .grid-stats.three { grid-template-columns: 1fr 1fr; }
  .two-col, .split, .sector-grid { grid-template-columns: 1fr; }
  .map { height: 52vh; min-height: 300px; }
  .map.tall { height: 60vh; }
}
@media (max-width: 640px) {
  :root { --sidebar-w: 56px; }
  .brand-text, .nav a .lbl, .side-foot .duty-box b, .duty-sub, .side-links, .credit, .nav .count { display: none; }
  .brand { justify-content: center; padding: 10px 0; }
  .nav { padding: 8px 6px; }
  .nav a { justify-content: center; padding: 10px 0; }
  .side-foot { padding: 8px 4px; }
  .duty-box { padding: 8px 4px; justify-content: center; border: 0; background: transparent; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .clock { display: none; }
  .content { padding: 14px 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .feed-card { flex-direction: column; }
  .feed-card .actions { flex-direction: row; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { margin-top: 6px; }
  .week { gap: 4px; }
  .day { padding: 8px 2px; font-size: 11px; }
  .filters input[type=search], .filters input[type=text] { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Leaflet tooltips */
.leaflet-tooltip { background: var(--navy-mid); color: var(--text-primary); border: 1px solid var(--navy-border); box-shadow: none; font-size: 11px; }
.leaflet-tooltip.unit-label-tip { background: transparent; border: 0; box-shadow: none; font-weight: 700; font-size: 12px; text-shadow: 0 1px 2px #000, 0 0 4px #000; padding: 0; }
.leaflet-tooltip.unit-label-tip::before { display: none; }
a.card.stat { color: inherit; text-decoration: none; }
a.card.stat:hover { border-color: var(--teal); }

/* ---------------------------------------------------------------- reports
   Single-hue magnitude charts (teal); numbers always shown as text. */
.stat .value.small-value { font-size: 20px; }
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: 150px 1fr 40px; gap: 8px; align-items: center; font-size: 12px; }
.hbar-label { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 14px; background: var(--navy-light); border-radius: 0 4px 4px 0; overflow: hidden; }
.hbar-track i { display: block; height: 100%; min-width: 2px; background: var(--teal); border-radius: 0 4px 4px 0; }
.hbar-val { text-align: right; font-variant-numeric: tabular-nums; }
.vbars { display: flex; align-items: flex-end; gap: 2px; height: 140px; padding-bottom: 18px; position: relative; border-bottom: 1px solid var(--navy-border); }
.vbar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; min-width: 0; }
.vbar i { display: block; background: var(--teal); border-radius: 4px 4px 0 0; min-height: 0; }
.vbar:hover i { background: var(--teal-dim); }
.vbar span { position: absolute; bottom: -17px; left: 0; font-size: 9.5px; color: var(--text-muted); white-space: nowrap; }
details summary { cursor: pointer; margin-top: 8px; }
table.heat { border-collapse: separate; border-spacing: 2px; width: 100%; font-size: 12px; }
.heat th { text-align: left; color: var(--text-secondary); font-weight: 600; padding: 6px 8px; white-space: nowrap; }
.heat thead th { text-align: center; font-size: 11px; }
.heat td { text-align: center; padding: 6px 8px; border-radius: 4px; font-variant-numeric: tabular-nums; background: var(--navy); }
.heat td.tot { font-weight: 700; background: transparent; }
.custom-date { width: auto !important; }
@media (max-width: 640px) { .hbar { grid-template-columns: 100px 1fr 32px; } }
