
        * { margin: 0; padding: 0; box-sizing: border-box; }
        
        :root {
            --primary: #667eea;
            --secondary: #764ba2;
            --success: #10b981;
            --danger: #ef4444;
            --warning: #f59e0b;
            --info: #06b6d4;
            --light: #f3f4f6;
            --dark: #1f2937;
            --bg: #ffffff;
            --bg-secondary: #f9fafb;
            --border: #e5e7eb;
            --text: #1f2937;
            --text-light: #6b7280;
            --radius: 12px;
            --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s ease;
        }

        /* QR Camera */
        .stab {
            padding: 10px 18px;
            border: none;
            background: none;
            color: var(--text-light);
            cursor: pointer;
            border-bottom: 3px solid transparent;
            font-size: 14px;
            white-space: nowrap;
            transition: all 0.2s;
        }
        .stab.active { color: var(--primary); border-bottom-color: var(--primary); }
        .stab:hover  { color: var(--primary); }

        /* DARK MODE */
        [data-theme="dark"] {
            --bg: #1f2937;
            --bg-secondary: #111827;
            --border: #374151;
            --text: #f9fafb;
            --text-light: #9ca3af;
            --light: #111827;
        }
        [data-theme="dark"] .app-header { background: #1f2937; }
        [data-theme="dark"] .card { background: #1f2937; }
        [data-theme="dark"] .form-input,
        [data-theme="dark"] .form-select { background: #111827; color: #f9fafb; border-color: #374151; }
        [data-theme="dark"] table thead tr { background: #111827 !important; }
        [data-theme="dark"] .modal-content { background: #1f2937; }
        [data-theme="dark"] .modal-header { border-color: #374151; }

        @keyframes slideIn {
            from { transform: translateX(-20px); opacity: 0; }
            to { transform: translateX(0); opacity: 1; }
        }
        @keyframes spin {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        html {
            scroll-behavior: smooth;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
            color: var(--text);
            line-height: 1.6;
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* LAYOUT */
        /* ═══════════════════════════════════════════════════════════ */

        .app-layout {
            display: grid;
            grid-template-columns: 260px 1fr;
            grid-template-rows: 70px 1fr;
            height: 100vh;
            overflow: hidden;
        }

        .app-sidebar {
            grid-row: 1 / 3;
            grid-column: 1;
            background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
            color: white;
            overflow-y: auto;
            box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px 0;
        }

        .app-header {
            grid-row: 1;
            grid-column: 2;
            background: var(--bg);
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 30px;
            box-shadow: var(--shadow);
        }

        .app-content {
            grid-row: 2;
            grid-column: 2;
            overflow-y: auto;
            padding: 30px;
            background: var(--light);
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* SIDEBAR */
        /* ═══════════════════════════════════════════════════════════ */

        .sidebar-logo {
            padding: 0 20px 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 20px;
            font-size: 18px;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .sidebar-logo i {
            font-size: 24px;
        }

        .sidebar-menu {
            list-style: none;
        }

        .sidebar-item {
            margin: 0;
        }

        .sidebar-link {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 12px 20px;
            color: rgba(255, 255, 255, 0.7);
            text-decoration: none;
            transition: var(--transition);
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
        }

        .sidebar-link:hover {
            background: rgba(255, 255, 255, 0.1);
            color: white;
        }

        .sidebar-link.active {
            background: linear-gradient(90deg, var(--primary), var(--secondary));
            color: white;
            border-right: 4px solid white;
        }

        .sidebar-link i {
            font-size: 18px;
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* HEADER */
        /* ═══════════════════════════════════════════════════════════ */

        .header-left {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .header-title {
            font-size: 20px;
            font-weight: 700;
            color: var(--text);
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 16px;
        }

        .btn-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--bg-secondary);
            border: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
            color: var(--text);
            transition: var(--transition);
            position: relative;
        }

        .btn-icon:hover {
            background: var(--border);
            transform: translateY(-2px);
        }

        .notif-badge {
            position: absolute;
            top: -5px;
            left: -5px;
            background: var(--danger);
            color: white;
            font-size: 10px;
            padding: 2px 6px;
            border-radius: 10px;
            font-weight: 700;
        }

        .user-profile {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 8px 12px;
            background: var(--bg-secondary);
            border-radius: var(--radius);
        }

        .user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            font-size: 14px;
        }

        .user-name {
            font-size: 13px;
            font-weight: 600;
            color: var(--text);
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* PAGES */
        /* ═══════════════════════════════════════════════════════════ */

        .page {
            display: none;
            animation: fadeIn 0.3s ease;
        }

        .page.active {
            display: block;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .page-header {
            margin-bottom: 30px;
        }

        .page-title {
            font-size: 32px;
            font-weight: 700;
            color: var(--text);
            margin-bottom: 8px;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .page-subtitle {
            font-size: 14px;
            color: var(--text-light);
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* CARDS */
        /* ═══════════════════════════════════════════════════════════ */

        .card {
            background: var(--bg);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
            transition: var(--transition);
        }

        .card:hover {
            box-shadow: var(--shadow);
            border-color: var(--primary);
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 24px;
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }

        .stat-value {
            font-size: 32px;
            font-weight: 700;
            margin-bottom: 8px;
        }

        .stat-label {
            font-size: 13px;
            opacity: 0.9;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            font-weight: 600;
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* TABLES */
        /* ═══════════════════════════════════════════════════════════ */

        .table-container {
            overflow-x: auto;
            border-radius: var(--radius);
            border: 1px solid var(--border);
        }

        .table {
            width: 100%;
            border-collapse: collapse;
            font-size: 13px;
        }

        .table thead {
            background: var(--bg-secondary);
            border-bottom: 2px solid var(--border);
        }

        .table th {
            padding: 16px;
            text-align: right;
            font-weight: 700;
            color: var(--text);
            text-transform: uppercase;
            letter-spacing: 0.5px;
            font-size: 12px;
        }

        .table td {
            padding: 16px;
            border-bottom: 1px solid var(--border);
        }

        .table tbody tr:hover {
            background: var(--bg-secondary);
        }

        .table tbody tr:last-child td {
            border-bottom: none;
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* BUTTONS */
        /* ═══════════════════════════════════════════════════════════ */

        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: var(--radius);
            cursor: pointer;
            font-size: 13px;
            font-weight: 600;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            gap: 8px;
            text-decoration: none;
        }

        .btn-primary {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: var(--shadow);
        }

        .btn-secondary {
            background: var(--bg-secondary);
            color: var(--text);
            border: 1px solid var(--border);
        }

        .btn-secondary:hover {
            background: var(--border);
        }

        .btn-danger {
            background: var(--danger);
            color: white;
        }

        .btn-danger:hover {
            background: #dc2626;
        }

        .btn-success {
            background: var(--success);
            color: white;
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* FORMS */
        /* ═══════════════════════════════════════════════════════════ */

        .form-group {
            margin-bottom: 16px;
        }

        .form-label {
            display: block;
            font-size: 12px;
            font-weight: 700;
            color: var(--text);
            margin-bottom: 6px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .form-input,
        .form-select,
        .form-textarea {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid var(--border);
            border-radius: 8px;
            background: var(--bg);
            color: var(--text);
            font-family: inherit;
            font-size: 13px;
            transition: var(--transition);
        }

        .form-input:focus,
        .form-select:focus,
        .form-textarea:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
        }

        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 12px;
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* MODALS */
        /* ═══════════════════════════════════════════════════════════ */

        .modal {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            padding: 20px;
            overflow-y: auto;
        }

        .modal.show {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .modal-content {
            background: var(--bg);
            border-radius: var(--radius);
            width: 100%;
            max-width: 600px;
            max-height: 90vh;
            overflow-y: auto;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
            animation: slideUp 0.3s ease;
        }

        @keyframes slideUp {
            from {
                transform: translateY(20px);
                opacity: 0;
            }
            to {
                transform: translateY(0);
                opacity: 1;
            }
        }

        .modal-header {
            padding: 20px;
            border-bottom: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .modal-header h2 {
            font-size: 18px;
            font-weight: 700;
            margin: 0;
        }

        .modal-close {
            background: none;
            border: none;
            font-size: 24px;
            cursor: pointer;
            color: var(--text);
            transition: var(--transition);
        }

        .modal-close:hover {
            color: var(--primary);
        }

        .modal-body {
            padding: 20px;
        }

        .modal-footer {
            padding: 20px;
            border-top: 1px solid var(--border);
            display: flex;
            gap: 10px;
            justify-content: flex-end;
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* BADGES */
        /* ═══════════════════════════════════════════════════════════ */

        .badge {
            display: inline-block;
            padding: 4px 10px;
            border-radius: 6px;
            font-size: 11px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .badge-success {
            background: rgba(16, 185, 129, 0.1);
            color: var(--success);
        }

        .badge-warning {
            background: rgba(245, 158, 11, 0.1);
            color: var(--warning);
        }

        .badge-danger {
            background: rgba(239, 68, 68, 0.1);
            color: var(--danger);
        }

        .badge-info {
            background: rgba(6, 182, 212, 0.1);
            color: var(--info);
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* LOGIN */
        /* ═══════════════════════════════════════════════════════════ */

        .login-page {
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
        }

        .login-box {
            background: var(--bg);
            padding: 40px;
            border-radius: var(--radius);
            width: 100%;
            max-width: 400px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
        }

        .login-title {
            font-size: 24px;
            font-weight: 700;
            text-align: center;
            margin-bottom: 8px;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .login-subtitle {
            text-align: center;
            color: var(--text-light);
            font-size: 13px;
            margin-bottom: 30px;
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* UTILITY */
        /* ═══════════════════════════════════════════════════════════ */

        .d-flex {
            display: flex;
        }

        .justify-between {
            justify-content: space-between;
        }

        .items-center {
            align-items: center;
        }

        .gap-10 {
            gap: 10px;
        }

        .gap-20 {
            gap: 20px;
        }

        .mb-20 {
            margin-bottom: 20px;
        }

        .mt-20 {
            margin-top: 20px;
        }

        /* ═══════════════════════════════════════════════════════════ */
        /* RESPONSIVE */
        /* ═══════════════════════════════════════════════════════════ */

        /* ═══════════════════════════════════════════════════════════ */
        /* SIDEBAR OVERLAY (mobile backdrop) */
        /* ═══════════════════════════════════════════════════════════ */
        #sidebarOverlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.5);
            z-index: 99;
        }
        #sidebarOverlay.show { display: block; }

        @media (max-width: 768px) {
            .app-layout {
                grid-template-columns: 1fr;
                grid-template-rows: 60px 1fr;
                height: 100vh;
                height: 100dvh;
            }

            /* ══ إظهار زر القائمة ══ */
            #menuBtn {
                display: flex !important;
            }

            .app-sidebar {
                display: block;
                position: fixed;
                right: -280px;
                left: auto;
                top: 0;
                width: 260px;
                max-width: 80vw;
                height: 100vh;
                height: 100dvh;
                z-index: 100;
                transition: right 0.25s ease;
            }

            .app-sidebar.show {
                right: 0;
            }

            .app-content {
                grid-column: 1;
                padding: 14px;
            }

            /* ══ الهيدر مضغوط ══ */
            .app-header {
                padding: 0 12px;
                grid-row: 1;
                grid-column: 1;
            }

            .header-title {
                font-size: 16px;
                max-width: 40vw;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

            .header-left { gap: 10px; }
            .header-right { gap: 6px; }

            .btn-icon {
                width: 34px;
                height: 34px;
                font-size: 16px;
            }

            .user-profile {
                padding: 5px 8px;
                gap: 6px;
            }
            .user-name {
                display: none; /* أخفِ الاسم، أبقِ الأفاتار فقط */
            }
            .user-avatar {
                width: 30px;
                height: 30px;
                font-size: 12px;
            }

            /* ══ البطاقات والشبكات ══ */
            .stats-grid {
                grid-template-columns: 1fr 1fr;
                gap: 10px;
            }

            .form-row {
                grid-template-columns: 1fr;
            }

            /* أي عمودين ثابتين inline → عمود واحد */
            [style*="grid-template-columns:1fr 1fr"],
            [style*="grid-template-columns: 1fr 1fr"] {
                grid-template-columns: 1fr !important;
            }

            .modal-content {
                width: 94%;
                max-width: none !important;
                max-height: 85vh;
                overflow-y: auto;
                margin: 0 auto;
            }

            .page-title {
                font-size: 19px;
            }
            .page-subtitle {
                font-size: 12px;
            }

            .page-header {
                flex-direction: column;
                align-items: flex-start !important;
                gap: 10px;
            }
            .page-header > div:last-child,
            .page-header button {
                width: 100%;
            }

            /* ══ الجداول: تمرير أفقي بدل القطع ══ */
            .card {
                padding: 14px !important;
                overflow-x: auto !important;
                -webkit-overflow-scrolling: touch;
            }
            .card table.table {
                min-width: 640px;
            }
            .table-container {
                -webkit-overflow-scrolling: touch;
            }

            /* ══ التبويبات القابلة للتمرير ══ */
            .stab {
                padding: 8px 12px;
                font-size: 13px;
            }

            /* ══ نموذج تسجيل الدخول ══ */
            .login-box {
                padding: 24px 20px;
                max-width: 92vw;
            }

            /* ══ الأزرار: مساحة لمس أكبر ══ */
            .btn {
                padding: 10px 14px;
                font-size: 13px;
            }

            /* شبكة تصنيفات الأجهزة بالداش بورد */
            #devicesByType {
                grid-template-columns: repeat(2, 1fr) !important;
            }
        }

        @media (max-width: 420px) {
            .stats-grid {
                grid-template-columns: 1fr;
            }
            #devicesByType {
                grid-template-columns: 1fr !important;
            }
            .header-title {
                max-width: 32vw;
                font-size: 15px;
            }
        }

        ::-webkit-scrollbar {
            width: 8px;
        }

        ::-webkit-scrollbar-track {
            background: transparent;
        }

        ::-webkit-scrollbar-thumb {
            background: var(--border);
            border-radius: 4px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: var(--text-light);
        }
 