:root {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --text: #1d1d1f;
  --muted: #6b7177;
  --line: rgba(15, 23, 42, 0.09);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.12);
  --teal: #16b8a3;
  --amber: #f0a23c;
  --red: #ef4444;
  --green: #16b8a3;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, #e7f0ff 0%, transparent 60%),
    radial-gradient(1000px 500px at -10% 110%, #e6fbf5 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 14px; font-weight: 600; margin-bottom: 12px; letter-spacing: -0.01em; }
#subtitle { color: var(--muted); margin-top: 2px; font-size: 13px; }

button, input, select { font: inherit; }

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 11px;
  min-height: 40px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 550;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover {
  border-color: rgba(10, 132, 255, 0.4);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

button:active { transform: translateY(0); }

.app-shell {
  min-height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
}

/* ---- Top bar + tabs ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 22px;
  background: rgba(255, 255, 255, 0.72);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }

.tab, .tab-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 11px;
  text-decoration: none;
  font-weight: 550;
  box-shadow: none;
  transition: background 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.tab:hover, .tab-link:hover {
  background: var(--panel-2);
  color: var(--text);
  transform: none;
}

.tab.active, .tab-link.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px rgba(10, 132, 255, 0.32);
}

main { padding: 20px 22px; }

.view { display: none; }
.view.active { display: block; animation: fade-in 0.25s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---- Cards / panels ---- */
.map-panel, .panel, .side-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---- Navigation view: compact radar + side column ---- */
.nav-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.map-panel {
  position: relative;
  height: 460px;
  overflow: hidden;
}

.map-toolbar {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

#radar {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: var(--radius);
}

.side-panel { padding: 16px; }

.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.metric-row article {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.metric-row span, label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-row strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* ---- Lists ---- */
.alert-list, .target-list, .compact-list { display: grid; gap: 8px; }

.alert, .target, .entry {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 11px 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.target:hover, .entry.clickable:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

.alert.ok { border-left-color: var(--green); }
.alert.warning { border-left-color: var(--amber); }
.alert.critical { border-left-color: var(--red); }
.entry.clickable { cursor: pointer; }
.entry.stale { border-left-color: var(--amber); opacity: 0.8; }
.entry.watched { border-left-color: var(--green); }

.target strong, .alert strong, .entry strong {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 600;
}

.target small, .alert small, .entry small {
  display: block;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.4;
}

.alert strong span, .entry strong span, .target strong span {
  color: var(--muted);
  font-weight: 550;
  font-size: 12px;
  white-space: nowrap;
}

/* ---- Two-column (Deals, AISStream settings) ---- */
.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.panel { padding: 18px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

input, select {
  width: 100%;
  margin-top: 5px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 11px;
  min-height: 40px;
  padding: 0 12px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin-right: 8px;
}

.status-strip {
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  margin: 12px 0;
}

.status-strip a, .hint a { color: var(--accent); }

.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.button-row button { flex: 1 1 120px; }

@media (max-width: 980px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .nav-grid, .two-col { grid-template-columns: 1fr; }
  .map-panel { height: 56vh; }
}

@media (max-width: 560px) {
  main { padding: 12px; }
  .tabs { display: grid; grid-template-columns: 1fr 1fr; }
  .form-grid, .metric-row { grid-template-columns: 1fr 1fr; }
}

/* ===== Live map page (FlightRadar-style) ===== */
.map-page {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: #e9eef2;
  color: var(--ov-text);
  --ov-bg: rgba(255, 255, 255, 0.82);
  --ov-text: #1d1d1f;
  --ov-muted: #6b7177;
  --ov-border: rgba(0, 0, 0, 0.08);
  --ov-hover: rgba(120, 120, 128, 0.16);
  --ov-accent: #0a84ff;
}

.map-page.theme-dark {
  background: #0d0f12;
  --ov-bg: rgba(28, 30, 33, 0.78);
  --ov-text: #f2f4f6;
  --ov-muted: #a6adb4;
  --ov-border: rgba(255, 255, 255, 0.12);
  --ov-hover: rgba(255, 255, 255, 0.12);
}

#map { position: absolute; inset: 0; }

.map-page .maplibregl-ctrl-group {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.map-overlay { position: absolute; z-index: 5; }

.glass,
.brand,
.map-nav,
.search-box,
.search-results,
.pill,
.map-actions,
.setup-hint {
  background: var(--ov-bg);
  color: var(--ov-text);
  border: 1px solid var(--ov-border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.top-left {
  top: 14px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.top-right {
  top: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

.brand { display: flex; gap: 11px; align-items: center; padding: 10px 15px; }
.brand-text strong { display: block; font-size: 15px; }
.brand-text small { color: var(--ov-muted); font-size: 12px; }

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #16b8a3;
  box-shadow: 0 0 0 4px rgba(22, 184, 163, 0.18);
  transition: background 0.3s;
}

.brand-dot.off { background: #f0a23c; box-shadow: 0 0 0 4px rgba(240, 162, 60, 0.18); }

.map-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 5px;
  max-width: min(560px, calc(100vw - 28px));
}

.map-nav a {
  padding: 7px 12px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--ov-text);
  font-size: 13px;
  transition: background 0.12s ease;
}

.map-nav a:hover { background: var(--ov-hover); }
.map-nav a.active { background: var(--ov-accent); color: #fff; }

.search-box { position: relative; padding: 0; }

.map-page .search-box input {
  width: 264px;
  max-width: 62vw;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--ov-text);
  min-height: 44px;
  padding: 0 15px;
  border-radius: 14px;
}

.map-page .search-box input::placeholder { color: var(--ov-muted); }
.map-page .search-box input:focus { outline: none; box-shadow: none; }

.search-results {
  position: absolute;
  top: 52px;
  right: 0;
  width: 300px;
  max-width: 80vw;
  display: grid;
  gap: 2px;
  padding: 6px;
}

.map-page .search-results button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--ov-text);
  min-height: auto;
  box-shadow: none;
}

.map-page .search-results button:hover { background: var(--ov-hover); transform: none; }
.search-results strong { display: block; font-size: 13px; }
.search-results small { color: var(--ov-muted); font-size: 12px; }
.search-empty { padding: 10px; color: var(--ov-muted); font-size: 13px; }

.stat-pills { display: flex; gap: 8px; }
.pill { padding: 8px 13px; border-radius: 11px; font-size: 12px; color: var(--ov-muted); }
.pill b { font-size: 14px; color: var(--ov-text); }

.map-actions { display: flex; gap: 4px; padding: 5px; }

.map-page .map-actions button {
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ov-text);
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  box-shadow: none;
}

.map-page .map-actions button:hover { background: var(--ov-hover); color: var(--ov-text); transform: none; }

/* ---- Vessel detail popup (anchored above the boat) ---- */
.vessel-popup .maplibregl-popup-content {
  background: var(--ov-bg);
  color: var(--ov-text);
  border: 1px solid var(--ov-border);
  border-radius: 14px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  padding: 14px 16px;
}

.vessel-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--ov-bg); }

.map-page .vessel-popup .maplibregl-popup-close-button {
  color: var(--ov-muted);
  font-size: 18px;
  padding: 2px 8px 0 0;
  background: transparent;
}

.vessel-card-head { padding-right: 18px; }
.vessel-card-head strong { font-size: 16px; display: block; }
.vessel-card-head small { display: block; margin-top: 2px; color: var(--ov-muted); font-size: 12px; }

.vessel-photo-wrap {
  margin-top: 12px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--ov-border);
}

.vessel-photo {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: cover;
  background: var(--ov-hover);
}

.vessel-card-grid {
  margin-top: 13px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px 16px;
}

.vessel-card-grid span {
  display: block;
  color: var(--ov-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.vessel-card-grid b { font-size: 14px; }

.setup-hint {
  left: 50%;
  transform: translateX(-50%);
  bottom: 28px;
  padding: 12px 18px;
  font-size: 13px;
}

.setup-hint a { color: var(--ov-accent); font-weight: 600; }

@media (max-width: 640px) {
  .map-page .search-box input { width: 180px; }
  .stat-pills { display: none; }
}
