:root {
  --bg: #151514;
  --surface: rgba(26, 26, 25, 0.92);
  --surface-2: #262624;
  --line: #383835;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f8e86;
  --accent: #3987e5;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --tl-h: 58px;
  --ch-h: 168px;
  --r: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sp { flex: 1; }
[hidden] { display: none !important; }

/* карта и Windy */
#stage { position: fixed; left: 0; right: 0; top: 0; bottom: var(--tl-h); }
#map { position: absolute; inset: 0; background: #20201f; }
body.split #map { right: 50%; }
#windyPane { position: absolute; top: 0; bottom: 0; left: 50%; right: 0; display: flex; flex-direction: column; border-left: 2px solid var(--line); background: var(--bg); }
#windyFrame { flex: 1; width: 100%; border: 0; }
.wp-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-2); flex-wrap: wrap; }
.leaflet-container { background: #20201f; font: inherit; }
.leaflet-control-attribution { background: rgba(20, 20, 19, 0.7) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--text-2) !important; }
.leaflet-bar a { background: var(--surface) !important; color: var(--text) !important; border-color: var(--line) !important; }
.leaflet-tooltip { background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.leaflet-tooltip:before { display: none; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: 0 4px 16px rgba(0,0,0,.5); }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.popup a { color: var(--accent); }

/* кнопки */
.btn { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block; }
.btn:hover:not(:disabled) { border-color: var(--text-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn.wide { width: 100%; padding: 9px; margin: 10px 0 6px; }
.btn.round { width: 40px; height: 40px; border-radius: 50%; padding: 0; font-size: 15px; flex: none; }

/* верх */
#topbar { position: fixed; top: 10px; left: 10px; display: flex; gap: 6px; align-items: center; z-index: 1000; max-width: calc(100vw - 20px); }
.brand { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.logo { color: var(--accent); }

/* версия программы */
.ver { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; white-space: nowrap; }
.ver b { font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; }
.ver span { font-size: 10px; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.ver.upd { background: var(--accent); border-color: var(--accent); }
.ver.upd b, .ver.upd span { color: #fff; }
#verPop { position: fixed; top: 54px; left: 10px; z-index: 2500; width: min(380px, calc(100vw - 20px)); max-height: 60vh; overflow: auto;
  background: #1a1a19; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
#verPop h4 { margin: 0 0 6px; font-size: 13px; }
#verPop .it { padding: 6px 0; border-top: 1px solid var(--line); font-size: 12px; }
#verPop .it b { color: var(--accent); font-variant-numeric: tabular-nums; }
#verPop .who { color: var(--text-2); }

/* панель маршрута */
#panel { position: fixed; top: 54px; left: 10px; width: 350px; max-height: calc(100% - var(--tl-h) - 70px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); z-index: 1001; backdrop-filter: blur(6px); }
#panel.closed { display: none; }
.p-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 6px; }
.p-body { padding: 0 12px 12px; overflow: auto; }
.f { display: flex; flex-direction: column; gap: 3px; color: var(--text-2); font-size: 12px; margin-top: 8px; }
.f input, .f select { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 7px; color: var(--text); min-width: 0; width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; column-gap: 8px; }
.drop { position: relative; margin-top: 8px; border: 1.5px dashed var(--line); border-radius: 8px; padding: 10px; color: var(--text-2); font-size: 12px; text-align: center; cursor: pointer; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop.over, body.dragging .drop { border-color: var(--accent); color: var(--text); }
#routeInfo { margin-top: 6px; min-height: 16px; }
body.viewer .local-only, body.noserver #publish { display: none !important; }
#publish { margin-top: 0; }
details { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
summary { cursor: pointer; color: var(--text-2); font-weight: 600; }
details p { margin: 6px 0; }
#wpTable { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 11.5px; font-variant-numeric: tabular-nums; }
#wpTable th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 2px; }
#wpTable td { padding: 3px 2px; border-top: 1px solid var(--line); white-space: nowrap; }
#wpTable td.nm { max-width: 70px; overflow: hidden; text-overflow: ellipsis; }
#wpTable input { width: 42px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 2px 3px; color: var(--text); }
#wpTable tr.before td { opacity: .45; }

/* слои */
#layers { position: fixed; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 4px; z-index: 1000; width: 150px; }
body.split #layers { right: calc(50% + 10px); }
.lay { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; text-align: left; cursor: pointer; }
.lay-h { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 4px 0 0 4px; text-shadow: 0 0 3px #000; }
#layers { max-height: calc(100% - var(--tl-h) - 100px); overflow-y: auto; scrollbar-width: none; }
body.charts #layers { max-height: calc(100% - var(--tl-h) - var(--ch-h) - 100px); }
body.live #layers { max-height: calc(100% - var(--tl-h) - 185px); }
body.charts.live #layers { max-height: calc(100% - var(--tl-h) - var(--ch-h) - 185px); }
.lay.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.lay-sep { height: 4px; }
.lay-opt { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--text-2); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.lay-opt select { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 3px; }
.lay-chk { display: flex; gap: 6px; align-items: center; font-size: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; cursor: pointer; }

/* карточка судна */
#card { position: fixed; left: 10px; bottom: calc(var(--tl-h) + 10px); width: 370px; max-height: calc(100% - var(--tl-h) - 80px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); z-index: 1000; backdrop-filter: blur(6px); }
#card { transition: transform .2s ease; }
#card.drag { transition: none; }
.card-h { padding: 9px 12px 6px; border-bottom: 1px solid var(--line); cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.grip { display: block; height: 14px; position: relative; touch-action: none; cursor: grab; }
.grip::before { content: ""; position: absolute; left: 50%; top: 5px; width: 38px; height: 4px; margin-left: -19px; border-radius: 2px; background: var(--muted); }
.card-h .tg { float: right; color: var(--muted); font-weight: 400; }
.card-h .tg::after { content: "▾"; }
.card-h .sum { display: none; font-size: 14px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
/* свёрнутое окно: одна строка — ветер и волна (время и так видно на ленте внизу) */
#card.collapsed #cardBody, #card.collapsed .card-h .pos, #card.collapsed .card-h .t { display: none; }
#card.collapsed .card-h .sum { display: block; }
#card.collapsed .card-h { border-bottom: 0; padding-bottom: 8px; }
#card.collapsed .card-h .sum { margin-top: 0; }
#card.collapsed .card-h .tg::after { content: "▴"; }
.card-h .t { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card-h .pos { color: var(--text-2); font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
#cardBody { padding: 4px 12px 10px; }
.row { padding: 7px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.row .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 1px; }
.row .s { color: var(--text-2); font-size: 12px; }
.arrow { display: inline-block; width: 14px; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { font-size: 11px; color: var(--text-2); border: 1px solid var(--line); border-radius: 10px; padding: 1px 7px 1px 5px; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 4px; }
.chip i, .lg i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.agree { font-size: 11px; text-transform: none; letter-spacing: 0; border-radius: 10px; padding: 1px 7px; white-space: nowrap; }
.agree.good { color: var(--good); border: 1px solid var(--good); }
.agree.warning { color: var(--warning); border: 1px solid var(--warning); }
.agree.critical { color: var(--critical); border: 1px solid var(--critical); }
.agree.none { color: var(--muted); border: 1px solid var(--line); }
.nodata { color: var(--muted); padding: 10px 0; }

/* графики */
#charts { position: fixed; left: 10px; right: 10px; bottom: calc(var(--tl-h) + 8px); height: var(--ch-h); display: flex; gap: 8px; z-index: 999; }
body.split #charts { right: calc(50% + 10px); }
body.charts #card, body.charts #legend { bottom: calc(var(--tl-h) + var(--ch-h) + 16px); }
body.charts #card { max-height: calc(100% - var(--tl-h) - var(--ch-h) - 80px); }
.chart { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); position: relative; padding: 6px 4px 2px; backdrop-filter: blur(6px); }
.ch-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 0 6px; font-size: 11.5px; color: var(--text-2); }
.ch-head b { color: var(--text); font-size: 12px; }
.lg { display: inline-flex; align-items: center; gap: 4px; }
.chart svg { display: block; width: 100%; height: calc(100% - 20px); }
.ch-tip { position: absolute; pointer-events: none; background: #0f0f0e; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 11.5px; white-space: nowrap; z-index: 5; font-variant-numeric: tabular-nums; }

/* шкала цвета */
#legend { position: fixed; right: 10px; bottom: calc(var(--tl-h) + 10px); z-index: 999; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px 4px; font-size: 10.5px; color: var(--text-2); width: 155px; }
body.live #legend { width: 215px; }
body.split #legend { right: calc(50% + 10px); }
#legend .live-h { display: flex; justify-content: space-between; align-items: center; gap: 6px; color: var(--text); }
#legend .bar { height: 8px; border-radius: 3px; margin: 3px 0 2px; }
#legend .lbl { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
#legend .lbl.abs { display: block; position: relative; height: 13px; }
#legend .lbl.abs span { position: absolute; top: 0; white-space: nowrap; }

/* лента времени */
#timeline { position: fixed; left: 0; right: 0; bottom: 0; height: var(--tl-h); background: #10100f; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 0 12px; z-index: 1002; }
.tlabel { width: 190px; flex: none; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.tlabel b { font-size: 14px; }
.tlabel span { font-size: 11px; }
.track { position: relative; flex: 1; min-width: 0; height: 40px; }
#slider { position: absolute; left: 0; right: 0; top: 4px; width: 100%; margin: 0; accent-color: var(--accent); }
#ticks { position: absolute; left: 0; right: 0; top: 24px; height: 14px; font-size: 10.5px; color: var(--muted); }
#ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
#ticks span::before { content: ""; position: absolute; left: 50%; top: -6px; height: 5px; border-left: 1px solid var(--line); }
#ticks .wpt { color: var(--text-2); top: -22px; font-size: 9px; }
#ticks .wpt::before { display: none; }
#rate { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px; flex: none; }

/* подписи изобар */
.iso-lbl { color: #fff; font-size: 10px; font-weight: 600; text-align: center; line-height: 14px; background: rgba(20,20,19,.7); border-radius: 3px; pointer-events: none; }

/* значок судна */
.ship { width: 26px; height: 26px; filter: drop-shadow(0 0 3px rgba(0,0,0,.9)); }
.ship svg { width: 26px; height: 26px; }

/* сообщения */
#toast { pointer-events: none; position: fixed; bottom: calc(var(--tl-h) + 10px); left: 50%; transform: translateX(-50%); background: #0f0f0e; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; z-index: 2000; max-width: 80vw; }
#toast.err { border-color: var(--critical); }
/* переключатель языка EN | RU */
.lang { flex: none; display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; height: 34px; padding: 0 2px; }
.lang button { background: none; border: 0; color: var(--muted); font: inherit; font-size: 12px; font-weight: 700; padding: 0 7px; height: 100%; cursor: pointer; letter-spacing: .3px; }
.lang button.on { color: var(--accent); }
.lang i { color: var(--line); font-style: normal; }
/* значок ⚠ в верхней панели и окно «Источники погоды» */
.alert { flex: none; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 17px; line-height: 1; cursor: pointer; padding: 0; color: var(--warning); }
.alert.bad { color: #fff; background: #b8322f; border-color: #e05a55; animation: alertPulse 1.6s ease-in-out 3; }
.alert.warn { color: #1b1300; background: var(--warning); border-color: var(--warning); }
.alert.ok { color: #fff; background: #1f7a52; border-color: var(--good); }
.alert[aria-expanded="true"] { box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
@keyframes alertPulse { 50% { box-shadow: 0 0 0 6px rgba(224,90,85,.35); } }
#notice { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); width: min(520px, calc(100vw - 20px)); max-height: calc(100% - var(--tl-h) - 74px); overflow: auto; z-index: 2400;
  background: #141413; border: 1px solid var(--warning); border-radius: var(--r); padding: 8px 12px 10px; box-shadow: 0 8px 24px rgba(0,0,0,.55); font-size: 12.5px; }
#notice .n-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
#notice .n-head b { font-size: 13px; }
#noticeText { margin-bottom: 6px; }
#noticeText p { margin: 0 0 5px; }
#noticeText p:last-child { margin-bottom: 0; }
#sources .src { display: flex; gap: 6px; align-items: baseline; padding: 3px 0; border-top: 1px solid var(--line); }
#sources .src .ic { width: 14px; flex: none; text-align: center; }
#sources .src.ok { color: var(--good); }
#sources .src.warn { color: var(--warning); }
#sources .src.bad { color: var(--serious); }
#sources .src-note { color: var(--muted); font-size: 11.5px; margin-top: 5px; }
.bk-note { margin-top: 6px; padding: 6px 8px; border-radius: 6px; background: rgba(230,170,40,.12); color: var(--warning); font-size: 11.5px; }

/* таблица */
#modal, .modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 3000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.m-box { background: #1a1a19; border: 1px solid var(--line); border-radius: var(--r); width: min(1300px, 100%); max-height: 100%; display: flex; flex-direction: column; }
.m-head { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.m-body { overflow: auto; }
.cmp { border-collapse: collapse; font-size: 12px; width: 100%; font-variant-numeric: tabular-nums; }
.cmp th { text-align: left; padding: 6px; color: var(--text-2); background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.cmp td { padding: 6px; border-top: 1px solid var(--line); vertical-align: top; }
.cmp-charts { display: flex; gap: 8px; padding: 8px; flex-wrap: wrap; }
.cmp-charts .chart { flex: 1 1 320px; min-width: 260px; height: 190px; }
#bigTable { border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; width: 100%; }
#bigTable th { position: sticky; top: 0; background: var(--surface-2); text-align: left; padding: 6px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
#bigTable td { padding: 5px 6px; border-top: 1px solid var(--line); white-space: nowrap; }
#bigTable tr.cur td { background: rgba(57,135,229,.18); }
#bigTable tr { cursor: pointer; }
.sev { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }

/* телефон */
@media (max-width: 760px) {
  :root { --tl-h: 64px; }
  #topbar { top: 6px; left: 6px; right: 6px; overflow-x: auto; scrollbar-width: none; }
  .brand { display: none; }
  #layers { top: 46px; right: 6px; left: 6px; width: auto; flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .lay, .lay-chk, .lay-opt { flex: none; }
  .lay-opt { flex-direction: row; align-items: center; }
  .lay-sep, .lay-h { display: none; }
  #panel { top: 6px; left: 6px; right: 6px; width: auto; max-height: calc(100% - var(--tl-h) - 12px); }
  #card { left: 6px; right: 6px; width: auto; bottom: calc(var(--tl-h) + 6px); max-height: 42%; }
  /* «ручка» сверху окна — тянуть вниз, чтобы свернуть, вверх — развернуть */
  .grip { display: block; height: 16px; position: relative; }
  .grip::before { content: ""; position: absolute; left: 50%; top: 6px; width: 38px; height: 4px; margin-left: -19px; border-radius: 2px; background: var(--muted); }
  #card .card-h { padding-top: 2px; }
  :root { --ch-h: 300px; }
  #charts { left: 6px; right: 6px; bottom: calc(var(--tl-h) + 6px); flex-direction: column; }
  body.charts #card { display: none; }
  #legend, body.charts #legend { top: 88px; bottom: auto; right: 6px; width: 150px; }
  #notice { top: 46px; left: 6px; right: 6px; width: auto; transform: none; max-height: calc(100% - var(--tl-h) - 60px); }
  .alert { width: 32px; height: 32px; }
  .lang { height: 32px; }
  .tlabel { width: 112px; }
  .tlabel b { font-size: 12px; }
  #timeline { gap: 8px; padding: 0 8px; }
  body.split #map { display: none; }
  body.split #windyPane { left: 0; }
  body.split #layers, body.split #legend, body.split #card, body.split #charts { display: none; }
  #toast { bottom: calc(var(--tl-h) + 8px); }
}
/* сравнение с Windy на неширокой карте: слои — строкой под верхней панелью, карточку прячем */
@media (min-width: 761px) and (max-width: 1500px) {
  body.split #layers { top: 54px; flex-direction: row; flex-wrap: wrap; width: auto; left: 10px; max-height: none; }
  body.split #layers .lay-h, body.split #layers .lay-sep, body.split #layers .lay-opt, body.split #layers .lay-chk { display: none; }
  body.split #card { display: none; }
}
