:root {
    --bg: #eef2f7;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #172033;
    --muted: #64748b;
    --line: #d8e0ec;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #059669;
    --danger: #dc2626;
    --shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
}

* {
    box-sizing: border-box;
}

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

body {
    overflow: hidden;
    color: var(--text);
    background: var(--bg);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(340px, 390px) 1fr;
    width: 100%;
    height: 100%;
}

.sidebar {
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    padding: 10px;
    overflow-y: auto;
    background: var(--panel);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow);
}

#map {
    min-width: 0;
    min-height: 0;
    background: #b6e1fc;
}

.card {
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.segmented-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 4px;
    background: #e9eef6;
    border-radius: 12px;
}

button {
    min-height: 32px;
    padding: 6px 10px;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 9px;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
    border-color: #94a3b8;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
}

button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.25);
    outline-offset: 2px;
}

.segmented-control button {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
}

button.active,
.segmented-control button.active {
    color: #ffffff;
    background: var(--primary);
    border-color: var(--primary-dark);
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.action-grid button {
    min-width: 0;
    padding: 6px 4px;
    font-size: 12px;
    text-align: center;
}

.primary-action {
    grid-column: 1 / -1;
    color: #ffffff;
    background: var(--success);
    border-color: #047857;
}

.primary-action:hover {
    border-color: #065f46;
}

.danger-action {
    color: #991b1b;
    background: #fff5f5;
    border-color: #fecaca;
}

.danger-action:hover {
    background: #fee2e2;
    border-color: #fca5a5;
}

.coordinates-card {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 180px;
}

.coordinate-list {
    flex: 1;
    min-height: 130px;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    list-style: none;
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.coordinate-list:empty::before {
    display: block;
    padding: 16px;
    color: var(--muted);
    content: "Пока нет точек. Кликните по карте, чтобы добавить первую.";
}

.coordinate-list li {
    border-bottom: 1px solid #e2e8f0;
}

.coordinate-list li:last-child {
    border-bottom: 0;
}

.coordinate-item {
    width: 100%;
    min-height: auto;
    padding: 9px 10px;
    color: var(--text);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    line-height: 1.35;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.coordinate-item:hover {
    background: #eaf2ff;
    border-color: transparent;
    box-shadow: none;
}

.gpx-card {
    margin-bottom: 0;
}

.empty-block,
.gpx-info {
    padding: 12px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
    background: var(--panel-soft);
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
}

.gpx-info {
    display: grid;
    gap: 7px;
    color: var(--text);
    background: #f0fdf4;
    border-style: solid;
    border-color: #bbf7d0;
}

.info-row {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 8px;
}

.info-row span {
    color: var(--muted);
}

.info-row strong {
    min-width: 0;
    overflow-wrap: anywhere;
}

.status-line {
    position: sticky;
    bottom: -1px;
    padding: 8px 10px;
    color: #991b1b;
    font-size: 13px;
    line-height: 1.35;
    background: #fff5f5;
    border: 1px solid #fecaca;
    border-radius: 10px;
}

.status-line[hidden] {
    display: none;
}

.leaflet-control-attribution {
    font-size: 11px;
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 330px 1fr;
    }

    .sidebar {
        padding: 10px;
    }
}

@media (max-width: 760px) {
    body {
        overflow: auto;
    }

    .app-shell {
        display: flex;
        flex-direction: column-reverse;
        min-height: 100%;
    }

    #map {
        height: 46vh;
        min-height: 300px;
    }

    .sidebar {
        min-height: 54vh;
        overflow: visible;
        border-top: 1px solid var(--line);
        border-right: 0;
        box-shadow: 0 -16px 36px rgba(15, 23, 42, 0.12);
    }

    .coordinates-card {
        flex: 1;
    }
}

@media (max-width: 460px) {
    .action-grid {
        grid-template-columns: 1fr;
    }

    .primary-action {
        grid-column: auto;
    }

    .segmented-control {
        grid-template-columns: 1fr;
    }

    .info-row {
        grid-template-columns: 1fr;
        gap: 2px;
    }
}
