:root {
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    --radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-main);
    color: var(--text-main);
    touch-action: manipulation;
}

.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* Main Workspace Container */
.main-workspace {
    flex: 1;
    height: 100%;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-main);
}

.map-view {
    width: 100%;
    height: 100%;
}

/* Plnoobrazovkový Dashboard Knihy Jízd */
.dashboard-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-main);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    padding: 24px 30px;
    overflow: hidden;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 16px;
}

.dashboard-filters {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-secondary {
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

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

.dashboard-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    margin-top: 6px;
}

.dashboard-table-container {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: auto;
    box-shadow: var(--shadow);
}

.trips-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.88rem;
}

.trips-table th {
    background: rgba(15, 23, 42, 0.8);
    padding: 14px 18px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.trips-table td {
    padding: 14px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.trips-table tbody tr {
    transition: background 0.2s ease;
}

.trips-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Fix pro čisté a ostré vykreslování dlaždic bez rozmazání a mezer na mobilech */
.leaflet-tile {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    outline: 1px solid transparent;
}

.leaflet-container img.leaflet-tile {
    max-width: none !important;
    max-height: none !important;
}

/* Modals */
.login-overlay, .modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(16px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box, .modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 30px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    position: relative;
}

.login-box {
    text-align: center;
    max-width: 400px;
}

.login-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 16px auto;
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4);
}

.login-box h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.login-box p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 24px;
}

.login-error {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-top: 10px;
}

/* Sidebar */
.sidebar {
    width: 380px;
    height: 100%;
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

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

.brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--danger);
}

.status-badge.connected .status-dot {
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
}

/* Tabs */
.tabs {
    display: flex;
    padding: 10px 14px;
    gap: 6px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    color: var(--text-main);
    background: var(--accent);
}

.tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: none;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Device Card */
.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.device-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.device-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

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

.device-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.device-color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    box-shadow: 0 0 6px currentColor;
}

.device-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.device-imei {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.edit-device-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.edit-device-btn:hover {
    color: white;
    background: var(--accent);
}

.device-badges {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.badge {
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge-speed {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.badge-ignition-on {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.badge-ignition-off {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.badge-geofence {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.device-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 8px;
}

/* Form */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 0.9rem;
    outline: none;
}

.form-control:focus {
    border-color: var(--accent);
}

.btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn:hover {
    background: var(--accent-hover);
}

/* Floating Controls */
.mobile-toggle {
    display: none;
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 1100;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.my-location-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1100;
    padding: 10px 16px;
    background: rgba(30, 41, 59, 0.9);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.my-location-btn:hover {
    background: var(--accent);
    transform: scale(1.05);
}

.my-location-btn.active {
    background: #10b981;
    border-color: #34d399;
}

/* Responsive & Safe Area padding pro mobilní lišty a gesta */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-toggle {
        display: block;
    }

    .dashboard-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-view {
        padding: 16px;
    }

    .dashboard-filters {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard-filters select, .dashboard-filters input {
        width: 100% !important;
    }

    .leaflet-bottom.leaflet-right {
        bottom: calc(36px + env(safe-area-inset-bottom, 0px)) !important;
        right: calc(14px + env(safe-area-inset-right, 0px)) !important;
    }

    .leaflet-control-layers {
        border-radius: 12px !important;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4) !important;
        background: rgba(30, 41, 59, 0.95) !important;
        color: white !important;
        border: 1px solid var(--border) !important;
    }

    .leaflet-control-layers-toggle {
        width: 46px !important;
        height: 46px !important;
        background-size: 26px 26px !important;
    }

    .leaflet-control-layers-expanded {
        padding: 14px !important;
        background: rgba(30, 41, 59, 0.98) !important;
        color: white !important;
        max-height: 60vh;
        overflow-y: auto;
        border-radius: 12px !important;
    }

    .leaflet-control-layers-expanded label {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 0.9rem;
        margin-bottom: 8px;
    }
}
