/* IoT CoActive — Professional light portal theme */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e2e8f0;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.04);
    --radius: 10px;
    --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
    font-family: var(--font);
    background: var(--body-bg);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 40;
    transition: transform 0.25s ease;
}
.main-wrap {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 30;
}
.main-content { padding: 1.5rem 1.75rem 2rem; flex: 1; min-width: 0; overflow-x: hidden; }
.main-wrap { min-width: 0; overflow-x: hidden; }

/* Brand */
.brand-block { padding: 1.25rem 1.25rem 1rem; border-bottom: 1px solid var(--border); }
.brand-row { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.brand-text { min-width: 0; flex: 1; }
.brand-logo {
    width: 40px; height: 40px; border-radius: 10px;
    background: var(--gradient, linear-gradient(135deg, var(--primary), var(--primary-dark)));
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; color: #fff; flex-shrink: 0;
}
.brand-logo-img {
    max-width: 140px; max-height: 48px; width: auto; height: auto;
    object-fit: contain; flex-shrink: 0; display: block;
}
.brand-preview {
    margin-bottom: 0.5rem; padding: 0.5rem; background: #fff;
    border: 1px solid var(--border); border-radius: 8px; min-height: 48px;
    display: flex; align-items: center;
}

/* Branding crop upload */
.branding-upload-block { margin-top: 0.5rem; }
.branding-frame-demo {
    border: 2px dashed #94a3b8;
    background: #fff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.65rem;
    position: relative;
}
.branding-frame-logo {
    width: 100%;
    max-width: 200px;
    aspect-ratio: 400 / 120;
}
.branding-frame-favicon {
    width: 64px;
    height: 64px;
}
.branding-frame-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.branding-slot .branding-choose-btn { margin-top: 0.35rem; }
.branding-ready-badge { display: block; margin-top: 0.35rem; color: #059669 !important; }

body.branding-crop-open { overflow: hidden; }
.branding-crop-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10050;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.branding-crop-backdrop[hidden] { display: none !important; }
.branding-crop-dialog {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
    width: min(920px, 100%);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.branding-crop-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.branding-crop-body {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 1rem;
    padding: 1rem 1.25rem;
    overflow: auto;
}
@media (max-width: 720px) {
    .branding-crop-body { grid-template-columns: 1fr; }
}
.branding-crop-workspace { min-width: 0; }
.branding-crop-frame-wrap {
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    max-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.branding-crop-frame-wrap.branding-frame-logo {
    aspect-ratio: 400 / 120;
    width: 100%;
    max-height: 280px;
}
.branding-crop-frame-wrap.branding-frame-favicon {
    width: 280px;
    height: 280px;
    max-width: 100%;
    margin: 0 auto;
}
.branding-crop-frame-wrap img {
    display: block;
    max-width: 100%;
}
.branding-crop-controls .form-label { font-size: 0.75rem; }
.branding-crop-adjust {
    border: none;
    margin: 0;
    padding: 0;
}
.branding-crop-adjust legend { padding: 0; }
.branding-crop-row {
    display: grid;
    grid-template-columns: 3.25rem 1fr auto;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.45rem;
}
.branding-crop-row:has(.branding-crop-zoom-btn) {
    grid-template-columns: 3.25rem auto 1fr auto;
}
.branding-crop-row-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
}
.branding-crop-range {
    width: 100%;
    min-width: 0;
    accent-color: var(--primary, #2563eb);
}
.branding-crop-pct {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 2.5rem;
    text-align: right;
}
.branding-crop-check {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin: 0.35rem 0 0.5rem;
    cursor: pointer;
}
.branding-crop-check input { margin-top: 0.15rem; }
.branding-crop-btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.branding-bg-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}
.branding-bg-row input[type="color"] {
    width: 44px;
    height: 36px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}
.branding-crop-preview-box {
    min-height: 80px;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.branding-crop-preview-logo {
    max-width: 100%;
    max-height: 56px;
    object-fit: contain;
}
.branding-crop-preview-favicon {
    width: 32px;
    height: 32px;
    object-fit: contain;
}
.branding-crop-footer {
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}
.brand-title { font-size: 1.05rem; font-weight: 700; color: var(--text); line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-sub { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Portal entity cards (groups, schools) */
.portal-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}
.entity-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.15rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.entity-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}
.entity-card-head { display: flex; align-items: center; gap: 0.85rem; }
.entity-card-logo {
    width: 52px; height: 52px; object-fit: contain; border-radius: 10px;
    background: #f8fafc; border: 1px solid var(--border); flex-shrink: 0;
}
.entity-card-logo-placeholder {
    display: flex; align-items: center; justify-content: center;
    font-size: 1.35rem; font-weight: 700; color: var(--primary);
    background: var(--primary-light, #eff6ff);
}
.entity-card-title { margin: 0; font-size: 1.05rem; font-weight: 700; line-height: 1.25; }
.entity-card-meta { margin: 0.15rem 0 0; font-size: 0.75rem; color: var(--text-muted); }
.entity-card-desc { margin: 0; line-height: 1.45; }
.entity-card-stats { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; }
.entity-stat strong { color: var(--text); }
.entity-card-links { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.entity-card-actions { padding-top: 0.35rem; border-top: 1px solid var(--border); margin-top: auto; }
.portal-empty { text-align: center; padding: 2.5rem 1.5rem; }

/* Attendance toolbar */
.att-toolbar {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem 1.25rem;
    padding: 1rem 1.25rem;
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1rem;
}
.att-toolbar-field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.att-toolbar-field .form-label { margin: 0; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.att-toolbar-month { display: flex; align-items: center; gap: 0.35rem; }
.att-toolbar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-left: auto; align-items: flex-end; }

/* Attendance calendar */
.att-filters { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.att-calendar-outer {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}
.att-calendar-wrap {
    overflow: auto;
    max-height: min(70vh, calc(100vh - 16rem));
    width: 100%;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    isolation: isolate;
}
.att-calendar-wrap .table-wrap {
    overflow: visible;
    max-width: none;
}
.att-calendar-wrap .att-calendar.data-table {
    width: max-content;
    min-width: 100%;
}
.att-calendar {
    font-size: 0.72rem;
    border-collapse: separate;
    border-spacing: 0;
}
.att-calendar th, .att-calendar td { padding: 0.2rem; text-align: center; vertical-align: middle; }
.att-sticky-col { position: sticky; left: 0; z-index: 2; background: #fff; text-align: left !important; min-width: 140px; padding: 0.35rem 0.5rem !important; border-right: 1px solid var(--border); }
.att-sticky-col2 { position: sticky; left: 140px; z-index: 2; background: #fff; min-width: 72px; border-right: 1px solid var(--border); }
.att-day-head { min-width: 1.65rem; font-weight: 600; line-height: 1.1; }
.att-day-head.att-col-weekend { background: #f1f5f9; }
.att-day-num { display: block; font-size: 0.7rem; }
.att-day-dow { display: block; font-size: 0.6rem; color: var(--text-muted); font-weight: 500; }
.att-cell {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.5rem; height: 1.5rem; border-radius: 4px; font-weight: 700; font-size: 0.65rem;
    border: none; cursor: default;
}
.att-cell-btn { cursor: pointer; }
.att-cell-btn:hover { filter: brightness(0.92); }
.att-present { background: #d1fae5; color: #047857; }
.att-late { background: #fef3c7; color: #b45309; }
.att-absent { background: #fee2e2; color: #b91c1c; }
.att-half_day { background: #e0e7ff; color: #4338ca; }
.att-holiday { background: #e2e8f0; color: #64748b; }
.att-weekend { background: #f8fafc; color: #94a3b8; }
.att-pending { background: #fff; color: #cbd5e1; border: 1px dashed var(--border); }
.att-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; font-size: 0.8rem; }

/* Nav */
.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.75rem 0.65rem; }
.nav-section-label {
    font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--text-muted);
    padding: 0.85rem 0.75rem 0.35rem;
}
.nav-link {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.55rem 0.75rem; margin-bottom: 2px;
    border-radius: 8px; color: var(--text-muted);
    text-decoration: none; font-size: 0.875rem; font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--primary-light); color: var(--primary); }
.nav-link.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}
.nav-svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-user {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
}
.sidebar-user strong { display: block; font-size: 0.875rem; color: var(--text); }
.sidebar-user span { color: var(--text-muted); font-size: 0.75rem; }
.btn-logout {
    margin-top: 0.5rem; background: none; border: none;
    color: var(--danger); font-size: 0.8rem; font-weight: 600;
    cursor: pointer; padding: 0;
}
.btn-logout:hover { text-decoration: underline; }

/* Page header */
.page-header { margin-bottom: 1.5rem; }
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--text); margin: 0 0 0.25rem; letter-spacing: -0.02em; }
.page-subtitle { font-size: 0.875rem; color: var(--text-muted); margin: 0; }
.breadcrumb { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.breadcrumb a { color: var(--primary); text-decoration: none; }

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-pad { padding: 1.25rem; }
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.95rem;
    display: flex; align-items: center; justify-content: space-between;
}
.card-header.primary { background: var(--primary); color: #fff; border: none; border-radius: var(--radius) var(--radius) 0 0; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { padding: 1.15rem 1.25rem; position: relative; overflow: hidden; }
.stat-card .stat-icon {
    width: 42px; height: 42px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; margin-bottom: 0.75rem;
}
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; font-weight: 500; }
.stat-blue .stat-icon { background: #dbeafe; }
.stat-green .stat-icon { background: #d1fae5; }
.stat-amber .stat-icon { background: #fef3c7; }
.stat-red .stat-icon { background: #fee2e2; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    padding: 0.5rem 1rem; border-radius: 8px; font-size: 0.875rem; font-weight: 600;
    border: 1px solid transparent; cursor: pointer; text-decoration: none;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--body-bg); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.ripple-btn {
    background: var(--primary); color: #fff; font-weight: 600;
    padding: 0.5rem 1rem; border-radius: 8px; border: none; cursor: pointer;
    text-decoration: none; display: inline-flex; align-items: center; gap: 0.4rem;
    font-size: 0.875rem;
}
.ripple-btn:hover { background: var(--primary-dark); }
.ripple-btn-outline {
    background: #fff; color: var(--text); border: 1px solid var(--border);
    box-shadow: none;
}
.ripple-btn-outline:hover { background: var(--body-bg); }

/* Forms */
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.35rem; }
.form-control, .form-select {
    width: 100%; padding: 0.5rem 0.75rem;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.875rem; color: var(--text); background: #fff;
}
.form-control:focus, .form-select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.form-grid { display: grid; gap: 1rem; }
.form-grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 640px) { .form-grid-2 { grid-template-columns: 1fr; } }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th {
    text-align: left; padding: 0.75rem 1rem;
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--text-muted);
    background: #f8fafc; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:hover { background: #f8fafc; }

/* Badges */
.badge {
    display: inline-flex; align-items: center; padding: 0.2rem 0.55rem;
    border-radius: 999px; font-size: 0.7rem; font-weight: 600;
}
.badge-success { background: #d1fae5; color: #047857; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-muted { background: #f1f5f9; color: #64748b; }
.badge-live {
    background: #d1fae5; color: #047857; border: 1px solid #a7f3d0;
    animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.7} }

/* Alerts flash */
.alert { padding: 0.85rem 1rem; border-radius: 8px; font-size: 0.875rem; margin-bottom: 1rem; }
.alert-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* Map layouts */
.map-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    min-height: calc(100vh - 140px);
    height: calc(100vh - 180px);
    max-height: calc(100vh - 180px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--card-bg);
}
.map-layout > .map-panel,
.map-layout > .map-canvas { min-height: 0; }
.map-panel {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
    background: #f8fafc;
}
.map-panel-header {
    flex-shrink: 0;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: #fff;
}
.map-panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0.75rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.map-canvas { min-height: 0; height: 100%; position: relative; }
.map-shell { min-height: 520px; height: calc(100vh - 180px); max-height: calc(100vh - 180px); }
#map, #map-history, #map-geofence, #map-route, #dash-mini-map { width: 100%; height: 100%; min-height: 400px; }
.fleet-card {
    background: #fff; border: 1px solid var(--border); border-radius: 8px;
    padding: 0.85rem; margin-bottom: 0.5rem; cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.fleet-card:hover, .fleet-card.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.12); }
.fleet-card h4 { margin: 0 0 0.25rem; font-size: 0.875rem; font-weight: 600; }
.fleet-card .meta { font-size: 0.75rem; color: var(--text-muted); }
.status-pills { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.status-pill {
    flex: 1; min-width: 70px; text-align: center; padding: 0.5rem;
    border-radius: 8px; font-size: 0.75rem; font-weight: 600;
    border: 1px solid var(--border); background: #fff;
}
.status-pill strong { display: block; font-size: 1.1rem; color: var(--text); }
.status-pill.total { border-color: #bfdbfe; background: #eff6ff; }
.status-pill.moving { border-color: #a7f3d0; background: #ecfdf5; }
.status-pill.idle { border-color: #fecaca; background: #fef2f2; }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 50%, #ecfdf5 100%); }
.login-card {
    width: 100%; max-width: 420px; background: #fff;
    border: 1px solid var(--border); border-radius: 16px;
    padding: 2.5rem; box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
}
.login-card h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
.login-card .sub { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1.75rem; }

/* Impersonation */
.impersonation-bar {
    position: sticky;
    top: 0;
    z-index: 10060;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.75rem 1.25rem;
    background: linear-gradient(90deg, #d97706, #dc2626);
    color: #fff;
    padding: 0.65rem 1rem;
    font-size: 0.82rem;
    box-shadow: 0 4px 12px rgba(180, 50, 0, 0.25);
}
.impersonation-bar-text { line-height: 1.4; }
.impersonation-bar-form { margin: 0; }
.impersonation-bar-btn {
    background: #fff;
    color: #b45309;
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
.impersonation-bar-btn:hover { background: #fffbeb; }

/* Users list & forms */
.users-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem 1.25rem;
    padding: 1rem 1.25rem;
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1rem;
}
.users-filter-field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.users-filter-field .form-label { margin: 0; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.users-filter-actions { display: flex; gap: 0.5rem; margin-left: auto; align-items: flex-end; }
.user-role-badge { font-weight: 600; }
.user-role-super { background: #dbeafe; color: #1d4ed8; }
.user-role-group { background: #e0f2fe; color: #0369a1; }
.user-role-school { background: #d1fae5; color: #047857; }
.user-role-parent { background: #ffedd5; color: #b45309; }
.user-table-name { display: flex; align-items: center; gap: 0.65rem; }
.user-avatar {
    width: 2.25rem; height: 2.25rem; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 700; color: #fff; flex-shrink: 0;
    background: var(--gradient, linear-gradient(135deg, #64748b, #475569));
}
.user-create-layout { display: grid; grid-template-columns: 1fr 280px; gap: 1.25rem; align-items: start; }
@media (max-width: 800px) { .user-create-layout { grid-template-columns: 1fr; } }
.user-create-aside {
    padding: 1rem 1.15rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 0.85rem;
}
.user-create-aside h4 { margin: 0 0 0.5rem; font-size: 0.9rem; }
.user-create-aside ul { margin: 0; padding-left: 1.1rem; color: var(--text-muted); line-height: 1.5; }
.user-field-group { display: none; }
.user-field-group.is-visible { display: block; }
.user-actions-cell { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }

/* Map / leaflet light */
.leaflet-container { background: #e2e8f0; font-family: inherit; }
.map-error {
    display: flex; align-items: center; justify-content: center; height: 100%;
    background: #f8fafc; color: var(--text-muted); text-align: center; padding: 2rem;
}
.map-status-banner { pointer-events: none; }

/* Utilities */
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.gap-2 { gap: 0.5rem; } .gap-3 { gap: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
.hidden { display: none !important; }
.portal-header { /* legacy */ color: var(--text); -webkit-text-fill-color: unset; background: none; }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.topbar-btn-icon {
    width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
    background: #fff; display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-muted);
    position: relative; z-index: 50;
}
.error-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--body-bg); }
.error-box { text-align: center; max-width: 400px; padding: 2rem; }

body.map-fullscreen #map, body.map-fullscreen #map-history, body.map-fullscreen #map-geofence,
body.map-fullscreen #map-route, body.map-fullscreen #dash-mini-map, body.map-fullscreen .map-canvas {
    position: fixed !important; inset: 0 !important; z-index: 9999 !important;
    height: 100vh !important; border-radius: 0 !important;
}

.map-fs-btn {
    position: absolute; top: 12px; right: 12px; z-index: 500;
}

.map-fs-exit {
    position: fixed; top: 16px; right: 16px; z-index: 10001;
    padding: 0.5rem 1rem; border-radius: 8px; border: none;
    background: #fff; color: #0f172a; font-weight: 600; font-size: 0.875rem;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18); cursor: pointer;
}
.map-fs-exit:hover { background: #f1f5f9; }

.crud-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin-top: 0.5rem; }
.crud-delete-form { display: inline; margin: 0; }
.btn-danger { color: #b91c1c; border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }

.geofence-item, .route-item { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.geofence-item:hover, .geofence-item.active,
.route-item:hover, .route-item.active {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.geofence-color-dot {
    width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
    border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12);
}

.iot-pin-marker { background: transparent; border: none; }
.iot-pin { display: flex; flex-direction: column; align-items: center; }
.iot-pin-cap {
    width: 28px; height: 28px; border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg); display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 11px;
    border: 2px solid #fff; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
}
.iot-pin-cap > * { transform: rotate(45deg); }
.iot-pin-label {
    margin-top: 4px; font-size: 10px; font-weight: 700; color: #0f172a;
    background: #fff; padding: 2px 6px; border-radius: 4px;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.iot-track-wrap, .iot-hist-wrap { background: transparent; border: none; }
.iot-track-marker, .iot-hist-marker {
    width: 32px; height: 32px; position: relative;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.iot-hist-marker { width: 22px; height: 22px; }
.iot-track-ring {
    position: absolute; inset: 2px; border-radius: 50%;
    border: 2px solid var(--dot, #2563eb); opacity: 0.35;
    animation: iot-pulse 2s ease-out infinite;
    pointer-events: none;
}
.iot-track-dot {
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--dot, #2563eb); border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
    position: relative; z-index: 2;
}
.iot-track-arrow {
    font-size: 16px; line-height: 1; color: var(--dot, #2563eb);
    text-shadow: 0 0 2px #fff, 0 1px 3px rgba(15, 23, 42, 0.15);
    position: relative; z-index: 2;
}
.iot-hist-dot {
    width: 10px; height: 10px; border-radius: 50%;
    border: 2px solid #fff; box-shadow: 0 1px 4px rgba(15, 23, 42, 0.2);
}
.iot-hist-arrow {
    font-size: 14px; line-height: 1; color: var(--c, #2563eb);
    text-shadow: 0 0 2px #fff;
}
@keyframes iot-pulse {
    0% { transform: scale(0.6); opacity: 0.6; }
    100% { transform: scale(1.4); opacity: 0; }
}

.leaflet-tooltip.iot-map-tooltip {
    background: #fff; color: #0f172a; border: 1px solid #e2e8f0;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12); font-size: 12px;
    padding: 0; border-radius: 8px;
}
.leaflet-tooltip.iot-tooltip-rich { padding: 0; }
.iot-point-tip {
    display: flex; flex-direction: column; gap: 0.2rem;
    padding: 0.5rem 0.65rem; font-size: 12px; line-height: 1.4; min-width: 160px;
}
.iot-point-tip strong { font-size: 13px; color: #0f172a; margin-bottom: 0.15rem; }
.iot-point-tip span { color: #475569; }

/* Center modal alerts — animated */
body.iot-modal-open { overflow: hidden; }

@keyframes iot-backdrop-in {
    from { opacity: 0; backdrop-filter: blur(0); }
    to { opacity: 1; backdrop-filter: blur(8px); }
}
@keyframes iot-backdrop-out {
    from { opacity: 1; }
    to { opacity: 0; }
}
@keyframes iot-card-in {
    0% { opacity: 0; transform: scale(0.88) translateY(24px); }
    70% { transform: scale(1.02) translateY(-4px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes iot-card-out {
    from { opacity: 1; transform: scale(1) translateY(0); }
    to { opacity: 0; transform: scale(0.92) translateY(12px); }
}
@keyframes iot-icon-pop {
    0% { opacity: 0; transform: scale(0.4) rotate(-12deg); }
    60% { transform: scale(1.08) rotate(4deg); }
    100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes iot-icon-pulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 transparent); }
    50% { transform: scale(1.06); filter: drop-shadow(0 0 12px rgba(245, 158, 11, 0.45)); }
}
@keyframes iot-icon-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}
@keyframes iot-draw-check {
    from { stroke-dashoffset: 48; }
    to { stroke-dashoffset: 0; }
}
@keyframes iot-draw-ring {
    from { stroke-dashoffset: 160; opacity: 0.3; }
    to { stroke-dashoffset: 0; opacity: 1; }
}
@keyframes iot-accent-shine {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.iot-modal-backdrop {
    position: fixed; inset: 0; z-index: 10050;
    display: flex; align-items: center; justify-content: center;
    padding: 1.25rem;
    background: rgba(15, 23, 42, 0.52);
    backdrop-filter: blur(0);
    opacity: 0;
}
.iot-modal-backdrop.iot-modal-visible {
    animation: iot-backdrop-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.iot-modal-backdrop.iot-modal-closing {
    animation: iot-backdrop-out 0.28s ease forwards;
    pointer-events: none;
}
.iot-modal-backdrop.iot-modal-closing .iot-modal {
    animation: iot-card-out 0.28s ease forwards;
}

.iot-modal {
    position: relative;
    width: 100%; max-width: 440px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow:
        0 0 0 1px rgba(15, 23, 42, 0.04),
        0 25px 50px -12px rgba(15, 23, 42, 0.28),
        0 12px 24px -8px rgba(37, 99, 235, 0.08);
    padding: 0 1.75rem 1.5rem;
    text-align: center;
    overflow: hidden;
    opacity: 0;
}
.iot-modal-visible .iot-modal {
    animation: iot-card-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.iot-modal-accent {
    height: 4px;
    margin: 0 -1.75rem 1.25rem;
    background-size: 200% 100%;
    animation: iot-accent-shine 3s linear infinite;
}
.iot-modal-success .iot-modal-accent { background: linear-gradient(90deg, #10b981, #34d399, #6ee7b7, #10b981); }
.iot-modal-info .iot-modal-accent { background: linear-gradient(90deg, #2563eb, #60a5fa, #93c5fd, #2563eb); }
.iot-modal-warning .iot-modal-accent { background: linear-gradient(90deg, #f59e0b, #fbbf24, #fcd34d, #f59e0b); }
.iot-modal-critical .iot-modal-accent { background: linear-gradient(90deg, #ef4444, #f87171, #fca5a5, #ef4444); }
.iot-modal-error .iot-modal-accent { background: linear-gradient(90deg, #dc2626, #f87171, #fecaca, #dc2626); }
.iot-modal-confirm .iot-modal-accent { background: linear-gradient(90deg, #8b5cf6, #a78bfa, #c4b5fd, #8b5cf6); }

.iot-modal-icon-wrap {
    width: 72px; height: 72px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    animation: iot-icon-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) 0.12s both;
}
.iot-modal-svg {
    width: 52px; height: 52px;
    display: block;
}
.iot-modal-ring {
    stroke-dasharray: 160;
    stroke-dashoffset: 160;
    animation: iot-draw-ring 0.7s ease 0.2s forwards;
}
.iot-modal-check {
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: iot-draw-check 0.45s ease 0.55s forwards;
}
.iot-modal-svg-pulse {
    animation: iot-icon-pulse 2s ease-in-out 0.8s infinite;
}
.iot-modal-svg-shake {
    animation: iot-icon-shake 0.55s ease 0.4s;
}

.iot-modal-icon-success {
    background: linear-gradient(145deg, #d1fae5, #ecfdf5);
    color: #059669;
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.25);
}
.iot-modal-icon-info {
    background: linear-gradient(145deg, #dbeafe, #eff6ff);
    color: #2563eb;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.2);
}
.iot-modal-icon-warning {
    background: linear-gradient(145deg, #fef3c7, #fffbeb);
    color: #d97706;
    box-shadow: 0 8px 24px rgba(245, 158, 11, 0.28);
}
.iot-modal-icon-critical {
    background: linear-gradient(145deg, #fee2e2, #fef2f2);
    color: #dc2626;
    box-shadow: 0 8px 28px rgba(239, 68, 68, 0.35);
}
.iot-modal-icon-error {
    background: linear-gradient(145deg, #fecaca, #fef2f2);
    color: #b91c1c;
    box-shadow: 0 8px 24px rgba(220, 38, 38, 0.28);
}
.iot-modal-icon-confirm {
    background: linear-gradient(145deg, #ede9fe, #f5f3ff);
    color: #7c3aed;
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.22);
}

.iot-modal-title {
    margin: 0 0 0.65rem;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #0f172a;
}
.iot-modal-body {
    margin: 0 0 1.35rem;
    font-size: 0.925rem;
    color: #64748b;
    line-height: 1.6;
    text-align: center;
    max-height: 50vh;
    overflow-y: auto;
}
.iot-modal-body p { margin: 0 0 0.5rem; }
.iot-modal-body strong { color: #334155; }
.iot-modal-footer {
    display: flex;
    gap: 0.65rem;
    justify-content: center;
    flex-wrap: wrap;
}
.iot-modal-footer .btn {
    min-width: 108px;
    padding: 0.55rem 1.25rem;
    font-weight: 600;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.iot-modal-footer .btn-primary {
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.iot-modal-footer .btn:hover {
    transform: translateY(-1px);
}
.iot-modal-footer .btn:active {
    transform: translateY(0);
}
.iot-modal-link { text-decoration: none; }

@media (max-width: 1024px) {
    .map-layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(200px, 38vh) 1fr;
        height: calc(100vh - 160px);
        max-height: calc(100vh - 160px);
    }
    .map-panel {
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .map-panel-body { max-height: none; }
}
/* Sidebar collapse (toggle) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 35;
    pointer-events: none;
}
@media (min-width: 769px) {
    .sidebar-overlay { display: none !important; }
    .app-shell.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }
    .app-shell.sidebar-collapsed .main-wrap {
        margin-left: 0;
    }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .app-shell:not(.sidebar-collapsed) .sidebar {
        transform: translateX(0);
        box-shadow: var(--shadow-lg, 0 12px 40px rgba(0, 0, 0, 0.15));
    }
    .app-shell:not(.sidebar-collapsed) .sidebar-overlay {
        display: block;
        pointer-events: auto;
    }
    .main-wrap { margin-left: 0; }
}
