:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --good: #059669;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
:root:not([data-theme="light"]) { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --panel: #111a2e; --panel-2: #0f172a; --text: #e2e8f0; --muted: #94a3b8;
    --line: #1f2a44; --accent: #60a5fa; --accent-soft: #1e3a5f; --warn-soft: #3b2a0a; --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2 { margin: 0; }
button { font: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 260px; }
.brand-mark { width: 28px; height: 28px; fill: var(--accent); }
.brand h1 { font-size: 17px; letter-spacing: .2px; }
.sub { margin: 0; color: var(--muted); font-size: 12px; }

.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge-live { background: #d1fae5; color: #065f46; }
.badge-sim { background: var(--warn-soft); color: var(--warn); }
.badge-muted { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge-bad { background: #fee2e2; color: #991b1b; }
.badge-live::before, .badge-sim::before { content: "●"; margin-right: 5px; }

.kpis { display: flex; gap: 10px; margin-left: auto; }
.kpi {
  display: flex; flex-direction: column; min-width: 120px;
  padding: 6px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
}
.kpi-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

.controls { display: flex; gap: 8px; }
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; }

.warmup { background: var(--warn-soft); color: var(--warn); padding: 8px 20px; font-size: 13px; }

/* ---------- main layout ---------- */
.layout {
  display: grid; grid-template-columns: 1fr 390px; gap: 14px;
  padding: 14px 20px; height: calc(100vh - 110px); min-height: 520px;
}
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
#map { position: absolute; inset: 0; background: var(--panel-2); }

.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; box-shadow: var(--shadow); display: grid; grid-template-columns: auto auto; gap: 3px 14px;
}
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.side {
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; background: none; border: 0; padding: 11px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 600;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.count { font-size: 11px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; margin-left: 4px; font-variant-numeric: tabular-nums; }
.tabpanel { flex: 1; overflow: auto; padding: 10px; min-height: 0; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

/* ---------- alert cards ---------- */
.feed { display: flex; flex-direction: column; gap: 8px; }
.card {
  border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px;
  padding: 9px 11px; background: var(--panel-2); cursor: pointer;
}
.card:hover { border-color: var(--accent); }
.card.exit { border-left-color: var(--muted); opacity: .85; }
.card.flash { animation: flash 2.4s ease-out; }
@keyframes flash { 0% { background: var(--accent-soft); } 100% { background: var(--panel-2); } }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card-title { font-weight: 700; }
.card-time { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.card-zone { color: var(--muted); font-size: 12px; margin: 1px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); }
.chip-sim { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ---------- vessel list ---------- */
.input {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); font: inherit;
}
.vlist { margin-top: 8px; }
.vrow {
  display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center;
  padding: 7px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.vrow:hover { background: var(--panel-2); }
.dot { width: 10px; height: 10px; border-radius: 3px; }
.vname { font-weight: 600; }
.vmeta { color: var(--muted); font-size: 12px; }
.vspeed { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- detail panel ---------- */
.detail {
  position: absolute; top: 12px; left: 12px; z-index: 600; width: 340px; max-height: calc(100% - 24px);
  overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
}
.detail h3 { margin: 0 24px 2px 0; font-size: 16px; }
.detail .vmeta { margin-bottom: 10px; }
.detail-close {
  position: absolute; top: 8px; right: 10px; border: 0; background: none; color: var(--muted);
  font-size: 22px; cursor: pointer; line-height: 1;
}
.detail h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.detail .ev { font-size: 12px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.detail a { color: var(--accent); }

/* ---------- log ---------- */
.log { padding: 0 20px 24px; }
.log-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.log-head h2 { font-size: 16px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.filters .input { width: auto; }
.table-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: auto; max-height: 460px;
}
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  position: sticky; top: 0; background: var(--panel-2); text-align: left; font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .3px;
}
.table td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--panel-2); }
.tag { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; }
.tag-entry { background: var(--accent-soft); color: var(--accent); }
.tag-exit { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }

/* ---------- map markers ---------- */
.ship-icon svg { overflow: visible; }
.leaflet-container { font: inherit; }

/* ---------- small screens ---------- */
@media (max-width: 980px) {
  .kpis { margin-left: 0; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 60vh; }
  .side { max-height: 480px; }
}
@media (max-width: 600px) {
  .topbar, .layout, .log { padding-left: 16px; padding-right: 16px; }
  .kpis { width: 100%; }
  .kpi { flex: 1; min-width: 0; }
  .controls { flex-wrap: wrap; }
  .detail { width: auto; right: 12px; }
  .filters { margin-left: 0; }
}

.who { align-self: center; font-size: 12px; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trialbar { background: var(--accent-soft); color: var(--accent); }
.chip-type { color: #fff; border-color: transparent; font-weight: 600; }

/* numbered bubble for ships close together */
.ship-cluster { display: grid; place-items: center; border-radius: 50%; background: rgba(37, 99, 235, .25); }
.ship-cluster span {
  display: grid; place-items: center; width: calc(100% - 8px); height: calc(100% - 8px); border-radius: 50%;
  background: #2563eb; color: #fff; font-weight: 700; font-size: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}

.region-pick { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.region-pick select { width: auto; padding: 6px 8px; }

/* ship search on the map */
.map-search { position: absolute; left: 12px; top: 12px; z-index: 600; width: min(340px, calc(100% - 70px)); }
.map-search .input { box-shadow: var(--shadow); }
.search-results {
  margin-top: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  max-height: 360px; overflow: auto;
}
.search-results .sr { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.search-results .sr:last-child { border-bottom: 0; }
.search-results .sr:hover, .search-results .sr.active { background: var(--panel-2); }
.search-results .sr-tag { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* personal ship alerts */
.watch-form { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); margin-bottom: 10px; }
.wf-title { font-weight: 700; }
.wf-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.wf-ship { position: relative; }
.wf-ship .search-results { position: absolute; left: 0; right: 0; z-index: 20; }
.wf-chosen { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px; }
.wf-chosen button { background: none; border: 0; color: inherit; cursor: pointer; font-size: 16px; }
.wf-circle { display: flex; flex-direction: column; gap: 6px; }
.wf-row { display: flex; gap: 6px; align-items: center; }
.wf-row label { display: flex; align-items: center; gap: 4px; font-size: 12px; white-space: nowrap; }
.wf-row label .input { width: 70px; }
.wf-hint { margin: 0; font-size: 12px; color: var(--muted); }
.wf-err { font-size: 12px; color: var(--bad); }
.btn-primary-solid { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.wrow { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.wrow .wname { font-weight: 600; cursor: pointer; }
.wrow .wmeta { font-size: 12px; color: var(--muted); }
.wrow .wactions { display: flex; gap: 4px; align-items: start; }
.wrow .wactions .btn { padding: 3px 8px; font-size: 12px; }
.wrow.paused { opacity: .6; }
.state-in { color: var(--good); font-weight: 600; }
.tag-alert { background: #fef3c7; color: #92400e; }
.chip-alert { background: #fef3c7; color: #92400e; border-color: transparent; font-weight: 600; }
.btn-watch { margin-top: 10px; width: 100%; }

/* developer credit and copyright */
.byline { margin: 1px 0 0; font-size: 11px; color: var(--muted); }
.byline a { color: inherit; font-weight: 600; text-decoration: none; }
.byline a:hover { color: var(--accent); text-decoration: underline; }
.site-foot { padding: 18px 20px 24px; text-align: center; font-size: 12px; color: var(--muted); }
.site-foot a { color: inherit; font-weight: 600; }
.page-center .site-foot { padding: 14px 0 0; }
