:root {
    color-scheme: light;
    --navy: #12395a;
    --blue: #176b87;
    --aqua: #14b8a6;
    --ink: #17324d;
    --muted: #64748b;
    --line: #dce7ef;
    --surface: #ffffff;
    --background: #f1f6f9;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
    background: var(--background);
    color: var(--ink);
    font-family: "Segoe UI", Tahoma, sans-serif;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 18px 28px;
    background: linear-gradient(125deg, #0d2d49, var(--navy) 55%, var(--blue));
    color: white;
    box-shadow: 0 4px 20px rgb(15 45 73 / 18%);
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-mark {
    display: flex;
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    align-items: center;
    justify-content: center;
    border: 1px solid rgb(255 255 255 / 38%);
    border-radius: 14px;
    background: rgb(255 255 255 / 12%);
    color: #78e6da;
}

.logo-mark svg {
    display: block;
    width: 30px;
    height: 30px;
    fill: none;
    stroke: currentcolor;
    stroke-linecap: round;
    stroke-width: 2.2;
}

.logo h1 {
    margin: 0 0 3px;
    font-size: clamp(18px, 2vw, 25px);
    line-height: 1.2;
}

.logo p {
    margin: 0;
    color: #c8d9e6;
    font-size: 13px;
}

.live-status {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid rgb(255 255 255 / 25%);
    border-radius: 999px;
    background: rgb(255 255 255 / 10%);
    font-size: 12px;
    font-weight: 600;
}

.live-status span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 4px rgb(74 222 128 / 18%);
}

.main-container {
    display: grid;
    flex: 1;
    grid-template-columns: minmax(320px, 40%) minmax(0, 1fr);
    min-height: 0;
}

.map-section {
    min-height: 520px;
    border-right: 1px solid var(--line);
    background: #dce8ee;
}

#map {
    width: 100%;
    height: 100%;
}

.data-section {
    min-width: 0;
    overflow-y: auto;
    padding: 24px;
}

.collapsible-container {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: 0 10px 30px rgb(22 50 77 / 8%);
}

.table-toggle {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 18px 20px;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    text-align: left;
}

.table-toggle:hover {
    background: #f8fbfc;
}

.table-toggle strong,
.table-toggle small {
    display: block;
}

.table-toggle strong {
    font-size: 18px;
}

.table-toggle small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.table-toggle::after {
    content: "⌃";
    color: var(--blue);
    font-size: 20px;
    transition: transform 160ms ease;
}

.table-toggle.collapsed::after {
    transform: rotate(180deg);
}

.data-table-container {
    overflow-x: auto;
}

.data-table-container.collapsed {
    display: none;
}

.buoy-table {
    width: 100%;
    min-width: 1050px;
    border-collapse: collapse;
}

.buoy-table th {
    position: sticky;
    top: 0;
    padding: 13px 12px;
    border-bottom: 1px solid var(--line);
    background: #edf5f8;
    color: #466278;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.35;
    text-align: center;
}

.buoy-table td {
    padding: 15px 12px;
    border-bottom: 1px solid #e8eff4;
    color: #314b61;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    text-align: center;
    white-space: pre-line;
}

.buoy-table tbody tr {
    transition: background 120ms ease;
}

.buoy-table tbody tr:nth-child(even) {
    background: #fbfdfe;
}

.buoy-table tbody tr:hover {
    background: #eef8f8;
}

.buoy-table tbody tr:last-child td {
    border-bottom: 0;
}

.buoy-table .buoy-name {
    color: var(--navy);
    font-size: 14px;
    font-weight: 700;
    text-align: left;
}

.inference {
    font-weight: 700;
}

.inference::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 7px;
    border-radius: 50%;
    background: currentColor;
    vertical-align: 1px;
}

.inference-safe {
    color: #15803d !important;
}

.inference-leak {
    color: #dc2626 !important;
}

.inference-waiting {
    color: #b06b09 !important;
}

.leaflet-popup-content h4 {
    margin: 0 0 8px;
    color: var(--navy);
}

footer {
    padding: 11px 28px;
    background: #0d2d49;
    color: #bdd0df;
}

footer p {
    margin: 0;
    font-size: 12px;
}

@media (max-width: 1050px) {
    .main-container {
        grid-template-columns: 1fr;
    }

    .map-section {
        min-height: 320px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
}

@media (max-width: 700px) {
    header {
        align-items: flex-start;
        padding: 15px 16px;
    }

    .logo-mark {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
        border-radius: 12px;
    }

    .logo-mark svg {
        width: 26px;
        height: 26px;
    }

    .logo p {
        display: none;
    }

    .live-status {
        padding: 7px 9px;
        font-size: 0;
    }

    .data-section {
        padding: 14px;
    }

    .map-section {
        min-height: 240px;
    }

    .collapsible-container {
        border-radius: 13px;
    }

    .table-toggle {
        padding: 15px 16px;
    }

    .table-toggle strong {
        font-size: 16px;
    }

    .data-table-container {
        overflow: visible;
    }

    .buoy-table,
    .buoy-table tbody,
    .buoy-table tr,
    .buoy-table td {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .buoy-table thead {
        display: none;
    }

    .buoy-table tbody {
        padding: 12px;
    }

    .buoy-table tbody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        overflow: hidden;
        margin-bottom: 12px;
        border: 1px solid var(--line);
        border-radius: 12px;
        background: white;
    }

    .buoy-table tbody tr:last-child {
        margin-bottom: 0;
    }

    .buoy-table td {
        position: relative;
        min-height: 60px;
        padding: 27px 12px 10px;
        border-bottom: 1px solid #e8eff4;
        text-align: left;
    }

    .buoy-table td:nth-child(odd) {
        border-right: 1px solid #e8eff4;
    }

    .buoy-table td::before {
        content: attr(data-label);
        position: absolute;
        margin-top: -17px;
        color: var(--muted);
        font-size: 9px;
        font-weight: 700;
        letter-spacing: 0.03em;
    }

    .buoy-table .buoy-name,
    .buoy-table td:nth-child(7),
    .buoy-table td:nth-child(8),
    .buoy-table td:nth-child(9),
    .buoy-table td:nth-child(10) {
        grid-column: 1 / -1;
        border-right: 0;
    }

    .buoy-table .buoy-name {
        min-height: auto;
        padding: 16px 12px 14px;
        background: #edf7f8;
        font-size: 15px;
    }

    .buoy-table .buoy-name::before {
        display: none;
    }

    footer {
        padding: 10px 16px;
        text-align: center;
    }
}
