:root {
    --ink: #1b212e;
    --ink-2: #232a3a;
    --ink-3: #2e3750;
    --bg: #f4f5f8;
    --surface: #ffffff;
    --line: #e6e8ef;
    --line-strong: #d5d9e4;
    --muted: #6b7385;
    --text: #262c3a;
    --amber: #e9a13b;
    --amber-soft: #fdf3e3;
    --amber-ink: #7a5310;
    --green: #1f9d55;
    --green-soft: #e7f6ee;
    --red: #d64545;
    --red-soft: #fdecec;
    --orange: #e07c24;
    --orange-soft: #fdf0e4;
    --slate-soft: #eef0f5;
    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(20, 24, 40, .05), 0 1px 6px rgba(20, 24, 40, .04);
    --shadow-md: 0 6px 24px rgba(20, 24, 40, .09);
    --font-display: 'Readex Pro', 'IBM Plex Sans Arabic', sans-serif;
    --font-body: 'IBM Plex Sans Arabic', 'Readex Pro', sans-serif;
    --sidebar-w: 258px;
}

* { box-sizing: border-box; }

html { font-size: 17px; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-family: var(--font-display); font-weight: 600; color: var(--ink); }

.num { font-variant-numeric: tabular-nums; letter-spacing: 0; }

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

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

.app-content { padding: 1.6rem 2rem 3rem; max-width: 1500px; width: 100%; margin: 0 auto; }

/* ---------- sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--ink) 0%, var(--ink-2) 100%);
    color: #cfd5e4;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .18) transparent;
    z-index: 1040;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .18); border-radius: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar-brand, .sidebar-foot { flex-shrink: 0; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.35rem 1.4rem 1.2rem;
}

.brand-mark {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: var(--amber);
    color: #2a1c04;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 4px 14px rgba(233, 161, 59, .35);
}

.brand-name { font-family: var(--font-display); font-weight: 700; color: #fff; font-size: 1.05rem; line-height: 1.2; }
.brand-sub { font-size: .68rem; color: #8d96ac; letter-spacing: .03em; }

.lane-rule {
    border: 0;
    border-top: 2px dashed rgba(233, 161, 59, .45);
    margin: 0 1.4rem .9rem;
    opacity: .9;
}

.side-label {
    font-size: .66rem;
    color: #7c8499;
    padding: .9rem 1.55rem .35rem;
    letter-spacing: .06em;
}

.side-nav { list-style: none; margin: 0; padding: 0 .8rem; display: flex; flex-direction: column; gap: 2px; }

.side-nav a {
    display: flex;
    align-items: center;
    gap: .8rem;
    color: #c3cadb;
    text-decoration: none;
    padding: .66rem .8rem;
    border-radius: 10px;
    font-size: .98rem;
    position: relative;
    transition: background .15s ease, color .15s ease;
}

.side-nav a i { font-size: 1.05rem; width: 22px; text-align: center; color: #8d96ac; transition: color .15s ease; }

.side-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-nav a:hover i { color: var(--amber); }

.side-nav a.active {
    background: rgba(233, 161, 59, .13);
    color: #fff;
    font-weight: 600;
}

.side-nav a.active::before {
    content: '';
    position: absolute;
    inset-inline-start: -0.8rem;
    top: 20%;
    height: 60%;
    width: 3.5px;
    border-radius: 4px;
    background: var(--amber);
}

.side-nav a.active i { color: var(--amber); }

.side-nav .nav-count {
    margin-inline-start: auto;
    background: var(--red);
    color: #fff;
    font-size: .68rem;
    border-radius: 20px;
    padding: .1rem .5rem;
    font-weight: 600;
}

.sidebar-foot { margin-top: auto; padding: 1rem 1.1rem 1.2rem; }
.side-label, .side-nav { flex-shrink: 0; }

.user-card {
    display: flex;
    align-items: center;
    gap: .7rem;
    background: rgba(255, 255, 255, .05);
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 12px;
    padding: .65rem .8rem;
}

.avatar {
    width: 36px; height: 36px;
    flex-shrink: 0;
    border-radius: 10px;
    background: var(--ink-3);
    color: var(--amber);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: .95rem;
}

.user-card .u-name { color: #fff; font-size: .84rem; font-weight: 600; line-height: 1.25; }
.user-card .u-role { color: #8d96ac; font-size: .7rem; }

.logout-btn {
    background: none;
    border: none;
    color: #8d96ac;
    margin-inline-start: auto;
    font-size: 1.05rem;
    padding: .3rem;
    border-radius: 8px;
    cursor: pointer;
    transition: color .15s ease, background .15s ease;
}

.logout-btn:hover { color: #ff8484; background: rgba(214, 69, 69, .12); }

/* ---------- topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.05rem 2rem;
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.burger {
    display: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    width: 40px; height: 40px;
    font-size: 1.1rem;
    color: var(--ink);
}

.page-title { font-size: 1.35rem; font-weight: 700; margin: 0; }
.page-sub { font-size: .85rem; color: var(--muted); margin-top: .12rem; }

.topbar-actions { margin-inline-start: auto; display: flex; gap: .6rem; align-items: center; }

/* ---------- buttons ---------- */
.btn { font-family: var(--font-body); border-radius: var(--radius-sm); font-size: .95rem; padding: .55rem 1.1rem; transition: transform .12s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease; }
.btn:active { transform: translateY(1px); }
.btn i { vertical-align: -1px; }

.btn-ink { background: var(--ink); color: #fff; border: 1px solid var(--ink); }
.btn-ink:hover { background: var(--ink-3); border-color: var(--ink-3); color: #fff; box-shadow: 0 6px 16px rgba(27, 33, 46, .25); }

.btn-amber { background: var(--amber); border: 1px solid var(--amber); color: #2a1c04; font-weight: 600; }
.btn-amber:hover { background: #f0ad4f; border-color: #f0ad4f; color: #2a1c04; box-shadow: 0 6px 16px rgba(233, 161, 59, .35); }

.btn-soft { background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink); }
.btn-soft:hover { background: var(--slate-soft); color: var(--ink); }

.btn-ghost-danger { background: transparent; border: 1px solid transparent; color: var(--red); }
.btn-ghost-danger:hover { background: var(--red-soft); color: var(--red); }

.btn-icon { width: 34px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; font-size: .9rem; }

/* ---------- stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .9rem; margin-bottom: 1.3rem; }

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: .95rem 1.15rem;
    transition: transform .15s ease, box-shadow .15s ease;
    display: block;
    text-decoration: none;
    color: inherit;
}

a.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); color: inherit; }

.stat .s-label { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: .4rem; }
.stat .s-label i { font-size: .9rem; }
.stat .s-value { font-family: var(--font-body); font-weight: 700; font-size: 1.6rem; color: var(--ink); margin-top: .2rem; font-variant-numeric: tabular-nums; line-height: 1.25; }
.stat .s-unit { font-size: .78rem; color: var(--muted); font-weight: 400; }
.stat .s-usd { font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: .1rem; direction: ltr; text-align: end; unicode-bidi: plaintext; }

.stat-warn { background: var(--amber-soft); border-color: #f3ddb4; }
.stat-warn .s-value, .stat-warn .s-label { color: var(--amber-ink); }
.stat-ok .s-value { color: var(--green); }
.stat-danger .s-value { color: var(--red); }

/* ---------- panels ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 1.3rem;
}

.panel-head {
    display: flex;
    align-items: center;
    gap: .8rem;
    flex-wrap: wrap;
    padding: 1rem 1.3rem;
    border-bottom: 1px solid var(--line);
}

.panel-title { font-size: 1.05rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: .5rem; }
.panel-title i { color: var(--amber); }
.panel-tools { margin-inline-start: auto; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.panel-body { padding: 1.3rem; }

/* ---------- toolbar / filters ---------- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .7rem .8rem;
    align-items: end;
    padding: 1rem 1.3rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.3rem;
}

.f-field { display: flex; flex-direction: column; gap: .28rem; }
.f-field > label { font-size: .8rem; color: var(--muted); font-weight: 600; padding-inline-start: .2rem; }
.f-field .form-control, .f-field .form-select { min-width: 130px; }
.f-field .select2-container { min-width: 175px; }

/* ---------- forms ---------- */
.form-control, .form-select {
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font-size: .95rem;
    padding: .52rem .85rem;
    color: var(--text);
    background-color: var(--surface);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--amber);
    box-shadow: 0 0 0 3.5px rgba(233, 161, 59, .18);
    outline: none;
}

.form-label { font-size: .86rem; font-weight: 600; color: var(--ink); margin-bottom: .3rem; }

.form-check-input:checked { background-color: var(--amber); border-color: var(--amber); }
.form-check-input:focus { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(233, 161, 59, .2); }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; }

.table-modern { width: 100%; border-collapse: separate; border-spacing: 0; margin: 0; font-size: .95rem; }

.table-modern thead th {
    background: #fafbfc;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 700;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    text-align: start;
}

.table-modern tbody td {
    padding: .82rem 1rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    background: var(--surface);
    transition: background .12s ease;
}

.table-modern tbody tr:last-child td { border-bottom: 0; }
.table-modern tbody tr:hover td { background: #f8f9fc; }

.table-modern tfoot td {
    padding: .85rem 1rem;
    background: var(--slate-soft);
    font-weight: 700;
    font-size: .9rem;
    border-top: 2px solid var(--line-strong);
    font-variant-numeric: tabular-nums;
}

.row-muted td { opacity: .55; }

.cell-main { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: .8rem; color: var(--muted); margin-top: .1rem; }

.name-cell { display: flex; align-items: center; gap: .65rem; }

.initial {
    width: 34px; height: 34px;
    flex-shrink: 0;
    border-radius: 10px;
    background: var(--slate-soft);
    color: var(--ink-3);
    font-weight: 700;
    font-size: .85rem;
    display: flex; align-items: center; justify-content: center;
}

/* ---------- chips & badges ---------- */
.chip-ton {
    display: inline-flex;
    align-items: baseline;
    gap: .25rem;
    background: var(--amber-soft);
    border: 1px solid #f0dcb2;
    color: var(--amber-ink);
    font-weight: 700;
    border-radius: 8px;
    padding: .2rem .6rem;
    font-size: .9rem;
    font-variant-numeric: tabular-nums;
}

.chip-ton small { font-weight: 500; font-size: .74rem; }

.badge-soft {
    display: inline-flex;
    align-items: center;
    gap: .32rem;
    border-radius: 20px;
    padding: .3rem .7rem;
    font-size: .78rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}

.badge-soft .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.b-sent { background: var(--green-soft); color: var(--green); }
.b-pending { background: var(--slate-soft); color: var(--muted); }
.b-retry { background: var(--orange-soft); color: var(--orange); }
.b-rejected { background: var(--red-soft); color: var(--red); }
.b-legacy { background: #f1f2f6; color: #8b91a3; }
.b-paid { background: var(--green-soft); color: var(--green); }
.b-unpaid { background: var(--amber-soft); color: var(--amber-ink); }

/* ---------- alerts ---------- */
.alert { border: 0; border-radius: var(--radius); font-size: .92rem; padding: .85rem 1.1rem; }
.alert-success { background: var(--green-soft); color: #14733e; }
.alert-danger { background: var(--red-soft); color: #a53030; }
.alert-info { background: #e8f1fd; color: #2c5c9e; }
.alert ul { margin: 0; padding-inline-start: 1.1rem; }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 3rem 1rem; }
.empty i { font-size: 2rem; color: var(--line-strong); display: block; margin-bottom: .6rem; }
.empty .e-title { font-weight: 700; color: var(--ink); font-size: .95rem; }
.empty .e-hint { color: var(--muted); font-size: .8rem; margin-top: .2rem; }

/* ---------- tabs (segmented) ---------- */
.segmented {
    display: inline-flex;
    background: var(--slate-soft);
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
    margin-bottom: 1.1rem;
    flex-wrap: wrap;
}

.segmented .nav-link {
    border: 0;
    border-radius: 9px;
    color: var(--muted);
    font-size: .95rem;
    font-weight: 600;
    padding: .5rem 1.2rem;
    transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}

.segmented .nav-link:hover { color: var(--ink); }

.segmented .nav-link.active {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

/* ---------- modals ---------- */
.modal-content { border: 0; border-radius: var(--radius-lg); box-shadow: 0 24px 60px rgba(15, 20, 35, .25); }
.modal-header { border-bottom: 1px solid var(--line); padding: 1.1rem 1.4rem; }
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-body { padding: 1.3rem 1.4rem; }
.modal-footer { border-top: 1px solid var(--line); padding: .9rem 1.4rem; }
.modal-backdrop.show { opacity: .45; }

/* ---------- pagination ---------- */
.pagination { gap: .3rem; }
.pagination .page-link {
    border: 1px solid var(--line);
    border-radius: 9px !important;
    color: var(--ink);
    font-size: .82rem;
    padding: .38rem .75rem;
    font-variant-numeric: tabular-nums;
}
.pagination .page-item.active .page-link { background: var(--ink); border-color: var(--ink); color: #fff; }
.pagination .page-link:focus { box-shadow: 0 0 0 3px rgba(233, 161, 59, .2); }

/* ---------- login ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ink);
    background-image: radial-gradient(circle at 85% 15%, rgba(233, 161, 59, .14), transparent 45%),
                      radial-gradient(circle at 10% 90%, rgba(233, 161, 59, .07), transparent 40%);
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 410px;
    background: var(--surface);
    border-radius: 22px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
    padding: 2.4rem 2.2rem 2.2rem;
}

.login-road {
    border: 0;
    border-top: 2.5px dashed rgba(233, 161, 59, .55);
    margin: 1.1rem 0 1.5rem;
}

/* ---------- settlement summary bar ---------- */
.summary-bar {
    position: sticky;
    bottom: 0;
    z-index: 1020;
    background: var(--ink);
    color: #dfe4ef;
    border-radius: var(--radius-lg);
    padding: 1rem 1.4rem;
    display: flex;
    align-items: center;
    gap: 1.6rem;
    flex-wrap: wrap;
    box-shadow: 0 -6px 30px rgba(15, 20, 35, .25);
}

.summary-bar .sm-item .l { font-size: .68rem; color: #99a1b5; }
.summary-bar .sm-item .v { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.summary-bar .sm-net .v { color: var(--amber); font-size: 1.3rem; }
.summary-bar .actions { margin-inline-start: auto; display: flex; gap: .6rem; }

/* ---------- misc ---------- */
.section-gap { margin-bottom: 1.3rem; }
.text-muted-2 { color: var(--muted); }
.mono-num { font-variant-numeric: tabular-nums; }

::selection { background: rgba(233, 161, 59, .3); }

:focus-visible { outline: 2.5px solid var(--amber); outline-offset: 2px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
    .app-content { padding: 1.2rem 1.2rem 2.4rem; }
    .topbar { padding: .9rem 1.2rem; }
}

@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        inset-inline-start: 0;
        transform: translateX(100%);
        transition: transform .25s ease;
        box-shadow: none;
    }

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

    .sidebar.open { transform: translateX(0); box-shadow: 0 0 60px rgba(0, 0, 0, .4); }

    .burger { display: inline-flex; align-items: center; justify-content: center; }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 18, 28, .45);
        z-index: 1035;
    }

    .sidebar-backdrop.show { display: block; }
}

@media (max-width: 640px) {
    html { font-size: 15.5px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .topbar-actions .btn span.btn-text { display: none; }
    .toolbar { padding: .9rem 1rem; }
    .f-field { flex: 1 1 45%; }
    .f-field .form-control, .f-field .form-select { min-width: 0; width: 100%; }
    .panel-head { padding: .9rem 1rem; }
    .summary-bar { gap: .9rem; padding: .9rem 1rem; }
}

/* ---------- select2 skin ---------- */
.select2-container { width: 100% !important; font-family: var(--font-body); }

.select2-container--default .select2-selection--single {
    height: auto;
    min-height: 42px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    display: flex;
    align-items: center;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text);
    font-size: .95rem;
    line-height: 1.5;
    padding: .5rem .85rem;
    padding-inline-end: 2.1rem;
    width: 100%;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 100%;
    top: 0;
    inset-inline-end: .7rem;
    inset-inline-start: auto;
    width: 20px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: var(--muted) transparent transparent transparent;
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent var(--muted) transparent;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--amber);
    box-shadow: 0 0 0 3.5px rgba(233, 161, 59, .18);
}

.select2-container--default.select2-container--disabled .select2-selection--single {
    background: var(--slate-soft);
    color: var(--muted);
    cursor: not-allowed;
}

.select2-dropdown {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    font-size: .95rem;
    z-index: 2000;
}

.select2-search--dropdown { padding: .55rem; }

.select2-search--dropdown .select2-search__field {
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: .45rem .7rem;
    font-family: var(--font-body);
    font-size: .95rem;
    outline: none;
}

.select2-search--dropdown .select2-search__field:focus {
    border-color: var(--amber);
    box-shadow: 0 0 0 3px rgba(233, 161, 59, .16);
}

.select2-results__option {
    padding: .55rem .9rem;
    font-size: .93rem;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background: var(--amber-soft);
    color: var(--amber-ink);
}

.select2-container--default .select2-results__option--selected {
    background: var(--slate-soft);
    color: var(--ink);
    font-weight: 600;
}

.select2-results__options { max-height: 300px !important; }

/* ---------- print ---------- */
.print-only { display: none; }

@media print {
    body { background: #fff; }
    .sidebar, .sidebar-backdrop, .topbar-actions, .toolbar, .burger,
    .btn, .pagination, .alert-dismissible, .d-print-none { display: none !important; }
    .topbar { position: static; border: 0; background: #fff; padding: 0 0 .6rem; }
    .app-content { padding: 0; max-width: 100%; }
    .panel, .stat { box-shadow: none; border: 1px solid #cfd3dd; break-inside: avoid; }
    .table-modern tbody tr:hover td { background: #fff; }
    .print-only { display: block; }
    a { text-decoration: none; color: inherit; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
