/* Global styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    color: #333;
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header h1 {
    font-size: 28px;
    margin-bottom: 5px;
}

.header .subtitle {
    font-size: 14px;
    opacity: 0.9;
}

.header-nav-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-nav {
    display: flex;
    gap: 16px;
    align-items: center;
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Profile button and dropdown (far right in header) */
.header-nav-right {
    display: flex;
    align-items: center;
    margin-left: auto;
}

.profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.profile-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.6);
}

.profile-btn .profile-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.3);
}

.profile-btn .profile-avatar-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-btn .profile-avatar-icon svg {
    width: 16px;
    height: 16px;
    fill: white;
}

.profile-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    min-width: 140px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 6px 0;
    z-index: 1000;
    display: none;
}

.profile-dropdown.open {
    display: block;
}

.profile-dropdown a {
    display: block;
    padding: 10px 16px;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s ease;
}

.profile-dropdown a:hover {
    background: #f0f0f0;
}

.profile-nav-wrap {
    position: relative;
}

/* Main container */
.container-main {
    display: flex;
    height: calc(100vh - 80px);
    gap: 0;
}

/* Sidebar: z-index so dropdowns (e.g. sync service menu) float above the map */
.sidebar {
    position: relative;
    z-index: 10;
    width: 300px;
    background: white;
    overflow-y: auto;
    border-right: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.sidebar-section {
    padding: 20px;
    border-bottom: 1px solid #f0f0f0;
}

.sidebar-section h3 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    color: #667eea;
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

/* Sync toolbar above container list */
.sync-section {
    padding-bottom: 12px;
}

.sync-toolbar {
    display: flex;
    align-items: stretch;
    gap: 0;
}

.sync-toolbar .sync-btn {
    flex: 1;
    min-width: 0;
    border-radius: 6px 0 0 6px;
}

.sync-dropdown-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
}

.sync-dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 100%;
    padding: 0 10px;
    font-size: 10px;
    border: none;
    border-radius: 0 6px 6px 0;
    background: #667eea;
    color: white;
    cursor: pointer;
    transition: background 0.2s ease;
    border-left: 1px solid rgba(255, 255, 255, 0.3);
}

.sync-dropdown-toggle:hover {
    background: #5568d3;
}

.sync-service-menu {
    position: absolute;
    top: 100%;
    right: 0;
    left: auto;
    margin-top: 4px;
    min-width: 160px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 6px 0;
    z-index: 1001;
    display: none;
}

.sync-service-menu[aria-hidden="false"] {
    display: block;
}

.sync-service-option {
    display: block;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: transparent;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    color: #333;
    transition: background 0.15s ease;
}

.sync-service-option:hover {
    background: rgba(102, 126, 234, 0.1);
}

.sync-service-option.selected {
    font-weight: 600;
    color: #667eea;
}

.sync-service-sep {
    margin: 6px 0;
    border: none;
    border-top: 1px solid #e8e8e8;
}

/* Controls */
.control-group {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 100px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

/* Speed slider */
#speedSlider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

#speedSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#speedSlider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#speedValue {
    background: #667eea;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    min-width: 35px;
    text-align: center;
}

/* Container list header: title left, [count] or [index/total] right */
.container-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.container-list-header h3 {
    margin-bottom: 0;
}

.container-list-count {
    font-size: 14px;
    font-weight: 600;
    color: #667eea;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.container-list {
    max-height: 300px;
    overflow-y: auto;
}

.container-item {
    padding: 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 8px;
    background: #f9f9f9;
    transition: all 0.2s ease;
    border-left: 3px solid #ddd;
}

.container-item:hover {
    background: #f0f0f0;
    border-left-color: #667eea;
    transform: translateX(4px);
}

.container-item.active {
    background: #e8ecff;
    border-left-color: #667eea;
}

.container-item-id {
    font-weight: 600;
    font-size: 13px;
    color: #333;
}

.container-item-route {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
}

.container-item-status {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Container info */
.container-info {
    font-size: 12px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.info-label {
    color: #999;
    font-weight: 500;
}

.info-value {
    color: #333;
    font-weight: 600;
}

.placeholder {
    color: #999;
    font-style: italic;
    padding: 8px 0;
}

.loading {
    color: #999;
    text-align: center;
    padding: 16px 0;
}

/* Map: z-index 0 so sidebar (z-index 10) and its dropdowns paint above */
.map-wrapper {
    flex: 1;
    position: relative;
    z-index: 0;
    overflow: hidden;
    display: flex;
}

.map-container {
    flex: 1;
    background: #e8e8e8;
    position: relative;
    overflow: hidden;
}

/* Animation drawer: right-edge vertical strip; content slides out to the left. Positioned to clear Leaflet attribution (~5px buffer). */
.animation-drawer {
    position: absolute;
    bottom: 28px;
    right: 0;
    z-index: 1000;
    display: flex;
    flex-direction: row-reverse;
    align-items: stretch;
    border-radius: 8px 0 0 8px;
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-right: none;
    background: rgba(255, 255, 255, 0.96);
    overflow: hidden;
}

/* Tab height: snug to rotated "Animation ▶". align-self: center so tab doesn't stretch; drawer height when collapsed comes from toggle only. */
.animation-drawer-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    width: 24px;
    min-width: 24px;
    height: 76px;
    max-height: 76px;
    padding: 4px 0;
    box-sizing: border-box;
    font-size: 12px;
    font-weight: 600;
    color: #667eea;
    background: rgba(255, 255, 255, 0.98);
    border: none;
    border-radius: 8px 0 0 8px;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.animation-drawer-toggle-text {
    display: inline-block;
    transform: rotate(-90deg);
    white-space: nowrap;
    line-height: 1;
    letter-spacing: 0.02em;
}

.animation-drawer-toggle:hover {
    background: rgba(102, 126, 234, 0.1);
}

.animation-drawer-content {
    padding: 12px 14px 14px;
    min-width: 200px;
    max-width: 220px;
    overflow: hidden;
    transition: max-width 0.25s ease-out, opacity 0.2s ease;
}

.animation-drawer.collapsed .animation-drawer-content {
    max-width: 0;
    min-width: 0;
    height: 0;
    min-height: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
}

.animation-drawer-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.animation-drawer-speed {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
}

.animation-drawer-speed label {
    font-size: 12px;
    font-weight: 600;
    color: #555;
    flex: 0 0 auto;
    min-width: 40px;
}

.animation-drawer-speed input[type="range"] {
    flex: 1 1 auto;
    min-width: 60px;
    max-width: 120px;
    width: auto;
}

.animation-drawer-speed #speedValue {
    font-size: 13px;
    font-weight: 600;
    color: white;
    flex: 0 0 auto;
    min-width: 2.5em;
    width: 2.5em;
    text-align: center;
    padding: 4px 8px;
    box-sizing: content-box;
}

/* Temporary debug labels: center lat/lng and zoom (for tuning defaults/limits) */
.map-debug-labels {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
    font-size: 13px;
    pointer-events: none;
}

.map-debug-labels .map-debug-line {
    font-weight: bold;
}

.leaflet-container {
    background: #c0c0c0;
}

/* Custom marker styles */
.container-marker {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 2px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
}

.container-marker:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
}

.container-marker.active {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border-color: #fff;
}

/* Marker popup */
.marker-popup {
    font-size: 12px;
}

.marker-popup-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.marker-popup-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid #f0f0f0;
}

.marker-popup-label {
    color: #999;
    font-weight: 500;
}

.marker-popup-value {
    color: #333;
    font-weight: 600;
}

/* Route polyline */
.container-route {
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Speed-based colors */
.speed-slow {
    color: #f5576c;
}

.speed-medium {
    color: #ffd89b;
}

.speed-fast {
    color: #30b08f;
}

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

    .sidebar {
        width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
    }

    .header h1 {
        font-size: 22px;
    }

    .header .subtitle {
        display: none;
    }
}

/* Scrollbar styling */
.sidebar::-webkit-scrollbar,
.container-list::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track,
.container-list::-webkit-scrollbar-track {
    background: #f5f5f5;
}

.sidebar::-webkit-scrollbar-thumb,
.container-list::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.container-list::-webkit-scrollbar-thumb:hover {
    background: #b0b0b0;
}

/* Panel Overlay */
.panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.panel-overlay.active {
    display: flex;
}

.panel-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    animation: panelSlideIn 0.3s ease;
}

@keyframes panelSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 30px;
    border-bottom: 1px solid #e0e0e0;
}

.panel-header h2 {
    margin: 0;
    font-size: 24px;
    color: #333;
}

.panel-close {
    background: none;
    border: none;
    font-size: 32px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.panel-close:hover {
    background: #f0f0f0;
    color: #333;
}

.panel-form {
    padding: 30px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.sku-list {
    margin-bottom: 12px;
}

.sku-item {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.sku-input,
.qty-input {
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.btn-remove-sku {
    background: #f5576c;
    color: white;
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.btn-remove-sku:hover {
    background: #e0455a;
}

.btn-add-sku {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-add-sku:hover {
    background: #5568d3;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid #e0e0e0;
}

.btn-nav {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    cursor: pointer;
}

.btn-nav:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Container Actions */
.container-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e0e0e0;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-danger {
    background: #f5576c;
    color: white;
    border: none;
}

.btn-danger:hover {
    background: #e0455a;
}

.form-disabled {
    background: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

/* Delete Dialog */
.delete-dialog {
    max-width: 400px;
}

.warning-text {
    color: #f5576c;
    font-weight: 600;
    margin-top: 12px;
}

/* Responsive panel */
@media (max-width: 768px) {
    .panel-content {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .container-actions {
        flex-direction: column;
    }
}
