/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #1e293b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }

/* ===== Pages ===== */
.page { display: none; }
.page.active { display: flex; }

/* ===== Login ===== */
.login-container { width: 100%; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%); }
.login-card { background: var(--card-bg); border-radius: 16px; padding: 40px; width: 400px; max-width: 90vw; box-shadow: var(--shadow-lg); }
.login-header { text-align: center; margin-bottom: 32px; }
.login-header .logo { font-size: 48px; margin-bottom: 8px; }
.login-header h1 { font-size: 24px; font-weight: 700; }
.login-header p { color: var(--text-light); font-size: 14px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-group input, .form-group select { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; transition: border-color 0.2s; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.checkbox-label input { width: auto; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 20px; border-radius: var(--radius); font-size: 14px; font-weight: 600; border: none; cursor: pointer; transition: all 0.2s; gap: 6px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }

/* ===== Layout ===== */
#app-page { width: 100%; min-height: 100vh; }
#sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 240px; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; z-index: 100; transition: transform 0.3s; }
#sidebar.collapsed { transform: translateX(-240px); }
.sidebar-header { padding: 20px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.logo-sm { font-size: 24px; }
.sidebar-title { font-size: 18px; font-weight: 700; color: white; }
.nav-menu { list-style: none; flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item { padding: 10px 20px; display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; transition: all 0.2s; border-left: 3px solid transparent; }
.nav-item:hover { background: rgba(255,255,255,0.05); }
.nav-item.active { background: var(--sidebar-active); border-left-color: var(--primary); color: white; }
.nav-icon { font-size: 16px; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08); }
.user-info { margin-bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
#sidebar-user-name { font-size: 14px; font-weight: 600; color: white; }

/* ===== Main Content ===== */
#main-content { margin-left: 240px; min-height: 100vh; transition: margin-left 0.3s; }
#sidebar.collapsed + #main-content { margin-left: 0; }
#topbar { display: flex; align-items: center; padding: 16px 24px; background: var(--card-bg); border-bottom: 1px solid var(--border); gap: 16px; position: sticky; top: 0; z-index: 50; }
.menu-toggle { background: none; border: none; font-size: 20px; cursor: pointer; display: none; }
#page-title { font-size: 18px; font-weight: 700; flex: 1; }
.topbar-actions { font-size: 13px; color: var(--text-light); }
.content-section { display: none; padding: 24px; }
.content-section.active { display: block; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.section-actions { display: flex; gap: 8px; }
.search-input { padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; min-width: 200px; }
.search-input:focus { outline: none; border-color: var(--primary); }

/* ===== Cards & Stats ===== */
.card { background: var(--card-bg); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.mt-2 { margin-top: 24px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.stat-card { background: var(--card-bg); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px; }
.stat-icon { font-size: 36px; }
.stat-value { font-size: 28px; font-weight: 700; display: block; }
.stat-label { font-size: 13px; color: var(--text-light); }

/* ===== Tables ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table thead th { text-align: left; padding: 12px 16px; border-bottom: 2px solid var(--border); font-weight: 600; font-size: 12px; text-transform: uppercase; color: var(--text-light); white-space: nowrap; }
.data-table tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table .actions { display: flex; gap: 6px; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-admin { background: #ede9fe; color: #7c3aed; }
.badge-dealer { background: #fef3c7; color: #d97706; }
.badge-user { background: #dbeafe; color: #2563eb; }
.badge-active { background: #dcfce7; color: #16a34a; }
.badge-inactive { background: #fee2e2; color: #dc2626; }
.badge-online { background: #dcfce7; color: #16a34a; }
.badge-offline { background: #f1f5f9; color: #64748b; }
.badge-trial { background: #e0f2fe; color: #0284c7; }
.badge-expired { background: #fee2e2; color: #dc2626; }
.badge-canceled { background: #f1f5f9; color: #64748b; }

/* ===== Plans Grid ===== */
.plans-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.plan-card { background: var(--card-bg); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.plan-card h4 { font-size: 18px; margin-bottom: 4px; }
.plan-card .plan-desc { font-size: 13px; color: var(--text-light); margin-bottom: 16px; }
.plan-card .plan-price { font-size: 32px; font-weight: 700; color: var(--primary); }
.plan-card .plan-price span { font-size: 14px; font-weight: 400; color: var(--text-light); }
.plan-card .plan-features { margin: 16px 0; flex: 1; }
.plan-card .plan-features li { font-size: 13px; padding: 4px 0; list-style: none; }
.plan-card .plan-features li::before { content: "✓ "; color: var(--success); font-weight: 700; }
.plan-card .plan-meta { font-size: 12px; color: var(--text-light); padding-top: 12px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; }

/* ===== Map ===== */
.map-card { padding: 0; overflow: hidden; }

/* ===== Notifications ===== */
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.notif-wrap { position: relative; }
.notif-btn { position: relative; background: none; border: 1px solid var(--border); border-radius: 50%; width: 38px; height: 38px; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.notif-btn:hover { background: var(--bg); }
.notif-badge, .nav-badge { position: absolute; top: -6px; right: -6px; background: var(--danger); color: white; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.nav-badge { position: static; margin-left: auto; }
.notif-panel { position: absolute; right: 0; top: 46px; width: 380px; max-width: calc(100vw - 32px); background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 120; }
.notif-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.notif-item:hover { background: #f8fafc; }
.notif-item .notif-icon { font-size: 18px; }
.notif-item .notif-text { flex: 1; font-size: 13px; color: var(--text); }
.notif-item .notif-time { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.notif-empty { padding: 24px; text-align: center; color: var(--text-light); font-size: 13px; }
.notif-panel-footer { padding: 10px 16px; text-align: center; font-size: 13px; border-top: 1px solid var(--border); }
tr.alert-unread td { font-weight: 600; background: #fffbeb; }
.badge-exit { background: #fee2e2; color: #dc2626; }
.badge-enter { background: #dcfce7; color: #16a34a; }
.badge-outside { background: #fee2e2; color: #dc2626; }
.badge-inside { background: #dcfce7; color: #16a34a; }

/* ===== Geofence ===== */
.geofence-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#gf-pick-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.map-picking { cursor: crosshair !important; }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 20px; cursor: pointer; transition: 0.2s; }
.switch .slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: white; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* ===== Pagination ===== */
.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 16px; padding: 12px 0; }
.pagination button { padding: 6px 12px; border: 1px solid var(--border); background: var(--card-bg); border-radius: var(--radius); cursor: pointer; font-size: 13px; }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content { position: relative; background: var(--card-bg); border-radius: 12px; padding: 24px; width: 460px; max-width: 90vw; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-light); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ===== Toast ===== */
.toast { position: fixed; bottom: 24px; right: 24px; padding: 12px 20px; border-radius: var(--radius); color: white; font-size: 14px; font-weight: 500; z-index: 300; box-shadow: var(--shadow-lg); transition: opacity 0.3s, transform 0.3s; }
.toast.hidden { opacity: 0; transform: translateY(20px); pointer-events: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

/* ===== Utility ===== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-light); font-size: 13px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    #sidebar { transform: translateX(-240px); }
    #sidebar.open { transform: translateX(0); }
    #main-content { margin-left: 0 !important; }
    .menu-toggle { display: block; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
    .data-table { font-size: 12px; }
    .data-table thead th, .data-table tbody td { padding: 8px; }
    .section-header { flex-direction: column; align-items: flex-start; }
}
