/* ============================================================
   Delivery Planner — Dark Dashboard Theme
   ============================================================ */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222536;
    --bg-card-hover: #2a2e42;
    --border: #2e3348;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0b4;
    --text-muted: #636882;
    --accent: #e8723a;
    --accent-light: #f4a261;
    --success: #00b894;
    --danger: #e17055;
    --warning: #fdcb6e;
    --blue: #3b82f6;
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 420px;
    --transition: 0.2s ease;
}

* {
    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);
    overflow: hidden;
    height: 100vh;
}

/* ---- App Layout ---- */
.app {
    display: flex;
    height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--accent-light);
}

.logo h1 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, #f4a261, #e8723a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ---- Stats Bar ---- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
}

.stat {
    text-align: center;
    padding: 8px 4px;
}

.stat-value {
    display: block;
    font-size: 22px;
    font-weight: 700;
    color: var(--accent-light);
    line-height: 1.2;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ---- Action Buttons ---- */
.actions {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), #d45d22);
    color: white;
    box-shadow: 0 4px 15px rgba(232, 114, 58, 0.3);
}

.btn-accent:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(232, 114, 58, 0.5);
    transform: translateY(-1px);
}

.btn-accent:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.hidden {
    display: none !important;
}

/* ---- Time Comparison ---- */
.comparison {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    animation: fadeIn 0.5s ease;
}

.comparison-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
}

.comparison-item.bad {
    background: rgba(225, 112, 85, 0.1);
    border: 1px solid rgba(225, 112, 85, 0.2);
}

.comparison-item.good {
    background: rgba(0, 184, 148, 0.1);
    border: 1px solid rgba(0, 184, 148, 0.2);
}

.comparison-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.comparison-item.bad .comparison-value {
    color: var(--danger);
    font-weight: 700;
    font-size: 16px;
}

.comparison-item.good .comparison-value {
    color: var(--success);
    font-weight: 700;
    font-size: 16px;
}

.comparison-desc {
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-muted);
    padding: 4px 14px 8px;
}

.comparison-arrow {
    text-align: center;
    color: var(--text-muted);
    padding: 2px;
}

.savings {
    text-align: center;
    margin-top: 10px;
    padding: 8px 12px;
    background: rgba(0, 184, 148, 0.08);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--success);
}

/* ---- Vehicles Section ---- */
.vehicles-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    animation: fadeIn 0.5s ease;
}

.vehicles-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.vehicle-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 8px;
    border-left: 3px solid;
    cursor: pointer;
    transition: all var(--transition);
}

.vehicle-card:hover {
    background: var(--bg-card-hover);
}

.vehicle-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.vehicle-name {
    font-weight: 600;
    font-size: 14px;
}

.vehicle-departure {
    font-size: 12px;
    color: var(--text-muted);
}

.vehicle-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-secondary);
}

.vehicle-stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

.vehicle-stat strong {
    color: var(--text-primary);
}

.capacity-bar {
    height: 4px;
    background: var(--bg-primary);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.capacity-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.8s ease;
}

/* ---- Orders Section ---- */
.orders-section {
    padding: 16px 20px 0;
}

.orders-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    background: var(--accent);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.orders-list {
    padding-bottom: 16px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-muted);
    text-align: center;
    gap: 12px;
}

.empty-state p {
    font-size: 13px;
}

.order-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition);
    animation: slideUp 0.3s ease;
}

.order-card:hover {
    border-color: var(--accent);
    background: var(--bg-card-hover);
}

.order-card.highlighted {
    border-color: var(--accent-light);
    box-shadow: 0 0 12px rgba(108, 92, 231, 0.2);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.order-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.order-cafe {
    font-weight: 600;
    font-size: 13px;
    line-height: 1.3;
}

.order-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    background: var(--bg-primary);
    padding: 2px 8px;
    border-radius: 4px;
}

.order-address {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.order-placed {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.7;
    margin-bottom: 8px;
}

.order-items {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.order-card.expanded .order-items {
    max-height: 200px;
}

.order-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    font-size: 12px;
}

.order-weight {
    color: var(--text-muted);
}

.order-total {
    font-weight: 600;
    color: var(--accent-light);
}

.order-zone-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

/* ---- Sidebar Footer ---- */
.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: var(--bg-secondary);
}

.sidebar-footer strong {
    color: var(--success);
}

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

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

/* Leaflet overrides — greyscale map for data contrast */
.leaflet-tile-pane {
    filter: grayscale(1) brightness(0.78) contrast(1.15);
}

.leaflet-control-zoom a {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}

.leaflet-control-attribution {
    background: rgba(15, 17, 23, 0.8) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: var(--text-secondary) !important;
}

/* ---- Map Legend ---- */
.map-legend {
    position: absolute;
    bottom: 30px;
    right: 16px;
    z-index: 1000;
    background: rgba(26, 29, 39, 0.92);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    min-width: 160px;
}

.map-legend h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    opacity: 0.7;
}

/* ---- Custom Markers ---- */
.marker-warehouse {
    background: var(--accent);
    border: 3px solid white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(232, 114, 58, 0.6);
}

.marker-coffee {
    width: 28px;
    height: 28px;
    background: var(--bg-card);
    border: 2px solid;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: transform 0.2s;
}

.marker-coffee:hover {
    transform: scale(1.2);
}

.marker-coffee.has-order {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
    50% { box-shadow: 0 2px 16px rgba(232, 114, 58, 0.5); }
}

/* ---- Fleet Config ---- */
.fleet-config {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.fleet-config h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.fleet-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fleet-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
}

.fleet-row label {
    white-space: nowrap;
    flex-shrink: 0;
}

.fleet-row label {
    font-size: 13px;
    color: var(--text-secondary);
}

.number-input {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.number-input input {
    width: 50px;
    text-align: center;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 6px 0;
    -moz-appearance: textfield;
}

.number-input input::-webkit-outer-spin-button,
.number-input input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.num-btn {
    background: transparent;
    border: none;
    color: var(--accent-light);
    font-size: 16px;
    font-weight: 700;
    padding: 6px 12px;
    cursor: pointer;
    transition: background var(--transition);
}

.num-btn:hover {
    background: var(--bg-card-hover);
}

.range-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Custom number stepper */
.num-stepper {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-card);
    height: 32px;
}

.num-stepper .step-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    background: transparent;
    border: none;
    color: var(--accent-light);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition);
    user-select: none;
    flex-shrink: 0;
}

.num-stepper .step-btn:hover {
    background: var(--bg-card-hover);
}

.num-stepper .step-btn:active {
    background: var(--accent);
    color: white;
}

.num-stepper .inline-number {
    width: 44px;
    text-align: center;
    background: transparent;
    border: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 0;
    -moz-appearance: textfield;
}

.num-stepper .inline-number:focus {
    outline: none;
    background: var(--bg-primary);
}

.num-stepper .inline-number::-webkit-outer-spin-button,
.num-stepper .inline-number::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.inline-time {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 10px;
    height: 32px;
    color-scheme: dark;
}

.inline-time:focus {
    outline: none;
    border-color: var(--accent);
}

.range-sep {
    color: var(--text-muted);
    font-size: 12px;
}

.fleet-summary {
    margin-top: 10px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

/* ---- Vehicle Rounds ---- */
.vehicle-rounds {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.round-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    padding: 6px 8px;
    background: var(--bg-primary);
    border-radius: 6px;
}

.round-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.round-zone {
    font-weight: 600;
    color: var(--text-primary);
}

.round-detail {
    color: var(--text-muted);
    font-size: 11px;
}

.round-info .capacity-bar {
    width: 100%;
    margin-top: 4px;
}

.round-info .round-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.round-info .round-header .capacity-bar {
    width: 100%;
}

/* ---- Timetable ---- */
.round-info .timetable {
    display: none;
    margin-top: 8px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
    overflow: hidden;
}

.round-info.expanded .timetable {
    display: block;
}

.tt-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    font-size: 11px;
    overflow: hidden;
}

.tt-icon {
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    font-size: 12px;
}

.tt-num {
    color: white;
    font-size: 9px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', sans-serif;
}

.tt-name {
    flex: 1;
    min-width: 0;
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tt-times {
    color: var(--text-muted);
    font-size: 10px;
    white-space: nowrap;
    flex-shrink: 0;
}

.tt-ready {
    font-size: 10px;
    color: var(--warning);
    padding-left: 28px;
    line-height: 1.4;
    word-break: break-word;
}

.tt-warehouse .tt-name {
    color: var(--accent-light);
}

.tt-wait {
    color: var(--warning);
    font-size: 10px;
    font-weight: 600;
}

.item-ready {
    color: var(--text-muted);
    font-size: 10px;
    float: right;
}

.tt-drive {
    text-align: center;
    font-size: 10px;
    color: var(--text-muted);
    padding: 2px 0;
    opacity: 0.7;
}

/* ---- Map Tooltips ---- */
.custom-tooltip {
    background: rgba(26, 29, 39, 0.95) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    padding: 8px 12px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 12px !important;
    line-height: 1.5 !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
    max-width: 250px !important;
}

.custom-tooltip::before {
    border-top-color: rgba(26, 29, 39, 0.95) !important;
}

/* ---- Animations ---- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 45vh;
    }
    .app {
        flex-direction: column;
    }
    .map-container {
        height: 55vh;
    }
}
