/* ===================================================================
   GLOBAL STYLES & THEME VARIABLES - Enhanced Global Design System
   =================================================================== */
:root {
    /* Color Palette - Modern & Professional */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-color-light: rgba(15, 23, 42, 0.04);
    --shadow-color-medium: rgba(15, 23, 42, 0.08);
    --shadow-color-heavy: rgba(15, 23, 42, 0.12);
    
    /* Accent Colors - Vibrant & Accessible */
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-secondary: #1e40af;
    --accent-success: #10b981;
    --accent-danger: #ef4444;
    --accent-warning: #f59e0b;
    --accent-info: #06b6d4;
    
    /* Typography - Modern Font Stack */
    --font-family-sans-serif: 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    
    /* Spacing System - Consistent & Scalable */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    
    /* Border Radius - Smooth & Modern */
    --border-radius-sm: 0.375rem;
    --border-radius-md: 0.5rem;
    --border-radius-lg: 0.75rem;
    --border-radius-xl: 1rem;
    --border-radius-full: 9999px;
    
    /* Transitions - Smooth & Natural */
    --transition-speed: 0.2s;
    --transition-speed-fast: 0.15s;
    --transition-speed-slow: 0.3s;
    --transition-ease: cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Z-Index Scale - Organized Layering */
    --z-base: 1;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal-backdrop: 1000;
    --z-modal: 1001;
    --z-tooltip: 2000;
    --z-toast: 9999;
}

[data-theme="dark"] {
    /* Dark Theme - Modern & Eye-Friendly */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #475569;
    --shadow-color-light: rgba(0, 0, 0, 0.3);
    --shadow-color-medium: rgba(0, 0, 0, 0.5);
    --shadow-color-heavy: rgba(0, 0, 0, 0.7);
    --accent-primary: #60a5fa;
    --accent-primary-hover: #3b82f6;
    --accent-secondary: #2563eb;
    --accent-success: #34d399;
    --accent-danger: #f87171;
    --accent-warning: #fbbf24;
    --accent-info: #22d3ee;
}

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-family-sans-serif);
    margin: 0;
    padding: 0;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    line-height: 1.6;
    transition: background-color var(--transition-speed-slow) var(--transition-ease), 
                color var(--transition-speed-slow) var(--transition-ease);
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ===================================================================
   TOP NAVIGATION BAR
   =================================================================== */
.top-nav {
    width: 100%;
    background: var(--bg-secondary);
    padding: 0 var(--spacing-xl);
    box-shadow: 0 1px 3px var(--shadow-color-light), 0 1px 2px var(--shadow-color-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    border-bottom: 1px solid var(--border-color);
    transition: background-color var(--transition-speed) var(--transition-ease), 
                border-color var(--transition-speed) var(--transition-ease),
                box-shadow var(--transition-speed) var(--transition-ease);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.top-nav .logo {
    font-size: 1.25rem;
    color: var(--text-primary);
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    transition: all var(--transition-speed) var(--transition-ease);
}

.top-nav .actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.top-nav .actions a,
.top-nav .actions button {
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    font-size: 0.875rem;
    border-radius: var(--border-radius-md);
    padding: 0.5rem 0.875rem;
    cursor: pointer;
    transition: all var(--transition-speed-fast) var(--transition-ease);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: var(--font-weight-medium);
    position: relative;
    overflow: hidden;
}

.top-nav .actions a::before,
.top-nav .actions button::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-primary);
    opacity: 0;
    transition: opacity var(--transition-speed-fast) var(--transition-ease);
    z-index: -1;
}

.top-nav .actions a:hover,
.top-nav .actions button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.top-nav .actions a:hover::before,
.top-nav .actions button:hover::before {
    opacity: 0.05;
}

.top-nav .actions a.admin-link {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-primary-hover) 100%);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.top-nav .actions a.admin-link:hover {
    background: linear-gradient(135deg, var(--accent-primary-hover) 0%, var(--accent-secondary) 100%);
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
}

.top-nav .actions a.admin-link::before {
    display: none;
}

/* ===================================================================
   MAIN CONTAINER & LAYOUT
   =================================================================== */
.container {
    display: flex;
    flex: 1;
    overflow: visible;
}

/* ===================================================================
   SIDEBAR
   =================================================================== */
.sidebar {
    width: 320px;
    background: var(--bg-secondary);
    padding: 20px;
    overflow-y: auto;
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
    transition: background-color var(--transition-speed) ease, border-color var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
}

.sidebar h2, .sidebar h3 {
    margin-top: 0;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.1em;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
}

.sidebar .sidebar-section {
    margin-bottom: 25px;
}

.sidebar input[type="text"] {
    width: 100%;
    padding: 10px 15px;
    margin-bottom: 15px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition-speed) ease;
}

.sidebar input[type="text"]:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
    outline: none;
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar .devices-list li,
.sidebar .group-devices li {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
}

.sidebar .devices-list li:last-child,
.sidebar .group-devices li:last-child {
    border-bottom: none;
}

.sidebar .devices-list li:hover,
.sidebar .group-devices li:hover {
    background-color: var(--bg-tertiary);
    color: var(--accent-primary);
}

.group-header {
    background-color: var(--bg-tertiary);
    font-weight: 600;
    cursor: pointer;
    position: relative;
    padding: 12px 15px;
    border-radius: var(--border-radius-md);
    margin-bottom: 5px;
    transition: all var(--transition-speed) ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.group-header:hover {
    background-color: var(--border-color);
}

.group-header::after {
    content: '▼';
    font-size: 12px;
    color: var(--text-secondary);
    transition: transform var(--transition-speed) ease;
}

.group-header.active::after {
    transform: rotate(180deg);
}

.group-devices {
    display: none;
    padding-left: 15px;
    border-left: 2px solid var(--accent-primary);
    margin: 10px 0 15px 5px;
}

/* Admin forms in sidebar */
.card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    margin-bottom: 15px;
    padding: 15px;
}
.card-header {
    font-weight: 600;
    margin-bottom: 10px;
}
.card label {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 5px;
    display: block;
}
.card select, .card input {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    margin-bottom: 10px;
}
.card button {
    width: 100%;
    padding: 10px;
    border: none;
    background-color: var(--accent-primary);
    color: #fff;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-weight: 600;
}
.card button:hover {
    background-color: var(--accent-secondary);
}

/* ===================================================================
   MAIN CONTENT AREA
   =================================================================== */
.main-content {
    flex: 1;
    padding: 25px;
    background: var(--bg-primary);
    overflow: visible;
    display: flex;
    flex-direction: column;
    gap: 25px;
    position: relative;
    min-height: 0;
}

.main-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: visible;
    min-width: 0;
}

.map-and-timeline {
    flex: 1;
    display: flex;
    gap: 20px;
    min-height: 0;
    align-items: flex-start;
}

/* ===================================================================
   CONTROLS BAR
   =================================================================== */
.controls {
    background: var(--bg-secondary);
    padding: var(--spacing-md) var(--spacing-lg);
    display: flex;
    flex-wrap: nowrap;
    gap: var(--spacing-md);
    align-items: center;
    border-radius: var(--border-radius-xl);
    box-shadow: 0 4px 6px -1px var(--shadow-color-light), 
                0 2px 4px -1px var(--shadow-color-light);
    margin-bottom: var(--spacing-xl);
    border: 1px solid var(--border-color);
    flex-shrink: 0;
    position: sticky;
    top: 90px;
    z-index: var(--z-sticky);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: box-shadow var(--transition-speed) var(--transition-ease);
}

.controls:hover {
    box-shadow: 0 10px 15px -3px var(--shadow-color-medium), 
                0 4px 6px -2px var(--shadow-color-light);
}

.controls-main {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    flex: 1 1 auto;
}

.controls-animation {
    flex: 0 0 auto;
    margin-inline-start: 0; /* خليه مباشرة بعد زر 📊 مع نفس مسافة الأزرار العادية */
    margin-inline-end: 0;
}

.controls .control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.controls label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 14px;
}

.controls select,
.controls input {
    padding: 8px 12px;
    font-size: 14px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all var(--transition-speed) ease;
    min-width: 150px;
}

.controls select:focus,
.controls input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
    outline: none;
}

.controls input#batteryDisplay {
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.5px;
    min-width: 70px;
    max-width: 80px;
    text-align: center;
    background: var(--bg-tertiary);
    cursor: default;
}

.controls button {
    padding: 8px 18px;
    font-size: 14px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--accent-primary);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.controls button.primary {
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-primary-hover) 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.controls button.primary:hover {
    background: linear-gradient(135deg, var(--accent-primary-hover) 0%, var(--accent-secondary) 100%);
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
    transform: translateY(-1px);
}

.controls button.primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

.controls button.secondary {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.controls button.secondary:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* ===================================================================
   MAP & SELECTED DEVICE INFO
   =================================================================== */
.map-container {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-xl);
    padding: var(--spacing-lg);
    box-shadow: 0 4px 6px -1px var(--shadow-color-light), 
                0 2px 4px -1px var(--shadow-color-light);
    border: 1px solid var(--border-color);
    margin-right: 0;
    display: flex;
    flex-direction: column;
    overflow: visible;
    position: sticky;
    top: 130px;
    gap: var(--spacing-md);
    align-self: flex-start;
    transition: box-shadow var(--transition-speed) var(--transition-ease),
                transform var(--transition-speed) var(--transition-ease);
}

.map-container:hover {
    box-shadow: 0 10px 15px -3px var(--shadow-color-medium), 
                0 4px 6px -2px var(--shadow-color-light);
}

#selectedDeviceContainer {
    margin-bottom: 15px;
    font-size: 1.1em;
    font-weight: 600;
}

#map {
    width: 100%;
    border-radius: var(--border-radius-lg);
    background-color: var(--bg-tertiary);
    aspect-ratio: 1 / 1;
    min-height: 420px;
    max-height: 650px;
    box-shadow: inset 0 2px 4px var(--shadow-color-light);
    transition: box-shadow var(--transition-speed) var(--transition-ease);
    overflow: hidden;
}

#map:focus-within {
    box-shadow: inset 0 2px 4px var(--shadow-color-light),
                0 0 0 3px rgba(59, 130, 246, 0.1);
}

.animation-panel {
    background: transparent; /* داخل نفس مربع التحكم الأبيض */
    color: var(--text-primary);
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    border: none;
    display: flex;
    flex-direction: row;
    gap: 6px;
    align-items: center;
    min-width: auto;
    max-width: none;
    flex-shrink: 0;
}

.animation-panel.is-disabled {
    opacity: 0.6;
}

.animation-panel__row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    width: 100%;
}

.animation-info {
    display: none; /* إخفاء معلومات الوقت/الحالة في شريط الحركة لتقليل الفراغ قبل الأزرار */
}

.animation-time-group {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.animation-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.animation-time-group strong {
    font-size: 12px;
    color: var(--text-primary);
    min-width: 50px;
}

.animation-status-text {
    font-weight: 600;
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.animation-panel__controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.animation-btn {
    background: #ff9800;
    border: none;
    color: #1e1e1e;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    font-size: 11px;
    white-space: nowrap;
}

.animation-btn:hover:not(:disabled) {
    background: #ffc107;
}

.animation-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.animation-speed-control {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 110px;
}

.animation-speed-control label {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.animation-speed-control span {
    font-weight: 600;
    min-width: 26px;
    text-align: center;
    font-size: 12px;
}

.animation-speed-control input[type="range"] {
    flex: 1;
    min-width: 60px;
    max-width: 80px;
}

.animation-progress-control {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 130px;
}

.animation-progress-control label {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.animation-progress-control input[type="range"] {
    flex: 1;
    min-width: 80px;
    max-width: 140px;
}

/* ===================================================================
   TIMELINE SIDEBAR (RIGHT SIDE)
   =================================================================== */
.timeline-sidebar {
    width: 400px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease;
    box-shadow: -2px 0 8px var(--shadow-color-light);
    overflow: hidden;
    position: sticky;
    top: 130px;
    max-height: calc(100vh - 150px);
}

.timeline-sidebar.collapsed {
    width: 0;
    transform: translateX(100%);
    border-left: none;
}

.logs {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 15px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.timeline-header h2 {
    margin: 0;
    font-size: 1.2em;
    font-weight: 600;
    color: var(--text-primary);
}

.timeline-toggle-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 6px 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 16px;
    transition: all var(--transition-speed) ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.timeline-toggle-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.timeline-sidebar.collapsed .timeline-toggle-btn {
    display: none;
}

#btnToggleTimeline {
    white-space: nowrap;
}

.timeline-content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 20px 20px;
    min-height: 0;
}

/* Timeline sidebar scrollbar styling */
.timeline-content-wrapper::-webkit-scrollbar {
    width: 6px;
}

.timeline-content-wrapper::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.timeline-content-wrapper::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.timeline-content-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Analytics Specific */
.analytics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--bg-primary);
    padding: 15px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
}
.stat-card .label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 5px;
}
.stat-card .value {
    font-size: 1.4em;
    font-weight: 600;
    color: var(--text-primary);
}
.chart-container {
    position: relative;
    height: 200px; /* Adjust as needed */
    width: 100%;
    margin-top: 15px;
}

/* ===================================================================
   VISUAL TIMELINE (LOGS)
   =================================================================== */
.logs-controls {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
}
.logs-controls input {
    flex-grow: 1;
    padding: 8px 12px;
    font-size: 14px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
}
.logs-controls button {
    padding: 8px 15px;
    font-size: 14px;
    /* Styles inherited from .controls button */
}

#logsTable {
    width: 100%;
    border-collapse: collapse;
}

#logsTable tbody {
    display: block;
    overflow-y: auto;
    padding-right: 5px; /* Space for scrollbar */
}

#logsTable tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.timeline-cell {
    padding: 15px 10px !important;
    position: relative;
}

.timeline-track {
    position: relative;
    padding-left: 35px; /* Space for the line and dot */
    min-height: 40px;
}

.timeline-sidebar .timeline-track {
    padding-left: 25px;
}

.timeline-line {
    position: absolute;
    left: 11px;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: var(--border-color);
}

.timeline-sidebar .timeline-line {
    left: 6px;
}

/* Hide line for first and last elements */
#logsTable tr:first-child .timeline-line { top: 18px; }
#logsTable tr:last-child .timeline-line { bottom: auto; height: 18px; }

.timeline-dot {
    position: absolute;
    left: 4px;
    top: 8px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 3px solid var(--bg-secondary);
    background-color: var(--text-secondary);
    z-index: 2;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.timeline-sidebar .timeline-dot {
    left: 0;
    width: 14px;
    height: 14px;
    border-width: 2px;
}

.timeline-dot.stop { background-color: var(--accent-danger); }
.timeline-dot.driving { background-color: var(--accent-success); }

.timeline-content {
    font-size: 14px;
    line-height: 1.5;
}

.timeline-sidebar .timeline-content {
    font-size: 13px;
    line-height: 1.4;
}

.timeline-content a {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    display: inline-block;
    word-break: break-word;
}

.timeline-content a:hover {
    color: var(--accent-primary);
    text-decoration: underline;
}

/* Table cells */
#logsTable td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
    font-size: 13px;
}
#logsTable tr:last-child td {
    border-bottom: none;
}

#logsTable tr {
    transition: background-color 0.2s ease;
}

#logsTable tr:hover {
    background-color: var(--bg-tertiary);
}

/* Timeline sidebar specific styles - vertical timeline layout */
.timeline-sidebar #logsTable {
    display: block;
    width: 100%;
}

.timeline-sidebar #logsTable thead {
    display: none;
}

.timeline-sidebar #logsTable tbody {
    display: block;
    width: 100%;
}

.timeline-sidebar #logsTable tr {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border-color);
    padding: 12px 0;
    position: relative;
}

.timeline-sidebar #logsTable tr:hover {
    background-color: var(--bg-tertiary);
}

.timeline-sidebar #logsTable td {
    display: block;
    width: 100% !important;
    padding: 2px 0;
    border-bottom: none;
}

.timeline-sidebar #logsTable td.timeline-time-cell {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
    margin-bottom: 4px;
    line-height: 1.6;
}

.timeline-time-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.timeline-time-row .label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 42px;
}

.timeline-time-row .value {
    font-size: 14px;
    font-weight: 600;
}

.copy-time-btn {
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 13px;
    transition: background 0.2s, color 0.2s;
}

.copy-time-btn:hover {
    background: var(--accent-primary);
    color: #fff;
}

.timeline-sidebar #logsTable td:nth-child(2) {
    flex: 1;
    padding-left: 0;
}

.timeline-sidebar #logsTable td.timeline-duration-cell {
    text-align: left;
    color: var(--text-secondary);
    font-size: 11px;
    margin-top: 4px;
    padding-top: 4px;
}

.duration-badge {
    display: inline-block;
    background: var(--bg-tertiary);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Timeline content in sidebar */
.timeline-sidebar .timeline-cell {
    padding: 0 !important;
}

.timeline-sidebar .timeline-track {
    position: relative;
    padding-left: 28px;
    min-height: 30px;
}

.timeline-sidebar .timeline-line {
    left: 7px;
    top: 0;
}

.timeline-sidebar .timeline-dot {
    left: 1px;
    top: 6px;
}

.timeline-sidebar .timeline-content {
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-primary);
}

/* ===================================================================
   MODAL STYLES (FOR FAVORITE PLACES)
   =================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-backdrop);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    animation: fadeInModal 0.3s var(--transition-ease);
}

@keyframes fadeInModal {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-secondary);
    padding: var(--spacing-xl) var(--spacing-2xl);
    border-radius: var(--border-radius-xl);
    box-shadow: 0 20px 25px -5px var(--shadow-color-heavy), 
                0 10px 10px -5px var(--shadow-color-medium);
    width: 90%;
    max-width: 480px;
    border: 1px solid var(--border-color);
    animation: modalSlideIn 0.3s var(--transition-ease);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-content h3 {
    margin: 0 0 20px 0;
    text-align: center;
    font-weight: 600;
}

.modal-content .form-group {
    margin-bottom: 15px;
}

.modal-content label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.modal-content input {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
}

.modal-content button {
    margin-top: 15px;
}

.modal-content button.secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
/* ===================================================================
   LOADING OVERLAY & TOAST
   =================================================================== */
#loadingOverlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none; /* Initially hidden */
    align-items: center;
    justify-content: center;
    z-index: var(--z-toast);
    flex-direction: column;
    gap: var(--spacing-lg);
    color: #fff;
    font-size: 1.1em;
    font-weight: var(--font-weight-medium);
    animation: fadeInOverlay 0.3s var(--transition-ease);
}

@keyframes fadeInOverlay {
    from {
        opacity: 0;
        backdrop-filter: blur(0px);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(8px);
    }
}

.spinner {
    width: 56px;
    height: 56px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-primary);
    border-right-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#toastContainer {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: #fff;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 
                0 4px 6px -2px rgba(0, 0, 0, 0.2);
    animation: fadein 0.4s var(--transition-ease), fadeout 0.4s 3.5s forwards;
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    font-weight: var(--font-weight-medium);
    min-width: 280px;
    max-width: 400px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.toast::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--accent-primary);
    opacity: 0.8;
}

.toast-icon {
    font-size: 1.2em;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    line-height: 1.5;
}

.toast-success {
    background: linear-gradient(135deg, #065f46 0%, #047857 100%);
}

.toast-success::before {
    background: var(--accent-success);
}

.toast-error {
    background: linear-gradient(135deg, #991b1b 0%, #b91c1c 100%);
}

.toast-error::before {
    background: var(--accent-danger);
}

.toast-warning {
    background: linear-gradient(135deg, #92400e 0%, #b45309 100%);
}

.toast-warning::before {
    background: var(--accent-warning);
}

.toast-info {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.toast-info::before {
    background: var(--accent-info);
}

[data-theme="dark"] .toast {
    background: linear-gradient(135deg, #334155 0%, #475569 100%);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .toast-success {
    background: linear-gradient(135deg, #047857 0%, #059669 100%);
}

[data-theme="dark"] .toast-error {
    background: linear-gradient(135deg, #b91c1c 0%, #dc2626 100%);
}

[data-theme="dark"] .toast-warning {
    background: linear-gradient(135deg, #b45309 0%, #d97706 100%);
}

[data-theme="dark"] .toast-info {
    background: linear-gradient(135deg, #334155 0%, #475569 100%);
}

@keyframes fadein {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeout {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(20px); }
}

/* ===================================================================
   UTILITIES & HELPERS
   =================================================================== */
/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===================================================================
   ENHANCED ANIMATIONS & INTERACTIONS
   =================================================================== */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Smooth transitions for interactive elements */
.sidebar .devices-list li,
.sidebar .group-devices li,
.controls button,
.card button {
    position: relative;
    overflow: hidden;
}

.sidebar .devices-list li::before,
.sidebar .group-devices li::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-primary);
    opacity: 0;
    transition: opacity var(--transition-speed-fast) var(--transition-ease);
    z-index: 0;
}

.sidebar .devices-list li:hover::before,
.sidebar .group-devices li:hover::before {
    opacity: 0.08;
}

.sidebar .devices-list li > *,
.sidebar .group-devices li > * {
    position: relative;
    z-index: 1;
}

/* Enhanced focus states for accessibility */
*:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-radius: var(--border-radius-sm);
}

/* Loading skeleton animation */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.loading-skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 0%,
        var(--bg-secondary) 50%,
        var(--bg-tertiary) 100%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
}

/* Responsive Design - Enhanced */
@media (max-width: 1200px) {
    .timeline-sidebar {
        width: 350px;
    }
    
    .controls {
        flex-wrap: wrap;
    }
}

@media (max-width: 992px) {
    .container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        order: 2;
        max-height: 300px; /* Collapsed sidebar */
        border-right: none;
        border-top: 1px solid var(--border-color);
    }
    .main-content {
        order: 1;
        flex-direction: column;
    }
    .map-and-timeline {
        flex-direction: column;
    }
    .timeline-sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color);
        max-height: none;
        position: static;
    }
    .map-container {
        margin-right: 0;
        margin-bottom: 0;
        position: static;
    }
}

@media (max-width: 768px) {
    .controls {
        flex-direction: column;
        align-items: stretch;
        position: static;
    }
    #map {
        aspect-ratio: auto;
        min-height: 320px;
    }
    .top-nav {
        padding: 0 15px;
        height: auto;
        flex-direction: column;
        align-items: flex-start;
        padding-top: 10px;
        padding-bottom: 10px;
    }
}

/* Settings Panel - Enhanced */
.settings-panel {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-backdrop);
    animation: fadeInModal 0.3s var(--transition-ease);
}
.settings-content {
    width: 90%;
    max-width: 720px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-xl);
    box-shadow: 0 20px 25px -5px var(--shadow-color-heavy), 
                0 10px 10px -5px var(--shadow-color-medium);
    padding: var(--spacing-xl);
    border: 1px solid var(--border-color);
    animation: modalSlideIn 0.3s var(--transition-ease);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.settings-content h3 {
    margin: 0 0 20px 0;
    text-align: center;
}
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}
.settings-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 500;
}
.settings-grid input {
    padding: 10px 12px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
}
.settings-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Delete/Edit buttons in sidebar */
.delete-btn, .edit-btn {
    padding: 0.375rem 0.75rem;
    border-radius: var(--border-radius-md);
    font-size: 0.75rem;
    font-weight: var(--font-weight-medium);
    transition: all var(--transition-speed-fast) var(--transition-ease);
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.delete-btn { 
    background: linear-gradient(135deg, var(--accent-danger) 0%, #dc2626 100%);
    color: #fff;
}

.edit-btn { 
    background: linear-gradient(135deg, var(--accent-warning) 0%, #f59e0b 100%);
    color: #1e293b;
}

.delete-btn:hover { 
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(239, 68, 68, 0.3);
}

.edit-btn:hover { 
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(245, 158, 11, 0.3);
}

.delete-btn:active,
.edit-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}