/* ============================================
   WebRadar – UI rework: mobiel + desktop, ADHD-vriendelijk
   ============================================ */

:root {
    /* Kleuren: donker thema met diepte */
    --bg: #0a0e14;
    --bg-elevated: #0d1117;
    --surface: #161b22;
    --surface-hover: #21262d;
    --surface-active: #30363d;
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.2);
    --text: #e6edf3;
    --text-muted: #8b949e;
    --text-subtle: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --accent-soft: rgba(88, 166, 255, 0.15);
    --success: #3fb950;
    --warning: #d29922;
    --error: #f85149;
    --focus-ring: 0 0 0 3px rgba(88, 166, 255, 0.5);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --touch-min: 44px;
    --sidebar-width: min(300px, 88vw);
    --header-height: 56px;
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
    --safe-left: env(safe-area-inset-left, 0);
    --safe-right: env(safe-area-inset-right, 0);
    --panel-map-size: 1;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Roboto", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    transition: background-color 0.25s ease;
}

/* ----- Top bar ----- */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    min-height: var(--header-height);
    padding: 0 16px;
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    padding-top: var(--safe-top);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 100;
}

.top-bar-title {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 0.02em;
    flex: 1;
    text-align: center;
    color: var(--text);
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-bar button {
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-hover);
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.top-bar button:hover {
    background: var(--surface-active);
    border-color: var(--accent);
    color: var(--accent-hover);
}

.top-bar button:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

#toggleSidebar {
    font-size: 1.4rem;
    line-height: 1;
}

/* Status indicator in header */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    min-height: 32px;
}

.status-pill::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.status-pill.connected::before {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-pill.disconnected::before {
    background: var(--error);
    box-shadow: 0 0 8px var(--error);
}

.status-pill.connected {
    background: rgba(63, 185, 80, 0.15);
    color: var(--success);
}

.status-pill.disconnected {
    background: rgba(248, 81, 73, 0.15);
    color: var(--error);
}

/* ----- Sidebar ----- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    max-width: 100%;
    height: 100%;
    height: 100dvh;
    padding: calc(var(--header-height) + var(--safe-top) + 20px) 20px 28px;
    padding-left: calc(20px + var(--safe-left));
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.25s ease, visibility 0.25s;
    visibility: hidden;
}

.sidebar.active {
    transform: translateX(0);
    visibility: visible;
}

.sidebar-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 16px 0;
    color: var(--text);
    letter-spacing: 0.02em;
}

.sidebar .divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

.sidebar .group-head {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 0 0 12px 0;
}

.setting-group {
    margin-bottom: 20px;
    text-align: left;
}

.setting-row {
    margin-bottom: 14px;
}

.setting-row label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 6px;
    color: var(--text);
}

.setting-row input[type="range"] {
    width: 100%;
    min-height: 32px;
    accent-color: var(--accent);
}

.setting-row input[type="color"],
.setting-row select {
    width: 100%;
    min-height: var(--touch-min);
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    cursor: pointer;
}

.setting-row input[type="color"]:hover,
.setting-row select:hover {
    border-color: var(--border-strong);
}

.setting-row input:focus-visible,
.setting-row select:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

.setting-row--checkbox label {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--touch-min);
    cursor: pointer;
}

.setting-row--checkbox input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

#resetSettings {
    width: 100%;
    min-height: var(--touch-min);
    padding: 14px 18px;
    margin-bottom: 12px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

#resetSettings:hover {
    background: rgba(248, 81, 73, 0.12);
    border-color: rgba(248, 81, 73, 0.4);
    color: var(--error);
}

#resetSettings:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-subtle);
}

/* ----- Main: radar + info ----- */
.radar-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: calc(var(--header-height) + 20px) 16px 28px;
    padding-top: calc(var(--header-height) + var(--safe-top) + 20px);
    padding-bottom: calc(28px + var(--safe-bottom));
}

/* Panels container: standaard flex (niet-vrije layout) */
.panels-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 100%;
}

.panels-container .panel-header,
.panels-container .resize-handle {
    display: none;
}

.panels-container .panel {
    width: 100%;
    max-width: 100%;
}

.panels-container .panel-content {
    display: block;
}

.radar-wrap {
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    min-height: 280px;
}

.radar-wrap.is-empty {
    border-style: dashed;
    border-color: var(--border-strong);
}

#radarCanvas {
    display: block;
    width: 100%;
    height: auto;
    max-height: 70vh;
    max-height: 70dvh;
    aspect-ratio: 1;
    object-fit: contain;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
    touch-action: none;
}

.info-panel {
    width: 100%;
    max-width: 100%;
    overflow: auto;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    -webkit-overflow-scrolling: touch;
}

#infoCanvas {
    display: block;
    width: 100%;
    height: auto;
    max-height: 400px;
}

/* ----- 600px: grotere telefoon / kleine tablet ----- */
@media (min-width: 600px) {
    .radar-main {
        padding-left: 24px;
        padding-right: 24px;
        gap: 24px;
    }

    .radar-wrap {
        min-height: 320px;
    }

    .sidebar {
        --sidebar-width: min(320px, 88vw);
    }
}

/* ----- 900px: desktop – side-by-side radar + info ----- */
@media (min-width: 900px) {
    .radar-main {
        flex-direction: row;
        justify-content: center;
        align-items: stretch;
        padding-left: 28px;
        padding-right: 28px;
        gap: 24px;
    }

    .panels-container {
        flex-direction: row;
        justify-content: center;
        align-items: stretch;
        gap: 24px;
    }

    .panels-container .panel--radar {
        flex: 1 1 0;
        min-width: 280px;
        max-width: min(calc(75vh * var(--panel-map-size)), calc(800px * var(--panel-map-size)));
    }

    .panels-container .panel--info {
        flex: 0 0 340px;
        max-width: 340px;
    }

    .radar-wrap {
        flex: 0 0 auto;
        max-width: min(calc(75vh * var(--panel-map-size)), calc(800px * var(--panel-map-size)));
        min-height: 400px;
    }

    #radarCanvas {
        max-height: 80vh;
        max-height: 80dvh;
        width: auto;
        min-width: 400px;
    }

    .info-panel {
        flex: 0 0 340px;
        max-width: 340px;
        max-height: 80vh;
        max-height: 80dvh;
    }

    #infoCanvas {
        max-height: none;
    }

    .sidebar {
        --sidebar-width: 300px;
    }
}

/* ----- 1200px: grote monitor – meer ruimte ----- */
@media (min-width: 1200px) {
    .radar-main {
        padding-left: 32px;
        padding-right: 32px;
        gap: 28px;
    }

    .panels-container .panel--radar,
    .radar-wrap {
        max-width: min(calc(80vh * var(--panel-map-size)), calc(900px * var(--panel-map-size)));
    }

    .panels-container .panel--info,
    .info-panel {
        flex: 0 0 380px;
        max-width: 380px;
    }

    .top-bar-title {
        font-size: 1.3rem;
    }
}

/* ----- Vrije panelen (drag & resize) – alleen desktop ----- */
@media (min-width: 900px) {
    body.layout-free .radar-main {
        padding: calc(var(--header-height) + var(--safe-top)) 0 0 0;
        height: calc(100vh - var(--header-height) - var(--safe-top));
        height: calc(100dvh - var(--header-height) - var(--safe-top));
        align-items: stretch;
        justify-content: stretch;
    }

    body.layout-free .panels-container {
        position: relative;
        flex: 1;
        width: 100%;
        max-width: 100%;
        gap: 0;
        align-items: stretch;
        justify-content: stretch;
    }

    body.layout-free .panels-container .panel-header,
    body.layout-free .panels-container .resize-handle {
        display: flex;
    }

    body.layout-free .panels-container .panel {
        position: absolute;
        display: flex;
        flex-direction: column;
        min-width: 200px;
        min-height: 180px;
        max-width: 100%;
        max-height: 100%;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-md);
        overflow: hidden;
        z-index: 1;
    }

    body.layout-free .panels-container .panel-header {
        flex-shrink: 0;
        padding: 10px 14px;
        background: var(--surface-hover);
        border-bottom: 1px solid var(--border);
        cursor: grab;
        user-select: none;
        align-items: center;
        justify-content: center;
    }

    body.layout-free .panels-container .panel-header:active {
        cursor: grabbing;
    }

    body.layout-free .panels-container .panel-title {
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text);
    }

    body.layout-free .panels-container .panel-content {
        flex: 1;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    body.layout-free .panels-container .radar-wrap,
    body.layout-free .panels-container .info-panel {
        flex: 1;
        max-width: none;
        max-height: none;
        border-radius: 0;
        min-height: 0;
    }

    body.layout-free .panels-container #radarCanvas {
        max-height: 100%;
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    body.layout-free .panels-container #infoCanvas {
        max-height: none;
    }

    .resize-handle {
        position: absolute;
        z-index: 2;
        background: transparent;
    }

    .resize-handle.resize-e {
        top: 0;
        right: 0;
        width: 8px;
        height: 100%;
        cursor: ew-resize;
    }

    .resize-handle.resize-w {
        top: 0;
        left: 0;
        width: 8px;
        height: 100%;
        cursor: ew-resize;
    }

    .resize-handle.resize-s {
        bottom: 0;
        left: 0;
        width: 100%;
        height: 8px;
        cursor: ns-resize;
    }

    .resize-handle.resize-se {
        bottom: 0;
        right: 0;
        width: 14px;
        height: 14px;
        cursor: nwse-resize;
    }

    .resize-handle.resize-sw {
        bottom: 0;
        left: 0;
        width: 14px;
        height: 14px;
        cursor: nesw-resize;
    }
}

/* ----- Focus & reduced motion ----- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

@supports not selector(:focus-visible) {
    button:focus,
    input:focus,
    select:focus {
        outline: none;
        box-shadow: var(--focus-ring);
    }
}
