:root {
    color-scheme: dark;
    --bg: #040a11;
    --panel: rgba(10, 21, 32, 0.92);
    --panel-border: rgba(126, 177, 215, 0.18);
    --text: #edf8ff;
    --muted: #92a9b9;
    --accent: #36f39a;
    --accent-soft: rgba(54, 243, 154, 0.15);
    --blue: #4eb8ff;
    --danger: #ff6f73;
    --warning: #ffca58;
    --radius: 24px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 18% 0%, rgba(0, 141, 204, 0.17), transparent 38%),
        radial-gradient(circle at 100% 0%, rgba(23, 121, 87, 0.13), transparent 28%),
        linear-gradient(145deg, #03070c, #07121d 60%, #04090f);
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(1500px, 100%); margin: 0 auto; padding: 24px; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    margin-bottom: 20px;
}
.eyebrow {
    margin: 0 0 5px;
    color: var(--accent);
    font-size: 0.76rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-weight: 800;
}
h1, h2 { margin: 0; line-height: 1.1; }
h1 { font-size: clamp(1.9rem, 3vw, 2.8rem); }
h2 { font-size: 1.16rem; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 13px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.08em;
}
.status-badge.simulated { color: #ffe6a7; background: rgba(255, 185, 63, 0.13); border: 1px solid rgba(255, 185, 63, 0.36); }
.status-badge.live { color: #d7ffe7; background: rgba(26, 176, 91, 0.30); border: 1px solid rgba(64, 235, 137, 0.82); box-shadow: 0 0 14px rgba(42, 220, 120, 0.18); }
.status-badge.delayed { color: #fff0bf; background: rgba(222, 139, 26, 0.28); border: 1px solid rgba(255, 182, 71, 0.82); box-shadow: 0 0 14px rgba(255, 166, 43, 0.16); }
.status-badge.waiting { color: #ffe2e5; background: rgba(203, 40, 57, 0.32); border: 1px solid rgba(255, 91, 105, 0.86); box-shadow: 0 0 14px rgba(255, 70, 86, 0.18); }

.dashboard { display: grid; grid-template-columns: minmax(0, 1.58fr) minmax(340px, 0.72fr); gap: 20px; align-items: start; }
.radar-card, .control-card {
    background: linear-gradient(150deg, rgba(13, 27, 40, 0.96), rgba(5, 13, 21, 0.96));
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}
.radar-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--panel-border);
}
.label { display: block; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
.toolbar-stats { display: flex; gap: 28px; text-align: right; }

.radar-stage-wrap {
    position: relative;
    display: grid;
    place-items: center;
    padding: clamp(18px, 4vw, 42px);
    min-height: 620px;
    background:
        linear-gradient(rgba(6, 20, 29, 0.72), rgba(6, 20, 29, 0.72)),
        repeating-linear-gradient(0deg, transparent 0 34px, rgba(79, 216, 182, 0.035) 35px),
        repeating-linear-gradient(90deg, transparent 0 34px, rgba(79, 216, 182, 0.035) 35px);
}
.radar-stage {
    position: relative;
    width: min(720px, 78vw, calc(100vh - 245px));
    aspect-ratio: 1;
    border-radius: 50%;
    overflow: hidden;
    border: 10px solid #102434;
    box-shadow: 0 0 0 1px rgba(118, 198, 234, 0.25), 0 0 60px rgba(21, 224, 143, 0.1), inset 0 0 55px rgba(0, 0, 0, 0.9);
    background: #02070b;
}
.radar-stage canvas { width: 100%; height: 100%; display: block; }
.zoom-controls {
    position: absolute;
    z-index: 6;
    top: 50%;
    right: clamp(12px, 2vw, 26px);
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid rgba(126, 177, 215, 0.24);
    border-radius: 16px;
    background: rgba(3, 12, 19, 0.82);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.38);
    backdrop-filter: blur(10px);
}
.zoom-button {
    width: 46px;
    height: 46px;
    padding: 0;
    border-radius: 13px;
    border: 1px solid rgba(121, 209, 174, 0.34);
    color: #eafff4;
    background: linear-gradient(150deg, rgba(33, 132, 96, 0.52), rgba(11, 54, 43, 0.82));
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 7px 18px rgba(0,0,0,0.24);
    font-size: 1.75rem;
    line-height: 1;
    font-weight: 800;
    transition: transform 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
}
.zoom-button:hover:not(:disabled),
.zoom-button:focus-visible:not(:disabled) {
    transform: translateY(-1px);
    border-color: rgba(83, 246, 171, 0.88);
    outline: none;
}
.zoom-button:disabled {
    cursor: not-allowed;
    opacity: 0.32;
}
.zoom-range-readout {
    min-width: 48px;
    color: #d8eee5;
    font-size: 0.7rem;
    font-weight: 900;
    text-align: center;
    letter-spacing: 0.03em;
}
.radar-glass {
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 50%;
    background: radial-gradient(circle at 34% 22%, rgba(255,255,255,0.08), transparent 25%), linear-gradient(125deg, rgba(255,255,255,0.025), transparent 30%);
}
.radar-message {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 20%;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    font-weight: 700;
}
.hidden { display: none !important; }
.radar-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 22px;
    padding: 16px 24px 20px;
    color: var(--muted);
    font-size: 0.82rem;
    border-top: 1px solid var(--panel-border);
}
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 7px; }
.legend-dot.underway { background: #58f0a4; }
.legend-dot.passenger { background: #5ec8ff; }
.legend-dot.fishing { background: #ffd262; }
.legend-dot.service { background: #ff9a5c; }
.legend-dot.anchored { background: #9ca8b4; }

.control-card { position: sticky; top: 18px; }
.panel-section { padding: 22px; }
.panel-section + .panel-section { border-top: 1px solid var(--panel-border); }
.section-heading { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.icon-button {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--panel-border);
    background: rgba(255,255,255,0.04);
    color: var(--text);
    font-size: 1.35rem;
}
.empty-state { color: var(--muted); line-height: 1.55; padding: 14px 0 2px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin: 0; }
.detail-grid > div { padding: 11px 12px; border-radius: 13px; background: rgba(255,255,255,0.035); border: 1px solid rgba(255,255,255,0.055); }
.detail-grid .wide { grid-column: 1 / -1; }
dt { color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
dd { margin: 0; font-weight: 750; word-break: break-word; }
.save-state { min-height: 20px; color: var(--accent); font-size: 0.8rem; }
.settings-note { margin: 0 0 12px; color: var(--muted); font-size: 0.76rem; line-height: 1.45; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; color: var(--muted); font-size: 0.78rem; margin: 0 0 6px 2px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input, select {
    width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(159, 201, 225, 0.18);
    background: rgba(0, 0, 0, 0.22);
    color: var(--text);
    padding: 11px 12px;
    outline: none;
}
input:focus, select:focus { border-color: rgba(54, 243, 154, 0.68); box-shadow: 0 0 0 3px rgba(54, 243, 154, 0.1); }
.toggle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 18px; }
.toggle { display: flex; align-items: center; gap: 9px; min-height: 44px; padding: 9px 10px; color: #c8d8e2; background: rgba(255,255,255,0.025); border: 1px solid rgba(255,255,255,0.05); border-radius: 12px; font-size: 0.78rem; }
.toggle input { display: none; }
.toggle span { position: relative; width: 34px; height: 20px; flex: 0 0 auto; border-radius: 999px; background: #263844; transition: 0.2s ease; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: white; transition: 0.2s ease; }
.toggle input:checked + span { background: #1f9b6a; }
.toggle input:checked + span::after { transform: translateX(14px); }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border-radius: 12px;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid transparent;
    font-weight: 800;
}
.button.primary { color: #032117; background: linear-gradient(135deg, #55f2aa, #20c884); box-shadow: 0 8px 25px rgba(28, 216, 139, 0.18); }
.button.secondary { color: var(--text); background: rgba(255,255,255,0.045); border-color: var(--panel-border); }
.button.full { width: 100%; }
.page-footer { padding: 18px 4px 0; color: #6f8796; font-size: 0.78rem; text-align: center; }

body.mode-marine { --accent: #57c7ff; --accent-soft: rgba(87,199,255,.14); }
body.mode-scdiving { --accent: #74ecff; --accent-soft: rgba(116,236,255,.13); }
body.fullscreen-radar .topbar,
body.fullscreen-radar .control-card,
body.fullscreen-radar .radar-toolbar,
body.fullscreen-radar .radar-footer,
body.fullscreen-radar .page-footer { display: none; }
body.fullscreen-radar .app-shell { width: 100%; padding: 0; }
body.fullscreen-radar .dashboard { display: block; }
body.fullscreen-radar .radar-card { border: 0; border-radius: 0; min-height: 100vh; }
body.fullscreen-radar .radar-stage-wrap { min-height: 100vh; padding: 12px; }
body.fullscreen-radar .radar-stage { width: min(96vw, 96vh); }
body.fullscreen-radar .zoom-controls { right: max(18px, env(safe-area-inset-right)); }

@media (max-width: 1050px) {
    .dashboard { grid-template-columns: 1fr; }
    .control-card { position: static; }
    .radar-stage-wrap { min-height: auto; }
    .radar-stage { width: min(720px, 88vw); }
}
@media (max-width: 650px) {
    .app-shell { padding: 14px; }
    .topbar { align-items: flex-start; }
    .topbar-actions { flex-direction: column; align-items: flex-end; }
    .status-badge { min-height: 30px; }
    .radar-toolbar { align-items: flex-start; padding: 16px; }
    .toolbar-stats { gap: 13px; }
    .toolbar-stats .label { font-size: 0.58rem; }
    .radar-stage-wrap { padding: 12px; }
    .radar-stage { width: min(92vw, 560px); border-width: 6px; }
    .zoom-controls {
        top: auto;
        right: 18px;
        bottom: 18px;
        transform: none;
        padding: 6px;
        gap: 5px;
        border-radius: 14px;
    }
    .zoom-button { width: 42px; height: 42px; font-size: 1.55rem; }
    .zoom-range-readout { font-size: 0.64rem; }
    .radar-footer { padding: 13px 16px 16px; }
    .field-row, .toggle-grid { grid-template-columns: 1fr; }
}
