/* ==========================================================================================
 * SeaTrace Pro — Command console UI (top cluster, region control, weather intelligence, map chrome)
 * Naming: .st-* ; ids preserved from the page: sea-selector, toggleSeasBtn, weather-toggle-sidebar,
 * bookmarkBtn, dashboardBtn, chatPromptBtn. Loaded after the page <style>, so it owns these controls.
 * ========================================================================================== */
:root{
  --st-bg0:#02070B;--st-bg1:#031018;--st-bg2:#061923;--st-bg3:#081F2A;
  --st-line:#0D3340;--st-line2:#134556;
  --st-g:#00E676;--st-g2:#00FF88;--st-b:#38BDF8;--st-b2:#64D8FF;--st-w:#FFD166;--st-d:#FF4D67;
  --st-tx:#CFE8EE;--st-mu:#6E909B;
  --st-mono:ui-monospace,"SF Mono","Cascadia Mono",Consolas,"Liberation Mono",monospace;
  --st-panel:rgba(3,16,24,.84);
}

/* the map owns its own stacking context so Leaflet's pane z-indexes (200-1000) can never cover page controls */
#map{z-index:0;background:#0a1a22}
.leaflet-container{font-family:system-ui,-apple-system,"Segoe UI",sans-serif}
.leaflet-container.st-pointer,.leaflet-container.st-pointer.leaflet-grab{cursor:pointer}
.st-vessel-canvas{position:absolute;left:0;top:0;pointer-events:none;max-width:none;transform-origin:0 0;will-change:transform}

/* ---------- shared panel + micro-label ---------- */
.st-console-control{
  position:relative;background:var(--st-panel);border:1px solid var(--st-line2);border-radius:2px;
  -webkit-backdrop-filter:blur(10px) saturate(1.2);backdrop-filter:blur(10px) saturate(1.2);
  box-shadow:0 6px 22px rgba(0,0,0,.45);color:var(--st-tx);font-weight:500;
}
.st-console-control::before,.st-console-control::after{ /* range-ring style corner ticks */
  content:"";position:absolute;width:7px;height:7px;pointer-events:none;
}
.st-console-control::before{left:-1px;top:-1px;border-left:1px solid var(--st-g);border-top:1px solid var(--st-g)}
.st-console-control::after{right:-1px;bottom:-1px;border-right:1px solid rgba(0,230,118,.45);border-bottom:1px solid rgba(0,230,118,.45)}
.st-intelligence-label{
  display:block;font:600 9px/1 var(--st-mono);letter-spacing:.22em;color:var(--st-mu);text-transform:uppercase;margin:0;
}

/* ---------- top cluster ---------- */
.st-topbar{
  position:fixed;top:12px;right:16px;z-index:990;display:flex;flex-wrap:wrap;justify-content:flex-end;
  align-items:stretch;gap:8px;max-width:calc(100vw - 440px);
}

/* ---------- vessel telemetry ---------- */
.st-vessel-telemetry{
  min-width:176px;padding:9px 14px 9px 14px;cursor:default;order:3;
  background:radial-gradient(circle at 100% 120%,rgba(0,230,118,.14),transparent 62%),var(--st-panel);
}
.st-vessel-telemetry:focus-visible{outline:2px solid var(--st-b2);outline-offset:2px}
.st-telemetry-status{display:flex;align-items:center;gap:7px;font:600 9px/1 var(--st-mono);letter-spacing:.2em;color:var(--st-g)}
.st-telemetry-dot{width:7px;height:7px;border-radius:50%;background:var(--st-g);box-shadow:0 0 7px var(--st-g);flex:none}
.st-telemetry-row{display:flex;align-items:baseline;gap:8px;margin-top:6px}
.st-total-vessels{
  font:700 25px/1 var(--st-mono);letter-spacing:.01em;color:#fff;font-variant-numeric:tabular-nums;
  text-shadow:0 0 14px rgba(0,230,118,.35);min-width:3ch;
}
.st-total-vessels.is-loading{font-size:15px;font-weight:600;color:var(--st-mu);text-shadow:none;letter-spacing:.06em}
.st-telemetry-label{font:600 9px/1 var(--st-mono);letter-spacing:.22em;color:var(--st-mu)}
.st-vessel-telemetry[data-state="live"] .st-telemetry-dot{animation:st-live 2.4s ease-in-out infinite}
.st-vessel-telemetry[data-state="loading"] .st-telemetry-status,.st-vessel-telemetry[data-state="sync"] .st-telemetry-status{color:var(--st-b2)}
.st-vessel-telemetry[data-state="loading"] .st-telemetry-dot,.st-vessel-telemetry[data-state="sync"] .st-telemetry-dot{background:var(--st-b2);box-shadow:0 0 7px var(--st-b2);animation:st-live 1.1s ease-in-out infinite}
.st-vessel-telemetry[data-state="stale"] .st-telemetry-status{color:var(--st-w)}
.st-vessel-telemetry[data-state="stale"] .st-telemetry-dot{background:var(--st-w);box-shadow:0 0 6px var(--st-w)}
.st-vessel-telemetry[data-state="error"] .st-telemetry-status,.st-vessel-telemetry[data-state="offline"] .st-telemetry-status{color:var(--st-d)}
.st-vessel-telemetry[data-state="error"] .st-telemetry-dot,.st-vessel-telemetry[data-state="offline"] .st-telemetry-dot{background:var(--st-d);box-shadow:0 0 6px var(--st-d)}
@keyframes st-live{50%{opacity:.35}}
/* type legend: opens under the telemetry panel on hover / focus / tap */
.st-legend{
  display:none;position:absolute;right:0;top:calc(100% + 6px);z-index:2;width:196px;padding:9px 11px;gap:5px 12px;flex-wrap:wrap;
  background:var(--st-panel);border:1px solid var(--st-line2);font:500 9px/1.2 var(--st-mono);letter-spacing:.1em;color:var(--st-tx);
  -webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);
}
.st-legend span{display:inline-flex;align-items:center;white-space:nowrap}
.st-legend i{width:9px;height:9px;border-radius:50%;margin-right:6px;box-shadow:0 0 0 1px rgba(2,7,11,.9)}
.st-vessel-telemetry:hover .st-legend,.st-vessel-telemetry:focus-within .st-legend,.st-vessel-telemetry.is-open .st-legend{display:flex}

/* ---------- region control (sea selector) ---------- */
.st-region-control{display:flex;flex-direction:column;justify-content:center;gap:6px;min-width:212px;padding:8px 12px 8px 14px;order:1}
.st-region-control .st-intelligence-label::before{
  content:"";display:inline-block;width:5px;height:5px;margin-right:7px;vertical-align:1px;background:var(--st-g);box-shadow:0 0 6px var(--st-g);
}
.st-region-field{position:relative}
#sea-selector{
  /* reset every old rule from the page; native <select> kept for a11y + the existing change handler */
  position:static;top:auto;right:auto;box-shadow:none;border-radius:0;
  -webkit-appearance:none;-moz-appearance:none;appearance:none;display:block;width:100%;margin:0;
  padding:0 24px 0 0;height:20px;background:transparent;border:0;color:#E6FFF3;
  font:600 14px/20px system-ui,-apple-system,"Segoe UI",sans-serif;letter-spacing:.01em;cursor:pointer;text-overflow:ellipsis;
}
#sea-selector option{background:#031018;color:#CFE8EE;font-weight:500}
#sea-selector:focus{outline:none}
.st-region-control:focus-within{border-color:var(--st-g);box-shadow:0 0 0 1px rgba(0,230,118,.35),0 6px 22px rgba(0,0,0,.45)}
.st-region-control:hover{border-color:rgba(0,230,118,.55)}
.st-region-caret{position:absolute;right:0;top:50%;width:14px;height:14px;margin-top:-7px;fill:none;stroke:var(--st-g);stroke-width:2;stroke-linecap:round;stroke-linejoin:round;pointer-events:none}

/* ---------- command buttons (sea intelligence, bookmark, dashboard, chat, theme) ---------- */
.st-command-button{
  position:static;transform:none;margin:0;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:10px;
  color:var(--st-tx);background:var(--st-panel);border:1px solid var(--st-line2);border-radius:2px;text-decoration:none;cursor:pointer;
  -webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);box-shadow:0 6px 22px rgba(0,0,0,.45);
  transition:border-color .15s,color .15s,background .15s,box-shadow .15s;font-family:var(--st-mono);line-height:1;padding:0;
}
.st-command-button svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;flex:none}
.st-command-button:hover,.st-command-button:focus-visible{color:var(--st-g2);border-color:var(--st-g);background:rgba(0,230,118,.08);box-shadow:0 0 0 1px rgba(0,230,118,.25),0 0 16px rgba(0,230,118,.2)}
.st-command-button:focus-visible{outline:2px solid var(--st-b2);outline-offset:2px}
.st-command-button:active{transform:translateY(1px)}
.st-command-button--icon{width:44px;min-height:44px}
.st-command-button--wide{padding:0 15px 0 12px;order:2;text-align:left}
.st-command-button--wide svg{width:24px;height:24px;color:var(--st-g)}
.st-command-text{display:flex;flex-direction:column;gap:5px}
.st-command-text b{font:700 11px/1 var(--st-mono);letter-spacing:.17em;color:#fff;transition:color .15s}
.st-command-text small{font:500 8px/1 var(--st-mono);letter-spacing:.2em;color:var(--st-mu)}
.st-command-button--wide:hover b,.st-command-button--wide:focus-visible b{color:var(--st-g2)}
.st-command-button--active,.st-command-button[aria-pressed="true"]{
  color:var(--st-g2);border-color:var(--st-g);background:rgba(0,230,118,.16);box-shadow:0 0 0 1px rgba(0,230,118,.35),0 0 18px rgba(0,230,118,.28);
}
.st-command-button--active svg,.st-command-button[aria-pressed="true"] svg{fill:rgba(0,255,136,.28)}
.st-command-dock{display:flex;gap:6px;align-items:stretch;order:2}
.st-command-dock .st-command-button--icon{min-height:0;height:auto}

/* ---------- weather intelligence ---------- */
#weather-toggle-sidebar{ /* old white panel rules fully replaced */
  position:absolute;left:80px;bottom:40px;top:auto;right:auto;z-index:999;width:240px;padding:0;overflow:visible;
  font-size:13px;
}
.st-weather-head{
  display:flex;align-items:center;justify-content:space-between;gap:10px;width:100%;margin:0;padding:10px 12px 10px 14px;background:transparent;border:0;
  color:inherit;cursor:pointer;text-align:left;font-family:var(--st-mono);
}
.st-weather-head:hover .st-weather-title b{color:var(--st-g2)}
.st-weather-head:focus-visible{outline:2px solid var(--st-b2);outline-offset:-2px}
.st-weather-title{display:flex;align-items:center;gap:10px;min-width:0}
.st-weather-title>svg{width:22px;height:22px;flex:none;fill:none;stroke:var(--st-g);stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}
.st-weather-title span{display:flex;flex-direction:column;gap:5px}
.st-weather-title b{font:700 10px/1 var(--st-mono);letter-spacing:.17em;color:#fff;transition:color .15s}
.st-weather-title small{font:500 8px/1 var(--st-mono);letter-spacing:.2em;color:var(--st-mu)}
.st-weather-chev{width:16px;height:16px;fill:none;stroke:var(--st-mu);stroke-width:2;stroke-linecap:round;stroke-linejoin:round;transition:transform .2s;flex:none}
.st-weather-console[data-collapsed="true"] .st-weather-chev{transform:rotate(-90deg)}
.st-weather-body{border-top:1px solid var(--st-line);padding:4px 0 6px}
.st-weather-console[data-collapsed="true"] .st-weather-body{display:none}
.st-weather-toggle{
  position:relative;display:flex;align-items:center;gap:11px;margin:0;padding:8px 14px;cursor:pointer;user-select:none;
  font:600 13px/1 system-ui,-apple-system,"Segoe UI",sans-serif;color:var(--st-tx);transition:background .15s,color .15s;
}
.st-weather-toggle:hover{background:rgba(0,230,118,.06)}
.st-weather-toggle:focus-within{background:rgba(56,189,248,.1);box-shadow:inset 2px 0 0 var(--st-b2)}
.st-weather-toggle input{position:absolute;opacity:0;width:1px;height:1px;margin:0;pointer-events:none}   /* real checkbox stays: focus, keyboard, JS */
.st-weather-icon{display:inline-flex;width:18px;height:18px;color:var(--st-mu);transition:color .15s}
.st-weather-icon svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
.st-weather-name{flex:1}
.st-switch{position:relative;width:32px;height:16px;border:1px solid var(--st-line2);background:var(--st-bg0);border-radius:9px;flex:none;transition:background .2s,border-color .2s,box-shadow .2s}
.st-switch::after{content:"";position:absolute;left:2px;top:2px;width:10px;height:10px;border-radius:50%;background:var(--st-mu);transition:transform .2s,background .2s,box-shadow .2s}
.st-weather-toggle input:checked ~ .st-switch{background:rgba(0,230,118,.2);border-color:var(--st-g);box-shadow:0 0 10px rgba(0,230,118,.3)}
.st-weather-toggle input:checked ~ .st-switch::after{transform:translateX(16px);background:var(--st-g2);box-shadow:0 0 8px var(--st-g)}
.st-weather-toggle input:checked ~ .st-weather-icon,.st-weather-toggle input:checked ~ .st-weather-name{color:var(--st-g2)}

/* ---------- search box (existing element, console styling) ---------- */
#search-box{top:12px}

/* ---------- Leaflet chrome ---------- */
.leaflet-bar{border:1px solid var(--st-line2)!important;border-radius:2px!important;box-shadow:0 6px 22px rgba(0,0,0,.45)!important;overflow:hidden}
.leaflet-bar a,.leaflet-bar a:hover{background:var(--st-panel);color:var(--st-tx);border-bottom:1px solid var(--st-line);width:34px;height:34px;line-height:34px;font:600 18px/34px var(--st-mono)}
.leaflet-bar a:hover{background:rgba(0,230,118,.12);color:var(--st-g2)}
.leaflet-bar a.leaflet-disabled{color:var(--st-line2);background:var(--st-bg1)}
.leaflet-bar a:last-child{border-bottom:0}
.leaflet-control-attribution{background:rgba(2,7,11,.78)!important;color:var(--st-mu)!important;font:500 10px/1.4 var(--st-mono)!important;padding:2px 8px!important;letter-spacing:.02em}
.leaflet-control-attribution a{color:var(--st-b2)!important;text-decoration:none}
.leaflet-control-attribution a:hover{text-decoration:underline}
.leaflet-touch .leaflet-bar,.leaflet-touch .leaflet-control-layers{border:1px solid var(--st-line2)}
.st-theme-toggle{width:34px;height:34px;min-height:0}
.st-theme-toggle svg{width:17px;height:17px}
.leaflet-control.st-theme-control{margin-bottom:8px}

/* dark basemap: the OSM raster is inverted + toned in CSS (no second tile set, no token); weather tiles live in their own pane and are untouched */
.st-theme-dark .leaflet-tile-pane{filter:invert(1) hue-rotate(180deg) saturate(.5) brightness(.8) contrast(.92)}
.st-theme-dark.leaflet-container{background:#0a1a22}
.st-theme-light.leaflet-container{background:#cfe3ea}
.st-sea-boundary{filter:drop-shadow(0 0 6px rgba(0,230,118,.45))}

/* ---------- responsive ---------- */
@media (max-width:1180px){.st-topbar{max-width:calc(100vw - 420px)}}
@media (max-width:900px){
  #search-box{left:78px!important;right:8px;top:8px;width:auto;box-sizing:border-box}
  #search-input{width:calc(100% - 92px)!important}
  .st-topbar{top:68px;left:78px;right:8px;max-width:none;justify-content:flex-start;gap:6px}
  .st-region-control{flex:1 1 150px;min-width:0;order:1}
  .st-vessel-telemetry{order:0;flex:1 1 100%;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:7px 12px}
  .st-telemetry-row{margin-top:0}
  .st-total-vessels{font-size:20px}
  .st-command-button--wide{order:2}
  .st-command-text small{display:none}
  .st-command-dock{order:3}
  .st-command-button--icon{width:40px}
  #weather-toggle-sidebar{left:78px;bottom:14px;width:min(240px,calc(100vw - 100px))}
  .leaflet-control-zoom{display:none}
}
@media (max-width:560px){
  .st-command-button--wide .st-command-text b{font-size:10px;letter-spacing:.12em}
  .st-command-button--wide{padding:0 11px 0 9px;gap:7px}
}
@media (prefers-reduced-motion:reduce){
  .st-vessel-telemetry[data-state] .st-telemetry-dot,.st-switch,.st-switch::after,.st-weather-chev{animation:none;transition:none}
}
