:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #1e3a5f;
    --primary-hover: #16304f;
    --primary-soft: #e7eef6;
    --accent: #0ea5e9;
    --success: #059669;
    --success-soft: #d1fae5;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --info: #0284c7;
    --info-soft: #e0f2fe;
    --sidebar-w: 264px;
    --header-h: 64px;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 4px 16px rgba(15, 23, 42, .08);
}

[data-bs-theme="dark"] {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #0f1626;
    --border: #1f2a3d;
    --text: #e5e7eb;
    --text-muted: #94a3b8;
    --primary: #38bdf8;
    --primary-hover: #0ea5e9;
    --primary-soft: #0c2436;
    --accent: #38bdf8;
    --success-soft: #052e22;
    --danger-soft: #3a0f12;
    --warning-soft: #3a2c08;
    --info-soft: #06283b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 4px 16px rgba(0, 0, 0, .5);
}

* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    font-family: 'Tajawal', 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    line-height: 1.55;
    font-size: clamp(0.875rem, 1vw, 1rem);
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
}

/* ---------- App Shell ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    margin-inline-start: var(--sidebar-w);
    transition: margin .25s ease;
}

.app-content {
    flex: 1;
    padding: 1.75rem;
}

.app-footer {
    padding: 1rem 1.75rem;
    color: var(--text-muted);
    font-size: .8125rem;
    border-top: 1px solid var(--border);
}

/* ---------- Sidebar ---------- */
.app-sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-inline-end: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .25s ease, width .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1.25rem;
    height: var(--header-h);
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 1.1rem;
}

[data-bs-theme="dark"] .brand-mark {
    color: #06283b;
}

.brand-mark.lg {
    width: 56px;
    height: 56px;
    font-size: 1.6rem;
    margin: 0 auto 1rem;
}

.brand-text {
    font-weight: 700;
    font-size: 1.05rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem .75rem;
    overflow-y: auto;
}

.sidebar-label {
    display: block;
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    font-weight: 600;
    padding: .75rem .75rem .35rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem .75rem;
    border-radius: 9px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: .9rem;
    margin-bottom: .15rem;
    transition: background .15s, color .15s;
}

.sidebar-link i {
    font-size: 1.05rem;
}

.sidebar-link:hover {
    background: var(--surface-2);
    color: var(--text);
}

.sidebar-link.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: .65rem;
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    flex-shrink: 0;
}

[data-bs-theme="dark"] .user-avatar {
    color: #06283b;
}

.user-avatar.sm {
    width: 30px;
    height: 30px;
    font-size: .8rem;
}

.user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: .875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: .75rem;
    color: var(--text-muted);
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 1035;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s;
}

.sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
}

/* ---------- Header ---------- */
.app-header {
    position: sticky;
    top: 0;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 1020;
}

.header-left {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.header-title {
    font-size: clamp(1rem, 1.5vw, 1.15rem);
    font-weight: 600;
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.icon-btn.sm {
    width: 32px;
    height: 32px;
    font-size: .95rem;
    border: 1px solid var(--border);
}

.icon-btn.danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: var(--danger);
}

.theme-icon-light {
    display: none;
}

[data-bs-theme="dark"] .theme-icon-dark {
    display: none;
}

[data-bs-theme="dark"] .theme-icon-light {
    display: inline-block;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .35rem .65rem;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
    font-size: .875rem;
    cursor: pointer;
}

.user-chip:hover {
    background: var(--surface-2);
}

/* ---------- Page ---------- */
.page-intro {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.page-heading {
    font-size: clamp(1.25rem, 2vw, 1.6rem);
    font-weight: 700;
    margin: 0;
}

.page-sub {
    color: var(--text-muted);
    margin: .15rem 0 0;
    font-size: clamp(0.8rem, 1vw, 0.9rem);
}

/* ---------- Stat cards ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    border-radius: 12px;
    font-size: 1.4rem;
    flex-shrink: 0;
    background: var(--primary-soft);
    color: var(--primary);
}

.tone-success .stat-icon { background: var(--success-soft); color: var(--success); }
.tone-info .stat-icon { background: var(--info-soft); color: var(--info); }
.tone-warning .stat-icon { background: var(--warning-soft); color: var(--warning); }
.tone-danger .stat-icon { background: var(--danger-soft); color: var(--danger); }

.stat-body {
    display: flex;
    flex-direction: column;
}

.stat-label {
    color: var(--text-muted);
    font-size: clamp(0.75rem, 0.8vw, 0.8125rem);
    font-weight: 500;
}

.stat-value {
    font-size: clamp(1.35rem, 2vw, 1.65rem);
    font-weight: 700;
    line-height: 1.1;
}

/* ---------- Panel ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.panel-title {
    font-size: clamp(0.9rem, 1.2vw, 1rem);
    font-weight: 600;
    margin: 0;
}

.panel-body {
    padding: 1.25rem;
}

.panel-body.p-0 {
    padding: 0;
}

.panel-foot {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
}

.panel-foot .pagination {
    margin: 0;
    justify-content: flex-end;
}

/* ---------- Filter bar ---------- */
.filter-bar {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
    width: 100%;
}

.filter-bar .form-select {
    width: auto;
    min-width: 150px;
}

.input-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon i {
    position: absolute;
    inset-inline-start: .85rem;
    color: var(--text-muted);
    pointer-events: none;
}

.input-icon .form-control {
    padding-inline-start: 2.4rem;
}

.input-icon.search {
    flex: 1;
    min-width: 220px;
}

/* ---------- Table ---------- */
.data-table thead th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    padding: .85rem 1rem;
    white-space: nowrap;
}

.data-table tbody td {
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--surface-2);
}

.data-table code {
    background: var(--surface-2);
    padding: .15rem .45rem;
    border-radius: 6px;
    color: var(--accent);
    font-size: .8rem;
}

.action-group {
    display: inline-flex;
    gap: .35rem;
}

/* ---------- Status badge ---------- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .25rem .65rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.status-badge.is-active {
    background: var(--success-soft);
    color: var(--success);
}

.status-badge.is-inactive {
    background: var(--surface-2);
    color: var(--text-muted);
}

/* Order status badges */
.status-badge.is-pending {
    background: var(--warning-soft);
    color: var(--warning);
}

.status-badge.is-processing {
    background: var(--info-soft);
    color: var(--info);
}

.status-badge.is-completed {
    background: var(--success-soft);
    color: var(--success);
}

.status-badge.is-failed {
    background: var(--danger-soft);
    color: var(--danger);
}

.status-badge.is-cancelled {
    background: var(--surface-2);
    color: var(--text-muted);
}

/* ---------- Detail grid ---------- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin: 0;
}

.detail-item dt {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: .25rem;
}

.detail-item dd {
    margin: 0;
    font-weight: 500;
}

/* ---------- Forms ---------- */
.form-label {
    font-weight: 500;
    font-size: .875rem;
    margin-bottom: .35rem;
}

.req {
    color: var(--danger);
}

.form-control,
.form-select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: .55rem .85rem;
    min-height: 44px;
}

.form-control:focus,
.form-select:focus {
    background: var(--surface);
    color: var(--text);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: .7;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: .75rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

/* ---------- Buttons ---------- */
.btn {
    border-radius: 9px;
    font-weight: 500;
    padding: .55rem 1rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

[data-bs-theme="dark"] .btn-primary {
    color: #06283b;
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #fff;
}

[data-bs-theme="dark"] .btn-primary:hover {
    color: #06283b;
}

.btn-outline-secondary {
    border-color: var(--border);
    color: var(--text);
}

.btn-outline-secondary:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}

/* ---------- Loading state ---------- */
.btn-spinner {
    display: none;
    margin-left: .4rem;
}

.btn.is-loading .btn-spinner {
    display: inline-block;
}

.btn.is-loading {
    pointer-events: none;
    opacity: .8;
}

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 3.5rem 1.5rem;
}

.empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 1.8rem;
    margin-bottom: 1rem;
}

.empty-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: .35rem;
}

.empty-message {
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

/* ---------- Toast ---------- */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    inset-inline-start: 1.5rem;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: .65rem;
}

.app-toast {
    display: flex;
    align-items: center;
    gap: .65rem;
    min-width: 280px;
    max-width: 360px;
    padding: .85rem 1rem;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--text-muted);
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: .875rem;
    transform: translateX(120%);
    transition: transform .3s ease;
}

.app-toast.show {
    transform: translateX(0);
}

.app-toast.success {
    border-inline-start-color: var(--success);
}

.app-toast.success i {
    color: var(--success);
}

.app-toast.error {
    border-inline-start-color: var(--danger);
}

.app-toast.error i {
    color: var(--danger);
}

.app-toast i {
    font-size: 1.15rem;
}

/* ---------- Auth ---------- */
.auth-body {
    background:
        radial-gradient(900px circle at 0% 0%, color-mix(in srgb, var(--primary) 18%, var(--bg)), var(--bg) 45%),
        var(--bg);
    min-height: 100vh;
}

.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.25rem;
    box-shadow: var(--shadow);
}

.auth-head {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-title {
    font-size: clamp(1.25rem, 2vw, 1.5rem);
    font-weight: 700;
    margin: 0;
}

.auth-subtitle {
    color: var(--text-muted);
    margin: .25rem 0 0;
    font-size: clamp(0.8rem, 1vw, 0.9rem);
}

.auth-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: .8rem;
    margin: 1.25rem 0 0;
}

/* ==========================================================================
   RESPONSIVE — Unified Breakpoint System
   Mobile:      ≤ 767.98px
   Tablet:      768px – 1023.98px
   Desktop:     ≥ 1024px  (default / base styles above)
   Large:       ≥ 1600px
   Ultra-wide:  ≥ 1920px
   ========================================================================== */

/* ------------------------------------------------
   Mobile (≤ 767.98px)
   ------------------------------------------------ */
@media (max-width: 767.98px) {

    /* -- Shell -- */
    .app-main {
        margin-inline-start: 0;
        width: 100%;
    }

    .app-content {
        padding: 1rem;
    }

    .app-header {
        padding: 0 1rem;
    }

    /* -- Sidebar offcanvas (RTL: slides from right) -- */
    .app-sidebar {
        transform: translateX(100%);
    }

    .app-sidebar.show {
        transform: translateX(0);
    }

    /* -- Grids → single column -- */
    .stat-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    /* -- Filter bar → stacked -- */
    .filter-bar {
        flex-direction: column;
    }

    .filter-bar .form-select,
    .input-icon.search {
        width: 100%;
        min-width: 0;
        flex: 1 1 100%;
    }

    /* -- Tables -- */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* -- Forms → stacked, full-width actions -- */
    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    /* -- Page intro → stacked -- */
    .page-intro {
        flex-direction: column;
        align-items: stretch;
        gap: .75rem;
    }

    .page-intro .btn {
        width: 100%;
    }

    /* -- Cards -- */
    .card {
        height: auto;
    }

    .row > div {
        margin-bottom: 1rem;
    }

    /* -- Auth card -- */
    .auth-card {
        padding: 1.5rem;
        border-radius: 12px;
    }

    /* -- Footer -- */
    .app-footer {
        padding: .75rem 1rem;
        text-align: center;
    }
}

/* ------------------------------------------------
   Tablet (768px – 1023.98px)
   ------------------------------------------------ */
@media (min-width: 768px) and (max-width: 1023.98px) {

    /* -- Compact sidebar -- */
    .app-sidebar {
        width: 220px;
    }

    .app-main {
        margin-inline-start: 220px;
    }

    .app-content {
        padding: 1.25rem;
    }

    /* -- Grids → 2 columns -- */
    .stat-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }

    .detail-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* -- Sidebar nav -- */
    .sidebar-link span {
        font-size: .85rem;
    }

    .sidebar-label {
        font-size: .625rem;
    }

    .brand-text {
        font-size: .95rem;
    }
}

/* ------------------------------------------------
   Below Desktop (< 1024px): hide sidebar toggle
   ------------------------------------------------ */
@media (max-width: 1023.98px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ------------------------------------------------
   Desktop (≥ 1024px)
   ------------------------------------------------ */
@media (min-width: 1024px) {
    .stat-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }

    .detail-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Hide mobile sidebar toggle and backdrop on desktop */
    .sidebar-toggle-btn {
        display: none;
    }

    .sidebar-backdrop {
        display: none;
    }
}

/* ------------------------------------------------
   Large Desktop (≥ 1600px)
   ------------------------------------------------ */
@media (min-width: 1600px) {
    .container,
    .container-fluid {
        max-width: 1500px;
        margin-inline: auto;
    }
}

/* ------------------------------------------------
   Ultra-wide (≥ 1920px)
   ------------------------------------------------ */
@media (min-width: 1920px) {
    .container,
    .container-fluid {
        max-width: 1700px;
    }

    .app-content {
        padding: 2rem 2.5rem;
    }

    .stat-grid {
        gap: 1.5rem;
    }
}