:root {
  --brand: #FF8A00;
  --bg: #111418;
  --panel: #1a1f26;
  --panel-2: #222933;
  --text: #e8eaed;
  --muted: #9aa4b2;
  --sev1: #95a5a6;
  --sev2: #f59e0b; /* severity scale, not the brand colour (--brand) */
  --sev3: #e67e22;
  --sev4: #e74c3c;
  --ok: #2ecc71;
}
* { box-sizing: border-box; }
/* Author `display` rules (e.g. .pub-tiles grid) otherwise beat the UA's
   [hidden] rule and elements the JS "hides" stay visible. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
}
:where(a, button, input, select, textarea, .btn):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 2px solid var(--brand);
  position: sticky;
  top: 0;
  z-index: 5;
}
header .brand { font-size: 16px; }
nav { display: flex; gap: 4px; flex: 1; }
nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
}
nav a.active, nav a:hover { color: var(--text); background: var(--panel-2); }
.user { color: var(--muted); display: flex; gap: 12px; }
.user a { color: var(--muted); }
main { padding: 20px; max-width: 1200px; margin: 0 auto; }

h2 { margin: 0 0 16px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
select, input, textarea, button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #333c48;
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
}
textarea { width: 100%; }
/* The action-rules JSON editor — monospace/tall belongs here, not on every
   textarea in the app (it used to leak into the public report form). */
.settings-grid textarea { min-height: 220px; font-family: ui-monospace, monospace; }
button { cursor: pointer; }
/* .btn works on <a> too — anchors get none of the element styling above. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid #333c48;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.btn:hover { background: #2a323d; border-color: #46525f; }
.btn.primary, button.primary { background: var(--brand); color: #1a1200; border-color: var(--brand); font-weight: 700; }
.btn.primary:hover { background: #ff9a20; border-color: #ff9a20; }
button.danger { background: #5c2320; border-color: #7a2d29; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #2a323d; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr.clickable:hover { background: var(--panel-2); cursor: pointer; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
/* Status modifiers for the dashboard's AI routing card. Dark text on both
   because the fills are light enough that white would fail contrast. */
.pill.ok { background: var(--ok); color: #06210f; }
.pill.err { background: var(--sev4); color: #2a0a06; }
.sev-1 { background: var(--sev1); color: #10181c; }
.sev-2 { background: var(--sev2); color: #201500; }
.sev-3 { background: var(--sev3); color: #201000; }
.sev-4 { background: var(--sev4); color: #fff; }
.st-open { color: var(--sev4); }
.st-acknowledged { color: var(--sev2); }
.st-in_progress { color: #3498db; }
.st-resolved { color: var(--ok); }
.st-dismissed { color: var(--muted); }

.detail {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(560px, 100vw);
  background: var(--panel);
  border-left: 1px solid #2a323d;
  padding: 20px;
  overflow-y: auto;
  z-index: 10;
}
.detail img { max-width: 100%; border-radius: 8px; }
.detail .close { float: right; }
.detail .row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.muted { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--panel); border-radius: 8px; padding: 14px; }
.card .big { font-size: 26px; font-weight: 700; }
.bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar > div { height: 100%; background: var(--brand); }
.settings-grid { display: grid; gap: 16px; max-width: 760px; }
.settings-grid label { display: block; color: var(--muted); margin-bottom: 4px; }
.notice { padding: 10px 14px; border-radius: 6px; background: var(--panel-2); margin: 10px 0; }
.notice.ok { border-left: 3px solid var(--ok); }
.notice.err { border-left: 3px solid var(--sev4); }

/* ── 3D building map ─────────────────────────────────────────────────────── */
.map-wrap { display: flex; gap: 14px; align-items: stretch; }
.map-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  height: calc(100vh - 170px);
  min-height: 420px;
  background: var(--bg);
  border: 1px solid #2a323d;
  border-radius: 8px;
  overflow: hidden;
}
.map-stage canvas { display: block; }
.map-floors {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100% - 20px);
  overflow-y: auto;
}
.map-floors .bldg {
  background: rgba(26, 31, 38, 0.9);
  border: 1px solid #2a323d;
  border-radius: 8px;
  padding: 8px;
  min-width: 120px;
}
.map-floors .lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 600; margin-bottom: 4px; }
.map-floors button { display: block; width: 100%; text-align: left; margin-top: 4px; padding: 4px 10px; }
.map-floors button.active { background: var(--brand); color: #201500; border-color: var(--brand); font-weight: 600; }
.map-tooltip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: rgba(26, 31, 38, 0.95);
  border: 1px solid var(--brand);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}
.map-toast {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: var(--panel);
  border-left: 3px solid var(--ok);
  border-radius: 6px;
  padding: 8px 14px;
}
.map-panel {
  width: 300px;
  flex: none;
  background: var(--panel);
  border-radius: 8px;
  padding: 14px;
  height: calc(100vh - 170px);
  min-height: 420px;
  overflow-y: auto;
}
.map-panel h3 { margin: 0 0 8px; }
.map-panel h3 + .muted { margin-top: 0; }
.map-panel h3:not(:first-child) { margin-top: 18px; }
.map-loc {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #2a323d;
}
.map-loc.pending { background: rgba(245, 158, 11, 0.08); border-radius: 6px; padding: 6px 8px; }
.map-loc button { flex: none; font-size: 12px; padding: 3px 10px; }
@media (max-width: 900px) {
  .map-wrap { flex-direction: column; }
  .map-stage { height: 60vh; }
  .map-panel { width: auto; height: auto; max-height: 40vh; }
}

/* ── Public front doors (landing + report form) ─────────────────────────── */
body.public {
  min-height: 100vh;
  background: radial-gradient(1100px 520px at 50% -240px, #1c222b 0%, var(--bg) 62%);
}
.pub-wrap { max-width: 900px; margin: 0 auto; padding: 22px 20px 56px; }
.pub-wrap.narrow { max-width: 620px; }

/* The bare `header` rule above targets the dashboard (sticky panel bar) —
   neutralize it for the public pages. */
.pub-header {
  position: static;
  background: none;
  border-bottom: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 0 0 26px;
}
.pub-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}
.pub-brand img { height: 26px; width: auto; display: block; flex: none; }
.pub-brand .sub { color: var(--muted); font-weight: 400; }
.pub-header .user { font-size: 13px; align-items: center; }
.pub-header .user a { color: var(--muted); text-decoration: none; }
.pub-header .user a:hover { color: var(--text); }

.pub-hero { margin-bottom: 22px; }
.pub-hero h1 { font-size: clamp(23px, 5vw, 31px); line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 8px; }
.pub-hero p { margin: 0; color: var(--muted); font-size: 15px; max-width: 56ch; }

.emergency {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: linear-gradient(180deg, #3b1512 0%, #2c1310 100%);
  border: 1px solid #7d2f27;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  font-size: 14px;
}
.emergency svg { flex: none; color: var(--sev4); margin-top: 1px; }
.emergency a {
  color: #ffb3ab;
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 179, 171, 0.4);
}

.pub-card {
  background: var(--panel);
  border: 1px solid #262e39;
  border-radius: 16px;
  padding: 22px;
  margin-bottom: 18px;
}
.pub-card h2 { margin: 0 0 8px; font-size: 19px; }
.pub-card > p { color: var(--muted); margin: 0 0 16px; }
.gate-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.gate-actions .btn { flex: 1 1 210px; min-height: 46px; }

/* Tiles: 2×2 on desktop so four options sit evenly. */
.pub-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.pub-tile {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid #262e39;
  border-radius: 14px;
  padding: 18px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.pub-tile:hover { border-color: var(--brand); background: #1e242d; transform: translateY(-2px); }
.tile-ico {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255, 138, 0, 0.13);
  color: var(--brand);
}
.pub-tile[data-kind='complaint'] .tile-ico { background: rgba(245, 158, 11, 0.13); color: var(--sev2); }
.pub-tile[data-kind='security'] .tile-ico { background: rgba(231, 76, 60, 0.13); color: var(--sev4); }
.pub-tile[data-kind='lost'] .tile-ico { background: rgba(154, 164, 178, 0.13); color: var(--muted); }
.tile-body { min-width: 0; }
.tile-body h3 { margin: 2px 0 5px; font-size: 16px; }
.tile-body p { margin: 0; font-size: 13.5px; color: var(--muted); }
.tile-ext { margin-left: auto; flex: none; color: var(--muted); }

/* Report form */
.field { margin-bottom: 18px; }
.field:last-of-type { margin-bottom: 0; }
.field > label { display: block; font-weight: 600; margin-bottom: 7px; }
.field .hint { color: var(--muted); font-weight: 400; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row > * { flex: 1 1 200px; }
.pub-card input[type='text'],
.pub-card textarea,
.pub-card select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  /* 16px keeps iOS from zooming the viewport on focus */
  font-size: 16px;
}
.pub-card textarea { min-height: 120px; resize: vertical; line-height: 1.5; }

.type-chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 22px; }
.type-chips button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 13px 6px;
  border-radius: 12px;
  border: 1px solid #2b333f;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.type-chips button:hover { color: var(--text); border-color: #46525f; }
.type-chips button.active { background: rgba(255, 138, 0, 0.13); border-color: var(--brand); color: var(--text); }
.type-chips button.active svg { color: var(--brand); }

/* Photo picker: the native file input is unusable-looking, so it's visually
   hidden behind a labelled drop zone (still focusable + keyboard operable). */
.photo-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.photo-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  border: 1.5px dashed #39424f;
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.photo-drop:hover { border-color: var(--brand); color: var(--text); }
.photo-input:focus-visible + .photo-drop { outline: 2px solid var(--brand); outline-offset: 2px; }
.photo-preview-wrap { position: relative; margin-top: 10px; }
#photo-preview { width: 100%; max-height: 280px; object-fit: cover; border-radius: 12px; display: block; }
.photo-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: rgba(17, 20, 24, 0.85);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
}
.photo-remove:hover { background: var(--sev4); border-color: var(--sev4); }

.btn.big { width: 100%; margin-top: 22px; padding: 14px; font-size: 16px; min-height: 50px; }
.btn[disabled] { opacity: 0.6; cursor: default; }

.pub-card.success { text-align: center; padding: 34px 22px; }
.success-ico {
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(46, 204, 113, 0.14);
  color: var(--ok);
}
.ref-chip {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid #333c48;
  border-radius: 8px;
  padding: 2px 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.success .row { justify-content: center; margin-top: 18px; }

.pub-footer { text-align: center; padding-top: 22px; font-size: 13px; }
.pub-footer a { color: var(--muted); }

/* ── Quick report (beta) ─────────────────────────────────────────────────── */
.quick-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.quick-head h2 { margin: 0; }
.beta-badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(255, 138, 0, 0.16);
  border: 1px solid rgba(255, 138, 0, 0.45);
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.linkish {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}
.linkish:hover { color: var(--text); }
.quick-drop { flex-direction: column; gap: 8px; padding: 34px 18px; font-size: 16px; }
.q-working { display: flex; align-items: center; gap: 12px; padding: 20px 4px; color: var(--muted); }
.spinner {
  width: 20px;
  height: 20px;
  flex: none;
  border: 2px solid #39424f;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
#q-preview { width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; display: block; }
.q-summary { margin: 16px 0 4px; }
.q-summary h3 { margin: 0 0 6px; font-size: 17px; }
.q-summary p { margin: 0 0 8px; font-size: 14px; }
.q-hazard { color: #ffb3ab; }
.q-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.q-chip {
  background: var(--panel-2);
  border: 1px solid #333c48;
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.q-dialog {
  border: 1px solid #2b333f;
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  padding: 22px;
  width: min(460px, calc(100vw - 32px));
}
.q-dialog::backdrop { background: rgba(8, 10, 13, 0.72); }
.q-dialog h3 { margin: 0 0 6px; font-size: 18px; }
.q-dialog p { margin: 0 0 14px; }
.q-dialog input[type='text'], .q-dialog select, .q-dialog textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 16px;
  margin-top: 8px;
}
.q-actions { display: flex; gap: 10px; margin-top: 18px; }
.q-actions .btn { flex: 1; min-height: 46px; }

@media (max-width: 720px) {
  /* Bottom sheet on phones — thumb-friendly and familiar. */
  .q-dialog {
    width: 100%;
    max-width: none;
    margin: auto auto 0;
    border-radius: 18px 18px 0 0;
    padding-bottom: max(22px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 720px) {
  .pub-tiles { grid-template-columns: 1fr; }
  .pub-wrap { padding: 18px 16px 44px; }
  .pub-header { padding-bottom: 20px; }
  .pub-card { padding: 18px; border-radius: 14px; }
  .type-chips button { font-size: 12px; padding: 11px 4px; }
}

body.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); padding: 40px; border-radius: 12px; text-align: center; border-top: 3px solid var(--brand); }
.login-card .btn { display: inline-block; margin-top: 12px; text-decoration: none; padding: 10px 18px; border-radius: 8px; }
