/* ============================================================
   نظام متابعة طلبيات الشراء — Design System v2
   Visual: deep slate + teal (no purple AI defaults)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800&family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap');

:root {
    --primary: #0f766e;
    --primary-dark: #0d5c56;
    --primary-light: #0d9488;
    --primary-soft: rgba(15, 118, 110, 0.12);
    --accent: #c2410c;
    --topbar-start: #0b3d3a;
    --topbar-end: #0d9488;
    --ink: #0f172a;
    --ink-muted: #64748b;
    --surface: #eef3f6;
    --surface-2: #e2eaf0;
    --card: #ffffff;
    --border: #d7e0e8;
    --success: #15803d;
    --danger: #b91c1c;
    --warning: #b45309;
    --info: #0369a1;
    --sidebar-width: 268px;
    --topbar-height: 56px;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 8px 28px rgba(15, 23, 42, 0.07);
    --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.05);
    --font: 'Cairo', 'IBM Plex Sans Arabic', sans-serif;

    /* Bootstrap bridge */
    --bs-primary: #0f766e;
    --bs-primary-rgb: 15, 118, 110;
    --bs-link-color: #0f766e;
    --bs-link-hover-color: #0d5c56;

    --primary-color: var(--primary);
    --secondary-color: #64748b;
    --success-color: var(--success);
    --danger-color: var(--danger);
    --warning-color: #d97706;
    --info-color: var(--info);
}

* {
    font-family: var(--font);
}

html {
    scroll-behavior: smooth;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: var(--font);
    background:
        radial-gradient(1200px 500px at 100% -10%, rgba(15, 118, 110, 0.08), transparent 55%),
        radial-gradient(900px 420px at 0% 100%, rgba(194, 65, 12, 0.05), transparent 50%),
        var(--surface);
    color: var(--ink);
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body.has-app-sidebar {
    overflow-x: hidden;
}

img, svg, video, canvas, iframe {
    max-width: 100%;
    height: auto;
}

.container,
.container-fluid {
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

.row {
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
}

.row > * {
    min-width: 0;
    max-width: 100%;
}

/* Bootstrap primary overrides */
.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    background: linear-gradient(135deg, var(--primary), var(--primary-light, #0d9488));
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    box-shadow: 0 6px 16px rgba(var(--bs-primary-rgb), 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(var(--bs-primary-rgb), 0.3);
}

.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.bg-primary {
    background-color: var(--primary) !important;
}

.text-primary {
    color: var(--primary) !important;
}

.badge.bg-primary {
    background-color: var(--primary) !important;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(15, 118, 110, 0.18);
}

/* ============================================================
   Page motion
   ============================================================ */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes pulseSoft {
    0%, 100% { box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.35); }
    50% { box-shadow: 0 0 0 10px rgba(15, 118, 110, 0); }
}

.animate-fade-in {
    animation: fadeUp 0.45s ease both;
}

.main-content > .page-toolbar,
.main-content > .mb-4,
.main-content > h4 {
    animation: fadeUp 0.4s ease both;
}

.main-content > .dashboard-cards,
.main-content > .custom-card,
.main-content > .row,
.main-content > .alert {
    animation: fadeUp 0.5s ease both;
    animation-delay: 0.05s;
}

.dashboard-cards .stat-card:nth-child(1) { animation-delay: 0.05s; }
.dashboard-cards .stat-card:nth-child(2) { animation-delay: 0.1s; }
.dashboard-cards .stat-card:nth-child(3) { animation-delay: 0.15s; }
.dashboard-cards .stat-card:nth-child(4) { animation-delay: 0.2s; }
.dashboard-cards .stat-card:nth-child(5) { animation-delay: 0.25s; }
.dashboard-cards .stat-card:nth-child(6) { animation-delay: 0.3s; }

/* ============================================================
   Login (base — detailed styles also in login.php)
   ============================================================ */
.login-page {
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

/* ============================================================
   Layout: content
   ============================================================ */
.main-content {
    margin-top: var(--topbar-height);
    padding: 24px;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

.has-app-sidebar .main-content {
    margin-right: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100% - var(--sidebar-width));
    box-sizing: border-box;
    overflow-x: hidden;
}

.page-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 1.35rem;
}

.page-toolbar h4,
.page-toolbar h5 {
    margin-bottom: 0;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.page-toolbar .toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ============================================================
   Dashboard stats
   ============================================================ */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: 16px;
    margin-bottom: 28px;
    width: 100%;
    max-width: 100%;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    border-right: 4px solid var(--primary);
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    animation: fadeUp 0.5s ease both;
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    inset: auto -20% -40% auto;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--primary-soft), transparent 70%);
    pointer-events: none;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-bottom: 14px;
}

.stat-card .stat-value {
    font-size: 26px;
    font-weight: 800;
    margin-bottom: 4px;
    letter-spacing: -0.03em;
    color: var(--ink);
}

.stat-card .stat-label {
    color: var(--ink-muted);
    font-size: 13px;
    font-weight: 600;
}

.stat-card.primary { border-right-color: var(--primary); }
.stat-card.primary .stat-icon { background: var(--primary-soft); color: var(--primary); }

.stat-card.success { border-right-color: var(--success); }
.stat-card.success .stat-icon { background: rgba(21, 128, 61, 0.12); color: var(--success); }

.stat-card.warning { border-right-color: var(--warning); }
.stat-card.warning .stat-icon { background: rgba(180, 83, 9, 0.12); color: var(--warning); }

.stat-card.danger { border-right-color: var(--danger); }
.stat-card.danger .stat-icon { background: rgba(185, 28, 28, 0.1); color: var(--danger); }

.stat-card.info { border-right-color: var(--info); }
.stat-card.info .stat-icon { background: rgba(3, 105, 161, 0.1); color: var(--info); }

.stat-card-split {
    grid-column: span 1;
    min-width: min(100%, 280px);
}

.stat-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.stat-split-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px;
    border-radius: 10px;
    background: rgba(15, 118, 110, 0.06);
    text-decoration: none;
    color: inherit;
    transition: background 0.2s ease, transform 0.2s ease;
}

.stat-split-item:hover {
    background: rgba(15, 118, 110, 0.12);
    transform: translateY(-1px);
    color: inherit;
}

.stat-split-item .split-title {
    font-size: 12px;
    color: var(--ink-muted);
    font-weight: 600;
}

.stat-split-item strong {
    font-size: 18px;
    color: var(--primary);
}

.stat-split-item small {
    font-size: 11px;
    color: var(--ink-muted);
}

.input-stat-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(15, 118, 110, 0.08);
    border: 1px solid var(--border);
}

.input-stat-chip strong {
    color: var(--primary);
}

/* ============================================================
   Cards / tables
   ============================================================ */
.custom-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    overflow: hidden;
}

.custom-card .card-header {
    background: linear-gradient(180deg, #f8fbfc, #f1f6f9);
    border-bottom: 1px solid var(--border);
    padding: 14px 18px;
    font-weight: 700;
}

.custom-card .card-body {
    padding: 18px;
}

.custom-table {
    width: 100%;
    max-width: 100%;
    table-layout: auto;
}

.custom-table thead th {
    background: #f4f8fa;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    color: #334155;
    padding: 12px 14px;
    white-space: normal;
    font-size: 13px;
    word-break: break-word;
}

/* قائمة الطلبيات: عناوين أعمدة أصغر وفي سطر واحد */
.orders-list-wrap {
    overflow-x: auto;
}
.orders-list-table {
    min-width: 1100px !important;
    width: max-content;
    max-width: none;
}
.orders-list-table thead th {
    font-size: 11px;
    font-weight: 600;
    padding: 8px 10px;
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
    line-height: 1.25;
    letter-spacing: 0;
}
.orders-list-table tbody td {
    padding: 10px;
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
}
.orders-list-table tbody td:nth-child(3) {
    white-space: normal;
    max-width: 220px;
}

.custom-table tbody td {
    padding: 12px 14px;
    vertical-align: middle;
    border-bottom: 1px solid #edf2f6;
    font-size: 14px;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.custom-table tbody tr {
    transition: background-color 0.15s ease;
}

.custom-table tbody tr:hover {
    background-color: #f5fafb;
}

.table-responsive,
.users-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: visible;
    -webkit-overflow-scrolling: touch;
}

.table-responsive .custom-table,
.users-table-wrap .custom-table {
    min-width: 0 !important;
    width: 100%;
}

/* بطاقات الجداول على الشاشات الصغيرة — بدون سكرول أفقي */
@media (max-width: 991.98px) {
    .table-responsive,
    .users-table-wrap {
        overflow-x: visible !important;
    }

    .table-responsive > .custom-table,
    .table-responsive > table.table,
    .users-table-wrap > .custom-table,
    table.custom-table.stack-on-mobile {
        min-width: 0 !important;
        width: 100% !important;
    }

    .table-responsive > .custom-table thead,
    .table-responsive > table.table thead,
    .users-table-wrap > .custom-table thead,
    table.custom-table.stack-on-mobile thead {
        display: none;
    }

    .table-responsive > .custom-table tbody,
    .table-responsive > table.table tbody,
    .users-table-wrap > .custom-table tbody,
    table.custom-table.stack-on-mobile tbody,
    .table-responsive > .custom-table tr,
    .table-responsive > table.table tr,
    .users-table-wrap > .custom-table tr,
    table.custom-table.stack-on-mobile tr,
    .table-responsive > .custom-table td,
    .table-responsive > table.table td,
    .users-table-wrap > .custom-table td,
    table.custom-table.stack-on-mobile td {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
    }

    .table-responsive > .custom-table tr,
    .table-responsive > table.table tr,
    .users-table-wrap > .custom-table tr,
    table.custom-table.stack-on-mobile tr {
        background: #fff;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        margin: 0 12px 12px;
        padding: 8px 4px;
        box-shadow: var(--shadow-sm);
    }

    .table-responsive > .custom-table tr:hover,
    .table-responsive > table.table tr:hover,
    .users-table-wrap > .custom-table tr:hover {
        background: #fff;
    }

    .table-responsive > .custom-table td,
    .table-responsive > table.table td,
    .users-table-wrap > .custom-table td,
    table.custom-table.stack-on-mobile td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        padding: 8px 12px !important;
        border-bottom: 1px dashed #e8eef2 !important;
        text-align: start !important;
        white-space: normal !important;
    }

    .table-responsive > .custom-table td:last-child,
    .table-responsive > table.table td:last-child,
    .users-table-wrap > .custom-table td:last-child,
    table.custom-table.stack-on-mobile td:last-child {
        border-bottom: none !important;
    }

    .table-responsive > .custom-table td::before,
    .table-responsive > table.table td::before,
    .users-table-wrap > .custom-table td::before,
    table.custom-table.stack-on-mobile td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--ink-muted);
        font-size: 12px;
        flex: 0 0 38%;
        max-width: 42%;
        line-height: 1.4;
    }

    .table-responsive > .custom-table td > *,
    .table-responsive > table.table td > *,
    .users-table-wrap > .custom-table td > * {
        margin-inline-start: auto;
        text-align: end;
    }

    .table-responsive > .custom-table td.col-actions,
    .users-table-wrap > .custom-table td.col-actions,
    .table-responsive > .custom-table td.sticky-actions,
    .users-table-wrap > .custom-table td.sticky-actions {
        display: block !important;
        position: static !important;
        box-shadow: none !important;
        min-width: 0 !important;
        background: transparent !important;
        padding-top: 10px !important;
    }

    .table-responsive > .custom-table td.col-actions::before,
    .users-table-wrap > .custom-table td.col-actions::before,
    .table-responsive > .custom-table td.sticky-actions::before,
    .users-table-wrap > .custom-table td.sticky-actions::before {
        display: block;
        margin-bottom: 8px;
        max-width: none;
        flex: none;
    }

    .users-actions {
        white-space: normal;
        width: 100%;
        justify-content: flex-start;
    }

    .users-actions .btn {
        flex: 1 1 auto;
    }
}

/* ============================================================
   Status badges
   ============================================================ */
.status-badge {
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    display: inline-block;
}

.status-draft { background: #e2e8f0; color: #475569; }
.status-pending { background: #ffedd5; color: #9a3412; }
.status-in_progress { background: #ccfbf1; color: #0f766e; }
.status-approved { background: #dcfce7; color: #166534; }
.status-rejected { background: #fee2e2; color: #991b1b; }
.status-completed { background: #dcfce7; color: #166534; }
.status-cancelled { background: #e2e8f0; color: #475569; }
.status-active { background: #dcfce7; color: #166534; }
.status-inactive { background: #e2e8f0; color: #64748b; }
.status-suspended { background: #fee2e2; color: #991b1b; }

.priority-low { color: var(--success); }
.priority-medium { color: var(--primary); }
.priority-high { color: #ea580c; }
.priority-urgent { color: var(--danger); }

/* ============================================================
   Buttons / actions
   ============================================================ */
.btn-action {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    margin: 0;
}

.users-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.users-table-wrap {
    width: 100%;
    max-width: 100%;
}

.users-table .sticky-actions {
    position: sticky;
    inset-inline-start: 0;
    z-index: 2;
    background: #fff;
    min-width: 0;
    box-shadow: -4px 0 8px rgba(15, 23, 42, 0.06);
}

.users-table thead .sticky-actions {
    z-index: 3;
    background: #f0f7f8;
}

.users-table .users-actions .btn {
    font-size: 12px;
    font-weight: 600;
    padding: 0.28rem 0.55rem;
}

@media (min-width: 992px) {
    .users-table .sticky-actions {
        min-width: 220px;
    }
}

@media print {
    .users-table .sticky-actions,
    .users-actions {
        display: none !important;
    }
}

/* ============================================================
   Approval timeline / routes
   ============================================================ */
.approval-timeline { position: relative; padding: 20px 0; }

.approval-step {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    position: relative;
}

.approval-step .step-indicator {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 15px;
    margin-left: 15px;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.approval-step .step-indicator.completed { background: var(--success); color: #fff; }
.approval-step .step-indicator.active { background: var(--primary); color: #fff; animation: pulseSoft 2s infinite; }
.approval-step .step-indicator.pending { background: #e2e8f0; color: #64748b; }
.approval-step .step-indicator.rejected { background: var(--danger); color: #fff; }

.approval-step .step-content {
    flex: 1;
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 14px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.approval-step .step-line {
    position: absolute;
    right: 19px;
    top: 40px;
    width: 3px;
    height: calc(100% - 40px);
    background: #dbe4ec;
}

.approval-step:last-child .step-line { display: none; }
.approval-step.completed .step-line { background: var(--success); }

.route-step-card {
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 15px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-right: 3px solid var(--primary);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.route-step-card:hover {
    box-shadow: var(--shadow-sm);
    transform: translateX(-2px);
}

.route-step-card .step-number {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    margin-left: 15px;
    flex-shrink: 0;
}

/* ============================================================
   Topbar
   ============================================================ */
.app-topbar.navbar,
nav.app-topbar {
    --bs-navbar-padding-y: 0;
    --bs-navbar-padding-x: 0;
    height: var(--topbar-height) !important;
    min-height: var(--topbar-height) !important;
    max-height: var(--topbar-height) !important;
    padding: 0 !important;
    margin: 0 !important;
    z-index: 1040;
    overflow: visible !important;
    background: linear-gradient(90deg, var(--topbar-start, #0b3d3a) 0%, var(--primary) 55%, var(--topbar-end, var(--primary-light, #0d9488)) 100%) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 24px rgba(11, 61, 58, 0.22) !important;
    display: flex !important;
    align-items: center !important;
}

.app-topbar .container-fluid {
    height: var(--topbar-height) !important;
    min-height: 0 !important;
    max-height: var(--topbar-height) !important;
    display: flex;
    align-items: center !important;
    justify-content: space-between;
    flex-wrap: nowrap;
    overflow: visible !important;
    position: relative;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin: 0 !important;
}

.app-topbar .container-fluid > .d-flex {
    align-items: center !important;
    min-height: 0;
    margin: 0;
    padding: 0;
}

.app-topbar .navbar-brand {
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1.2;
    font-weight: 800;
    letter-spacing: -0.02em;
    display: inline-flex !important;
    align-items: center;
    gap: 0.35rem;
    height: auto;
    position: relative;
}

.app-topbar .navbar-brand .brand-text {
    display: inline-block;
    position: relative;
}

/* سبلاش اسم النظام بعد تسجيل الدخول */
.brand-splash-play .brand-icon {
    animation: brandIconSplash 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.brand-splash-play .brand-text {
    animation: brandTextSplash 1.35s cubic-bezier(0.22, 1, 0.36, 1) both;
    background: linear-gradient(
        105deg,
        #ffffff 0%,
        #ffffff 40%,
        rgba(255, 255, 255, 0.55) 50%,
        #ffffff 60%,
        #ffffff 100%
    );
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
}

@keyframes brandTextSplash {
    0% {
        opacity: 0;
        transform: translateY(-10px) scale(0.94);
        letter-spacing: 0.08em;
        filter: blur(5px);
        background-position: 100% 0;
    }
    45% {
        opacity: 1;
        filter: blur(0);
        transform: translateY(0) scale(1.02);
        background-position: 40% 0;
    }
    100% {
        opacity: 1;
        transform: none;
        letter-spacing: normal;
        filter: none;
        background-position: 0 0;
        color: #fff;
        -webkit-text-fill-color: #fff;
        background: none;
    }
}

@keyframes brandIconSplash {
    0% {
        opacity: 0;
        transform: scale(0.4) rotate(-25deg);
    }
    55% {
        opacity: 1;
        transform: scale(1.2) rotate(8deg);
    }
    100% {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .brand-splash-play .brand-icon,
    .brand-splash-play .brand-text {
        animation: none !important;
        color: #fff !important;
        -webkit-text-fill-color: #fff !important;
        background: none !important;
    }
}

.navbar-brand {
    max-width: 55vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin: 0;
    flex-shrink: 0;
    position: static;
}

.topbar-actions .nav-item { display: flex; align-items: center; }

.topbar-actions .nav-link,
.app-topbar #sidebarToggle {
    box-sizing: border-box;
    border: 0 !important;
    box-shadow: none !important;
    outline: none !important;
    transform: none !important;
    transition: background-color 0.15s ease, opacity 0.15s ease !important;
}

.topbar-actions .nav-link:hover,
.topbar-actions .nav-link:focus,
.topbar-actions .nav-link:active,
.topbar-actions .nav-link.show,
.app-topbar #sidebarToggle:hover,
.app-topbar #sidebarToggle:focus,
.app-topbar #sidebarToggle:active {
    transform: none !important;
    box-shadow: none !important;
    border: 0 !important;
    outline: none !important;
    background: rgba(255, 255, 255, 0.12) !important;
    border-radius: 10px;
}

.topbar-actions .nav-link::after,
.topbar-icon-btn::after,
.topbar-user-btn::after,
.notif-bell-btn::after {
    display: none !important;
    content: none !important;
}

.topbar-icon-btn,
.notif-bell-btn {
    position: relative;
    width: 40px;
    height: 40px;
    min-width: 40px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1;
    color: #fff !important;
    border-radius: 10px;
}

.notif-bell-btn .fa-bell { font-size: 1.1rem; line-height: 1; }

.notif-bell-btn .notif-badge {
    position: absolute;
    top: 4px;
    inset-inline-start: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 10px;
    line-height: 16px;
    border-radius: 999px;
    pointer-events: none;
}

.topbar-user-btn {
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    padding: 2px 10px 2px 8px !important;
    margin: 0 !important;
    color: #fff !important;
    white-space: nowrap;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.22) !important;
    max-width: min(280px, 42vw);
    box-sizing: border-box !important;
}

.topbar-user-btn:hover,
.topbar-user-btn:focus,
.topbar-user-btn.show {
    background: rgba(255, 255, 255, 0.2) !important;
    border-color: rgba(255, 255, 255, 0.35) !important;
}

.topbar-avatar {
    width: 34px !important;
    height: 34px !important;
    flex-shrink: 0;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.55);
}

.topbar-user-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    min-width: 0;
    line-height: 1.15;
    gap: 2px;
}

.topbar-fullname {
    display: block;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.92rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0;
}

.topbar-login,
.topbar-username {
    display: block !important;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.78rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.92);
    opacity: 1;
    line-height: 1.1;
}

.topbar-user-caret {
    font-size: 0.65rem;
    opacity: 0.85;
    flex-shrink: 0;
    margin-inline-start: 2px;
}

.topbar-user-summary strong {
    font-size: 0.95rem;
}

.topbar-user-summary small {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.app-topbar #sidebarToggle {
    width: 40px;
    height: 40px;
    min-width: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    margin: 0 !important;
    flex-shrink: 0;
    border-radius: 10px;
}

.app-topbar .topbar-actions > .nav-item.dropdown { position: static; }

.app-topbar .dropdown-menu.topbar-dropdown {
    position: absolute !important;
    top: 100% !important;
    inset-inline-end: 0.75rem !important;
    inset-inline-start: auto !important;
    margin: 0.35rem 0 0 !important;
    transform: none !important;
    z-index: 1080;
    float: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.app-topbar .notif-dropdown {
    min-width: 300px;
    width: min(350px, calc(100vw - 24px));
    padding: 0;
}

.app-topbar .dropdown-menu.topbar-dropdown.show { display: block; }

/* ============================================================
   Sidebar — button navigation
   ============================================================ */
.app-sidebar {
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    background: linear-gradient(180deg, #ffffff 0%, #f3f8f7 100%);
    box-shadow: -8px 0 28px rgba(15, 23, 42, 0.07);
    border-left: 1px solid var(--border);
    z-index: 1030;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.app-sidebar-inner {
    padding: 10px 8px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.app-sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 4px;
    min-width: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--topbar-start, #0b3d3a), var(--primary));
    color: #fff;
    box-shadow: 0 8px 18px rgba(15, 118, 110, 0.24);
}

.app-sidebar-user img {
    flex-shrink: 0;
    width: 44px !important;
    height: 44px !important;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.45);
}

.app-sidebar-user-meta {
    min-width: 0;
    flex: 1;
}

.app-sidebar-user strong {
    font-size: 13px;
    display: block;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #fff;
}

.app-sidebar-user small {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.78);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    margin-top: 1px;
}

.app-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-group {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    margin: 0;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: #334155;
    text-decoration: none;
    font-weight: 700;
    font-size: 13px;
    text-align: start;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.sidebar-btn-main {
    background: #fff;
    border-color: #dce8e6;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.sidebar-btn-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-btn-text {
    flex: 1;
    min-width: 0;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-caret {
    font-size: 11px;
    color: #94a3b8;
    transition: transform 0.2s ease;
    margin-inline-start: 2px;
}

.sidebar-btn:hover {
    background: var(--primary-soft);
    border-color: rgba(var(--bs-primary-rgb), 0.28);
    color: var(--primary);
}

.sidebar-btn:hover .sidebar-btn-icon {
    background: rgba(var(--bs-primary-rgb), 0.14);
}

.sidebar-btn.active,
.sidebar-btn.active-group {
    background: linear-gradient(90deg, rgba(var(--bs-primary-rgb), 0.14), rgba(var(--bs-primary-rgb), 0.05));
    border-color: rgba(var(--bs-primary-rgb), 0.22);
    color: var(--primary-dark);
    box-shadow: inset -3px 0 0 var(--primary);
}

.sidebar-btn.active .sidebar-btn-icon,
.sidebar-btn.active-group .sidebar-btn-icon {
    background: linear-gradient(135deg, var(--primary), var(--primary-light, #0d9488));
    color: #fff;
}

.sidebar-submenu {
    display: none;
    flex-direction: column;
    gap: 2px;
    padding: 3px 0 2px 0;
    margin: 2px 0 2px 10px;
    border-inline-start: 2px solid #d5e7e5;
    padding-inline-start: 6px;
}

.sidebar-group.open > .sidebar-submenu {
    display: flex;
}

.sidebar-group.open > .sidebar-group-toggle .sidebar-caret {
    transform: rotate(180deg);
    color: #0f766e;
}

.sidebar-btn-sub {
    padding: 5px 7px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 8px;
    margin: 0;
}

.sidebar-btn-sub .sidebar-btn-icon {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    font-size: 11px;
    background: #eef5f4;
}

.sidebar-btn-sub.active {
    background: rgba(15, 118, 110, 0.12);
    border-color: transparent;
    box-shadow: none;
}

.sidebar-btn-sub.active .sidebar-btn-icon {
    background: #0f766e;
    color: #fff;
}

.sidebar-btn-logout {
    color: #b91c1c;
}

.sidebar-btn-logout .sidebar-btn-icon {
    background: #fee2e2;
    color: #b91c1c;
}

.sidebar-btn-logout:hover {
    background: #fff5f5;
    border-color: #fecaca;
    color: #991b1b;
}

.sidebar-notif-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

html[dir="ltr"] .sidebar-btn.active,
html[dir="ltr"] .sidebar-btn.active-group {
    box-shadow: inset 3px 0 0 var(--primary);
}

html[dir="ltr"] .sidebar-submenu {
    margin: 2px 0 2px 0;
    margin-inline-start: 10px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--topbar-height);
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1025;
}

.sidebar-backdrop.show { display: block; }
body.sidebar-open { overflow: hidden; }

@media (max-width: 1199.98px) {
    .app-sidebar { transform: translateX(100%); }
    .app-sidebar.show { transform: translateX(0); }
    .has-app-sidebar .main-content {
        margin-right: 0;
        width: 100%;
        max-width: 100%;
    }
    .dashboard-cards {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
        gap: 12px;
    }
    .stat-card { padding: 16px; }
    .stat-card .stat-value { font-size: 22px; }
}

/* ============================================================
   Notifications
   ============================================================ */
.notif-dropdown { width: min(350px, calc(100vw - 24px)); padding: 0; overflow: hidden; }
.notif-list { max-height: 320px; overflow-y: auto; }

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f1f5f9;
    transition: background-color 0.15s;
}

.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: #f5fafb; color: inherit; }
.notif-item.unread { background: #f0fdfa; }
.notif-item.unread:hover { background: #ccfbf1; }

.notif-item-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ecf4f3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.notif-item-body {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.notif-item-body strong { font-size: 13px; line-height: 1.35; color: var(--ink); }
.notif-item-body small {
    font-size: 12px;
    color: var(--ink-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.notif-item-body em { font-style: normal; font-size: 11px; color: #94a3b8; }

.notif-page-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid #eef1f4;
}
.notif-page-item.unread { background: #f0fdfa; }
.notif-page-item .notif-item-icon { width: 36px; height: 36px; font-size: 15px; }

/* ============================================================
   Modals / forms extras
   ============================================================ */
.modal-content {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.modal-header {
    background: linear-gradient(180deg, #f8fbfc, #f1f6f9);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
}

/* إبقاء زر الحفظ ظاهرًا في نوافذ الأدوار الطويلة */
.role-modal-form.modal-content {
    max-height: min(92vh, 900px);
}

.modal-dialog-scrollable .role-modal-form > .modal-body {
    overflow-y: auto;
}

.sticky-modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: #fff !important;
    flex-shrink: 0;
    display: flex !important;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
}

.po-item-row {
    background: #f5f9fb;
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px !important;
    border: 1px solid var(--border);
}

.po-total-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
}

.po-total-bar > div { flex: 1 1 220px; }

.chart-wrap {
    position: relative;
    width: 100%;
    overflow-x: auto;
}

.chart-wrap canvas {
    max-width: 100%;
    height: auto !important;
}

.custom-card,
.row { max-width: 100%; }

/* ============================================================
   App footer — credit
   ============================================================ */
.app-footer {
    margin-top: 8px;
    margin-right: 0;
    padding: 0 24px 20px;
}

.has-app-sidebar .app-footer {
    margin-right: var(--sidebar-width);
}

.app-footer-inner {
    border-top: 1px solid var(--border);
    padding-top: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.app-footer-credit {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--ink-muted);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.app-footer-credit i {
    color: var(--primary);
    font-size: 12px;
    opacity: 0.9;
}

@media (max-width: 1199.98px) {
    .has-app-sidebar .app-footer {
        margin-right: 0;
    }
}

@media (max-width: 767.98px) {
    .app-footer {
        padding: 0 12px 16px;
    }

    .app-footer-credit {
        font-size: 12px;
    }
}

/* ============================================================
   Print
   ============================================================ */
@media print {
    .navbar, .app-sidebar, .sidebar, .sidebar-backdrop, .btn, .toast-container, #sidebarToggle, .app-footer {
        display: none !important;
        position: static !important;
        height: 0 !important;
        overflow: hidden !important;
    }
    html, body {
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }
    .main-content,
    .has-app-sidebar .main-content {
        margin-top: 0 !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        overflow: visible !important;
    }
    .custom-card {
        box-shadow: none !important;
        border: 1px solid #dee2e6 !important;
        break-inside: auto !important;
        page-break-inside: auto !important;
    }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 991.98px) {
    .main-content { padding: 16px; }
    .dashboard-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .app-topbar .container-fluid {
        flex-wrap: nowrap;
        gap: 4px;
    }
    .custom-card .card-body {
        overflow-x: hidden;
    }
    .form-select,
    .form-control {
        max-width: 100%;
    }
}

@media (max-width: 767.98px) {
    .main-content { padding: 12px; }
    .dashboard-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        margin-bottom: 20px;
    }
    .stat-card { padding: 14px; border-radius: 12px; }
    .stat-card .stat-icon {
        width: 40px; height: 40px; font-size: 18px; margin-bottom: 10px; border-radius: 10px;
    }
    .stat-card .stat-value { font-size: 20px; }
    .stat-card .stat-label { font-size: 12px; line-height: 1.3; }
    .custom-card { border-radius: 12px; margin-bottom: 14px; }
    .custom-card .card-header,
    .custom-card .card-body { padding: 12px 14px; }
    .page-toolbar { flex-direction: column; align-items: stretch; }
    .page-toolbar .toolbar-actions { width: 100%; }
    .page-toolbar .btn { flex: 1 1 auto; }
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px;
    }
    h4 { font-size: 1.15rem; }
    .toast-container {
        width: calc(100% - 24px);
        left: 50%;
        transform: translateX(-50%);
        margin-top: 64px !important;
        padding: 0 !important;
    }
    .btn-group {
        flex-wrap: wrap;
        width: 100%;
    }
    .btn-group .btn {
        flex: 1 1 auto;
    }
    .po-item-row .row > [class*="col-"] {
        width: 100%;
        max-width: 100%;
    }
}

@media (max-width: 575.98px) {
    .dashboard-cards { grid-template-columns: 1fr; }
    .navbar-brand { font-size: 0.95rem; max-width: 42vw; }
    .stat-card {
        display: flex;
        align-items: center;
        gap: 12px;
        border-right-width: 3px;
    }
    .stat-card .stat-icon { margin-bottom: 0; flex-shrink: 0; }
    .topbar-user-btn {
        max-width: min(200px, 48vw);
        padding: 3px 8px 3px 6px !important;
    }
    .topbar-fullname,
    .topbar-login,
    .topbar-username {
        max-width: 110px;
        display: block !important;
    }
    .topbar-user-caret { display: none; }
}

@media (max-width: 379.98px) {
    .main-content { padding: 8px; }
    .stat-card .stat-value { font-size: 18px; }
}

/* ---- Batch 1: organisation logo in the top bar ---- */
.app-topbar .brand-logo-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    line-height: 0;
}

.app-topbar .brand-logo {
    height: 30px;
    width: auto;
    max-width: 110px;
    object-fit: contain;
    display: block;
}

/* ============================================================
   Batch 1.1 (UX polish): brand mark, orders list, order view
   ============================================================ */

/* ---- Brand mark in the top bar: white tile + two text lines ---- */
.app-topbar .navbar-brand {
    gap: 10px;
    min-width: 0;
}

.app-topbar .brand-logo-chip {
    width: 38px;
    height: 38px;
    padding: 3px;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(2, 20, 18, 0.25);
}

.app-topbar .brand-logo {
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: contain;
}

.app-topbar .brand-lines {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    line-height: 1.25;
}

.app-topbar .navbar-brand .brand-text {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The lighter end of the top-bar gradient is darkened a little (same hue) so the 12px white
   second line reaches 4.5:1. Done as an overlay because the gradient colours come from settings. */
html body.app-body nav.app-topbar.navbar {
    background-image:
        linear-gradient(90deg, rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.16) 100%),
        linear-gradient(90deg, var(--topbar-start, #0b3d3a) 0%, var(--primary) 55%, var(--topbar-end, var(--primary-light, #0d9488)) 100%) !important;
}

.app-topbar .brand-sub {
    display: block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0;
    color: #ffffff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 991.98px) {
    .app-topbar .brand-sub { display: none; }
    .app-topbar .brand-logo-chip { width: 34px; height: 34px; }
}

/* ---- Orders list ---- */
/* The sticky table header needs ancestors that are not scroll containers: clip instead of hidden.
   Browsers without :has()/clip simply keep the old non-sticky header. */
body:has(.orders-list-page) {
    overflow-x: clip;
}

.main-content.orders-list-page {
    overflow-x: clip;
}

.orders-card {
    overflow: visible;
}

.orders-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
}

.orders-wrap .orders-table {
    width: 100%;
    min-width: 880px !important;
    table-layout: auto;
    font-variant-numeric: tabular-nums;
}

.orders-table thead th {
    padding: 11px 14px;
    font-size: 12.5px;
    font-weight: 700;
    color: #475569;
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
}

.orders-table tbody td {
    padding: 12px 14px;
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
    vertical-align: middle;
}

.orders-table .ot-title {
    width: 100%;
    white-space: normal;
}

.orders-table .ot-number {
    display: block;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.orders-table .ot-number:hover,
.orders-table .ot-number:focus-visible {
    color: var(--primary-dark);
    text-decoration: underline;
}

.orders-table .ot-sub {
    display: block;
    margin-top: 2px;
    font-size: 12px;
    color: var(--ink-muted);
}

.orders-table .ot-main {
    display: block;
    font-weight: 600;
    color: var(--ink);
}

.ot-flag {
    display: inline-block;
    margin-top: 4px;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    background: #fef3c7;
    color: #92400e;
    white-space: nowrap;
}

.orders-table .ot-title-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    min-width: 15rem;
    font-weight: 600;
    line-height: 1.55;
    color: var(--ink);
    overflow-wrap: break-word;
}

.orders-table .ot-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0 14px;
    margin-top: 3px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--ink-muted);
}

.orders-table .ot-witness {
    color: #166534;
    font-weight: 600;
}

.orders-table .ot-code {
    display: inline-block;
    min-width: 36px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    background: var(--surface-2);
    color: #334155;
}

.orders-table .ot-date {
    color: #475569;
}

.orders-table .col-actions {
    text-align: end;
}

.orders-table .users-actions {
    flex-wrap: nowrap;
    justify-content: flex-end;
}

.orders-table .ot-delete {
    margin-inline-start: 6px;
}

@media (min-width: 1200px) {
    .orders-wrap {
        overflow: visible;
    }

    .orders-table thead th {
        position: sticky;
        top: var(--topbar-height);
        z-index: 5;
        box-shadow: 0 1px 0 var(--border);
    }

    .orders-table thead th:first-child { border-start-start-radius: var(--radius); }
    .orders-table thead th:last-child { border-start-end-radius: var(--radius); }
}

/* phone / tablet: one compact card per order (number + status, title, meta, actions) */
@media (max-width: 991.98px) {
    .orders-wrap > .orders-table.custom-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px 12px;
        padding: 14px;
    }

    .orders-wrap > .orders-table.custom-table tr.ot-empty {
        display: block;
    }

    .orders-wrap > .orders-table.custom-table td {
        display: block;
        padding: 0 !important;
        border-bottom: 0 !important;
    }

    .orders-wrap > .orders-table.custom-table td::before {
        content: none;
    }

    .orders-wrap > .orders-table.custom-table td > * {
        margin-inline-start: 0;
        text-align: start;
    }

    .orders-table .ot-num { grid-column: 1; grid-row: 1; }
    .orders-table .ot-status { grid-column: 2; grid-row: 1; }
    .orders-table .ot-title { grid-column: 1 / -1; }
    .orders-table .ot-type { display: none !important; }
    .orders-table .ot-op { grid-column: 1; }
    .orders-table .ot-date { grid-column: 2; align-self: end; font-size: 12.5px; }
    .orders-table .ot-num .ot-number,
    .orders-table .ot-num .ot-sub { display: inline; }
    .orders-table .ot-num .ot-sub { margin-inline-start: 8px; }
    .orders-table .ot-op .ot-main,
    .orders-table .ot-op .ot-sub { display: inline; font-size: 12.5px; }
    .orders-table .ot-op .ot-sub::before { content: "·"; margin-inline: 6px; }
    .orders-table .ot-title-text { min-width: 0; }

    .orders-wrap > .orders-table.custom-table td.col-actions {
        grid-column: 1 / -1;
        padding-top: 10px !important;
        border-top: 1px solid var(--border);
    }

    .orders-table .users-actions {
        justify-content: flex-start;
    }

    .orders-table .users-actions .btn {
        flex: 0 0 auto;
        min-width: 44px;
        min-height: 40px;
    }
}

/* ---- Order view ---- */
.order-view .ov-header {
    margin-bottom: 20px;
}

.ov-crumb {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--ink-muted);
}

.ov-crumb a {
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
}

.ov-crumb a:hover,
.ov-crumb a:focus-visible {
    text-decoration: underline;
}

.ov-head-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px 20px;
}

.ov-ident {
    min-width: 0;
    flex: 1 1 320px;
}

.ov-number-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.ov-number-line .ot-flag {
    margin-top: 0;
}

.ov-number {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.ov-title {
    max-width: 60ch;
    margin: 6px 0 0;
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.4;
    color: var(--ink);
    text-wrap: balance;
    overflow-wrap: anywhere;
}

.ov-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.ov-tools-danger {
    margin-inline-start: 6px;
    padding-inline-start: 14px;
    border-inline-start: 1px solid var(--border);
}

.ov-facts {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 32px;
    margin: 16px 0 0;
    padding: 14px 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--ink);
}

.ov-facts dt,
.ov-grid dt {
    margin-bottom: 3px;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-muted);
}

.ov-facts dd {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
}

/* Action panel: only rendered for the user who can act on the current step */
.ov-action {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(0, 2fr);
    gap: 18px 32px;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--card);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.ov-action-head h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary-dark);
}

.ov-action-head p {
    margin: 0;
    font-size: 14px;
    line-height: 1.75;
    color: #334155;
}

.ov-action-head .ov-action-note {
    margin-top: 8px;
    font-size: 12.5px;
    color: var(--ink-muted);
}

#approvalActionForm .mb-3 {
    margin-bottom: 12px !important;
}

#approvalActionForm .form-label {
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 700;
}

#approvalActionForm textarea {
    min-height: 78px;
    resize: vertical;
}

#approvalActionForm > .d-flex {
    align-items: center;
    gap: 10px !important;
}

#approvalActionForm .btn {
    flex-grow: 0 !important;
    min-height: 42px;
    padding-inline: 18px;
    font-weight: 700;
}

/* primary: approve */
#approvalActionForm .btn-success {
    --bs-btn-color: #ffffff;
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-color: #ffffff;
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-active-color: #ffffff;
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    padding-inline: 28px;
}

/* destructive: reject, kept apart from the primary */
#approvalActionForm .btn-danger {
    --bs-btn-color: var(--danger);
    --bs-btn-bg: transparent;
    --bs-btn-border-color: var(--danger);
    --bs-btn-hover-color: #ffffff;
    --bs-btn-hover-bg: var(--danger);
    --bs-btn-hover-border-color: var(--danger);
    --bs-btn-active-color: #ffffff;
    --bs-btn-active-bg: var(--danger);
    --bs-btn-active-border-color: var(--danger);
    margin-inline-start: auto;
}

/* secondary: return to the previous step */
#approvalActionForm .btn-warning {
    --bs-btn-color: #334155;
    --bs-btn-bg: transparent;
    --bs-btn-border-color: #94a3b8;
    --bs-btn-hover-color: #ffffff;
    --bs-btn-hover-bg: #475569;
    --bs-btn-hover-border-color: #475569;
    --bs-btn-active-color: #ffffff;
    --bs-btn-active-bg: #334155;
    --bs-btn-active-border-color: #334155;
}

.ov-reason-msg {
    margin: 10px 0 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--danger);
}

.ov-reason-msg[hidden] {
    display: none;
}

/* details */
.ov-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 18px 24px;
    margin: 0;
}

.ov-grid dd {
    margin: 0;
    font-size: 14.5px;
    font-weight: 600;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.ov-num {
    font-variant-numeric: tabular-nums;
}

.ov-muted {
    font-weight: 500;
    color: var(--ink-muted);
}

.ov-prose {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.ov-prose h6 {
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-muted);
}

.ov-prose p {
    max-width: 70ch;
    line-height: 1.8;
}

/* route timeline */
.ov-timeline {
    margin: 0;
    padding: 0;
    list-style: none;
}

.ov-step {
    position: relative;
    display: flex;
    gap: 12px;
    padding-bottom: 18px;
}

.ov-step:last-child {
    padding-bottom: 0;
}

.ov-step::before {
    content: "";
    position: absolute;
    inset-inline-start: 15px;
    top: 34px;
    bottom: 2px;
    width: 2px;
    background: var(--border);
}

.ov-step:last-child::before {
    display: none;
}

.ov-step.completed::before {
    background: var(--success);
}

.ov-step-dot {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    flex: 0 0 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 800;
    background: var(--surface-2);
    color: #475569;
}

.ov-step.completed .ov-step-dot {
    background: var(--success);
    color: #ffffff;
}

.ov-step.active .ov-step-dot {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.ov-step-body {
    min-width: 0;
    padding-top: 4px;
}

.ov-step-name {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.55;
    color: var(--ink);
}

.ov-step.pending .ov-step-name {
    font-weight: 600;
    color: #475569;
}

.ov-step-tag {
    display: inline-block;
    margin-inline-start: 6px;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    background: var(--primary-soft);
    color: var(--primary-dark);
    vertical-align: middle;
}

.ov-step-meta {
    display: flex;
    flex-wrap: wrap;
    margin-top: 2px;
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--ink-muted);
}

.ov-step-meta > span + span::before {
    content: "·";
    margin-inline: 6px;
}

.ov-step-meta i {
    font-size: 11px;
}

/* approval history */
.ov-history {
    max-height: 320px;
    overflow-y: auto;
}

.ov-hist {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.ov-hist:first-child { padding-top: 0; }
.ov-hist:last-child { padding-bottom: 0; border-bottom: 0; }

.ov-hist-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.ov-hist-user {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--ink);
}

.ov-hist-time {
    font-size: 12px;
    color: var(--ink-muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.ov-hist-action {
    display: inline-block;
    margin-top: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.ov-tone-success { background: #dcfce7; color: #166534; }
.ov-tone-danger { background: #fee2e2; color: #991b1b; }
.ov-tone-warning { background: #fef3c7; color: #92400e; }
.ov-tone-info { background: #e0f2fe; color: #075985; }

.ov-hist-step {
    margin-inline-start: 6px;
    font-size: 12px;
    color: var(--ink-muted);
}

.ov-hist-comment {
    margin: 6px 0 0;
    font-size: 13px;
    line-height: 1.7;
    color: #334155;
}

@media (max-width: 767.98px) {
    .ov-title { font-size: 1.25rem; }
    .ov-facts { gap: 12px 24px; padding: 12px 14px; }
    .ov-action { grid-template-columns: 1fr; gap: 14px; padding: 16px; }
    .ov-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
    .ov-tools-danger { margin-inline-start: 0; padding-inline-start: 0; border-inline-start: 0; }

    #approvalActionForm .btn-success { flex: 1 1 100% !important; }
    #approvalActionForm .btn-danger,
    #approvalActionForm .btn-warning { flex: 1 1 0 !important; margin-inline-start: 0; padding-inline: 10px; }
    #approvalActionForm .btn-danger { flex: 0 1 34% !important; }
    #approvalActionForm .btn { min-height: 46px; }
}

@media print {
    .ov-action,
    .ov-crumb,
    .ov-tools { display: none !important; }
}
