:root {
  color-scheme: dark;
  --bg: #07080d;
  --glass: rgba(10, 12, 21, .83);
  --line: rgba(255,255,255,.15);
  --text: #f7f8fd;
  --muted: #a3aabb;
  --cyan: #00d4ff;
  --orange: #ff6b35;
  --green: #00ff88;
  --purple: #a855f7;
  font-family: Inter, "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body, #map { width: 100%; height: 100%; }
body { margin: 0; overflow: hidden; background: var(--bg); color: var(--text); }
.glass {
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: 0 18px 60px rgba(0,0,0,.28);
  backdrop-filter: blur(16px);
}
.world-header {
  position: absolute;
  z-index: 3;
  top: 18px;
  right: 18px;
  left: 18px;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  padding: 17px 20px;
  border-radius: 18px;
  pointer-events: none;
}
.world-header > * { pointer-events: auto; }
.eyebrow {
  margin: 0 0 4px;
  color: var(--cyan);
  font: 800 10px "JetBrains Mono", Consolas, monospace;
  letter-spacing: .12em;
}
h1 { margin: 0; font-size: clamp(20px, 3vw, 34px); }
.world-header p:last-child { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
nav { display: flex; gap: 8px; }
nav a, button, select, input, textarea {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 11px;
  background: rgba(255,255,255,.06);
  color: var(--text);
  font: inherit;
}
nav a, button {
  text-decoration: none;
  font-size: 11px;
  cursor: pointer;
}
button.active { border-color: var(--cyan); background: rgba(0,212,255,.15); color: var(--cyan); }
button:disabled { cursor: not-allowed; opacity: .5; }
select, input, textarea { width: 100%; }
textarea { resize: vertical; line-height: 1.55; }
option { background: #121621; color: var(--text); }

.control-panel {
  position: absolute;
  z-index: 3;
  top: 128px;
  right: 18px;
  width: min(355px, calc(100% - 36px));
  padding: 18px;
  border-radius: 18px;
}
.clock-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.clock-line span, .clock-line strong { display: block; }
#day-name { color: var(--muted); font-size: 12px; }
#clock { margin-top: 2px; color: var(--cyan); font: 800 34px "JetBrains Mono", Consolas, monospace; direction: ltr; }
.office-state { padding: 7px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.office-state.open { color: var(--green); background: rgba(0,255,136,.11); }
.office-state.closed { color: var(--orange); background: rgba(255,107,53,.12); }
#timeline { width: 100%; margin: 12px 0; accent-color: var(--cyan); }
.speed-controls, .jump-controls { display: flex; flex-wrap: wrap; gap: 6px; }
.jump-controls { margin-top: 7px; direction: ltr; }
.world-mode-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
}
.presence-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin-top: 15px; }
.presence-grid span { padding: 9px; border-radius: 10px; background: rgba(255,255,255,.045); color: var(--muted); font-size: 11px; }
.presence-grid b { color: var(--text); font-size: 16px; }
.route-legend { display: grid; gap: 6px; margin-top: 13px; }
.route-legend span { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; }
.route-legend i { width: 18px; height: 3px; border-radius: 4px; }
.facility-directory {
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.facility-directory > label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}
.facility-list {
  display: grid;
  gap: 6px;
  max-height: 170px;
  margin-top: 8px;
  overflow: auto;
}
.facility-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  width: 100%;
  text-align: right;
  background: rgba(255,255,255,.04);
}
.facility-card strong { font-size: 11px; }
.facility-card small { color: var(--muted); font-size: 9px; }
.facility-card code { color: var(--cyan); font-size: 9px; direction: ltr; }
.claim { max-height: 84px; overflow: auto; margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; line-height: 1.65; }

.compliance-panel {
  position: absolute;
  z-index: 3;
  top: 128px;
  left: 18px;
  width: min(410px, calc(100% - 36px));
  max-height: calc(100% - 180px);
  padding: 17px;
  overflow: auto;
  border-radius: 18px;
}
.panel-heading, .section-heading, .chat-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.panel-heading h2, .chat-heading h2, .section-heading h3 {
  margin: 0;
}
.panel-heading h2 { font-size: 19px; }
.session-pill, .chat-meta code {
  display: inline-flex;
  padding: 6px 8px;
  border: 1px solid rgba(0,212,255,.28);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(0,212,255,.08);
  font: 700 9px "JetBrains Mono", Consolas, monospace;
  direction: ltr;
  white-space: nowrap;
}
.panel-boundary {
  margin: 7px 0 12px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.55;
}
.indicator-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.indicator-card {
  min-height: 68px;
  padding: 9px 7px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 11px;
  background: linear-gradient(145deg, rgba(255,255,255,.055), rgba(255,255,255,.02));
}
.indicator-card strong {
  display: block;
  color: var(--green);
  font: 800 17px "JetBrains Mono", Consolas, monospace;
  direction: ltr;
}
.indicator-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.35;
}
.indicator-card.alert strong { color: var(--orange); }
.indicator-card.money strong { color: var(--purple); font-size: 13px; }
.indicator-bar {
  height: 3px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 9px;
  background: rgba(255,255,255,.09);
}
.indicator-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--green));
}
.campaign-launcher {
  margin-top: 12px;
  border: 1px solid rgba(168,85,247,.3);
  border-radius: 13px;
  background: rgba(168,85,247,.06);
}
.campaign-launcher summary {
  padding: 11px 12px;
  color: #dec8ff;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
#campaign-form {
  display: grid;
  gap: 9px;
  padding: 0 12px 12px;
}
#campaign-form label {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.8;
}
.form-row {
  display: grid;
  grid-template-columns: 105px 1fr;
  gap: 8px;
}
.human-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  border-radius: 9px;
  color: var(--green);
  background: rgba(0,255,136,.07);
  font-size: 9px;
}
.human-badge code {
  color: var(--muted);
  font-size: 8px;
  direction: ltr;
}
.privacy-note {
  margin: 0;
  color: var(--orange);
  font-size: 8px;
}
.primary-action {
  border-color: rgba(0,212,255,.42);
  background: linear-gradient(135deg, rgba(0,212,255,.21), rgba(168,85,247,.19));
  color: #fff;
  font-weight: 800;
}
.ledger-section { margin-top: 13px; }
.section-heading { align-items: center; }
.section-heading h3 { font-size: 13px; }
.campaign-ledger {
  display: grid;
  gap: 7px;
  margin-top: 8px;
}
.empty-state {
  padding: 15px;
  border: 1px dashed var(--line);
  border-radius: 11px;
  color: var(--muted);
  text-align: center;
  font-size: 10px;
}
.campaign-card {
  width: 100%;
  padding: 10px;
  text-align: right;
  background: rgba(255,255,255,.04);
}
.campaign-card.active { border-color: var(--orange); background: rgba(255,107,53,.08); }
.campaign-card strong, .campaign-card span { display: block; }
.campaign-card strong { font-size: 11px; }
.campaign-card span { margin-top: 4px; color: var(--muted); font-size: 9px; }
.campaign-card .campaign-stats {
  display: flex;
  gap: 10px;
  margin-top: 7px;
  color: var(--text);
  font-size: 9px;
}
.campaign-outcomes {
  display: grid;
  gap: 5px;
  margin: -2px 0 4px;
  padding: 0 7px 7px;
  border-right: 2px solid rgba(255,107,53,.35);
}
.inspection-outcome {
  display: grid;
  gap: 3px;
  width: 100%;
  text-align: right;
  background: rgba(255,255,255,.025);
}
.inspection-outcome strong { font-size: 10px; }
.inspection-outcome span, .inspection-outcome small { color: var(--muted); font-size: 8px; }
.inspection-outcome.escalated { border-color: rgba(255,49,88,.5); }
.inspection-outcome.remediation-required { border-color: rgba(255,107,53,.4); }

.chat-drawer {
  position: absolute;
  z-index: 7;
  left: 18px;
  bottom: 40px;
  display: none;
  width: min(430px, calc(100% - 36px));
  max-height: min(620px, calc(100% - 58px));
  padding: 16px;
  border-radius: 18px;
}
.chat-drawer.open {
  display: flex;
  flex-direction: column;
}
.chat-heading h2 { font-size: 19px; }
#close-chat {
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 22px;
}
.chat-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 9px;
}
.chat-meta span {
  padding: 5px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,.055);
}
.chat-responsibility {
  margin: 9px 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.55;
}
.chat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 7px;
  min-height: 110px;
  max-height: 270px;
  padding: 10px;
  overflow: auto;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  background: rgba(0,0,0,.18);
}
.chat-message {
  max-width: 88%;
  padding: 9px 10px;
  border-radius: 11px;
  font-size: 10px;
  line-height: 1.65;
  white-space: pre-wrap;
}
.chat-message.user {
  align-self: flex-start;
  border-bottom-right-radius: 3px;
  background: rgba(0,212,255,.12);
}
.chat-message.employee {
  align-self: flex-end;
  border-bottom-left-radius: 3px;
  background: rgba(168,85,247,.14);
}
.chat-message.system {
  align-self: center;
  max-width: 100%;
  color: var(--orange);
  text-align: center;
  background: rgba(255,107,53,.08);
}
.chat-route {
  margin-top: 8px;
  padding: 9px;
  border: 1px solid rgba(0,255,136,.24);
  border-radius: 10px;
  color: var(--green);
  background: rgba(0,255,136,.06);
  font-size: 9px;
}
.chat-route button { margin-top: 6px; width: 100%; }
#chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px;
  margin-top: 8px;
}
#chat-input { min-height: 54px; }
.chat-boundary {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 8px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.map-status {
  position: absolute;
  z-index: 4;
  left: 18px;
  bottom: 40px;
  padding: 10px 13px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 11px;
}
.map-status.ready { color: var(--green); }
.map-status.failed { color: var(--orange); }
footer {
  position: absolute;
  z-index: 3;
  right: 18px;
  bottom: 10px;
  left: 18px;
  color: rgba(255,255,255,.68);
  font-size: 9px;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: 25px; }
.maplibregl-popup-content { background: #111522; color: var(--text); border: 1px solid var(--line); border-radius: 12px; }
.maplibregl-popup-tip { border-top-color: #111522 !important; }
.maplibregl-popup-content button { width: 100%; margin-top: 7px; }

@media (max-width: 700px) {
  .world-header { right: 9px; left: 9px; top: 9px; padding: 13px; }
  .world-header p:last-child { display: none; }
  .control-panel { top: 102px; right: 9px; width: calc(100% - 18px); padding: 13px; }
  .claim, .route-legend { display: none; }
  .presence-grid { grid-template-columns: repeat(4, 1fr); }
  .presence-grid span { padding: 7px 4px; text-align: center; }
  .presence-grid b { display: block; }
  .compliance-panel {
    top: auto;
    right: 9px;
    bottom: 34px;
    left: 9px;
    width: auto;
    max-height: 42vh;
    padding: 12px;
  }
  .indicator-grid { grid-template-columns: repeat(4, 1fr); }
  .indicator-card { min-height: 58px; padding: 7px 5px; }
  .indicator-card strong { font-size: 14px; }
  .campaign-launcher:not([open]) + .ledger-section { margin-top: 7px; }
  .chat-drawer {
    right: 9px;
    bottom: 9px;
    left: 9px;
    width: auto;
    max-height: calc(100% - 18px);
  }
}
