/* ===== CSS Variables ===== */
:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #121212;
    --bg-tertiary: #1a1a1a;
    --text-primary: #e5e5e5;
    --text-secondary: #8a8a8a;
    --text-muted: #555555;
    --accent-primary: #10b981;
    --accent-secondary: #059669;
    --accent-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --success: #10b981;
    --warning: #d97706;
    --danger: #dc2626;
    --border-color: #2a2a2a;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --sidebar-width: 480px;
    --sidebar-min-width: 350px;
    --sidebar-max-width: 700px;
}


/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ===== Layout ===== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-min-width);
    max-width: var(--sidebar-max-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 24px;
    gap: 24px;
    position: relative;
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    background: transparent;
    cursor: ew-resize;
    transition: background 0.2s ease;
    z-index: 100;
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--accent-primary);
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 40px;
    background: var(--border-color);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.resize-handle:hover::after {
    opacity: 1;
}

.sidebar-header {
    text-align: center;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ===== Demo Section ===== */
.demo-section {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
}

.demo-icon {
    font-size: 1.5rem;
}

.demo-controls {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.demo-select {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.demo-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.demo-btn {
    padding: 10px 16px;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: #0a0a0a;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.demo-btn:hover {
    background: var(--accent-secondary);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
}

.demo-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== API Key Section ===== */
.api-key-section {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
    border: 1px solid var(--border-color);
}

.api-key-section .section-header {
    cursor: pointer;
    margin-bottom: 0;
}

.api-key-section .section-header.collapsed {
    margin-bottom: 0;
}

.api-icon {
    font-size: 1.25rem;
}

.collapse-icon {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.api-key-section .section-header:not(.collapsed) .collapse-icon {
    transform: rotate(180deg);
}

.api-key-content {
    margin-top: 12px;
}

.api-key-content.hidden {
    display: none;
}

.api-key-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: monospace;
}

.api-key-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.api-key-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.save-api-btn {
    padding: 8px 16px;
    background: var(--success);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.save-api-btn:hover {
    background: #16a34a;
}

.api-key-status {
    font-size: 0.75rem;
    color: var(--success);
}

.api-key-info {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.api-key-info a {
    color: var(--accent-primary);
    text-decoration: none;
}

.api-key-info a:hover {
    text-decoration: underline;
}

/* ===== Sector Selection ===== */
.sector-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.sector-section label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.sector-select {
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    min-width: 180px;
}

.sector-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* ===== Auto Fetch Section (Coming Soon) ===== */
.auto-fetch-section {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
    border: 1px dashed var(--border-color);
}

.disabled-section {
    opacity: 0.6;
    position: relative;
}

.coming-soon-badge {
    background: var(--text-muted);
    color: var(--bg-primary);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.auto-fetch-controls {
    display: flex;
    gap: 8px;
    margin: 12px 0;
}

.city-select,
.district-select {
    flex: 1;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.8rem;
}

.auto-fetch-btn {
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: not-allowed;
}

.coming-soon-info {
    font-size: 0.75rem;
    color: #b8860b;
    line-height: 1.4;
    padding: 8px;
    background: rgba(184, 134, 11, 0.15);
    border-radius: var(--radius-sm);
    border-left: 3px solid #b8860b;
}

/* ===== Sections ===== */
.location-section {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.section-icon {
    font-size: 1.5rem;
}

.section-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.section-desc {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* ===== Search ===== */
.search-container {
    position: relative;
    margin-bottom: 12px;
}

.search-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* ===== Suggestions Dropdown ===== */
.suggestions-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.suggestions-dropdown.active {
    display: block;
}

.suggestion-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

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

.suggestion-item:hover {
    background: var(--bg-tertiary);
}

.suggestion-name {
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 2px;
}

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

/* ===== Location List ===== */
.location-list {
    list-style: none;
    max-height: 150px;
    overflow-y: auto;
}

.location-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 0.875rem;
}

.location-item:last-child {
    margin-bottom: 0;
}

.location-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.remove-btn:hover {
    background: var(--danger);
    color: white;
}

.list-count {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: right;
    margin-top: 8px;
}

/* ===== Settings ===== */
.settings-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.settings-section label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.number-input {
    width: 60px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    text-align: center;
}

.number-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* ===== Optimize Button ===== */
.optimize-btn {
    width: 100%;
    padding: 16px 24px;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-md);
    color: #0a0a0a;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: none;
}

.optimize-btn:hover {
    background: var(--accent-secondary);
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.2);
}

.optimize-btn:active {
    transform: translateY(0);
}

.optimize-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: var(--text-muted);
}

/* ===== Result Area ===== */
.result-area {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
}

.result-area.hidden {
    display: none;
}

.result-area h3 {
    font-size: 1rem;
    margin-bottom: 12px;
}

.result-item {
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border-left: 3px solid var(--accent-primary);
    cursor: pointer;
    transition: background 0.2s ease;
}

.result-item:hover {
    background: var(--bg-tertiary);
}

.result-header {
    display: flex;
    flex-direction: column;
}

.result-shop-name {
    font-weight: 600;
    margin-bottom: 2px;
}

.result-shop-address {
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-connections {
    color: var(--text-secondary);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.expand-icon {
    font-size: 0.65rem;
    transition: transform 0.2s ease;
}

/* Expandable Details */
.result-details {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.result-details.hidden {
    display: none;
}

.connected-point {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
}

.connected-point:last-child {
    border-bottom: none;
}

.point-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    margin-right: 12px;
}

.point-name {
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.point-address {
    color: var(--text-muted);
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.point-distance {
    color: var(--success);
    font-weight: 600;
    white-space: nowrap;
}

.total-distance {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-primary);
    border-radius: var(--radius-sm);
    text-align: center;
    font-weight: 600;
    color: var(--accent-primary);
}

/* ===== Map ===== */
.map-container {
    flex: 1;
    position: relative;
}

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

/* ===== Custom Leaflet Markers ===== */
.custom-marker {
    background: var(--accent-gradient);
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: var(--shadow);
}

.demand-marker {
    background: #3b82f6;
}

.candidate-marker {
    background: #f59e0b;
}

.selected-marker {
    background: #22c55e;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(34, 197, 94, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

/* ===== Loading State ===== */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        max-height: 50vh;
        overflow-y: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 16px;
    }

    .resize-handle {
        display: none;
    }

    .map-container {
        height: 50vh;
        min-height: 50vh;
    }

    #map {
        width: 100%;
        height: 100%;
        min-height: 50vh;
        touch-action: pan-x pan-y pinch-zoom;
    }

    .sidebar-header h1 {
        font-size: 1.25rem;
    }

    .section-header h2 {
        font-size: 0.9rem;
    }

    .location-list {
        max-height: 120px;
    }

    .demo-controls {
        flex-direction: column;
    }

    .demo-btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .sidebar {
        padding: 12px;
        gap: 16px;
    }

    .sidebar-header h1 {
        font-size: 1.1rem;
    }

    .subtitle,
    .section-desc {
        font-size: 0.7rem;
    }

    .search-input {
        font-size: 0.8rem;
        padding: 10px 12px;
    }

    .optimize-btn {
        font-size: 0.9rem;
        padding: 14px 20px;
    }

    .location-item {
        font-size: 0.8rem;
        padding: 8px 10px;
    }
}