:root {
    --brand: #e85d04;
    --brand-dark: #c44b00;
    --brand-soft: #fff1e6;
    --sidebar: #1c2331;
    --sidebar-soft: #252e3f;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --surface: #f5f6f8;
    --success: #16803c;
    --danger: #c02626;
    --warning: #b45309;
    --info: #0e7490;
}

@font-face {
    font-family: 'Cairo';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../fonts/cairo-400.woff2') format('woff2');
}
@font-face {
    font-family: 'Cairo';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('../fonts/cairo-600.woff2') format('woff2');
}
@font-face {
    font-family: 'Cairo';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../fonts/cairo-700.woff2') format('woff2');
}

* { font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif; }

body {
    background: var(--surface);
    color: var(--ink);
    font-size: 0.92rem;
    min-height: 100vh;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { color: var(--brand); }

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

/* Sidebar */
.sidebar {
    width: 264px;
    flex: 0 0 264px;
    background: linear-gradient(180deg, #1c2331 0%, #171d28 100%);
    color: #cbd5e1;
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1040;
    transition: transform .25s ease;
    scrollbar-width: thin;
    scrollbar-color: #3b465c transparent;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.15rem 1.15rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    color: #fff;
}
.sidebar-brand .logo {
    width: 42px; height: 42px; border-radius: 12px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #ff8a3d, var(--brand));
    font-size: 1.35rem; color: #fff; box-shadow: 0 6px 16px rgba(232,93,4,.35);
}
.sidebar-brand strong { font-size: 1rem; line-height: 1.25; display: block; }
.sidebar-brand small { font-size: .68rem; color: #94a3b8; }
.sidebar-nav { padding: .75rem .65rem 2rem; }
.nav-section {
    font-size: .66rem; letter-spacing: .04em; color: #7c8aa3;
    padding: 1rem .75rem .4rem; text-transform: uppercase; font-weight: 700;
}
.sidebar .nav-link {
    color: #cbd5e1; border-radius: 9px; padding: .55rem .7rem;
    display: flex; align-items: center; gap: .6rem; font-size: .84rem;
    margin-bottom: .15rem; transition: .15s;
}
.sidebar .nav-link i { font-size: 1rem; width: 20px; text-align: center; opacity: .9; }
.sidebar .nav-link:hover { background: var(--sidebar-soft); color: #fff; }
.sidebar .nav-link.active {
    background: linear-gradient(90deg, rgba(232,93,4,.95), rgba(232,93,4,.75));
    color: #fff; box-shadow: 0 6px 14px rgba(232,93,4,.22);
}

/* Main */
.main-area { flex: 1 1 auto; min-width: 0; margin-inline-start: 264px; display: flex; flex-direction: column; }
.topbar {
    background: #fff; border-bottom: 1px solid var(--line);
    padding: .6rem 1.25rem; position: sticky; top: 0; z-index: 1030;
    display: flex; align-items: center; gap: .75rem;
}
.topbar .search-box { flex: 0 1 420px; position: relative; }
.topbar .search-box input { padding-inline-start: 2.2rem; background: #f8f9fb; }
.topbar .search-box i { position: absolute; inset-inline-start: .75rem; top: 50%; transform: translateY(-50%); color: #94a3b8; }
.content { padding: 1.35rem; flex: 1; }
.content-footer { padding: .9rem 1.35rem; color: var(--muted); font-size: .75rem; border-top: 1px solid var(--line); }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.15rem; }
.page-head h1 { font-size: 1.25rem; font-weight: 700; margin: 0; }
.page-head .subtitle { color: var(--muted); font-size: .78rem; margin-top: .15rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .45rem; }

/* Cards */
.card { border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: #fff; border-bottom: 1px solid var(--line); font-weight: 700; border-radius: 14px 14px 0 0 !important; padding: .8rem 1rem; }
.card-body { padding: 1rem; }
.card-title-sm { font-weight: 700; font-size: .95rem; margin: 0; }

.stat-card { border-radius: 14px; background: #fff; border: 1px solid var(--line); padding: 1rem; height: 100%; position: relative; overflow: hidden; }
.stat-card .label { color: var(--muted); font-size: .76rem; }
.stat-card .value { font-size: 1.4rem; font-weight: 700; margin-top: .25rem; }
.stat-card .icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1.15rem; background: var(--brand-soft); color: var(--brand); }
.stat-card .hint { font-size: .7rem; color: var(--muted); margin-top: .3rem; }
.stat-card.cash .icon { background: #e8f7ee; color: var(--success); }
.stat-card.receive .icon { background: #e7f1fe; color: #1d4ed8; }
.stat-card.pay .icon { background: #fdeaea; color: var(--danger); }
.stat-card.advance .icon { background: #f3ecff; color: #6d28d9; }

/* Tables */
.table { font-size: .82rem; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .55rem .65rem; }
.table thead th { background: #f8f9fb; color: #475569; font-weight: 700; font-size: .74rem; white-space: nowrap; border-bottom: 1px solid var(--line); }
.table-hover tbody tr:hover { background: #fffaf5; }
.table td { vertical-align: middle; }
.table-responsive { border-radius: 10px; }
.table-actions { display: flex; gap: .25rem; justify-content: flex-end; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; direction: ltr; text-align: inline-end; unicode-bidi: embed; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Badges */
.badge-soft { font-weight: 600; padding: .32em .6em; border-radius: 6px; font-size: .7rem; }
.badge-open { background: #eef2ff; color: #3730a3; }
.badge-completed, .badge-paid, .badge-posted { background: #e8f7ee; color: #166534; }
.badge-partial { background: #fff7e6; color: #92400e; }
.badge-cancelled, .badge-reversed, .badge-expired { background: #fdeaea; color: #991b1b; }
.badge-valid { background: #e8f7ee; color: #166534; }
.badge-expiring { background: #fff7e6; color: #92400e; }
.badge-unknown, .badge-muted { background: #f1f5f9; color: #475569; }
.badge-role { background: #eef2ff; color: #3730a3; }

/* Forms */
.form-label { font-size: .8rem; font-weight: 600; color: #374151; margin-bottom: .3rem; }
.form-control, .form-select { font-size: .84rem; border-radius: 8px; border-color: #d9dee6; padding: .45rem .65rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .18rem rgba(232,93,4,.12); }
.form-text { font-size: .7rem; }
.required::after { content: ' *'; color: var(--danger); }
.input-group-text { font-size: .8rem; background: #f8f9fb; }
fieldset.form-section { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; background: #fff; }
fieldset.form-section legend { float: none; width: auto; padding: 0 .45rem; font-size: .82rem; font-weight: 700; color: var(--brand-dark); margin-bottom: .5rem; }

.btn { font-size: .82rem; border-radius: 8px; font-weight: 600; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-soft { background: var(--brand-soft); color: var(--brand-dark); border: 1px solid #ffd8bb; }
.btn-soft:hover { background: #ffe3cc; color: var(--brand-dark); }
.btn-icon { padding: .28rem .45rem; line-height: 1; }

/* Misc */
.alert { border-radius: 10px; font-size: .82rem; border: 0; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.2rem; color: #cbd5e1; display: block; margin-bottom: .6rem; }

.filter-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .85rem; margin-bottom: 1rem; }
.filter-card .form-control, .filter-card .form-select { font-size: .8rem; }
.breadcrumb { font-size: .74rem; margin-bottom: .35rem; }
.breadcrumb-item + .breadcrumb-item::before { content: '/'; }

.kv { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: .35rem .75rem; font-size: .82rem; }
.kv dt { color: var(--muted); font-weight: 500; margin: 0; }
.kv dd { margin: 0; font-weight: 600; }

.money-positive { color: var(--success); }
.money-negative { color: var(--danger); }
.money-muted { color: var(--muted); }
.text-small { font-size: .74rem; }
.divider { height: 1px; background: var(--line); margin: 1rem 0; }

.login-page {
    min-height: 100vh; display: grid; place-items: center;
    background: radial-gradient(1200px 600px at 80% 10%, #ffd9bd 0%, transparent 55%), linear-gradient(135deg, #171d28, #2a3446);
    padding: 1.5rem;
}
.login-card { width: 100%; max-width: 430px; border-radius: 18px; background: #fff; box-shadow: 0 24px 60px rgba(0,0,0,.35); overflow: hidden; }
.login-head { background: linear-gradient(135deg, #ff8a3d, var(--brand)); color: #fff; padding: 1.6rem 1.5rem; }
.login-head .logo { width: 54px; height: 54px; border-radius: 14px; background: rgba(255,255,255,.18); display: grid; place-items: center; font-size: 1.6rem; margin-bottom: .75rem; }
.login-body { padding: 1.5rem; }

.nav-tabs .nav-link { font-size: .82rem; font-weight: 600; color: var(--muted); border: 0; border-bottom: 2px solid transparent; }
.nav-tabs .nav-link.active { color: var(--brand-dark); border-bottom-color: var(--brand); background: transparent; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding-inline-start: 1.25rem; padding-bottom: .85rem; border-inline-start: 2px solid #eef1f5; margin-inline-start: .35rem; }
.timeline li::before { content: ''; position: absolute; inset-inline-start: -.35rem; top: .2rem; width: .6rem; height: .6rem; border-radius: 50%; background: var(--brand); }
.timeline li:last-child { border-inline-start-color: transparent; padding-bottom: 0; }

.chart-wrap { position: relative; height: 260px; }

.doc-list { list-style: none; padding: 0; margin: 0; }
.doc-list li { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px dashed var(--line); font-size: .8rem; }
.doc-list li:last-child { border-bottom: 0; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 1035; }
.sidebar-backdrop.show { display: block; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    .sidebar.show { transform: translateX(0); }
    .main-area { margin-inline-start: 0; }
    .content { padding: .9rem; }
    .topbar { padding: .55rem .9rem; }
    .topbar .search-box { display: none; }
    .table-responsive { font-size: .78rem; }
}

@media print {
    .sidebar, .topbar, .content-footer, .page-actions, .no-print { display: none !important; }
    .main-area { margin: 0; }
    .content { padding: 0; }
    body { background: #fff; }
    .card { border: 0; box-shadow: none; }
}
