/* ============ MERIDIAN — control-room design system ============ */
:root {
  --bg: #070a0f;
  --bg2: #0a0e15;
  --panel: #0b1018;
  --panel2: #0e1420;
  --line: rgba(120, 150, 180, 0.12);
  --line2: rgba(120, 150, 180, 0.07);
  --text: #e6edf3;
  --muted: #8aa0b4;
  --muted2: #607387;
  --accent: #36d2ff;
  --accent-dim: rgba(54, 210, 255, 0.12);
  --amber: #ffb454;
  --red: #ff5a5a;
  --green: #4bd6a0;

  --font-display: "Bahnschrift", "DIN Alternate", "Segoe UI Variable Display",
    "Segoe UI", system-ui, sans-serif;
  --font-sans: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-mono: "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono",
    ui-monospace, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(120, 150, 180, 0.18);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(120, 150, 180, 0.3); }

/* ============ LAYOUT ============ */
#app {
  display: grid;
  grid-template-columns: 300px 1fr 344px;
  grid-template-rows: 58px 1fr 150px;
  grid-template-areas:
    "topbar topbar topbar"
    "left   map    right"
    "left   feed   right";
  height: 100vh;
  width: 100vw;
}

#topbar { grid-area: topbar; }
#left-rail { grid-area: left; }
#map-wrap { grid-area: map; }
#right-panel { grid-area: right; }
#feed { grid-area: feed; }

/* ============ TOP BAR ============ */
#topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 18px;
  background: linear-gradient(180deg, #0c121b, #090d14);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  color: var(--accent);
  font-size: 19px;
  text-shadow: 0 0 14px rgba(54, 210, 255, 0.7);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 3px;
  font-size: 18px;
}
.brand-sub {
  font-size: 9.5px;
  letter-spacing: 2.5px;
  color: var(--muted2);
  text-transform: uppercase;
}

.clock-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding-left: 14px;
  border-left: 1px solid var(--line);
}
.micro-label {
  font-size: 8.5px;
  letter-spacing: 2px;
  color: var(--muted2);
  text-transform: uppercase;
}
.clock { font-size: 17px; color: var(--accent); letter-spacing: 1px; }

.time-controls { display: flex; align-items: center; gap: 10px; }
.speed-group { display: flex; gap: 2px; background: rgba(0,0,0,0.3); border-radius: 7px; padding: 2px; }

.ctrl, .speed {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 7px;
  height: 32px;
  min-width: 34px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s ease;
}
.speed { border: none; background: transparent; min-width: 36px; }
.ctrl:hover, .speed:hover { color: var(--text); background: rgba(54, 210, 255, 0.08); }
.speed.on {
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(54, 210, 255, 0.3);
}

.search-block { margin-left: auto; }
#search {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  width: 220px;
  font-family: var(--font-mono);
  font-size: 12px;
}
#search::placeholder { color: var(--muted2); }

/* ============ LEFT RAIL ============ */
#left-rail, #right-panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px 14px 24px;
}
#right-panel { border-right: none; border-left: 1px solid var(--line); display: flex; flex-direction: column; }

.rail-title {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--muted);
  margin-bottom: 14px;
}
.rail-sub {
  font-size: 9.5px;
  letter-spacing: 2.4px;
  color: var(--muted2);
  text-transform: uppercase;
  margin: 20px 0 10px;
}
.rail-hint { font-size: 10.5px; color: var(--muted2); margin-top: 9px; line-height: 1.5; }

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi-card {
  background: linear-gradient(160deg, #0e1521, #0b1019);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.kpi-card:nth-child(5) { grid-column: span 2; }
.kpi-val {
  font-size: 22px;
  color: var(--text);
  letter-spacing: 0.5px;
  line-height: 1;
}
.kpi-label {
  font-size: 9.5px;
  letter-spacing: 1.2px;
  color: var(--muted2);
  text-transform: uppercase;
}
#kpi-disrupt-card.alert {
  border-color: rgba(255, 90, 90, 0.5);
  box-shadow: 0 0 0 1px rgba(255, 90, 90, 0.2), 0 0 18px rgba(255, 90, 90, 0.12);
}
#kpi-disrupt-card.alert .kpi-val { color: var(--red); }

/* commodity bars */
.bar-row { display: grid; grid-template-columns: 70px 1fr 54px; align-items: center; gap: 8px; margin-bottom: 7px; }
.bar-label { font-size: 10px; letter-spacing: 0.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 6px; background: rgba(255,255,255,0.05); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 4px; transition: width 0.4s ease; box-shadow: 0 0 8px currentColor; }
.bar-val { font-family: var(--font-mono); font-size: 10px; color: var(--muted); text-align: right; }

/* filter chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  --chip: var(--accent);
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 14px;
  padding: 5px 11px;
  font-size: 10.5px;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { color: var(--text); border-color: var(--chip); }
.chip.on {
  color: #06121a;
  background: var(--chip);
  border-color: var(--chip);
  font-weight: 600;
  box-shadow: 0 0 12px -2px var(--chip);
}

/* ============ MAP ============ */
#map-wrap { position: relative; background: var(--bg); overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }

.legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  max-width: 360px;
  padding: 9px 12px;
  background: rgba(8, 12, 18, 0.7);
  border: 1px solid var(--line);
  border-radius: 9px;
  backdrop-filter: blur(8px);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 7px currentColor; }
.legend-name { font-size: 9.5px; letter-spacing: 0.6px; color: var(--muted); text-transform: uppercase; }

.map-btn {
  position: absolute;
  right: 14px;
  bottom: 14px;
  background: rgba(8, 12, 18, 0.7);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 10px;
  letter-spacing: 1.5px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.15s ease;
}
.map-btn:hover { color: var(--accent); border-color: rgba(54,210,255,0.4); }

.motion-note {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(8, 12, 18, 0.8);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 16px;
  padding: 5px 14px;
  font-size: 10.5px;
  letter-spacing: 1px;
}

.tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: rgba(9, 13, 20, 0.94);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  max-width: 250px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
}
.tip-title { font-family: var(--font-display); font-size: 13px; letter-spacing: 0.6px; margin-bottom: 3px; }
.tip-row { font-size: 11px; color: var(--muted); line-height: 1.5; }
.tip-row.mono { font-family: var(--font-mono); font-size: 10.5px; }
.tip-row.alert { color: var(--red); }

/* ============ RIGHT PANEL — DETAIL ============ */
#detail { flex: 0 0 auto; min-height: 0; }
.empty-state { text-align: center; padding: 30px 14px 24px; color: var(--muted2); }
.empty-icon { font-size: 34px; color: rgba(54, 210, 255, 0.35); margin-bottom: 10px; }
.empty-title { font-family: var(--font-display); letter-spacing: 2px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.empty-text { font-size: 11.5px; line-height: 1.6; max-width: 240px; margin: 0 auto; }

.d-kicker { font-size: 9px; letter-spacing: 2.5px; color: var(--accent); text-transform: uppercase; margin-bottom: 5px; }
.d-title { font-family: var(--font-display); font-size: 18px; letter-spacing: 0.4px; line-height: 1.15; margin-bottom: 10px; }
.d-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.d-chip {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.8px;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 5px;
  padding: 3px 8px;
}
.d-banner {
  font-size: 11px;
  border-radius: 7px;
  padding: 8px 10px;
  margin-bottom: 12px;
  line-height: 1.4;
}
.d-banner.alert { background: rgba(255, 90, 90, 0.1); border: 1px solid rgba(255, 90, 90, 0.4); color: #ffb3b3; }
.d-banner.warn { background: rgba(255, 180, 84, 0.1); border: 1px solid rgba(255, 180, 84, 0.4); color: #ffd9a3; }

.stat-block {
  background: rgba(255, 255, 255, 0.018);
  border: 1px solid var(--line2);
  border-radius: 9px;
  padding: 4px 11px;
  margin-bottom: 6px;
}
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line2); }
.stat-row:last-child { border-bottom: none; }
.stat-label { font-size: 11px; color: var(--muted2); letter-spacing: 0.4px; }
.stat-val { font-size: 12.5px; color: var(--text); }
.stat-val.mono { font-family: var(--font-mono); }

.d-sub { font-size: 9px; letter-spacing: 2.2px; color: var(--muted2); text-transform: uppercase; margin: 14px 0 7px; }
.d-list { display: flex; flex-direction: column; gap: 4px; }
.d-listrow {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line2);
  border-radius: 7px;
  padding: 7px 9px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.12s ease;
}
.d-listrow:hover { background: rgba(54, 210, 255, 0.07); border-color: rgba(54, 210, 255, 0.3); }
.row-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 6px currentColor; }
.row-mode { font-size: 9.5px; letter-spacing: 1px; color: var(--muted2); min-width: 46px; }
.row-main { font-size: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-tag { font-family: var(--font-mono); font-size: 8.5px; letter-spacing: 0.8px; padding: 2px 5px; border-radius: 4px; }
.row-tag.alert { color: var(--red); background: rgba(255, 90, 90, 0.12); }
.row-tag.warn { color: var(--amber); background: rgba(255, 180, 84, 0.12); }
.d-muted { font-size: 11px; color: var(--muted2); padding: 4px 2px; }

.prog-track { height: 6px; background: rgba(255,255,255,0.06); border-radius: 4px; overflow: hidden; margin: 4px 0 4px; }
.prog-fill { height: 100%; border-radius: 4px; box-shadow: 0 0 10px currentColor; transition: width 0.4s ease; }

.status-disrupted { color: var(--red); }
.status-delayed { color: var(--amber); }
.status-on-time { color: var(--green); }

/* ============ AI PANEL ============ */
#ai-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.ai-status { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--muted); margin-bottom: 11px; }
.ai-dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.ai-dot.ok { background: var(--green); color: var(--green); }
.ai-dot.off { background: var(--muted2); color: var(--muted2); }

.ai-ask { display: flex; gap: 7px; align-items: stretch; }
#ai-input {
  flex: 1;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12px;
  padding: 9px 10px;
  resize: none;
  line-height: 1.45;
}
#ai-input::placeholder { color: var(--muted2); }

.btn-primary {
  background: var(--accent);
  color: #04141d;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  letter-spacing: 1px;
  font-size: 11px;
  padding: 0 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-primary:hover { box-shadow: 0 0 16px -2px var(--accent); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

.ai-examples { display: flex; flex-wrap: wrap; gap: 5px; margin: 9px 0; }
.ai-example {
  background: rgba(54, 210, 255, 0.06);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 12px;
  padding: 4px 9px;
  font-size: 10px;
  cursor: pointer;
  text-align: left;
  transition: all 0.12s ease;
}
.ai-example:hover { color: var(--accent); border-color: rgba(54, 210, 255, 0.4); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 10.5px;
  letter-spacing: 1.2px;
  cursor: pointer;
  width: 100%;
  transition: all 0.15s ease;
}
.btn-ghost:hover { color: var(--accent); border-color: rgba(54, 210, 255, 0.4); }
.btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost.small { width: auto; padding: 6px 12px; margin-top: 10px; }

.ai-output { margin-top: 12px; overflow-y: auto; flex: 1 1 auto; min-height: 40px; }

.ai-q { display: flex; gap: 8px; margin-bottom: 9px; }
.ai-q-mark {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #04141d;
  background: var(--accent);
  border-radius: 4px;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  font-weight: 700;
}
.ai-q-text { font-size: 12px; color: var(--muted); line-height: 1.45; font-style: italic; }

.ai-answer {
  background: linear-gradient(160deg, rgba(54,210,255,0.05), rgba(54,210,255,0.01));
  border: 1px solid rgba(54, 210, 255, 0.18);
  border-radius: 9px;
  padding: 11px 12px;
}
.ai-answer-head { font-size: 8.5px; letter-spacing: 2.5px; color: var(--accent); margin-bottom: 7px; }
.ai-answer-body { font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; color: var(--text); }

/* AI loading */
.ai-loading { padding: 6px 0; }
.ai-scan {
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%;
  animation: scan 1.3s linear infinite;
  margin-bottom: 9px;
}
@keyframes scan { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.ai-loading-label { font-size: 11px; color: var(--muted); letter-spacing: 0.4px; }

.ai-error {
  background: rgba(255, 90, 90, 0.07);
  border: 1px solid rgba(255, 90, 90, 0.35);
  border-radius: 9px;
  padding: 11px 12px;
}
.ai-error-title { color: var(--red); font-size: 12px; font-weight: 600; margin-bottom: 5px; }
.ai-error-msg { font-size: 11.5px; color: #ffc0c0; line-height: 1.5; }

/* ============ FEED ============ */
#feed {
  background: var(--panel);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.feed-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 9.5px;
  letter-spacing: 2.5px;
  color: var(--muted2);
  text-transform: uppercase;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line2);
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: blink 1.8s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.feed-list { overflow-y: auto; padding: 4px 0; flex: 1; }
.feed-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 16px;
  font-size: 11.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}
.feed-time { color: var(--muted2); font-size: 10.5px; flex: 0 0 auto; }
.feed-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 6px currentColor; }
.feed-text { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ MODAL ============ */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden, .hidden { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 6, 10, 0.72); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  background: linear-gradient(160deg, #0e1521, #0a0f17);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  width: 440px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal-title { font-family: var(--font-display); letter-spacing: 3px; font-size: 15px; margin-bottom: 9px; }
.modal-sub { font-size: 11.5px; color: var(--muted); line-height: 1.6; margin-bottom: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field-label { font-size: 9px; letter-spacing: 2px; color: var(--muted2); text-transform: uppercase; }
.field input, .field select {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.field-hint { font-size: 10px; color: var(--muted2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 6px; }
.modal-actions .btn-ghost, .modal-actions .btn-primary { width: auto; padding: 9px 18px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1040px) {
  #app { grid-template-columns: 250px 1fr 300px; }
  #search { width: 150px; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 56vh auto auto auto;
    grid-template-areas: "topbar" "map" "left" "right" "feed";
    height: auto;
    min-height: 100vh;
  }
  #left-rail, #right-panel { border: none; border-top: 1px solid var(--line); max-height: none; }
  #topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 12px; }
  .search-block { margin-left: 0; }
  #feed { max-height: 200px; }
}
