:root {
  color-scheme: dark;
  --bg: #03070d;
  --panel: rgba(6, 14, 24, 0.94);
  --panel-2: rgba(10, 22, 36, 0.92);
  --line: rgba(212, 160, 55, 0.24);
  --gold: #d8a63e;
  --gold-2: #f3ce72;
  --text: #f5f2e9;
  --muted: #8d9aab;
  --green: #42d79e;
  --red: #ff6b6b;
  --blue: #55b7ff;
  --orange: #f0a64a;
  --purple: #b18cff;
  --sidebar: 340px;
  --topbar: 74px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) 1fr; grid-template-rows: var(--topbar) 1fr; width: 100%; height: 100%; }
.topbar { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-width: 0; padding: 0 18px; background: linear-gradient(180deg, rgba(3,9,16,.99), rgba(4,11,19,.97)); border-bottom: 1px solid var(--line); z-index: 30; box-shadow: 0 10px 28px rgba(0,0,0,.32); }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; min-width: 0; }
.brand img { width: 48px; height: 48px; object-fit: contain; filter: drop-shadow(0 0 13px rgba(216,166,62,.25)); }
.brand span { display: grid; line-height: 1; }
.brand b { font-family: Georgia, "Times New Roman", serif; letter-spacing: .16em; font-size: 18px; color: var(--gold-2); }
.brand small { margin-top: 7px; letter-spacing: .19em; font-size: 8px; color: var(--muted); }
.topbar-center { display: flex; align-items: center; gap: 14px; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid rgba(66,215,158,.28); border-radius: 999px; background: rgba(66,215,158,.08); font-size: 11px; letter-spacing: .12em; }
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px var(--green); }
.status-pill.connecting i { background: var(--orange); box-shadow: 0 0 12px var(--orange); }
.status-pill.offline i { background: var(--red); box-shadow: 0 0 12px var(--red); }
.status-pill.demo { border-color: rgba(66,215,158,.34); background: rgba(66,215,158,.10); }
.status-pill.demo i { background: var(--green); box-shadow: 0 0 14px var(--green); animation: statusPulse 1.8s ease-in-out infinite; }
@keyframes statusPulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .62; transform: scale(.82); } }
.utc-clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; letter-spacing: .06em; }
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 9px; }
.settings-btn, .home-btn, .icon-btn { height: 38px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.025); color: var(--text); cursor: pointer; transition: .2s ease; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.settings-btn, .home-btn { padding: 0 14px; font-size: 12px; }
.icon-btn { width: 38px; }
.icon-btn svg { width: 18px; fill: currentColor; }
.settings-btn:hover, .home-btn:hover, .icon-btn:hover { border-color: var(--gold); color: var(--gold-2); background: rgba(216,166,62,.08); }

.sidebar { min-height: 0; z-index: 20; background: linear-gradient(180deg, rgba(6,15,25,.99), rgba(3,10,18,.99)); border-right: 1px solid var(--line); display: grid; grid-template-rows: auto auto auto 1fr auto; overflow: hidden; }
.search-wrap { position: relative; margin: 15px 14px 10px; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; fill: #788798; }
.search-wrap input { width: 100%; height: 42px; padding: 0 12px 0 38px; color: var(--text); background: rgba(255,255,255,.035); border: 1px solid rgba(255,255,255,.08); border-radius: 11px; outline: 0; }
.search-wrap input:focus { border-color: rgba(216,166,62,.7); box-shadow: 0 0 0 3px rgba(216,166,62,.08); }
.filter-row { display: flex; gap: 6px; overflow-x: auto; padding: 0 14px 12px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter { white-space: nowrap; border: 1px solid rgba(255,255,255,.075); border-radius: 999px; background: transparent; color: var(--muted); padding: 7px 10px; cursor: pointer; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.filter.active, .filter:hover { color: #111; background: var(--gold-2); border-color: var(--gold-2); }
.list-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-top: 1px solid rgba(255,255,255,.05); border-bottom: 1px solid rgba(255,255,255,.05); color: var(--muted); font-size: 11px; }
.list-header strong { color: var(--text); font-size: 14px; }
.list-header button { border: 0; background: transparent; color: var(--gold-2); cursor: pointer; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.vessel-list { min-height: 0; overflow-y: auto; padding: 6px; scrollbar-color: rgba(216,166,62,.35) transparent; }
.vessel-item { width: 100%; display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 9px; padding: 10px; border: 1px solid transparent; border-radius: 11px; background: transparent; cursor: pointer; text-align: left; transition: .18s ease; }
.vessel-item:hover { background: rgba(255,255,255,.035); border-color: rgba(255,255,255,.06); }
.vessel-item.active { background: rgba(216,166,62,.09); border-color: rgba(216,166,62,.35); }
.ship-icon { width: 31px; height: 31px; border-radius: 9px; display: grid; place-items: center; background: rgba(85,183,255,.1); color: var(--blue); }
.ship-icon svg { width: 18px; fill: currentColor; transform: rotate(var(--heading)); }
.ship-icon.tanker { color: var(--orange); background: rgba(240,166,74,.1); }
.ship-icon.cargo { color: var(--blue); }
.ship-icon.passenger { color: var(--purple); background: rgba(177,140,255,.1); }
.ship-icon.other { color: #b9c4cf; background: rgba(185,196,207,.08); }
.vessel-meta { min-width: 0; }
.vessel-meta strong, .vessel-meta small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.vessel-meta strong { font-size: 12px; font-weight: 650; letter-spacing: .02em; }
.vessel-meta small { color: var(--muted); margin-top: 4px; font-size: 9px; letter-spacing: .06em; }
.vessel-speed { text-align: right; }
.vessel-speed b { display: block; font-size: 12px; font-variant-numeric: tabular-nums; }
.vessel-speed small { color: var(--muted); font-size: 9px; }
.sidebar-footer { padding: 10px 14px; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-footer p { margin: 0; color: #718094; font-size: 9px; line-height: 1.45; }
.sidebar-footer b { color: #9eabba; }

.map-area { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #07101a; }
#map { position: absolute; inset: 0; }
.maplibregl-ctrl-group { background: rgba(5,13,22,.9) !important; border: 1px solid var(--line); box-shadow: none !important; }
.maplibregl-ctrl-group button { filter: invert(1) opacity(.8); }
.maplibregl-ctrl-attrib { background: rgba(3,8,14,.74) !important; color: #9aa7b6 !important; }
.maplibregl-ctrl-attrib a { color: #c4ccd6 !important; }

.stats-grid { position: absolute; z-index: 5; top: 16px; left: 16px; right: 16px; display: grid; grid-template-columns: repeat(5, minmax(105px, 1fr)); gap: 9px; pointer-events: none; }
.stats-grid article { min-width: 0; padding: 12px 14px; border: 1px solid rgba(216,166,62,.22); border-radius: 12px; background: linear-gradient(180deg, rgba(5,15,25,.9), rgba(4,11,19,.82)); backdrop-filter: blur(12px); box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.stats-grid span { display: block; color: var(--gold-2); font-size: 9px; letter-spacing: .14em; }
.stats-grid strong { display: block; margin: 5px 0 2px; font-size: 23px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats-grid small { display: block; color: var(--muted); font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.legend { position: absolute; z-index: 5; left: 16px; bottom: 16px; display: flex; flex-wrap: wrap; gap: 12px; max-width: calc(100% - 405px); padding: 9px 12px; border: 1px solid rgba(255,255,255,.08); border-radius: 10px; background: rgba(4,12,20,.84); backdrop-filter: blur(10px); color: #aeb9c5; font-size: 9px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.cargo { background: var(--blue); }.dot.tanker { background: var(--orange); }.dot.passenger { background: var(--purple); }.dot.other { background: #bdc8d3; }
.zone-key i { width: 13px; height: 7px; border: 1px dashed var(--gold); background: rgba(216,166,62,.08); }

.alerts-panel { position: absolute; z-index: 6; right: 16px; top: 132px; width: 315px; max-height: 245px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); backdrop-filter: blur(14px); box-shadow: 0 18px 45px rgba(0,0,0,.28); overflow: hidden; }
.panel-title { height: 42px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; border-bottom: 1px solid rgba(255,255,255,.06); font-size: 11px; }
.panel-title > div { display: flex; align-items: center; gap: 8px; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(66,215,158,.5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(66,215,158,0); } 100% { box-shadow: 0 0 0 0 rgba(66,215,158,0); } }
.panel-title button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; }
.alerts-list { max-height: 202px; overflow-y: auto; padding: 6px; }
.alert-item { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; padding: 8px; border-radius: 9px; }
.alert-item:hover { background: rgba(255,255,255,.03); }
.alert-icon { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: rgba(66,215,158,.1); color: var(--green); font-size: 13px; }
.alert-icon.exit { color: var(--orange); background: rgba(240,166,74,.1); }
.alert-item strong { display: block; font-size: 10px; }
.alert-item small { display: block; margin-top: 3px; color: var(--muted); font-size: 8px; }
.alert-time { color: #718094; font-size: 8px; }
.empty-state { margin: 18px 10px; color: var(--muted); text-align: center; font-size: 10px; }

.detail-panel { position: absolute; z-index: 7; right: 16px; bottom: 16px; width: 365px; padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: linear-gradient(155deg, rgba(7,18,30,.97), rgba(4,11,19,.97)); backdrop-filter: blur(15px); box-shadow: 0 20px 55px rgba(0,0,0,.36); transform: translateY(calc(100% + 25px)); opacity: 0; pointer-events: none; transition: .28s ease; }
.detail-panel.open { transform: translateY(0); opacity: 1; pointer-events: auto; }
.close-detail { position: absolute; top: 8px; right: 10px; width: 30px; height: 30px; border: 0; background: transparent; color: var(--muted); font-size: 24px; cursor: pointer; }
.eyebrow { margin: 0 0 7px; color: var(--gold-2); font-size: 9px; letter-spacing: .18em; }
.detail-panel h2 { margin: 0; max-width: 290px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: Georgia, "Times New Roman", serif; font-size: 22px; font-weight: 500; }
.detail-panel .mmsi { margin: 6px 0 14px; color: var(--muted); font-size: 10px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.detail-grid div { padding: 10px; border: 1px solid rgba(255,255,255,.06); border-radius: 9px; background: rgba(255,255,255,.02); min-width: 0; }
.detail-grid span, .detail-grid b { display: block; }
.detail-grid span { margin-bottom: 5px; color: var(--muted); font-size: 8px; text-transform: uppercase; letter-spacing: .08em; }
.detail-grid b { font-size: 11px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.detail-actions { display: flex; gap: 8px; margin-top: 12px; }
.detail-actions button { flex: 1; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: rgba(216,166,62,.08); color: var(--gold-2); cursor: pointer; font-size: 10px; }
.detail-actions button:hover { background: var(--gold); color: #101010; }

.demo-banner { position: absolute; z-index: 8; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; max-width: 520px; padding: 9px 13px; border: 1px solid rgba(216,166,62,.45); border-radius: 10px; background: rgba(20,15,5,.9); color: #d8c69f; font-size: 9px; box-shadow: 0 10px 35px rgba(0,0,0,.32); }
.demo-banner b { color: var(--gold-2); white-space: nowrap; letter-spacing: .08em; }
.demo-banner.hidden { display: none; }

.settings-dialog { width: min(520px, calc(100vw - 30px)); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: #07111d; color: var(--text); box-shadow: 0 30px 100px rgba(0,0,0,.55); }
.settings-dialog::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(4px); }
.settings-dialog form { position: relative; padding: 25px; }
.dialog-close { position: absolute; right: 12px; top: 10px; border: 0; background: transparent; color: var(--muted); font-size: 25px; cursor: pointer; }
.settings-dialog h2 { margin: 0 0 10px; font-family: Georgia, "Times New Roman", serif; font-weight: 500; color: var(--gold-2); }
.settings-dialog p { color: #aab5c2; line-height: 1.6; font-size: 12px; }
.settings-dialog label { display: block; margin: 18px 0 7px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.settings-dialog input { width: 100%; height: 44px; border: 1px solid rgba(255,255,255,.11); border-radius: 10px; background: rgba(255,255,255,.04); color: var(--text); padding: 0 12px; outline: 0; }
.settings-dialog input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(216,166,62,.09); }
.dialog-actions { display: flex; gap: 9px; margin: 15px 0; }
.dialog-actions button { flex: 1; height: 40px; border: 1px solid var(--line); border-radius: 9px; background: transparent; cursor: pointer; font-size: 11px; }
.dialog-actions .primary { background: var(--gold); border-color: var(--gold); color: #111; font-weight: 700; }
.settings-dialog small { color: #728195; line-height: 1.5; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 28px; transform: translate(-50%, 20px); padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: rgba(4,12,20,.96); color: var(--text); opacity: 0; pointer-events: none; transition: .25s ease; font-size: 11px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
  :root { --sidebar: 300px; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); right: 350px; }
  .stats-grid article:nth-child(4), .stats-grid article:nth-child(5) { display: none; }
  .topbar { grid-template-columns: 1fr auto; }
  .topbar-center { display: none; }
}

@media (max-width: 780px) {
  :root { --topbar: 62px; }
  html, body { overflow: auto; }
  .app-shell { display: block; height: auto; min-height: 100%; }
  .topbar { position: sticky; top: 0; height: var(--topbar); grid-template-columns: 1fr auto; padding: 0 10px; }
  .brand img { width: 40px; height: 40px; }
  .brand b { font-size: 14px; }
  .brand small { font-size: 6px; }
  .home-btn, .icon-btn { display: none; }
  .settings-btn { height: 34px; padding: 0 10px; }
  .map-area { height: 64vh; min-height: 480px; }
  .sidebar { display: block; border-right: 0; border-top: 1px solid var(--line); }
  .vessel-list { max-height: 55vh; }
  .sidebar-footer { padding-bottom: 24px; }
  .stats-grid { top: 10px; left: 10px; right: 10px; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stats-grid article { padding: 9px; }
  .stats-grid strong { font-size: 18px; }
  .alerts-panel { top: 100px; right: 10px; width: 250px; max-height: 185px; }
  .alerts-list { max-height: 143px; }
  .detail-panel { left: 10px; right: 10px; bottom: 10px; width: auto; }
  .legend { display: none; }
  .demo-banner { left: 10px; right: 10px; bottom: 10px; transform: none; max-width: none; }
  .demo-banner span { display: none; }
}
