/* ==================== CSS Variables ==================== */
:root {
    --bg-primary: #0b0f19;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2332;
    --bg-card: #162031;
    --bg-input: #0f1724;
    --bg-hover: #1e2d42;
    --border-primary: #1e3a5f;
    --border-secondary: #243b5a;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.4);
    --accent-cyan: #06b6d4;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --accent-orange: #f97316;
    --status-ready: #22c55e;
    --status-running: #3b82f6;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-card: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-elevated: 0 4px 14px rgba(0,0,0,0.5), 0 0 0 1px rgba(30,58,95,0.5);
    --transition-fast: 150ms cubic-bezier(0.4,0,0.2,1);
    --transition-smooth: 250ms cubic-bezier(0.4,0,0.2,1);
    --font-sans: 'Inter', 'PingFang SC', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    --bg-hover: #e2e8f0;
    --border-primary: #e2e8f0;
    --border-secondary: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #2563eb;
    --accent-glow: rgba(37,99,235,0.3);
    --shadow-card: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-elevated: 0 4px 14px rgba(0,0,0,0.1), 0 0 0 1px rgba(226,232,240,0.8);
}

@media (prefers-color-scheme: light) {
    [data-theme="auto"] {
        --bg-primary: #f8fafc;
        --bg-secondary: #ffffff;
        --bg-tertiary: #f1f5f9;
        --bg-card: #ffffff;
        --bg-input: #f8fafc;
        --bg-hover: #e2e8f0;
        --border-primary: #e2e8f0;
        --border-secondary: #cbd5e1;
        --text-primary: #0f172a;
        --text-secondary: #475569;
        --text-muted: #94a3b8;
        --accent: #2563eb;
        --accent-glow: rgba(37,99,235,0.3);
        --shadow-card: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
        --shadow-elevated: 0 4px 14px rgba(0,0,0,0.1), 0 0 0 1px rgba(226,232,240,0.8);
    }
}

/* ==================== Base ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow: hidden;
    letter-spacing: -0.01em;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 20% 10%, rgba(59,130,246,0.06) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 80%, rgba(6,182,212,0.04) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-secondary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ==================== App Layout ==================== */
.app-container {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 200px 1fr 280px;
    grid-template-rows: 52px 1fr 32px 24px;
    grid-template-areas:
        "topbar topbar topbar"
        "sidebar main panel"
        "statusbar statusbar statusbar"
        "copyright copyright copyright";
    height: 100vh;
    gap: 0;
}

/* ==================== Topbar ==================== */
.topbar {
    grid-area: topbar;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 50;
    backdrop-filter: blur(12px);
    background: rgba(17,24,39,0.85);
}
[data-theme="light"] .topbar { background: rgba(255,255,255,0.9); }
@media (prefers-color-scheme: light) { [data-theme="auto"] .topbar { background: rgba(255,255,255,0.9); } }

.topbar-brand { display: flex; align-items: center; gap: 10px; }

.topbar-logo {
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), var(--accent-cyan));
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    box-shadow: 0 0 16px var(--accent-glow);
}
.topbar-logo svg { width: 18px; height: 18px; }

.topbar-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}
.topbar-title span {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.status-indicator {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--status-ready);
    box-shadow: 0 0 8px rgba(34,197,94,0.6);
}
.status-indicator--running {
    background: var(--status-running);
    box-shadow: 0 0 8px rgba(59,130,246,0.6);
    animation: pulse 1.6s infinite;
}
@keyframes pulse {
    0%,100% { box-shadow: 0 0 6px rgba(59,130,246,0.4); }
    50% { box-shadow: 0 0 18px rgba(59,130,246,0.8); }
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.topbar-btn, .topbar-select {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}
.topbar-btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.topbar-btn:hover, .topbar-select:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(59,130,246,0.2);
}

.topbar-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 26px;
    min-width: 130px;
}
.topbar-select option { background: var(--bg-secondary); color: var(--text-primary); }

.topbar-btn--run {
    background: linear-gradient(135deg, var(--accent), #2563eb);
    border-color: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 8px 20px;
    box-shadow: 0 0 20px var(--accent-glow), 0 2px 8px rgba(0,0,0,0.3);
    letter-spacing: 0.02em;
}
.topbar-btn--run:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 0 30px rgba(59,130,246,0.6), 0 4px 12px rgba(0,0,0,0.4);
    transform: translateY(-1px);
}
.topbar-btn--run:active { transform: translateY(0); }

.topbar-btn--stop {
    background: var(--accent-rose);
    border-color: var(--accent-rose);
    color: #fff;
    font-weight: 600;
}

/* ==================== Sidebar ==================== */
.sidebar {
    grid-area: sidebar;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    padding: 12px 0;
    overflow-y: auto;
    z-index: 40;
    gap: 2px;
}

.sidebar-section { padding: 0 8px; margin-bottom: 2px; }
.sidebar-section-title {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 8px 10px 4px;
    user-select: none;
}

.sidebar-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px;
    margin: 1px 0;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    user-select: none;
}
.sidebar-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.7; }
.sidebar-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-secondary);
}
.sidebar-item:hover svg { opacity: 1; }
.sidebar-item--active {
    background: rgba(59,130,246,0.12);
    color: var(--accent);
    border-color: rgba(59,130,246,0.35);
    font-weight: 600;
}
.sidebar-item--active svg { opacity: 1; color: var(--accent); }

/* ==================== Main Content ==================== */
.main-content {
    grid-area: main;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    min-width: 0;
}

/* ==================== Right Panel ==================== */
.right-panel {
    grid-area: panel;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    z-index: 30;
}
.right-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-primary);
}
.right-panel-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
}
.btn-icon {
    background: transparent; border: none; color: var(--text-muted);
    cursor: pointer; padding: 4px; border-radius: 4px;
    transition: all var(--transition-fast);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon svg { width: 14px; height: 14px; }

.progress-bar { height: 3px; background: var(--bg-tertiary); }
.progress-fill { height: 100%; background: var(--accent); transition: width 0.3s; width: 0%; }

.console-content {
    flex: 1; overflow-y: auto; padding: 8px 12px;
    font-family: var(--font-mono); font-size: 0.72rem; line-height: 1.5;
}
.console-line { color: var(--text-secondary); }
.console-line.info { color: var(--accent); }
.console-line.success { color: var(--accent-emerald); }
.console-line.warning { color: var(--accent-amber); }
.console-line.error { color: var(--accent-rose); }

/* ==================== Map ==================== */
.map-container {
    position: relative;
    background: var(--bg-input);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    height: 455px;
    cursor: grab;
    box-shadow: var(--shadow-card);
}
.map-container:active { cursor: grabbing; }
#map-canvas { width: 100%; height: 100%; }

.map-legend {
    position: absolute; top: 10px; right: 10px;
    background: rgba(17,24,39,0.9);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    display: flex; flex-direction: column; gap: 5px;
    font-size: 0.7rem;
    backdrop-filter: blur(8px);
    z-index: 10;
}
[data-theme="light"] .map-legend { background: rgba(255,255,255,0.9); }
@media (prefers-color-scheme: light) { [data-theme="auto"] .map-legend { background: rgba(255,255,255,0.9); } }

.map-legend-item { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.map-legend-dot { width: 8px; height: 8px; flex-shrink: 0; }
.map-legend-dot--depot { background: var(--accent-rose); border-radius: 2px; }
.map-legend-dot--customer { background: var(--accent); border-radius: 50%; }
.map-legend-dot--launch { background: var(--accent-emerald); clip-path: polygon(50% 0%, 0% 100%, 100% 100%); }
.map-legend-line { width: 14px; height: 0; border-top: 2px dashed; flex-shrink: 0; }
.map-legend-line--truck { border-color: var(--accent); }
.map-legend-line--drone { border-color: var(--accent-orange); }

.map-controls {
    position: absolute; bottom: 10px; left: 10px;
    display: flex; gap: 4px; z-index: 10;
}
.map-ctrl-btn {
    width: 28px; height: 28px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-primary);
    background: rgba(17,24,39,0.9);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(8px);
    transition: all var(--transition-fast);
    font-size: 0.85rem; font-weight: 700;
    font-family: var(--font-mono);
}
[data-theme="light"] .map-ctrl-btn { background: rgba(255,255,255,0.9); }
@media (prefers-color-scheme: light) { [data-theme="auto"] .map-ctrl-btn { background: rgba(255,255,255,0.9); } }
.map-ctrl-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }

/* ==================== Stats Row ==================== */
.stats-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    display: flex; align-items: center; gap: 8px;
    transition: all var(--transition-smooth);
    box-shadow: var(--shadow-card);
}
.stat-card:hover { border-color: var(--border-secondary); box-shadow: var(--shadow-elevated); }
.stat-icon {
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 16px; height: 16px; }
.stat-icon--depot { background: rgba(244,63,94,0.15); color: var(--accent-rose); }
.stat-icon--customer { background: rgba(59,130,246,0.15); color: var(--accent); }
.stat-icon--truck { background: rgba(6,182,212,0.15); color: var(--accent-cyan); }
.stat-icon--drone { background: rgba(16,185,129,0.15); color: var(--accent-emerald); }
.stat-icon--time { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.stat-info { display: flex; flex-direction: column; min-width: 0; }
.stat-value { font-weight: 700; font-size: 1.1rem; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; }

/* ==================== Card & Form ==================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: var(--shadow-card);
    transition: all var(--transition-smooth);
}
.card:hover { border-color: var(--border-secondary); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title { font-weight: 700; font-size: 0.88rem; color: var(--text-primary); }
.card-badge {
    font-size: 0.65rem; font-weight: 600;
    padding: 2px 8px; border-radius: 20px;
    background: rgba(59,130,246,0.15); color: var(--accent);
}

.page { display: none; }
.page.active { display: block; }

.param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.param-group { display: flex; flex-direction: column; gap: 3px; }
.param-label { font-size: 0.7rem; font-weight: 600; color: var(--text-secondary); }
.param-input {
    width: 100%; padding: 7px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-primary);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: var(--font-mono);
    transition: all var(--transition-fast);
}
.param-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* ==================== Table ==================== */
.table-container { overflow-x: auto; max-height: 400px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
th {
    padding: 8px 10px; text-align: left;
    font-weight: 700; color: var(--text-secondary);
    font-size: 0.68rem; text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
    position: sticky; top: 0; z-index: 1;
}
td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border-primary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.72rem;
}
tr:hover td { background: var(--bg-hover); }
.table-input {
    width: 100%; padding: 4px 6px;
    background: var(--bg-input); border: 1px solid var(--border-primary);
    border-radius: 4px; color: var(--text-primary);
    font-size: 0.72rem; font-family: var(--font-mono);
}
.table-actions { display: flex; gap: 4px; }
.table-actions button {
    padding: 3px 6px; background: transparent;
    border: 1px solid var(--border-primary); border-radius: 4px;
    color: var(--text-muted); cursor: pointer; font-size: 0.68rem;
    transition: all var(--transition-fast);
}
.table-actions button:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.table-actions button.delete:hover { background: rgba(244,63,94,0.1); color: var(--accent-rose); border-color: var(--accent-rose); }

/* ==================== Buttons ==================== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 0.78rem; font-weight: 500;
    cursor: pointer; transition: all var(--transition-fast);
    font-family: var(--font-sans);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
    background: var(--bg-tertiary); border-color: var(--border-primary);
    color: var(--text-secondary);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

/* ==================== Result ==================== */
.result-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.result-card {
    background: var(--bg-tertiary); border: 1px solid var(--border-primary);
    border-radius: var(--radius-md); padding: 10px; text-align: center;
}
.result-label { font-size: 0.68rem; color: var(--text-muted); margin-bottom: 4px; }
.result-value { font-size: 1.1rem; font-weight: 700; color: var(--accent); }

#chart-canvas {
    width: 100%;
    height: 280px;
    background: var(--bg-input);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    display: block;
}

#plan-content {
    background: var(--bg-input); border: 1px solid var(--border-primary);
    border-radius: var(--radius-md); padding: 12px;
    font-family: var(--font-mono); font-size: 0.72rem;
    line-height: 1.6; max-height: 400px; overflow-y: auto;
    white-space: pre-wrap; color: var(--text-secondary);
}

/* ==================== Statusbar ==================== */
.statusbar {
    grid-area: statusbar;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px;
    font-size: 0.68rem; color: var(--text-muted);
    z-index: 50;
}
.statusbar-left, .statusbar-center, .statusbar-right { display: flex; align-items: center; gap: 10px; }
.statusbar-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--status-ready); box-shadow: 0 0 6px rgba(34,197,94,0.4);
}
.statusbar-dot--running { background: var(--status-running); animation: pulse 1.6s infinite; }
.statusbar-sep { opacity: 0.4; }
.statusbar strong { color: var(--text-primary); font-weight: 600; }

/* ==================== Copyright ==================== */
.copyright {
    grid-area: copyright;
    text-align: center;
    padding: 4px 16px;
    font-size: 0.6rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==================== Responsive ==================== */
@media (max-width: 1200px) {
    .app-container { 
        grid-template-columns: 180px 1fr 240px; 
    }
    .stats-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 180px 1fr;
        grid-template-rows: 52px 1fr 32px 24px;
        grid-template-areas:
            "topbar topbar"
            "sidebar main"
            "statusbar statusbar"
            "copyright copyright";
    }
    .right-panel { display: none; }
    .stats-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
    .app-container {
        grid-template-columns: 1fr;
        grid-template-rows: 48px auto 1fr auto 24px;
        grid-template-areas:
            "topbar"
            "sidebar"
            "main"
            "statusbar"
            "copyright";
    }
    .sidebar {
        flex-direction: row;
        overflow-x: auto;
        padding: 6px;
        gap: 4px;
        border-right: none;
        border-bottom: 1px solid var(--border-primary);
    }
    .sidebar-section { display: flex; gap: 4px; padding: 0; }
    .sidebar-section-title { display: none; }
    .sidebar-item { white-space: nowrap; padding: 6px 10px; font-size: 0.72rem; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .topbar-actions { gap: 4px; }
    .topbar-btn span { display: none; }
    .topbar-select { min-width: 100px; font-size: 0.72rem; }
    .map-container { height: 350px; }
    .param-grid { grid-template-columns: 1fr; }
}
