/* ===== CSS VARIABLES - DARK MODE ===== */
:root, [data-theme="dark"] {
    --bg-primary: #0b0e14;
    --bg-secondary: #111622;
    --bg-card: #161c2a;
    --bg-elevated: #1c2333;
    --bg-hover: #222a3c;
    --border: #232d42;
    --border-light: #1e2738;
    --text-primary: #e8ecf1;
    --text-secondary: #8892a6;
    --text-muted: #5a6478;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-bg: rgba(59,130,246,.12);
    --success: #22c55e;
    --success-bg: rgba(34,197,94,.12);
    --danger: #ef4444;
    --danger-bg: rgba(239,68,68,.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245,158,11,.12);
    --purple: #a855f7;
    --purple-bg: rgba(168,85,247,.12);
    --shadow: 0 1px 3px rgba(0,0,0,.4);
    --shadow-lg: 0 4px 16px rgba(0,0,0,.5);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --sidebar-w: 240px;
    --topbar-h: 56px;
}

/* ===== CSS VARIABLES - LIGHT MODE ===== */
[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-elevated: #f8f9fb;
    --bg-hover: #eef0f4;
    --border: #e2e5ea;
    --border-light: #edf0f4;
    --text-primary: #1a1d24;
    --text-secondary: #5f6878;
    --text-muted: #9ca3b0;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-bg: rgba(37,99,235,.08);
    --success: #16a34a;
    --success-bg: rgba(22,163,74,.08);
    --danger: #dc2626;
    --danger-bg: rgba(220,38,38,.08);
    --warning: #d97706;
    --warning-bg: rgba(217,119,6,.08);
    --purple: #9333ea;
    --purple-bg: rgba(147,51,234,.08);
    --shadow: 0 1px 3px rgba(0,0,0,.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,.1);
}

/* ===== RESET ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background: var(--bg-primary); color: var(--text-primary); overflow: hidden; height: 100vh; height: 100dvh; transition: background .3s, color .3s; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

/* ===== PWA MODE ===== */
body.pwa-mode { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
body.pwa-mode .sidebar { top: env(safe-area-inset-top); }
body.pwa-mode .menu-toggle { top: calc(12px + env(safe-area-inset-top)); }
body.pwa-mode .topbar { padding-top: env(safe-area-inset-top); }

/* ===== iOS SAFE AREAS ===== */
@supports (padding: env(safe-area-inset-top)) {
    .sidebar { top: env(safe-area-inset-top); }
    .menu-toggle { top: calc(12px + env(safe-area-inset-top)); }
    .topbar { padding-top: env(safe-area-inset-top); }
    .geofence-bottom { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* ===== APP LAYOUT ===== */
.app { display: flex; height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar { width: var(--sidebar-w); background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; z-index: 100; transition: background .3s; }
.sidebar-brand { padding: 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.brand-icon { width: 36px; height: 36px; background: var(--accent-bg); color: var(--accent); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-size: 15px; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.brand-name em { font-style: normal; color: var(--accent); }
.brand-sub { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.sidebar-nav { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-btn { display: flex; align-items: center; gap: 12px; background: transparent; border: none; color: var(--text-secondary); padding: 11px 14px; border-radius: var(--radius); cursor: pointer; font-size: 13px; font-weight: 500; transition: all .15s; text-align: left; width: 100%; }
.nav-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-btn.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.nav-btn i { width: 18px; text-align: center; font-size: 14px; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.theme-toggle { background: var(--bg-hover); border: 1px solid var(--border); color: var(--text-secondary); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 13px; transition: all .2s; }
.theme-toggle:hover { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.conn-status { font-size: 11px; color: var(--success); display: flex; align-items: center; gap: 6px; }
.conn-dot { width: 6px; height: 6px; background: var(--success); border-radius: 50%; }

/* ===== MENU TOGGLE (mobile) ===== */
.menu-toggle { display: none; position: fixed; top: 12px; left: 12px; z-index: 200; background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); width: 40px; height: 40px; border-radius: 10px; cursor: pointer; font-size: 16px; align-items: center; justify-content: center; box-shadow: var(--shadow); }

/* ===== MAIN CONTENT ===== */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ===== TOPBAR ===== */
.topbar { padding: 0 24px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; height: var(--topbar-h); flex-shrink: 0; transition: background .3s; }
.topbar h2 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.topbar h2 i { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-info { display: flex; gap: 8px; }
.info-chip { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-secondary); background: var(--bg-card); border: 1px solid var(--border); padding: 5px 10px; border-radius: 20px; }
.info-chip i { font-size: 11px; color: var(--accent); }
.online-chip i { color: var(--success); }

/* ===== CONTENT ===== */
.content { flex: 1; overflow: hidden; padding: 0; display: flex; flex-direction: column; }
.tab-content { display: none; flex: 1; overflow-y: auto; padding: 20px 24px; }
.tab-content.active { display: flex; flex-direction: column; }
#tab-geocercas { padding: 0; overflow: hidden; }

/* ===== STATS ===== */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 20px 24px 12px; flex-shrink: 0; }
.stat-card { background: var(--bg-card); border-radius: var(--radius); padding: 16px; border: 1px solid var(--border); display: flex; align-items: center; gap: 14px; transition: all .2s; }
.stat-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.stat-icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 16px; }
.stat-icon.blue { background: var(--accent-bg); color: var(--accent); }
.stat-icon.purple { background: var(--purple-bg); color: var(--purple); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.orange { background: var(--warning-bg); color: var(--warning); }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .8px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; }

/* ===== GEOFENCE LAYOUT ===== */
.geofence-layout { display: flex; flex: 1; min-height: 0; margin: 0; }
.geofence-map { flex: 1; position: relative; min-width: 0; }
.geofence-sidebar { width: 320px; background: var(--bg-secondary); border-left: 1px solid var(--border); display: flex; flex-direction: column; transition: background .3s; flex-shrink: 0; }
.geofence-sidebar-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.geofence-sidebar-header h3 { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; }
.header-actions { display: flex; gap: 6px; }
.geofence-list { flex: 1; overflow-y: auto; padding: 8px; }
.geofence-actions { padding: 12px 16px; border-top: 1px solid var(--border); }

/* ===== GEOFENCE BOTTOM ===== */
.geofence-bottom { display: grid; grid-template-columns: 1fr 320px 320px; gap: 12px; padding: 12px 24px 20px; flex-shrink: 0; }
.panel-card { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; transition: background .3s; }
.panel-card-header { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-card-header h3 { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-card-body { padding: 8px; max-height: 200px; overflow-y: auto; }

/* ===== FENCE ITEMS ===== */
.fence-item { background: var(--bg-elevated); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 4px; border: 1px solid var(--border-light); cursor: pointer; transition: all .15s; }
.fence-item:hover { border-color: var(--accent); background: var(--bg-hover); }
.fence-item.selected { border-color: var(--accent); background: var(--accent-bg); }
.fence-name { font-weight: 600; font-size: 13px; }
.fence-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; }

/* ===== GEOFENCE EVENTS ===== */
.ge-event { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); margin-bottom: 3px; font-size: 12px; transition: background .15s; }
.ge-event:hover { background: var(--bg-hover); }
.ge-event.ge-enter { border-left: 3px solid var(--success); }
.ge-event.ge-exit { border-left: 3px solid var(--danger); }
.ge-event i { font-size: 12px; flex-shrink: 0; }
.ge-event.ge-enter i { color: var(--success); }
.ge-event.ge-exit i { color: var(--danger); }
.ge-event-info { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ge-event-name { font-weight: 600; font-size: 12px; }
.ge-event-fence { font-size: 11px; color: var(--text-muted); }
.ge-event-time { font-size: 10px; color: var(--text-muted); flex-shrink: 0; }

/* ===== MAP TOOLS ===== */
.map-tools { position: absolute; top: 12px; right: 12px; z-index: 1000; display: flex; flex-direction: column; gap: 4px; }
.btn-map { width: 36px; height: 36px; background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); border-radius: 8px; cursor: pointer; font-size: 13px; display: flex; align-items: center; justify-content: center; transition: all .15s; box-shadow: var(--shadow); }
.btn-map:hover { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.btn-map.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-map-primary { color: var(--accent); }
.btn-map-danger { color: var(--danger); }
.btn-map-danger:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

/* ===== MODAL ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); backdrop-filter: blur(4px); z-index: 3000; display: none; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal { background: var(--bg-card); border-radius: var(--radius-lg); border: 1px solid var(--border); width: 480px; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-sm { width: 420px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-header .close { background: none; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; padding: 0 4px; line-height: 1; }
.modal-header .close:hover { color: var(--danger); }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .8px; font-weight: 600; }
.form-group input, .form-group select, .form-group textarea { width: 100%; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; color: var(--text-primary); font-size: 13px; transition: border-color .2s; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.form-group textarea { min-height: 60px; resize: vertical; font-family: monospace; font-size: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.text-muted { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }

/* ===== VEHICLE CHECKBOXES ===== */
.vehicle-checkboxes { max-height: 180px; overflow-y: auto; background: var(--bg-primary); border-radius: var(--radius-sm); padding: 6px; border: 1px solid var(--border); }
.vehicle-checkboxes label { display: flex; align-items: center; padding: 7px 8px; cursor: pointer; border-radius: 4px; font-size: 13px; margin-bottom: 0; transition: background .15s; }
.vehicle-checkboxes label:hover { background: var(--bg-hover); }
.vehicle-checkboxes input[type="checkbox"] { width: auto; margin-right: 10px; accent-color: var(--accent); }

/* ===== PUSH RESULT ===== */
.push-item { padding: 8px 12px; border-radius: var(--radius-sm); margin-bottom: 4px; font-size: 12px; }
.push-ok { background: var(--success-bg); color: var(--success); }
.push-fail { background: var(--danger-bg); color: var(--danger); }

/* ===== BUTTONS ===== */
.btn { padding: 9px 18px; border-radius: var(--radius-sm); border: none; cursor: pointer; font-size: 13px; font-weight: 500; transition: all .15s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 11px; }
.btn-block { width: 100%; justify-content: center; }

/* ===== PAGE HEADER ===== */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.page-header h2 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.page-header h2 i { color: var(--accent); }
.page-header-actions { display: flex; gap: 8px; }

/* ===== ALARM TABLE ===== */
.alarm-table { width: 100%; border-collapse: collapse; }
.alarm-table th { text-align: left; padding: 10px 14px; font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .8px; font-weight: 600; border-bottom: 2px solid var(--border); background: var(--bg-elevated); }
.alarm-table td { padding: 10px 14px; font-size: 12px; border-bottom: 1px solid var(--border-light); }
.alarm-table tr:hover td { background: var(--bg-hover); }
.alarm-badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 10px; font-weight: 600; }
.alarm-badge i { margin-right: 4px; }
.ge-enter-badge { background: var(--success-bg); color: var(--success); }
.ge-exit-badge { background: var(--danger-bg); color: var(--danger); }
.alarm-badge-system { background: var(--purple-bg); color: var(--purple); }
.alarm-comment { font-size: 11px; color: var(--text-secondary); max-width: 280px; }

/* ===== VEHICLES PAGE ===== */
.vehicle-card { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); padding: 14px 16px; margin-bottom: 8px; transition: all .2s; }
.vehicle-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.vehicle-card-top { display: flex; justify-content: space-between; align-items: center; }
.plate { font-weight: 700; font-size: 14px; }
.devid { font-size: 11px; color: var(--text-muted); margin-left: 8px; }
.vehicle-card-gps { font-size: 11px; color: var(--text-muted); margin-top: 4px; padding: 4px 0; }
.vehicle-card-fences { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.fence-tag { background: var(--bg-elevated); border: 1px solid var(--border-light); padding: 2px 8px; border-radius: 4px; font-size: 10px; color: var(--text-muted); }

/* ===== STATUS ===== */
.status { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 10px; font-weight: 600; }
.status.online { background: var(--success-bg); color: var(--success); }
.status.offline { background: var(--danger-bg); color: var(--danger); }
.badge { display: inline-block; background: var(--bg-elevated); border: 1px solid var(--border-light); padding: 2px 8px; border-radius: 8px; font-size: 10px; color: var(--text-muted); }

/* ===== VEHICLE CARD (sidebar) ===== */
.vh-card { background: var(--bg-elevated); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 4px; border: 1px solid var(--border-light); }
.vh-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.vh-devid { font-weight: 600; font-size: 12px; }
.vh-card-body { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); }

/* ===== LOADING / EMPTY / ERROR ===== */
.loading { color: var(--text-muted); padding: 20px; text-align: center; font-size: 13px; }
.error-msg { color: var(--danger); padding: 8px; font-size: 13px; }
.empty-msg { color: var(--text-muted); padding: 20px; text-align: center; font-size: 13px; }

/* ===== VEHICLE MARKER ON MAP ===== */
.vehicle-marker-container { background: none !important; border: none !important; }
.vehicle-marker { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.vehicle-marker.online { background: var(--accent); }
.vehicle-marker.offline { background: var(--danger); opacity: .75; }
.marker-popup { font-size: 12px; line-height: 1.6; }
.marker-popup b { color: var(--text-primary); }

/* ===== LEAFLET ===== */
.leaflet-container { background: var(--bg-primary) !important; }
.leaflet-control-zoom { border: 1px solid var(--border) !important; }
.leaflet-control-zoom a { background: var(--bg-card) !important; color: var(--text-primary) !important; }
.leaflet-control-attribution { display: none !important; }
.leaflet-popup-content-wrapper { background: var(--bg-card) !important; color: var(--text-primary) !important; border-radius: 10px !important; border: 1px solid var(--border) !important; box-shadow: var(--shadow-lg) !important; }
.leaflet-popup-tip { background: var(--bg-card) !important; }

/* ===== LOADING SPINNER ===== */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading { color: var(--text-muted); padding: 20px; text-align: center; font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.loading::before { content: ''; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 5000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; font-size: 13px; animation: slideIn 0.3s ease; min-width: 280px; }
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-info { border-left: 4px solid var(--accent); }
.toast i { font-size: 16px; flex-shrink: 0; }
.toast-success i { color: var(--success); }
.toast-error i { color: var(--danger); }
.toast-info i { color: var(--accent); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }

/* ===== BUTTON EFFECTS ===== */
.btn { position: relative; overflow: hidden; }
.btn::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent); transform: translateX(-100%); transition: transform 0.3s; }
.btn:hover::after { transform: translateX(100%); }
.btn:active { transform: scale(0.97); }

/* ===== STAT CARD ANIMATIONS ===== */
.stat-card { transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-value { transition: color 0.2s; }
.stat-card:hover .stat-value { color: var(--accent); }

/* ===== FENCE ITEM ANIMATIONS ===== */
.fence-item { transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); }
.fence-item:hover { transform: translateX(4px); }
.fence-item.selected { transform: translateX(4px); }

/* ===== TABLE ROW HOVER ===== */
.alarm-table tr { transition: background 0.15s; }
.alarm-table tr:hover td { background: var(--bg-hover); }

/* ===== VEHICLE CARD ANIMATIONS ===== */
.vehicle-card { transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); }
.vehicle-card:hover { transform: translateY(-2px); }

/* ===== MAP MARKER PULSE ===== */
.vehicle-marker.online::after { content: ''; position: absolute; width: 100%; height: 100%; border-radius: 50%; background: var(--accent); animation: pulse 2s ease-out infinite; z-index: -1; }
@keyframes pulse { 0% { transform: scale(1); opacity: 0.5; } 100% { transform: scale(2); opacity: 0; } }

/* ===== MODAL ANIMATION ===== */
.modal-overlay.show .modal { animation: modalIn 0.25s ease; }
@keyframes modalIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ===== EMPTY STATE ===== */
.empty-msg { color: var(--text-muted); padding: 40px 20px; text-align: center; font-size: 13px; }
.empty-msg::before { content: '\f075'; font-family: 'Font Awesome 6 Free'; font-weight: 900; display: block; font-size: 24px; color: var(--border); margin-bottom: 8px; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== RESPONSIVE - TABLET ===== */
@media (max-width: 1024px) {
    .sidebar { position: fixed; left: -260px; top: 0; height: 100vh; z-index: 150; transition: left .3s ease; box-shadow: var(--shadow-lg); }
    .sidebar.open { left: 0; }
    .menu-toggle { display: flex; }
    .topbar { padding-left: 60px; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .geofence-sidebar { width: 280px; }
    .geofence-bottom { grid-template-columns: 1fr 1fr; }
}

/* ===== RESPONSIVE - MOBILE ===== */
@media (max-width: 640px) {
    .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 16px 8px; }
    .stat-card { padding: 12px; gap: 10px; }
    .stat-icon { width: 36px; height: 36px; font-size: 14px; }
    .stat-value { font-size: 20px; }
    .geofence-layout { flex-direction: column; }
    .geofence-map { min-height: 50vh; }
    .geofence-sidebar { width: 100%; max-height: 250px; border-left: none; border-top: 1px solid var(--border); }
    .geofence-bottom { grid-template-columns: 1fr; padding: 8px 16px 16px; }
    .page-header { flex-direction: column; gap: 10px; align-items: flex-start; }
    .page-header-actions { width: 100%; }
    .modal { width: calc(100% - 32px); margin: 16px; }
    .form-row { grid-template-columns: 1fr; }
    .tab-content { padding: 12px 16px; }
    #tab-geocercas { padding: 0; }
    .topbar-info { gap: 4px; }
    .info-chip { padding: 4px 8px; font-size: 10px; }
    .alarm-table { font-size: 11px; }
    .alarm-table th, .alarm-table td { padding: 8px 10px; }
    
    /* Better touch targets */
    .btn { min-height: 44px; min-width: 44px; }
    .btn-sm { min-height: 36px; min-width: 36px; }
    .nav-btn { min-height: 48px; }
    .fence-item { min-height: 60px; }
    .vehicle-card { min-height: 80px; }
    
    /* Stack buttons vertically on mobile */
    .page-header-actions { flex-direction: column; }
    .page-header-actions .btn { width: 100%; justify-content: center; }
    
    /* Better modal on mobile */
    .modal { max-height: 90vh; border-radius: 16px 16px 0 0; position: fixed; bottom: 0; top: auto; }
    .modal-overlay.show { align-items: flex-end; }
    
    /* Improve map tools for touch */
    .map-tools { top: 8px; right: 8px; }
    .btn-map { width: 44px; height: 44px; font-size: 16px; }
    
    /* Better scrollbar for touch */
    ::-webkit-scrollbar { width: 3px; }
    
    /* Panel cards stack on mobile */
    .panel-card-body { max-height: 150px; }
    
    /* Alarm table responsive */
    .alarm-table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ===== RESPONSIVE - VERY SMALL SCREENS ===== */
@media (max-width: 380px) {
    .stats-row { grid-template-columns: 1fr; }
    .stat-card { padding: 10px; }
    .stat-value { font-size: 18px; }
    .brand-name { font-size: 14px; }
    .brand-sub { font-size: 9px; }
    .sidebar { width: 220px; }
}

/* ===== LANDSCAPE MODE ===== */
@media (max-height: 500px) and (orientation: landscape) {
    .geofence-map { min-height: 60vh; }
    .geofence-bottom { display: none; }
    .stats-row { padding: 8px 16px; gap: 8px; }
    .stat-card { padding: 8px; }
    .stat-icon { width: 32px; height: 32px; font-size: 12px; }
    .stat-value { font-size: 16px; }
}

/* ===== TABLET LANDSCAPE ===== */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .geofence-bottom { grid-template-columns: 1fr 1fr; }
}

/* ===== HIGH DPI SCREENS ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .vehicle-marker { border-width: 1px; }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
    .fence-item:hover { transform: none; }
    .vehicle-card:hover { transform: none; }
    .stat-card:hover { transform: none; }
    .btn:hover::after { display: none; }
    .btn:active { transform: scale(0.95); }
}

/* ===== ALARM FILTERS ===== */
.alarm-filters { display: flex; align-items: flex-end; gap: 12px; padding: 14px 20px; background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.alarm-filters .filter-group { display: flex; flex-direction: column; gap: 4px; }
.alarm-filters .filter-group label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .8px; font-weight: 600; }
.alarm-filters .filter-group select,
.alarm-filters .filter-group input { background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; color: var(--text-primary); font-size: 12px; min-width: 160px; }
.alarm-filters .filter-group select:focus,
.alarm-filters .filter-group input:focus { outline: none; border-color: var(--accent); }
.alarm-filter-count { font-size: 11px; color: var(--text-muted); margin-left: auto; white-space: nowrap; }

/* ===== COPY MODAL ===== */
.copy-info { background: var(--accent-bg); border: 1px solid var(--accent); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 14px; font-size: 12px; color: var(--accent); display: flex; align-items: center; gap: 8px; }
.copy-info i { font-size: 14px; }

/* ===== MULTAS ===== */
.multas-summary { margin-bottom: 16px; }
.multas-summary-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.ms-card { background: var(--bg-card); border-radius: var(--radius); padding: 16px; border: 1px solid var(--border); text-align: center; transition: all .2s; }
.ms-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.ms-card.ms-danger { border-left: 4px solid var(--danger); }
.ms-card.ms-warning { border-left: 4px solid var(--warning); }
.ms-card.ms-success { border-left: 4px solid var(--success); }
.ms-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .8px; font-weight: 600; margin-bottom: 4px; }
.ms-value { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.ms-card.ms-danger .ms-value { color: var(--danger); }
.ms-card.ms-warning .ms-value { color: var(--warning); }
.ms-card.ms-success .ms-value { color: var(--success); }

.checkpoint-row { background: var(--bg-elevated); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px; }
.checkpoint-row .form-group { margin-bottom: 8px; }
.checkpoint-row .form-row { gap: 8px; }
.checkpoint-row .form-row .form-group { flex: 1; }

@media (max-width: 640px) {
    .multas-summary-cards { grid-template-columns: 1fr; gap: 8px; }
    .ms-value { font-size: 18px; }
}
