:root {
  --bg: #070b13;
  --bg-2: #0b1120;
  --panel: #111827;
  --panel-2: #0e1626;
  --border: #1f2a3d;
  --border-2: #2a3b57;
  --text: #e6edf6;
  --muted: #8aa0bd;
  --muted-2: #5f7290;
  --accent: #2dd4bf;
  --accent-2: #38bdf8;
  --accent-3: #818cf8;
  --low: #22c55e;
  --medium: #f59e0b;
  --high: #fb923c;
  --critical: #ef4444;
  --mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html {
  height: 100%;
  margin: 0;
  overflow-x: hidden;
  width: 100%;
  -webkit-text-size-adjust: 100%;
}
body {
  height: 100%;
  margin: 0;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  font-family: var(--sans);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(45, 212, 191, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(56, 189, 248, 0.07), transparent 55%),
    var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.95), rgba(11, 17, 32, 0.85));
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
  max-width: 100%;
  overflow: hidden;
}
.topbar-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  width: 100%;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand-text { min-width: 0; }
.brand img { height: 38px; width: auto; display: block; flex-shrink: 0; filter: drop-shadow(0 0 10px rgba(45,212,191,.25)); }
.brand .title { font-size: 17px; font-weight: 700; letter-spacing: 0.4px; line-height: 1.2; }
.brand .title span { color: var(--accent); }
.brand .subtitle { font-size: 11px; color: var(--muted); letter-spacing: 1.2px; text-transform: uppercase; }

.user-picker-compact {
  flex-shrink: 0;
  max-width: 42%;
  font-size: 13px;
  padding: 7px 8px;
}

.pills { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; width: 100%; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.pill b { color: var(--text); font-weight: 600; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--low); box-shadow: 0 0 8px var(--low); }
.pill.warn .dot { background: var(--medium); box-shadow: 0 0 8px var(--medium); }
.pill.live .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: blink 1.6s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.35} }

.user-select { display: flex; align-items: center; gap: 8px; }
.mobile-api-panel { display: none; }
.mobile-hero { display: none; }
.mobile-feed-preview { display: none; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent-2);
  font-size: inherit;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.hero-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  text-align: center;
}
.hero-stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 8px;
}
.hero-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
}
.hero-value.accent { color: var(--accent); }
.hero-value.warn { color: var(--medium); }
.hero-value.bad { color: var(--critical); }
.hero-label {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.hero-sub { margin: 12px 0 0; font-size: 13px; line-height: 1.4; }
.feed-compact { max-height: 220px; overflow-y: auto; gap: 8px; }
.mobile-link-list { display: flex; flex-direction: column; gap: 10px; }
.mobile-link-btn {
  display: block;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--accent-2);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}
.mobile-link-btn:active { background: rgba(45, 212, 191, 0.12); border-color: var(--accent); }
.mobile-api-hint { font-size: 13px; line-height: 1.45; margin: 0 0 14px; }
select, input[type=text], textarea {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font-family: var(--sans); font-size: 13px;
}
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; width: 100%; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); }

.btn {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border-2); border-radius: 8px;
  padding: 7px 13px; font-size: 13px; cursor: pointer; font-weight: 500;
  transition: all .15s ease;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: linear-gradient(180deg, #14b8a6, #0d9488); border-color: #0d9488; color: #06231f; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); color: #06231f; }
.btn.sm { padding: 4px 9px; font-size: 12px; }

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr 460px;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 60px - 36px - 32px);
  min-height: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
.col { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: hidden; }
.col.scroll { overflow-y: auto; }

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  min-width: 0;
  max-width: 100%;
}
.card h2 {
  margin: 0 0 12px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--muted); font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
}
.card h2 .hint { font-size: 10px; color: var(--muted-2); letter-spacing: 0.5px; text-transform: none; }

/* ===== KPI tiles ===== */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
}
.kpi .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi .value.accent { color: var(--accent); }
.kpi .value.warn { color: var(--medium); }
.kpi .value.bad { color: var(--critical); }
.kpi .delta { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ===== Workflows ===== */
.workflow { margin-bottom: 8px; }
.workflow-btn {
  width: 100%; text-align: left; padding: 11px 12px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--border); cursor: pointer;
  color: var(--text); transition: all .15s ease;
}
.workflow-btn:hover { border-color: var(--accent); transform: translateX(2px); }
.workflow-btn .wf-title { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.workflow-btn .wf-desc { font-size: 11px; color: var(--muted); margin-top: 3px; }
.wf-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 6px; font-size: 11px; font-weight: 700;
  background: rgba(45,212,191,.12); color: var(--accent); border: 1px solid rgba(45,212,191,.3);
}

/* ===== Onboarding panel ===== */
.onboarding-card { border-color: rgba(45, 212, 191, 0.22); }
.onb-lead { margin: 0 0 12px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.onb-lead strong { color: var(--text); }
.onb-lead code { font-family: var(--mono); font-size: 11px; color: var(--accent-2); }

.onb-entity-chain {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-bottom: 12px; padding: 10px 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  font-size: 11px;
}
.onb-entity {
  padding: 4px 8px; border-radius: 6px;
  background: rgba(56, 189, 248, 0.1); border: 1px solid rgba(56, 189, 248, 0.25);
  color: var(--accent-2); font-weight: 600;
}
.onb-arrow { color: var(--muted-2); font-size: 10px; }

.onb-rbac {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 9px 11px; border-radius: 10px; font-size: 12px; line-height: 1.45;
  margin-bottom: 12px; border: 1px solid var(--border);
}
.onb-rbac .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 4px; }
.onb-rbac.ok { background: rgba(34, 197, 94, 0.08); border-color: rgba(34, 197, 94, 0.25); color: var(--muted); }
.onb-rbac.ok .dot { background: var(--low); }
.onb-rbac.ok b { color: var(--low); }
.onb-rbac.warn { background: rgba(245, 158, 11, 0.08); border-color: rgba(245, 158, 11, 0.25); color: var(--muted); }
.onb-rbac.warn .dot { background: var(--medium); }
.onb-rbac.warn b { color: var(--medium); }

.onb-phases { display: flex; flex-direction: column; gap: 8px; }
.onb-phase {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel-2); overflow: hidden;
}
.onb-phase-summary {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto;
  gap: 2px 10px; padding: 10px 12px; cursor: pointer; list-style: none;
  align-items: center;
}
.onb-phase-summary::-webkit-details-marker { display: none; }
.onb-phase-num {
  grid-row: 1 / span 2;
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 7px; font-size: 11px; font-weight: 700;
  background: rgba(45, 212, 191, 0.12); color: var(--accent); border: 1px solid rgba(45, 212, 191, 0.3);
}
.onb-phase-title { font-weight: 600; font-size: 13px; color: var(--text); }
.onb-phase-when { grid-column: 2; font-size: 11px; }
.onb-phase-body { padding: 0 12px 12px; border-top: 1px solid var(--border); }
.onb-phase-desc { margin: 10px 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
.onb-phase-desc code { font-family: var(--mono); font-size: 11px; color: var(--accent-2); }

.onb-paths { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.onb-path { padding: 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.15); border: 1px solid var(--border); }
.onb-path-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.onb-path-code { font-family: var(--mono); font-size: 11px; color: var(--text); word-break: break-all; }
.onb-path-meta { font-size: 11px; line-height: 1.4; margin-bottom: 8px; }
.onb-doc-link { color: var(--accent-2); text-decoration: none; }
.onb-doc-link:hover { text-decoration: underline; }
.onb-open-btn { margin-top: 2px; }

.onb-verify .onb-phase-num { background: rgba(34, 197, 94, 0.12); color: var(--low); border-color: rgba(34, 197, 94, 0.3); }
.onb-verify-list { list-style: none; margin: 0; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.onb-verify-item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center;
  padding: 8px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.12); border: 1px solid var(--border);
  font-size: 12px;
}
.onb-verify-item code { grid-column: 1 / -1; font-family: var(--mono); font-size: 10px; }

.onb-caveats {
  margin-top: 10px; border: 1px dashed var(--border); border-radius: 10px;
  padding: 0 12px; font-size: 12px; color: var(--muted);
}
.onb-caveats summary { cursor: pointer; padding: 10px 0; font-weight: 600; color: var(--muted); list-style: none; }
.onb-caveats summary::-webkit-details-marker { display: none; }
.onb-caveats ul { margin: 0 0 12px; padding-left: 18px; line-height: 1.5; }
.onb-caveats code { font-family: var(--mono); font-size: 11px; color: var(--accent-2); }

/* ===== Map ===== */
.map-card { flex: 1; min-height: 0; padding: 0; overflow: hidden; position: relative; }
.map-card::after {
  content: "";
  position: absolute; bottom: 48px; right: 52px; z-index: 4;
  width: 72px; height: 72px; opacity: 0.07; pointer-events: none;
  background: url("/static/logo.png") center/contain no-repeat;
}
#map { position: absolute; inset: 0; }
.map-legend {
  position: absolute; bottom: 12px; left: 12px; z-index: 5;
  background: rgba(11,17,32,.85); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; font-size: 11px; backdrop-filter: blur(6px);
}
.map-legend .row { display: flex; align-items: center; gap: 7px; margin: 3px 0; color: var(--muted); }
.map-legend .marker-dot { width: 10px; height: 10px; border-radius: 50%; }
.map-overlay-title {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  background: rgba(11,17,32,.85); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 12px; font-size: 12px; backdrop-filter: blur(6px);
}
.map-overlay-title b { color: var(--accent); }

.asset-marker {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.4), 0 0 10px currentColor;
  cursor: pointer;
}

/* ===== Live feed ===== */
.feed-card { height: 220px; display: flex; flex-direction: column; }
.feed { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.feed-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 7px 9px; border-radius: 8px; background: var(--panel-2);
  border-left: 3px solid var(--accent-2); font-size: 12px;
  animation: slideIn .3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px);} to {opacity:1; transform:none;} }
.feed-item .fi-time { color: var(--muted-2); font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.feed-item .fi-body { flex: 1; }
.feed-item .fi-type { font-weight: 600; color: var(--accent-2); }
.feed-item.sev-high { border-left-color: var(--high); }
.feed-item.sev-high .fi-type { color: var(--high); }
.feed-item.sev-critical { border-left-color: var(--critical); }
.feed-item.sev-critical .fi-type { color: var(--critical); }

/* ===== Explorer ===== */
.explorer { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.explorer-search { margin-bottom: 10px; width: 100%; }
.endpoint-groups { overflow-y: auto; flex: 1; padding-right: 4px; }
.eg-tag { margin-bottom: 6px; }
.eg-tag > summary {
  cursor: pointer; padding: 7px 8px; border-radius: 8px; background: var(--panel-2);
  font-size: 12px; font-weight: 600; color: var(--text); list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.eg-tag > summary::-webkit-details-marker { display: none; }
.eg-tag > summary .count { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 11px; }
.endpoint {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin: 3px 0 3px 6px;
  border-radius: 7px; cursor: pointer; border: 1px solid transparent;
}
.endpoint:hover { background: var(--panel-2); border-color: var(--border); }
.endpoint.selected { background: rgba(45, 212, 191, 0.1); border-color: var(--accent); }
.method {
  font-family: var(--mono); font-size: 10px; font-weight: 700; padding: 2px 6px;
  border-radius: 5px; min-width: 46px; text-align: center;
}
.method.get { background: rgba(56,189,248,.15); color: var(--accent-2); }
.method.post { background: rgba(34,197,94,.15); color: var(--low); }
.method.patch { background: rgba(245,158,11,.15); color: var(--medium); }
.method.delete { background: rgba(239,68,68,.15); color: var(--critical); }
.endpoint .path { font-family: var(--mono); font-size: 11.5px; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Response viewer ===== */
.viewer-card { height: 320px; display: flex; flex-direction: column; }
.viewer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.status-chip { font-family: var(--mono); font-size: 11px; padding: 2px 8px; border-radius: 5px; font-weight: 700; }
.status-chip.s2 { background: rgba(34,197,94,.15); color: var(--low); }
.status-chip.s4 { background: rgba(245,158,11,.15); color: var(--medium); }
.status-chip.s5 { background: rgba(239,68,68,.15); color: var(--critical); }
.viewer-meta { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.viewer-body {
  flex: 1; overflow: auto; background: #05080f; border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; margin: 0;
  font-family: var(--mono); font-size: 12px; line-height: 1.5; white-space: pre;
}
.req-editor { margin-bottom: 8px; display: none; }
.req-editor.show { display: block; }
.req-editor label { font-size: 11px; color: var(--muted); display: block; margin-bottom: 4px; }

/* JSON syntax highlight */
.j-key { color: var(--accent-2); }
.j-str { color: #a5d6a7; }
.j-num { color: #ffcb6b; }
.j-bool { color: #c792ea; }
.j-null { color: var(--muted-2); }

/* ===== Workflow result modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3,6,12,.78); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 24px;
  backdrop-filter: blur(4px);
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--border-2); border-radius: 14px;
  width: min(820px, 100%); max-height: 86vh; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-head .close { margin-left: auto; cursor: pointer; color: var(--muted); font-size: 20px; background: none; border: none; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.step {
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; overflow: hidden;
}
.step-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel-2); }
.step-head .step-n { font-weight: 700; color: var(--accent); }
.step-head .step-call { font-family: var(--mono); font-size: 11.5px; color: var(--muted); margin-left: auto; }
.step-desc { padding: 8px 12px; font-size: 12.5px; color: var(--text); }
.step-finding { padding: 0 12px 10px; font-size: 12px; color: var(--accent); }
.step pre {
  margin: 0; padding: 10px 12px; background: #05080f; font-family: var(--mono);
  font-size: 11px; max-height: 180px; overflow: auto; border-top: 1px solid var(--border); white-space: pre;
}
.wf-summary {
  background: rgba(45,212,191,.08); border: 1px solid rgba(45,212,191,.3);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-size: 13px; line-height: 1.55;
}
.wf-summary b { color: var(--accent); }

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #3a4f73; }

.toast {
  position: fixed; bottom: 18px; right: 18px; z-index: 200;
  background: var(--panel); border: 1px solid var(--border-2); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 12px 16px; font-size: 13px; max-width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); transform: translateY(20px); opacity: 0;
  transition: all .25s ease; pointer-events: none;
}
.toast.show { transform: none; opacity: 1; }
.toast.err { border-left-color: var(--critical); }

.muted { color: var(--muted); }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border-2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== AI banner ===== */
.ai-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 18px; font-size: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.ai-banner .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.ai-banner.live { background: rgba(45,212,191,.06); }
.ai-banner.live .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.ai-banner.fallback .dot { background: var(--medium); }
.ai-banner a { color: var(--accent-2); }

/* ===== Data panels ===== */
.panel-compact { padding: 12px 14px; }
.panel-compact h2 { margin-bottom: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.data-table th {
  text-align: left; color: var(--muted); font-weight: 600;
  padding: 4px 6px; border-bottom: 1px solid var(--border);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
}
.data-table td { padding: 5px 6px; border-bottom: 1px solid rgba(31,42,61,.5); }
.data-table tr.shp-row { cursor: pointer; }
.data-table tr.shp-row:hover, .data-table tr.shp-row.active { background: rgba(45,212,191,.08); }
.explorer-detail { font-size: 11px; margin-bottom: 8px; padding: 6px 8px; background: var(--panel-2); border-radius: 6px; }
.arrivals-card { padding-bottom: 10px; }
.arrivals-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.arrival-chip {
  font-size: 11px; padding: 5px 9px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
}
.heatmap-mini { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.heatmap-mini li { padding: 5px 0; border-bottom: 1px solid rgba(31,42,61,.4); }
.risk-low { color: var(--low); }
.risk-medium { color: var(--medium); }
.risk-high { color: var(--high); }
.risk-critical { color: var(--critical); }

/* ===== Site footer ===== */
.site-footer {
  padding: 8px 18px;
  font-size: 11px;
  color: var(--muted-2);
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
}
.site-footer .footer-line { display: block; margin-bottom: 4px; }
.site-footer .footer-links { display: inline-flex; flex-wrap: wrap; gap: 8px 12px; justify-content: center; }
.site-footer a { color: var(--accent-2); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ===== Mobile bottom navigation ===== */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  background: linear-gradient(180deg, rgba(14, 22, 38, 0.97), rgba(11, 17, 32, 0.99));
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
  padding: 8px 10px max(10px, env(safe-area-inset-bottom, 0px));
  gap: 4px;
  justify-content: space-around;
  pointer-events: auto;
  touch-action: manipulation;
}
.mobile-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 48px;
  min-width: 0;
  padding: 6px 4px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.mobile-nav-btn .nav-icon {
  font-size: 18px;
  line-height: 1;
  font-family: var(--mono);
}
.mobile-nav-btn.active {
  color: var(--accent);
  background: rgba(45, 212, 191, 0.1);
}
.mobile-nav-btn:active { transform: scale(0.97); }

/* ===== Tablet: single-column stack ===== */
@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 60px - 36px - 32px);
  }
  .col { overflow: visible; }
  .map-card { height: 420px; flex: none; }
  .explorer { min-height: 360px; }
  .viewer-card { height: 280px; }
}

@media (min-width: 768px) {
  .topbar {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 16px;
  }
  .topbar-main { flex: 0 1 auto; width: auto; }
  .user-picker-compact { max-width: 200px; }
  .pills { width: auto; flex: 1; justify-content: flex-end; min-width: 0; }
}

/* ===== Mobile: tabbed panels + compact chrome ===== */
@media (max-width: 767px) {
  html.is-mobile,
  html.is-mobile body {
    overflow-x: hidden;
    position: relative;
  }

  body {
    font-size: 15px;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }

  .desktop-only { display: none !important; }

  .topbar {
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top, 0px));
    gap: 0;
  }
  .brand img { height: 32px; }
  .brand .title { font-size: 16px; }
  .brand .subtitle { font-size: 10px; letter-spacing: 0.8px; }
  .user-picker-compact { max-width: 46%; font-size: 14px; min-height: 40px; }

  .ai-banner {
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.4;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    flex-wrap: wrap;
  }

  .mobile-nav { display: flex; }

  .mobile-hero,
  .mobile-feed-preview { display: block; }

  .layout {
    display: block;
    gap: 0;
    padding: 10px 12px calc(88px + env(safe-area-inset-bottom, 0px));
    height: auto;
    min-height: 0 !important;
    overflow-x: hidden;
    position: relative;
    z-index: 1;
  }
  .col {
    display: block;
    width: 100%;
    min-width: 0;
    overflow: visible;
  }
  .col.scroll { overflow: visible; }

  /* Tab panels: one visible set at a time */
  .card[data-panel] { display: none !important; }
  body[data-mobile-tab="overview"] .card[data-panel="overview"] {
    display: block !important;
    margin-bottom: 10px;
  }
  body[data-mobile-tab="map"] .card[data-panel="map"] {
    display: flex !important;
    flex-direction: column;
    margin-bottom: 10px;
  }
  body[data-mobile-tab="alerts"] .card[data-panel="alerts"] {
    display: flex !important;
    flex-direction: column;
    margin-bottom: 10px;
  }
  body[data-mobile-tab="dev"] .mobile-api-panel {
    display: block !important;
    margin-bottom: 10px;
  }
  .desktop-dev-panel { display: none !important; }

  /* Keep hidden map fully inert on non-map tabs (Safari touch bleed) */
  body:not([data-mobile-tab="map"]) .map-card {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
  }

  .card h2 {
    font-size: 11px;
    flex-wrap: wrap;
    gap: 6px;
    line-height: 1.3;
  }
  .card h2 .hint { font-size: 11px; }

  /* KPIs: 2-col grid that fits viewport (no horizontal page scroll) */
  .kpis {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
  }
  .kpi {
    flex: unset;
    width: auto;
    min-width: 0;
    padding: 12px 10px;
  }
  .kpi .label { font-size: 11px; line-height: 1.25; }
  .kpi .value { font-size: 22px; }

  .arrivals-strip {
    flex-wrap: wrap;
    overflow: visible;
    gap: 8px;
  }
  .arrival-chip { font-size: 12px; padding: 8px 10px; }

  .data-table { font-size: 13px; }
  .data-table th { font-size: 11px; }
  .data-table td { padding: 8px 6px; }
  .table-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .heatmap-mini { font-size: 14px; }
  .heatmap-mini li { padding: 8px 0; }

  /* Map tab */
  body[data-mobile-tab="map"] .map-card {
    min-height: calc(100dvh - 140px - env(safe-area-inset-bottom, 0px));
    height: calc(100dvh - 140px - env(safe-area-inset-bottom, 0px));
  }
  .map-legend {
    font-size: 11px;
    left: 8px;
    right: 8px;
    max-width: none;
  }
  .map-overlay-title {
    font-size: 12px;
    left: 8px;
    right: 48px;
    max-width: none;
  }

  /* Alerts tab */
  body[data-mobile-tab="alerts"] .feed-card {
    min-height: calc(100dvh - 140px - env(safe-area-inset-bottom, 0px));
    height: auto;
  }
  .feed-item { font-size: 14px; padding: 10px; }
  .feed-item .fi-time {
    white-space: normal;
    font-size: 11px;
  }

  .site-footer {
    font-size: 12px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    display: none;
  }

  .toast {
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    max-width: none;
    font-size: 14px;
  }
  .modal-backdrop { padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .modal { max-height: calc(100dvh - 80px - env(safe-area-inset-bottom, 0px)); width: 100%; }

  /* MapLibre controls stay inside viewport */
  .maplibregl-ctrl-top-right { top: 44px; right: 4px; }
}
