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

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ================================
   Layout
   ================================ */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.header {
    text-align: center;
    padding: 8px 0;
}

.logo {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.tagline {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.main-layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 16px;
    flex: 1;
    min-height: 0;
}

.panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-left {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.panel-right {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ================================
   Sections
   ================================ */
.section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.section-title .icon {
    font-size: 1.1rem;
}

/* ================================
   City Selector
   ================================ */
.city-selector {
    display: flex;
    gap: 8px;
}

.city-select {
    flex: 1;
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    outline: none;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.city-select:focus {
    border-color: var(--primary);
}

.city-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.city-select option[value=""] {
    color: var(--text-muted);
}

/* ================================
   Search Box
   ================================ */
.search-box {
    display: flex;
    gap: 8px;
}

.search-input {
    flex: 1;
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
    background: var(--surface);
}

.search-input:focus {
    border-color: var(--primary);
}

/* ================================
   Suggestions Dropdown
   ================================ */
.suggestions {
    display: none;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.suggestions.show {
    display: block;
}

.suggestion-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

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

.suggestion-item:hover {
    background: var(--primary-light);
}

.suggestion-item.selected {
    background: var(--primary-light);
}

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

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

/* ================================
   Home Set Indicator
   ================================ */
.home-set-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #166534;
}

.home-set-indicator .check-icon {
    color: var(--success);
    font-weight: 700;
}

.btn-clear-home {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.75rem;
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
}

/* ================================
   Location List
   ================================ */
.location-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 40px;
}

.location-list-empty {
    padding: 16px;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-light);
    background: #f8fafc;
    border-radius: 8px;
    border: 1.5px dashed var(--border);
}

.location-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: border-color 0.2s;
}

.location-item:hover {
    border-color: var(--primary);
}

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

.location-name {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.location-addr {
    font-size: 0.7rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.location-remove {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.location-remove:hover {
    color: var(--danger);
    background: #fee2e2;
}

.location-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
}

/* ================================
   Transport Mode Selector
   ================================ */
.mode-selector {
    display: flex;
    gap: 8px;
}

.mode-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 8px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: all 0.2s;
}

.mode-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.mode-btn.active {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.mode-icon {
    font-size: 1.2rem;
}

/* ================================
   Buttons
   ================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

.btn-calculate {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(99,102,241,0.35);
}

.btn-calculate:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(99,102,241,0.45);
}

.btn-calculate:disabled {
    background: #c7d2fe;
    box-shadow: none;
    transform: none;
}

.hint-text {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

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

.amap-container {
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
    z-index: 0;
}

.map-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    z-index: 1;
    pointer-events: none;
}

.map-placeholder.hidden {
    display: none;
}

.placeholder-content {
    text-align: center;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 8px;
}

.placeholder-content p {
    font-size: 0.875rem;
}

/* ================================
   Result Panel
   ================================ */
.result-panel {
    border-top: 1px solid var(--border);
    padding: 16px 20px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.result-panel.show {
    display: block;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.result-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.result-summary {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.segments-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.segment-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--bg);
    font-size: 0.82rem;
}

.segment-badge {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(99,102,241,0.3);
}

.segment-arrow {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.segment-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.segment-locations {
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.segment-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.segment-duration {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    white-space: nowrap;
}

.result-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.total-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--primary-light);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
}

.result-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
}

/* ================================
   Loading Overlay
   ================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 9999;
}

.loading-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.loading-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ================================
   Toast
   ================================ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #1e293b;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s ease;
    z-index: 9998;
    max-width: 90%;
    text-align: center;
}

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

.toast.error {
    background: var(--danger);
}

.toast.success {
    background: var(--success);
}

/* ================================
   AMap Custom Marker Styles
   ================================ */
.custom-home-marker {
    width: 54px;
    height: 54px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    border: 4px solid #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    box-shadow: 0 4px 16px rgba(99,102,241,0.5), 0 0 0 2px rgba(99,102,241,0.3);
    cursor: pointer;
    animation: home-pulse 2s ease-in-out infinite;
}

@keyframes home-pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(99,102,241,0.5), 0 0 0 2px rgba(99,102,241,0.3); }
    50% { box-shadow: 0 4px 24px rgba(99,102,241,0.7), 0 0 0 6px rgba(99,102,241,0.15); }
}

.custom-num-marker {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 800;
    color: #fff;
    box-shadow: 0 4px 16px rgba(239,68,68,0.5), 0 0 0 3px rgba(239,68,68,0.2);
    cursor: pointer;
    border: 3px solid rgba(255,255,255,0.9);
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.amap-label-home {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    padding: 5px 12px;
    border-radius: 18px;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    border: 2px solid rgba(255,255,255,0.8);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.amap-label-num-box {
    background: linear-gradient(135deg, rgba(0,0,0,0.85), rgba(0,0,0,0.75));
    color: #fff;
    padding: 5px 10px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    border: 2px solid rgba(255,255,255,0.2);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Legacy label (small circle number) */
.amap-label-num {
    background: var(--primary);
    color: #fff;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}

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

::-webkit-scrollbar-track {
    background: transparent;
}

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

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

/* ================================
   Responsive
   ================================ */
@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .panel-left {
        max-height: none;
    }

    .amap-container {
        height: 300px;
        position: relative;
    }
}
