* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --success: #10b981;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Header */
header {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.logo {
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 18px;
}

.rig-chip {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
}

.rig-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font: inherit;
}

.user-info:hover {
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.container {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 70px);
}

/* Map Section */
.map-section {
    background-color: var(--bg-primary);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    min-height: 520px;
}

.map-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
    position: relative;
}

.search-wrap {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.search-box {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
    background-color: var(--bg-tertiary);
    font-family: inherit;
}

.search-box:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--bg-primary);
}

.suggestions {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 60;
    max-height: 280px;
    overflow-y: auto;
}

.suggestions[hidden] {
    display: none;
}

.suggestion {
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.suggestion:last-child {
    border-bottom: none;
}

.suggestion:hover,
.suggestion.active {
    background-color: var(--bg-tertiary);
}

.suggestion-kind {
    color: var(--text-secondary);
    font-size: 0.7rem;
    white-space: nowrap;
}

.suggestion-empty {
    padding: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.filter-btn {
    padding: 0.75rem 1rem;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    font-family: inherit;
    color: var(--text-primary);
}

.filter-btn:hover,
.filter-btn[aria-expanded='true'] {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

.popover {
    position: absolute;
    top: calc(100% - 0.35rem);
    right: 1rem;
    width: 290px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
    padding: 1rem;
    z-index: 70;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.popover[hidden] {
    display: none;
}

.popover h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.field input[type='text'],
.field input[type='number'],
.field input[type='range'],
.field select,
.field textarea {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.field input[type='range'] {
    padding: 0;
    border: none;
    accent-color: var(--primary);
}

.field textarea {
    resize: vertical;
    min-height: 62px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
}

.check-row input {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

.map-container {
    flex: 1;
    background: linear-gradient(135deg, #e0e7ff 0%, #dbeafe 100%);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 14px;
    overflow: hidden;
    min-height: 380px;
    touch-action: none;
}

#map-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
}

#map-canvas.dragging {
    cursor: grabbing;
}

.map-placeholder {
    text-align: center;
    opacity: 0.7;
    position: absolute;
    top: 1rem;
    left: 1rem;
    text-align: left;
    background-color: rgba(255, 255, 255, 0.85);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    pointer-events: none;
    border: 1px solid var(--border-color);
}

.map-controls {
    position: absolute;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 20;
}

.map-control-btn {
    width: 44px;
    height: 44px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    color: var(--text-primary);
}

.map-control-btn:hover {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

.map-legend {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    background-color: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    pointer-events: none;
    color: var(--text-secondary);
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.panel {
    background-color: var(--bg-primary);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.panel-title-icon {
    font-size: 18px;
}

.panel-title .spacer {
    flex: 1;
}

.panel-note {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.wind-forecast {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.wind-item {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
}

.wind-time {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 40px;
}

.wind-track {
    flex: 1;
    min-width: 30px;
}

.wind-bar {
    height: 24px;
    background: linear-gradient(90deg, var(--secondary), var(--warning));
    border-radius: 4px;
    position: relative;
    min-width: 6px;
}

.wind-speed {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-left: 0.5rem;
    min-width: 58px;
    text-align: right;
}

.chargers-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 300px;
    overflow-y: auto;
}

.charger-item {
    padding: 0.75rem;
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    border-left: 3px solid var(--primary);
    cursor: pointer;
    transition: all 0.2s;
}

.charger-item:hover,
.charger-item.selected {
    background-color: var(--bg-secondary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.charger-item.selected,
.campsite-item.selected {
    outline: 2px solid var(--primary);
}

.charger-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.charger-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.charger-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background-color: var(--bg-primary);
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
}

.badge-fit {
    background-color: #dcfce7;
    color: #166534;
}

.badge-check {
    background-color: #dbeafe;
    color: #0c4a6e;
}

.badge-warn {
    background-color: #fee2e2;
    color: #991b1b;
}

.item-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.row-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.link-btn {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
}

.link-btn:hover {
    text-decoration: underline;
}

.btn {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    font-family: inherit;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    width: 100%;
}

.btn-secondary:hover {
    background-color: var(--bg-secondary);
}

.btn-small {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
}

.btn-danger {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.btn-row {
    display: flex;
    gap: 0.5rem;
}

.campsite-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 250px;
    overflow-y: auto;
}

.campsite-item {
    padding: 0.75rem;
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    border-left: 3px solid var(--secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.campsite-item:hover {
    background-color: var(--bg-secondary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.campsite-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.campsite-details {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.route-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.route-summary {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem;
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 0.875rem;
}

.route-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.route-stat-label {
    color: var(--text-secondary);
}

.route-stat-value {
    font-weight: 600;
    color: var(--text-primary);
}

.warning-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background-color: #fef3c7;
    border-left: 3px solid var(--warning);
    border-radius: 4px;
    font-size: 0.75rem;
    color: #92400e;
    margin-top: 0.75rem;
}

.warning-badge.ok {
    background-color: #dcfce7;
    border-left-color: var(--success);
    color: #166534;
}

.warning-icon {
    font-size: 14px;
}

.tab-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-family: inherit;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.scrollable {
    overflow-y: auto;
    max-height: 300px;
}

.elevation-chart {
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 0.25rem;
    height: 60px;
    margin-top: 0.5rem;
}

.chart-bar {
    flex: 1;
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    border-radius: 2px 2px 0 0;
    opacity: 0.8;
    min-height: 2px;
}

.chart-bar.steep {
    background: linear-gradient(180deg, var(--warning), #b45309);
    opacity: 1;
}

.chart-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.leg-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.leg-item {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    font-size: 0.75rem;
    padding: 0.5rem 0.6rem;
    background-color: var(--bg-tertiary);
    border-radius: 6px;
}

.leg-index {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: var(--primary);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.leg-index.charge {
    background-color: var(--warning);
}

.leg-index.camp {
    background-color: var(--secondary);
}

.leg-body {
    flex: 1;
}

.leg-title {
    font-weight: 600;
    color: var(--text-primary);
}

.leg-meta {
    color: var(--text-secondary);
}

.remove-x {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0 0.2rem;
}

.remove-x:hover {
    color: var(--danger);
}

.empty-note {
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding: 0.6rem 0;
}

/* Dialogs */
dialog {
    border: none;
    border-radius: 12px;
    padding: 0;
    width: min(460px, 92vw);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
}

dialog::backdrop {
    background: rgba(17, 24, 39, 0.45);
}

.dialog-body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 82vh;
    overflow-y: auto;
}

.dialog-title {
    font-size: 1.05rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dialog-sub {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.dialog-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 0.25rem;
}

.dialog-actions .btn {
    width: auto;
    min-width: 96px;
}

.fit-report {
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 0.78rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.fit-score {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    font-size: 0.95rem;
}

.fit-meter {
    flex: 1;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 999px;
    overflow: hidden;
}

.fit-meter span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--danger), var(--warning), var(--secondary));
}

.fit-line {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.fit-line b {
    color: var(--text-primary);
    font-weight: 600;
}

.imagery {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.imagery figure {
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.imagery canvas {
    width: 100%;
    display: block;
    background: #d6d3d1;
}

.imagery figcaption {
    font-size: 0.65rem;
    color: var(--text-secondary);
    padding: 0.3rem 0.45rem;
}

.photo-strip {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.photo-strip img {
    width: 64px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    transform: translateX(-50%) translateY(150%);
    background-color: var(--text-primary);
    color: #fff;
    padding: 0.7rem 1.1rem;
    border-radius: 8px;
    font-size: 0.8rem;
    z-index: 300;
    transition: transform 0.25s ease;
    max-width: 90vw;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success);
    display: inline-block;
}

.status-dot.offline {
    background-color: var(--warning);
}

/* Responsive */
@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr 300px;
        gap: 1rem;
        padding: 1rem;
    }

    .panel {
        padding: 1rem;
    }
}

@media (max-width: 720px) {
    header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .header-left {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .user-info {
        width: 100%;
        justify-content: center;
    }

    .container {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem;
        min-height: auto;
    }

    .map-header {
        flex-direction: column;
    }

    .search-wrap,
    .search-box {
        width: 100%;
    }

    .filter-btn {
        width: 100%;
    }

    .popover {
        left: 1rem;
        right: 1rem;
        width: auto;
    }

    .sidebar {
        order: -1;
    }

    .panel {
        max-height: 400px;
        overflow-y: auto;
        padding: 0.75rem;
    }

    .chargers-list,
    .campsite-list,
    .scrollable {
        max-height: 200px;
    }

    .tab-buttons {
        flex-wrap: wrap;
    }

    .map-controls {
        bottom: 1rem;
        right: 1rem;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* Scrollbar styling */
.chargers-list::-webkit-scrollbar,
.campsite-list::-webkit-scrollbar,
.scrollable::-webkit-scrollbar {
    width: 6px;
}

.chargers-list::-webkit-scrollbar-track,
.campsite-list::-webkit-scrollbar-track,
.scrollable::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

.chargers-list::-webkit-scrollbar-thumb,
.campsite-list::-webkit-scrollbar-thumb,
.scrollable::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chargers-list::-webkit-scrollbar-thumb:hover,
.campsite-list::-webkit-scrollbar-thumb:hover,
.scrollable::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
