:root {
    --sidebar-w: 250px;
    --sidebar-bg: #14243b;
    --sidebar-fg: #c9d4e3;
    --sidebar-active: #2563eb;
    --app-bg: #dfe5ee;
    --panel-border: #c9d2de;
    --panel-head: #eef2f7;
    --grid-head: #dde5f0;
    --grid-line: #d6dde7;
}

html, body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--app-bg);
    font-size: 1rem;
    color: #1f2a37;
}

h1:focus { outline: none; }
.min-w-0 { min-width: 0; }
.pre-wrap { white-space: pre-wrap; }

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

.app-sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1040;
}

.app-sidebar .brand {
    display: flex; align-items: center; gap: .6rem;
    padding: 1.1rem 1.2rem;
    font-weight: 700; color: #fff; font-size: 1.05rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.app-sidebar .brand i { font-size: 1.5rem; color: #60a5fa; }

.app-sidebar .nav { padding: .6rem; }
.app-sidebar .nav-link {
    color: var(--sidebar-fg);
    border-radius: .5rem;
    padding: .55rem .8rem;
    margin-bottom: 2px;
    display: flex; align-items: center; gap: .6rem;
}
.app-sidebar .nav-link i { font-size: 1.1rem; width: 1.3rem; text-align: center; }
.app-sidebar .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.app-sidebar .nav-link.active { background: var(--sidebar-active); color: #fff; }
.app-sidebar .nav-section {
    font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
    color: #7f93ad; padding: 1rem .8rem .3rem;
}

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.app-topbar {
    display: flex; align-items: center;
    background: #fff;
    padding: .55rem 1.25rem;
    border-bottom: 1px solid var(--panel-border);
    box-shadow: 0 1px 4px rgba(16,24,40,.08);
    position: sticky; top: 0; z-index: 1030;
}
.user-chip { max-width: 220px; }

.app-content { padding: 1.25rem; }

.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        inset-block: 0;
        inset-inline-start: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    [dir="rtl"] .app-sidebar { transform: translateX(100%); }
    .app-sidebar.open, [dir="rtl"] .app-sidebar.open { transform: none; }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1035; }
    .app-content { padding: .75rem; }
}

/* ---------- Cards / stats ---------- */
.card {
    border: 1px solid var(--panel-border);
    border-radius: .75rem;
    box-shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}
.card-header {
    background: var(--panel-head);
    border-bottom: 1px solid var(--panel-border);
    font-weight: 600;
    padding: .7rem 1rem;
}
.card-header:first-child { border-radius: .75rem .75rem 0 0; }
.card-footer { background: var(--panel-head); border-top: 1px solid var(--panel-border); }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: 1rem; }
h1.h4 { font-weight: 700; color: #14243b; }
.stat-card { transition: transform .1s ease, box-shadow .1s ease; }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 .25rem .75rem rgba(0,0,0,.06); }
.stat-card { border-width: 1px; border-inline-start-width: 5px !important; }
.stat-icon {
    width: 48px; height: 48px; border-radius: .7rem;
    display: flex; align-items: center; justify-content: center; font-size: 1.4rem;
}

/* ---------- Tables ---------- */
.table { --bs-table-border-color: var(--grid-line); --bs-table-striped-bg: #f4f7fb; --bs-table-hover-bg: #e7effb; }
.table > thead > tr > th, .table-light > tr > th, thead.table-light th {
    background: var(--grid-head) !important;
    color: #24364d;
    font-weight: 700;
    border-bottom: 2px solid #b9c5d5;
    font-size: .9rem;
    padding-top: .65rem; padding-bottom: .65rem;
}
.table > tbody > tr > td { border-bottom: 1px solid var(--grid-line); }
.order-table th { white-space: nowrap; }
.order-table td { white-space: normal; }
.order-table .cell-customer { min-width: 150px; }
.order-table td { font-size: .95rem; padding-top: .6rem; padding-bottom: .6rem; }
.order-table .order-no { font-weight: 700; text-decoration: none; color: #0b5ed7; letter-spacing: .2px; }
.order-table .col-attach { width: 70px; }
.attach-pill {
    display: inline-flex; align-items: center; gap: .15rem;
    background: #eef3fb; border: 1px solid #c7d4e8; color: #34557f;
    border-radius: 1rem; padding: .05rem .5rem; font-size: .82rem; font-weight: 600;
}
.row-overdue > td { background-color: #fdecec !important; }
.order-table .cell-customer { max-width: 260px; }
.order-table tbody tr { cursor: pointer; }
.row-urgent { box-shadow: inset 4px 0 0 #dc3545; }
[dir="rtl"] .row-urgent { box-shadow: inset -4px 0 0 #dc3545; }
.status-badge { font-weight: 600; font-size: .8rem; padding: .38em .7em; }
.sla-badge { font-weight: 500; }
.report-table td, .report-table th { white-space: nowrap; font-size: .92rem; }

/* ---------- Order details ---------- */
.action-panel { background: #f7faff; }
.info-grid dt { font-weight: 600; color: #6c757d; font-size: .88rem; }
.info-grid dd { margin-bottom: .6rem; }
.timing-card .stage-current { background: #eef4ff; }
.timing-table td { padding: .2rem 0; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before {
    content: ""; position: absolute; top: 0; bottom: 0;
    inset-inline-start: 15px; width: 2px; background: #e3e7ee;
}
.timeline-item { position: relative; padding-inline-start: 46px; padding-bottom: 1rem; }
.timeline-icon {
    position: absolute; inset-inline-start: 0; top: 0;
    width: 32px; height: 32px; border-radius: 50%;
    background: #fff; border: 2px solid #ced4da; color: #6c757d;
    display: flex; align-items: center; justify-content: center; font-size: .95rem;
}
.tl-success .timeline-icon { border-color: #198754; color: #198754; }
.tl-danger .timeline-icon { border-color: #dc3545; color: #dc3545; }
.tl-warning .timeline-icon { border-color: #ffc107; color: #b58105; }
.tl-primary .timeline-icon { border-color: #0d6efd; color: #0d6efd; }
.tl-comment .timeline-icon { border-color: #6f42c1; color: #6f42c1; }
.timeline-notes {
    margin-top: .3rem; padding: .45rem .7rem;
    background: #f6f8fb; border-radius: .5rem; white-space: pre-wrap; font-size: .9rem;
}
.tl-comment .timeline-notes { background: #f3effb; }

/* ---------- Attachments ---------- */
.attach-list .deleted { opacity: .55; text-decoration: line-through; }
.drop-zone {
    display: flex; flex-direction: column; align-items: center; gap: .2rem;
    border: 2px dashed #b9c4d3; border-radius: .7rem; padding: 1.2rem;
    cursor: pointer; color: #4b5b70; background: #fafbfd; text-align: center;
}
.drop-zone:hover { border-color: #0d6efd; background: #f2f7ff; }
.preview-frame { width: 100%; height: 75vh; border: 0; }
.preview-img { max-height: 75vh; }

/* ---------- Pickers ---------- */
.picker-list { z-index: 1060; max-height: 300px; overflow-y: auto; }

/* ---------- Auth ---------- */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #14243b 0%, #1e3a5f 100%); padding: 1rem;
}
.auth-card { width: 100%; max-width: 420px; border: 0; }

/* ---------- Modal ---------- */
.modal.d-block { background: transparent; }

/* ---------- Blazor ---------- */
#blazor-error-ui {
    background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: .6rem 1.25rem .7rem 1.25rem; position: fixed; width: 100%; z-index: 2000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.blazor-error-boundary::after { content: "An error has occurred."; }
.validation-message { color: #dc3545; font-size: .85rem; }

@media print {
    .app-sidebar, .app-topbar, .action-panel, .btn { display: none !important; }
    .app-content { padding: 0; }
}

/* ---------- Forms ---------- */
.form-control, .form-select { border-color: #b9c4d3; }
.form-control:focus, .form-select:focus { border-color: #0d6efd; }
.form-label { font-weight: 600; color: #34475e; }
.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; padding: 0; border-radius: .5rem; color: #34475e;
}
.btn-icon:hover { background: #eef2f7; }
.font-switch .btn { font-weight: 700; min-width: 38px; }

/* ---------- Collapsed sidebar ---------- */
.app-sidebar { transition: width .18s ease; }
@media (min-width: 992px) {
    .app-shell.collapsed .app-sidebar { width: 68px; }
    .app-shell.collapsed .app-sidebar .nav-text { display: none; }
    .app-shell.collapsed .app-sidebar .brand { justify-content: center; padding-inline: 0; }
    .app-shell.collapsed .app-sidebar .nav-link { justify-content: center; padding-inline: 0; }
    .app-shell.collapsed .app-sidebar .nav-link i { font-size: 1.25rem; }
    .app-shell.collapsed .app-sidebar .nav-section { padding: .6rem 0 .2rem; border-top: 1px solid rgba(255,255,255,.1); margin: .4rem .5rem 0; }
}

/* ---------- Bell dropdown ---------- */
.bell-wrap { position: relative; }
.bell-backdrop { position: fixed; inset: 0; z-index: 1049; }
.bell-panel {
    position: absolute; top: calc(100% + 8px); inset-inline-end: 0; z-index: 1050;
    width: 380px; max-width: 92vw; background: #fff; border: 1px solid var(--panel-border); border-radius: .75rem; overflow: hidden;
}
.bell-head { display: flex; align-items: center; padding: .7rem 1rem; background: var(--panel-head); border-bottom: 1px solid var(--panel-border); }
.bell-list { max-height: 420px; overflow-y: auto; }
.bell-foot { display: block; text-align: center; padding: .6rem; border-top: 1px solid var(--panel-border); font-weight: 600; text-decoration: none; background: #fafbfd; }
.notif-item {
    display: flex; gap: .7rem; align-items: flex-start; width: 100%; text-align: start;
    background: #fff; border: 0; border-bottom: 1px solid #edf0f4; padding: .7rem 1rem; position: relative;
}
.notif-item:hover { background: #f2f6fc; }
.notif-item.unread, .notif-row.unread { background: #eef5ff; }
.notif-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.notif-title { font-weight: 600; color: #1f2a37; }
.unread .notif-title { font-weight: 700; }
.notif-meta { font-size: .85rem; color: #4b5b70; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-time { font-size: .8rem; color: #6c7a8c; }
.notif-dot { width: 9px; height: 9px; border-radius: 50%; background: #0d6efd; flex-shrink: 0; margin-top: .45rem; }
.notif-icon {
    width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.05rem;
}
.notif-primary { background: #dbe8ff; color: #0b5ed7; }
.notif-info { background: #d6f3f9; color: #087990; }
.notif-success { background: #d4f1df; color: #146c43; }
.notif-danger { background: #fbdcdc; color: #b02a37; }
.notif-warning { background: #fff0c2; color: #8a6100; }
.notif-purple { background: #e8defa; color: #5a32a3; }
.notif-secondary { background: #e4e7eb; color: #4b5563; }

/* ---------- Notifications page ---------- */
.notif-day { font-weight: 700; color: #34475e; margin: .5rem .25rem .4rem; font-size: .95rem; }
.notif-card { overflow: hidden; }
.notif-row {
    display: flex; align-items: center; gap: .9rem; padding: .85rem 1rem;
    border-bottom: 1px solid #e6eaf0; cursor: pointer;
}
.notif-row:last-child { border-bottom: 0; }
.notif-row:hover { background: #f2f6fc; }
.notif-row.unread { box-shadow: inset 4px 0 0 #0d6efd; }
[dir="rtl"] .notif-row.unread { box-shadow: inset -4px 0 0 #0d6efd; }
.notif-row .notif-meta { white-space: normal; margin-top: .15rem; }
.notif-side { min-width: 120px; }

/* ---------- Grid footer / pager ---------- */
.grid-pager {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: .6rem; width: 100%;
}
.grid-pager .page-size { width: auto; min-width: 72px; }
.grid-pager .btn-group .btn { min-width: 34px; }
