/* Vazirmatn Font */
@font-face {
  font-family: 'Vazir';
  src: url('./assets/fonts/vazirmatn-arabic.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Vazir';
  src: url('./assets/fonts/vazirmatn-arabic.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}

:root {
      --primary: #1a73e8;
      --primary-hover: #155abf;
      --bg-color: #f8f9fa;
      --panel-bg: #ffffff;
      --text-main: #333333;
      --text-muted: #666666;
      --border-color: #dee2e6;
      --vehicle-color: #4caf50;
      --job-color: #ff6f00;
      --depot-color: #9c27b0;
      --danger: #dc3545;
    }

    [data-theme="dark"] {
      --bg-color: #121212;
      --panel-bg: #1e1e1e;
      --text-main: #e0e0e0;
      --text-muted: #aaaaaa;
      --border-color: #333333;
    }

    * { box-sizing: border-box; font-family: 'Vazir', sans-serif; }

    body, html {
      margin: 0; padding: 0; height: 100%;
      background-color: var(--bg-color);
      color: var(--text-main);
      overflow: hidden;
      transition: background-color 0.3s, color 0.3s;
    }

    /* Layout */
    .app-container {
      display: flex; height: 100vh;
      position: relative;
      transition: all 0.3s ease;
    }

    #toggleSidebarBtn {
        position: absolute;
        top: 10px;
        right: 10px;
        z-index: 20;
        background: var(--panel-bg);
        border: 1px solid var(--border-color);
    }

    .sidebar {
      width: 400px; min-width: 400px;
      background: var(--panel-bg);
      border-left: 1px solid var(--border-color);
      display: flex; flex-direction: column;
      z-index: 10;
      transition: margin-right 0.3s ease;
    }
    .sidebar.collapsed {
        margin-right: -400px;
    }
    .sidebar.collapsed + .map-area #toggleSidebarBtn {
        right: 10px; /* Keep it visible */
    }


    .map-area {
      flex-grow: 1; position: relative;
    }

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

    /* Sidebar Panels */
    .panel-header {
      padding: 15px; border-bottom: 1px solid var(--border-color);
      display: flex; justify-content: space-between; align-items: center;
    }

    .panel-content {
      flex-grow: 1; overflow-y: auto; padding: 15px;
    }

    .tabs {
      display: flex; border-bottom: 1px solid var(--border-color);
    }
    .tab {
      flex: 1; text-align: center; padding: 10px; cursor: pointer;
      border-bottom: 2px solid transparent; font-weight: bold;
    }
    .tab.active { border-bottom-color: var(--primary); color: var(--primary); }

    /* Buttons */
    button {
      cursor: pointer; border: none; border-radius: 4px;
      padding: 8px 12px; font-weight: bold; transition: all 0.2s;
    }
    .btn-primary { background: var(--primary); color: white; }
    .btn-primary:hover { background: var(--primary-hover); }
    .btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-main); }
    .btn-icon { padding: 4px 8px; font-size: 14px; }

    .list-section {
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-bottom: 15px;
        overflow: hidden;
        background: var(--panel-bg);
    }

    .list-section-header {
        padding: 10px 15px;
        background: var(--bg-color);
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-weight: bold;
        user-select: none;
        border-bottom: 1px solid transparent;
        transition: background-color 0.2s;
    }

    .list-section-header:hover {
        background: var(--border-color);
    }

    .list-section.collapsed .list-section-header {
        border-bottom-color: transparent;
    }

    .list-section:not(.collapsed) .list-section-header {
        border-bottom-color: var(--border-color);
    }

    .list-section-header .toggle-icon {
        transition: transform 0.3s ease;
        font-size: 10px;
    }

    .list-section.collapsed .toggle-icon {
        transform: rotate(90deg);
    }

    .list-section.collapsed #vehicles-list-container,
    .list-section.collapsed #jobs-list-container {
        display: none;
    }

    #vehicles-list, #jobs-list {
        max-height: 400px;
        overflow-y: auto;
        padding: 10px;
    }

    /* List Items */
    .list-item {
      background: var(--bg-color); border: 1px solid var(--border-color);
      border-radius: 6px; padding: 10px; margin-bottom: 10px;
      display: flex; flex-direction: column; gap: 8px;
    }
    .list-item-header {
      display: flex; justify-content: space-between; align-items: center;
    }
    .item-actions button { margin-right: 5px; }

    /* Notifications / Toasts */
    .toast-container {
      position: absolute; bottom: 20px; right: 20px; z-index: 9999;
      display: flex; flex-direction: column; gap: 10px;
    }
    .toast {
      background: rgba(0, 0, 0, 0.8); color: white; padding: 10px 20px;
      border-radius: 4px;
      animation: slideIn 0.3s, fadeOut 0.3s 3s forwards;
    }

    @keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
    @keyframes fadeOut { to { opacity: 0; visibility: hidden; } }

    /* Modals */
    dialog {
      border: 1px solid var(--border-color); border-radius: 8px;
      background: var(--panel-bg); color: var(--text-main);
      padding: 20px; width: 450px; max-width: 90vw;
    }
    dialog::backdrop { background: rgba(0,0,0,0.5); }

    .form-group { margin-bottom: 15px; }
    .form-group label { display: block; margin-bottom: 5px; font-size: 14px; }
    .form-group input[type="text"],
    .form-group input[type="number"],
    .form-group select {
      width: 100%; padding: 8px; border: 1px solid var(--border-color);
      border-radius: 4px; background: var(--bg-color); color: var(--text-main);
    }
    .form-group-inline { display: flex; align-items: center; gap: 10px; }


    /* Time Slider Visuals */
    .time-slider-container {
        margin: 10px 0;
        padding-top: 20px;
        direction: ltr;
    }

    .time-slider-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
        direction: rtl;
    }

    .time-slider-title {
        display: flex;
        align-items: center;
        gap: 5px;
        font-weight: bold;
        font-size: 16px;
    }

    .time-slider-value-display {
        background: rgba(26, 115, 232, 0.1);
        color: var(--primary);
        padding: 4px 12px;
        border-radius: 4px;
        font-weight: bold;
        font-family: monospace;
        letter-spacing: 1px;
        direction: ltr;
    }

    .time-slider-track-wrap {
        position: relative;
        height: 40px;
        border-radius: 8px;
        background: #495F9F;
        background: linear-gradient(90deg,rgba(73, 95, 159, 1) 0%, rgba(99, 156, 247, 1) 19%, rgba(181, 213, 255, 1) 35%, rgba(167, 205, 252, 1) 50%, rgba(226, 175, 86, 1) 75%, rgba(73, 95, 159, 1) 100%);
        /*background: linear-gradient(to right, #4b83ea 0%, #4b83ea 25%, #92bdf6 50%, #e6b24a 75%, #6a6276 100%);*/
        margin-bottom: 15px;
    }

    /* Track segments based on image */
    .time-slider-track-wrap::before {
        content: '';
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        border-radius: 8px;
        border: 2px solid rgba(255,255,255,0.3);
        pointer-events: none;
    }

    /* Time markers */
    .time-marker {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 1px;
        background: rgba(255,255,255,0.5);
    }
    .time-marker-0 { left: 0%; }
    .time-marker-6 { left: 25%; }
    .time-marker-12 { left: 50%; }
    .time-marker-18 { left: 75%; }
    .time-marker-24 { left: 100%; }

    .time-label {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        color: white;
        font-size: 12px;
        text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    }
    .time-label-0 { left: 5px; }
    .time-label-6 { left: calc(25% - 5px); }
    .time-label-12 { left: 50%; transform: translate(-50%, -50%); opacity: 0.5; }
    .time-label-18 { left: calc(75% + 5px); }
    .time-label-24 { right: 5px; }

    /* Period labels */
    .period-labels {
        display: flex;
        justify-content: space-between;
        padding: 0 10px;
        color: var(--text-muted);
        font-size: 14px;
    }

    /* Custom range slider styling */
    .multi-range-slider {
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
    }

    .multi-range-slider input[type=range] {
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        appearance: none;
        background: transparent;
        pointer-events: none;
        margin: 0;
        padding: 0;
    }

    .multi-range-slider input[type=range]::-webkit-slider-thumb {
        pointer-events: all;
        appearance: none;
        width: 20px;
        height: 36px;
        background-color: white;
        border-radius: 6px;
        cursor: ew-resize;
        position: relative;
        z-index: 10;
        /* Inner line */
        background-image: linear-gradient(#ccc, #ccc);
        background-size: 2px 14px;
        background-repeat: no-repeat;
        background-position: center;
    }

    .multi-range-slider input[type=range]::-moz-range-thumb {
        pointer-events: all;
        appearance: none;
        width: 20px;
        height: 36px;
        background-color: white;
        border-radius: 6px;
        border: none;
        cursor: ew-resize;
        position: relative;
        z-index: 10;
        background-image: linear-gradient(#ccc, #ccc);
        background-size: 2px 14px;
        background-repeat: no-repeat;
        background-position: center;
    }

    /* Highlight between thumbs */
    .slider-highlight {
        position: absolute;
        height: 100%;
        background: transparent;
        border-top: 2px solid white;
        border-bottom: 2px solid white;
        top: 0;
        z-index: 1;
        pointer-events: none;
        filter: blur(4px);
    }


    /* Custom Markers */
    .custom-marker {
      width: 28px;
      height: 28px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      font-weight: bold;
      cursor: pointer;
      border: 3px solid white;
      border-radius: 50%;
      /*transition: background-color 0.3s, border-color 0.3s, transform 0.2s;*/
    }
    .custom-marker > span {
    }
    .custom-marker:active { cursor: grabbing; }
    .custom-marker.hovered, .custom-marker:hover {
        transform: scale(1.2);
        z-index: 1000 !important;
    }

    .marker-popup { color: #333; padding: 5px; min-width: 150px; }
    .marker-popup p { margin: 5px 0; border-bottom: 1px solid #eee; padding-bottom: 5px;}

    /* Code & JSON Display */
    .code-box-wrapper {
        position: relative;
    }
    .copy-btn {
        position: absolute;
        top: 8px;
        left: 8px;
        background: rgba(255,255,255,0.1);
        color: white;
        border: 1px solid rgba(255,255,255,0.2);
        padding: 4px 6px;
        font-size: 12px;
        opacity: 0.5;
        transition: opacity 0.2s;
    }
    .code-box-wrapper:hover .copy-btn {
        opacity: 1;
    }
    pre {
      background: #2d2d2d; color: #f8f8f2; padding: 15px;
      border-radius: 6px; overflow-x: auto; direction: ltr; text-align: left;
      font-family: monospace; font-size: 13px; max-height: 300px;
    }

    .hidden { display: none !important; }

    /* Timeline */
    #timeline-container {
        position: absolute;
        bottom: 10px;
        left: 10px;
        right: 10px;
        background: var(--panel-bg);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 15px;
        z-index: 15;
        max-height: 180px;
        overflow-y: auto;
        transition: all 0.3s ease;
    }
    #timeline-container.collapsed {
        padding-top: 5px;
        padding-bottom: 5px;
        max-height: 40px;
        overflow: hidden;
    }
    #toggle-timeline-btn {
        position: absolute;
        top: 5px;
        left: 5px;
        padding: 2px 6px;
        font-size: 12px;
    }
    .timeline-track {
        margin-bottom: 10px;
    }
    .timeline-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 5px;
    }
    .timeline-bar {
        width: 100%;
        height: 25px;
        display: flex;
        align-items: center;
        position: relative;
    }
    .timeline-line {
        width: 100%;
        height: 3px;
        background-color: var(--border-color);
        position: absolute;
        border-radius: 2px;
    }
    .timeline-job-dot {
        position: absolute;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        border: 2px solid white;
        cursor: pointer;
        transform: translateX(-50%);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 10px;
        color: white;
        font-weight: bold;
        transition: transform 0.2s;
    }
    .timeline-job-dot:hover {
        z-index: 10;
        transform: translateX(-50%) scale(1.2);
    }

    /* Toggle Switch */
    .toggle-switch {
        display: flex;
        align-items: center;
        gap: 10px;
    }
    .toggle-switch label {
        margin-bottom: 0;
    }

    .switch {
      position: relative;
      display: inline-block;
      width: 44px;
      height: 24px;
    }

    .switch input {
      opacity: 0;
      width: 0;
      height: 0;
    }

    .slider {
      position: absolute;
      cursor: pointer;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: #ccc;
      -webkit-transition: .4s;
      transition: .4s;
    }

    .slider:before {
      position: absolute;
      content: "";
      height: 18px;
      width: 18px;
      left: 3px;
      bottom: 3px;
      background-color: white;
      -webkit-transition: .4s;
      transition: .4s;
    }

    input:checked + .slider {
      background-color: var(--primary);
    }

    input:focus + .slider {
    }

    input:checked + .slider:before {
      -webkit-transform: translateX(20px);
      -ms-transform: translateX(20px);
      transform: translateX(20px);
    }

    /* Rounded sliders */
    .slider.round {
      border-radius: 24px;
    }

    .slider.round:before {
      border-radius: 50%;
    }


    /* Mobile Styles */
    @media (max-width: 768px) {
        .app-container {
            flex-direction: column;
        }
        #toggleSidebarBtn {
            display: none; /* Hide desktop button on mobile */
        }
        .sidebar {
            width: 100%;
            min-width: 100%;
            height: 50vh; /* Default height */
            max-height: 90vh;
            position: absolute;
            bottom: 0;
            border-left: none;
            border-top: 1px solid var(--border-color);
            transform: translateY(calc(100% - 50px)); /* Almost hidden */
            transition: transform 0.3s ease-in-out;
        }
        .sidebar.collapsed {
            transform: translateY(calc(100% - 50px)); /* Almost hidden */
            margin-right: 0;
        }
        .sidebar:not(.collapsed) {
            transform: translateY(calc(50vh - 50px));
        }
        .panel-header {
            cursor: grab;
        }
        .map-area {
            height: 100%;
        }
        #timeline-container {
            max-height: 150px;
        }
    }
/* ── API Key modal (ported from trafficDashboardDemo) ── */
#api-key-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
}
#api-key-overlay.hidden { display: none; }
#api-key-card {
    background: #fff;
    color: #1f2937;
    border-radius: 14px;
    padding: 32px 36px;
    width: 560px;
    max-width: 94vw;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    direction: rtl;
}
#api-key-card h3 {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 24px;
}
.api-key-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.api-key-row label {
    font-size: 13px;
    color: #374151;
    white-space: nowrap;
    min-width: 150px;
    text-align: right;
}
.api-key-row input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    font-family: monospace;
    color: #1f2937;
    background: #f9fafb;
    outline: none;
    direction: ltr;
}
.api-key-row input:focus { border-color: #3b82f6; background: #fff; }
#api-key-save {
    width: 100%;
    margin-top: 10px;
    padding: 11px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}
#api-key-save:hover { background: #2563eb; }
#api-key-error {
    color: #dc2626;
    font-size: 12px;
    text-align: center;
    margin-top: 8px;
    min-height: 18px;
}
