:root {
    --primary-color: #0ea5e9;
    --primary-hover: #0284c7;
    --secondary-color: #6366f1;
    --background-dark: #0f172a;
    --background-card: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent-glow: rgba(14, 165, 233, 0.15);
    --border-color: #334155;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-width: 230px;
    --sidebar-collapsed-width: 68px;
}

/* Scale down desktop to ~90% – matches the user's preferred zoom */
html {
    font-size: 14px;
}

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

body {
    background-color: var(--background-dark);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    font-size: 0.875rem;
}

[lang="ar"] * {
    font-family: 'Noto Kufi Arabic', 'Inter', system-ui, -apple-system, sans-serif;
}

/* Glassmorphism Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: rgba(10, 15, 25, 0.8);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease, left 0.3s ease, right 0.3s ease;
    overflow: hidden;
}

[dir="ltr"] .sidebar {
    left: 0;
    border-right: 1px solid var(--border-color);
}

[dir="rtl"] .sidebar {
    right: 0;
    border-left: 1px solid var(--border-color);
    border-right: none;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    padding: 2rem 0.75rem;
}

.logo {
    font-size: 1.3rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    white-space: nowrap;
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .logo span {
    display: none;
}

.sidebar.collapsed .logo {
    justify-content: center;
    gap: 0;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    padding: 0.55rem 0.85rem;
    border-radius: 10px;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    font-size: 0.85rem;
}

.nav-item:hover,
.nav-item.active {
    background: var(--accent-glow);
    color: var(--primary-color);
}

.nav-item span {
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.2s ease;
}

.sidebar.collapsed .nav-item span {
    display: none;
    opacity: 0;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0.75rem;
}

.nav-item i {
    font-size: 1.1rem;
}

/* Main Content Area */
.main-content {
    padding: 1.5rem 2rem;
    min-height: 100vh;
    transition: margin 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[dir="ltr"] .main-content {
    margin-left: var(--sidebar-width);
}

[dir="rtl"] .main-content {
    margin-right: var(--sidebar-width);
}

[dir="ltr"] .main-content.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

[dir="rtl"] .main-content.sidebar-collapsed {
    margin-right: var(--sidebar-collapsed-width);
}



.collapse-btn {
    margin-top: auto;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-radius: 10px;
    transition: all 0.3s ease;
    width: 100%;
    font-size: 0.82rem;
}

.collapse-btn:hover {
    background: var(--accent-glow);
    color: var(--primary-color);
}

.sidebar.collapsed .collapse-btn {
    justify-content: center;
}

.sidebar.collapsed .collapse-btn span {
    display: none;
}

.sidebar.collapsed .collapse-btn i {
    transform: rotate(180deg);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.welcome-text h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0.35rem;
}

[dir="rtl"] .user-profile {
    flex-direction: row-reverse;
}

[dir="rtl"] .user-profile div:first-child {
    text-align: left !important;
}

.welcome-text p {
    color: var(--text-muted);
}

/* Dashboard Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--background-card);
    padding: 1.15rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.icon-blue {
    background: rgba(14, 165, 233, 0.1);
    color: var(--primary-color);
}

.icon-purple {
    background: rgba(99, 102, 241, 0.1);
    color: var(--secondary-color);
}

.icon-green {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
}

.icon-orange {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 0.15rem;
}

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

/* Tables & Recent Activity */
.section-card {
    background: var(--background-card);
    border-radius: 18px;
    border: 1px solid var(--border-color);
    padding: 1.4rem;
    margin-bottom: 1.5rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 0.55rem 1.15rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.82rem;
    cursor: pointer;
    transition: opacity 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-primary:hover {
    opacity: 0.9;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
}

td {
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.82rem;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-pending {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.status-completed,
.status-delivered {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
}

.status-repairing,
.status-inspecting,
.status-testing {
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
}

/* Clickable Rows */
.clickable-row {
    cursor: pointer;
    transition: background 0.2s ease;
}

.clickable-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Pagination */
.pg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 0.5rem;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--background-dark);
    border: 1px solid var(--border-color);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pg-btn:hover:not(.pg-disabled):not(.pg-active):not(.pg-ellipsis) {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary);
    border-color: var(--primary);
}

.pg-active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 600;
}

.pg-disabled {
    opacity: 0.35;
    cursor: default;
}

.pg-ellipsis {
    border: none;
    background: transparent;
    cursor: default;
}

/* Icon Action Buttons */
.icon-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--background-card);
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.icon-action-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: var(--accent-glow);
}

.icon-action-btn--danger:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Tabs */
.tab-bar {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0;
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-count {
    background: var(--border-color);
    color: var(--text-muted);
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
}

.tab-btn.active .tab-count {
    background: var(--accent-glow);
    color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-color);
    border-radius: 26px;
    transition: all 0.3s ease;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--primary-color);
}

.toggle-switch input:checked+.toggle-slider::before {
    transform: translateX(22px);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--background-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    width: 100%;
    max-width: 440px;
    animation: modalSlideIn 0.3s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.15rem 1.4rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.modal-body {
    padding: 1.15rem 1.4rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    padding: 0.85rem 1.4rem 1.15rem;
    border-top: 1px solid var(--border-color);
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-20px) scale(0.97);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--background-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s ease;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loader {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

[dir="rtl"] th,
[dir="rtl"] td {
    text-align: right;
}

[dir="rtl"] .stat-card:hover {
    transform: translateY(-5px);
}

/* RTL Arabic font & general overrides */
[dir="rtl"] body {
    font-family: 'Noto Kufi Arabic', 'Inter', system-ui, sans-serif;
}

[dir="rtl"] .section-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .section-header h3 i {
    margin-right: 0;
    margin-left: 0.4rem;
}

[dir="rtl"] .btn-primary i {
    margin-right: 0;
    margin-left: 0.35rem;
}

[dir="rtl"] .nav-item i {
    margin-right: 0;
    margin-left: 0.6rem;
}

[dir="rtl"] .collapse-btn i {
    transform: rotate(180deg);
}

[dir="rtl"] .inv-table thead th {
    text-align: right;
}

[dir="rtl"] .inv-table thead th[style*="text-align:right"],
[dir="rtl"] .inv-table tbody td[style*="text-align:right"] {
    text-align: left !important;
}

/* ═══ Mobile Hamburger ═══ */
.mobile-hamburger {
    display: none;
    position: fixed;
    top: 0.75rem;
    z-index: 200;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--background-card);
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

[dir="ltr"] .mobile-hamburger { left: 0.75rem; }
[dir="rtl"] .mobile-hamburger { right: 0.75rem; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

/* ═══ Tablet (≤1024px) ═══ */
@media (max-width: 1024px) {
    html {
        font-size: 14px;
    }

    .sidebar {
        width: 68px;
        padding: 1.5rem 0.6rem;
    }

    .nav-item span,
    .logo span,
    .collapse-btn span {
        display: none;
    }

    .sidebar.collapsed .collapse-btn i {
        transform: none;
    }

    [dir="ltr"] .main-content,
    [dir="ltr"] .main-content.sidebar-collapsed {
        margin-left: 68px;
        padding: 1.25rem;
    }

    [dir="rtl"] .main-content,
    [dir="rtl"] .main-content.sidebar-collapsed {
        margin-right: 68px;
        padding: 1.25rem;
    }
}

/* ═══ Mobile (≤768px) ═══ */
@media (max-width: 768px) {
    html {
        font-size: 15px;
    }

    .mobile-hamburger {
        display: flex;
    }

    .sidebar {
        width: var(--sidebar-width);
        padding: 2rem 1.25rem;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    [dir="rtl"] .sidebar {
        transform: translateX(100%);
    }

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

    .sidebar .nav-item span,
    .sidebar .logo span,
    .sidebar .collapse-btn {
        display: flex;
        opacity: 1;
    }

    .sidebar .collapse-btn {
        display: none;
    }

    [dir="ltr"] .main-content,
    [dir="ltr"] .main-content.sidebar-collapsed {
        margin-left: 0;
        padding: 1rem;
        padding-top: 3.5rem;
    }

    [dir="rtl"] .main-content,
    [dir="rtl"] .main-content.sidebar-collapsed {
        margin-right: 0;
        padding: 1rem;
        padding-top: 3.5rem;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .welcome-text h1 {
        font-size: 1.35rem;
    }

    .user-profile {
        display: none !important;
    }

    /* Stats cards */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .stat-card {
        padding: 1rem;
        border-radius: 14px;
    }

    .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
        border-radius: 10px;
    }

    .stat-value {
        font-size: 1.35rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    /* Section cards */
    .section-card {
        padding: 1rem;
        border-radius: 16px;
        margin-bottom: 1rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .section-header .btn-primary {
        width: 100%;
        justify-content: center;
    }

    /* Tables → card layout on mobile */
    .mobile-cards thead { display: none; }
    .mobile-cards,
    .mobile-cards tbody,
    .mobile-cards tr,
    .mobile-cards td {
        display: block;
        width: 100%;
    }

    .mobile-cards tr {
        background: var(--background-dark);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .mobile-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.4rem 0;
        border: none;
        font-size: 0.85rem;
    }

    .mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        margin-right: 1rem;
        flex-shrink: 0;
        font-size: 0.8rem;
    }

    [dir="rtl"] .mobile-cards td::before {
        margin-right: 0;
        margin-left: 1rem;
    }

    .mobile-cards td:last-child {
        border-bottom: none;
    }

    /* Tabs smaller */
    .tab-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 0;
    }

    .tab-btn {
        padding: 0.6rem 0.75rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* Modals */
    .modal-content {
        max-width: 95vw;
        margin: 1rem;
        max-height: 90vh;
        overflow-y: auto;
        border-radius: 16px;
    }

    .modal-header { padding: 1rem 1.25rem 0.75rem; }
    .modal-body { padding: 1rem 1.25rem; }
    .modal-footer { padding: 0.75rem 1.25rem 1rem; flex-wrap: wrap; }

    /* Buttons */
    .btn-primary {
        padding: 0.65rem 1rem;
        font-size: 0.85rem;
        border-radius: 10px;
    }

    /* Pagination */
    .pg-btn {
        min-width: 30px;
        height: 30px;
        font-size: 0.8rem;
    }

    /* Generic responsive grids used inline across templates */
    .mob-stack {
        grid-template-columns: 1fr !important;
    }

    .dash-bottom-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ═══ Small phones (≤480px) ═══ */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 0.85rem;
    }

    .stat-value {
        font-size: 1.15rem;
    }

    [dir="ltr"] .main-content,
    [dir="ltr"] .main-content.sidebar-collapsed {
        padding: 0.75rem;
        padding-top: 3.5rem;
    }

    [dir="rtl"] .main-content,
    [dir="rtl"] .main-content.sidebar-collapsed {
        padding: 0.75rem;
        padding-top: 3.5rem;
    }

    .welcome-text h1 {
        font-size: 1.15rem;
    }
}