:root {
    --brand: #005b3a; --brand-dark: #00452c; --brand-soft: #e3f1ea; --ink: #101417;
    --g1: #46935d; --g2: #2a6336; --d1: #394050; --d2: #10141f;
    --bg: #f3f5f7; --card: #fff; --text: #101417; --muted: #6b7785; --line: #e4e8ec;
    --bar-h: 56px; --bottom-h: 64px; --side-w: 250px;
}
html { -webkit-text-size-adjust: 100%; }
body { font-family: 'Cairo', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 16px; }
a { color: var(--brand); }
.btn-success { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark); --bs-btn-active-bg: var(--brand-dark); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-success { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); }
.btn, .form-control, .form-select { min-height: 46px; border-radius: 12px; }
.btn-sm { min-height: 36px; border-radius: 10px; }
.form-control, .form-select { font-size: 16px; }      /* يمنع تكبير الصفحة تلقائياً في iPhone */
.form-label { font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
textarea.form-control { min-height: 0; }

/* ---------- الهيكل ---------- */
.appbar { position: sticky; top: 0; z-index: 1030; height: calc(var(--bar-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0; display: flex; align-items: center; gap: 10px; background: #fff; color: var(--text); border-bottom: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.appbar .brand { display: flex; align-items: center; text-decoration: none; }
.brand-logo { height: 34px; width: auto; display: block; }
.auth-logo { width: 220px; max-width: 70%; height: auto; }
.appbar-title { flex: 1; text-align: center; font-weight: 700; color: var(--brand); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page { padding: 14px 12px calc(var(--bottom-h) + 28px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.sidebar { display: none; }
.bottombar { position: fixed; bottom: 0; inset-inline: 0; z-index: 1030; height: calc(var(--bottom-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--line); display: flex; align-items: stretch; justify-content: space-around; box-shadow: 0 -2px 10px rgba(0,0,0,.06); }
.b-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--muted); text-decoration: none; background: none; border: 0; font-size: .72rem; font-family: inherit; }
.b-item i { font-size: 1.35rem; line-height: 1; }
.b-item.active { color: var(--brand); font-weight: 700; }
.b-fab { width: 58px; height: 58px; border-radius: 50%; border: 0; background: linear-gradient(160deg, var(--g1), var(--g2)); color: #fff; font-size: 1.7rem; margin-top: -22px; align-self: flex-start; box-shadow: 0 6px 16px rgba(0,91,58,.45); display: flex; align-items: center; justify-content: center; }
.sheet { border-radius: 20px 20px 0 0; max-height: 80vh; }
.sheet-tall { height: auto; }
.more-links { display: flex; flex-direction: column; }
.more-links .nav-item-link { padding: 14px 20px; border-bottom: 1px solid var(--line); }
.nav-item-link { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; padding: 11px 18px; font-weight: 600; }
.nav-item-link i { font-size: 1.2rem; color: var(--brand); width: 24px; text-align: center; }
.nav-item-link.active { background: var(--brand-soft); color: var(--brand-dark); }
.nav-sep { padding: 10px 18px 4px; font-size: .78rem; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 10px; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 8px; padding: 4px 2px; text-decoration: none; font-weight: 700; font-size: .85rem; text-align: center; color: var(--ink); background: none; }
.tile i { width: 64px; height: 64px; border-radius: 18px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.8rem; background: linear-gradient(160deg, var(--g1), var(--g2)); box-shadow: 0 6px 12px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.28); }
.tile.t-dark i { background: linear-gradient(160deg, var(--d1), var(--d2)); }
.tile:active i { transform: scale(.95); }

@media (min-width: 992px) {
    .sidebar { display: block; position: fixed; top: var(--bar-h); bottom: 0; inset-inline-start: 0; width: var(--side-w); background: #fff; border-inline-end: 1px solid var(--line); overflow-y: auto; padding-top: 8px; z-index: 1020; }
    body.has-shell .page { margin-inline-start: var(--side-w); max-width: none; padding: 22px 28px 40px; }
    body.has-shell .page > * { max-width: 1000px; }
    .bottombar { display: none; }
    .tiles { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- مكونات ---------- */
.card-lite { background: var(--card); border-radius: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); padding: 14px; margin-bottom: 12px; }
.card-lite h6 { font-weight: 700; margin-bottom: 10px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.page-head h4 { margin: 0; font-weight: 700; font-size: 1.25rem; }
.row-item { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 12px; margin-bottom: 8px; text-decoration: none; color: inherit; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.row-item:active { background: #f8faf9; }
.row-icon { width: 42px; height: 42px; flex: none; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; background: var(--brand-soft); color: var(--brand); }
.row-icon.i-primary { background: #e8eaf6; color: #283593; } .row-icon.i-warning { background: #fff4e0; color: #9a5b00; }
.row-icon.i-danger { background: #fdecea; color: #b71c1c; } .row-icon.i-secondary { background: #eceff1; color: #455a64; } .row-icon.i-info { background: #e3f2fd; color: #0b5394; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: .82rem; color: var(--muted); }
.row-amt { text-align: end; font-weight: 700; white-space: nowrap; }
.row-amt small { display: block; font-weight: 400; font-size: .75rem; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
@media (min-width: 768px) { .stat-grid.cols-4 { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border-radius: 16px; padding: 12px 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border-inline-start: 5px solid var(--brand); }
.stat .lbl { font-size: .8rem; color: var(--muted); } .stat .val { font-size: 1.25rem; font-weight: 700; }
.stat.s-blue { border-color: #1976d2; } .stat.s-red { border-color: #d32f2f; } .stat.s-orange { border-color: #f57c00; } .stat.s-purple { border-color: #7b1fa2; }
.pos { color: #2a6336; } .neg { color: #c62828; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: .88rem; font-weight: 600; white-space: nowrap; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; } .empty i { font-size: 2.5rem; display: block; margin-bottom: 6px; opacity: .5; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--line); } .kv:last-child { border-bottom: 0; }
.kv.total { font-weight: 700; font-size: 1.1rem; }
.fab-add { position: fixed; inset-inline-end: 16px; bottom: calc(var(--bottom-h) + 18px + env(safe-area-inset-bottom)); z-index: 1000; width: 54px; height: 54px; border-radius: 50%; background: linear-gradient(160deg, var(--g1), var(--g2)); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; text-decoration: none; box-shadow: 0 6px 16px rgba(0,0,0,.25); }
@media (min-width: 992px) { .fab-add { bottom: 24px; } }
.auth-box { max-width: 440px; margin: 0 auto; padding: 28px 14px; }
.search-box { position: relative; }
.search-results { position: absolute; z-index: 20; inset-inline: 0; top: 100%; max-height: 300px; overflow-y: auto; background: #fff; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.search-results button { display: flex; width: 100%; justify-content: space-between; gap: 8px; text-align: start; border: 0; background: none; padding: 12px; border-bottom: 1px solid var(--line); font-family: inherit; }
.search-results button:active { background: var(--brand-soft); }

/* ---------- سطور الفاتورة ---------- */
.line { background: #fff; border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.line .l-name { font-weight: 700; }
.line .stepper { display: flex; align-items: stretch; }
.line .stepper button { width: 42px; border: 1px solid var(--line); background: #f5f7f8; font-size: 1.3rem; line-height: 1; }
.line .stepper button:first-child { border-radius: 0 12px 12px 0; } .line .stepper button:last-child { border-radius: 12px 0 0 12px; }
.line .stepper input { width: 64px; text-align: center; border-radius: 0; border-inline: 0; }
.line .l-total { font-weight: 700; min-width: 80px; text-align: end; }
.sticky-total { position: sticky; bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom)); z-index: 900; background: #fff; border-radius: 16px; box-shadow: 0 -4px 18px rgba(0,0,0,.15); padding: 10px 14px; margin-top: 10px; }
@media (min-width: 992px) { .sticky-total { bottom: 12px; } }

/* ---------- الطباعة ---------- */
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .page { margin: 0 !important; padding: 0 !important; max-width: none !important; }
    .card-lite, .row-item, .stat { box-shadow: none !important; border: 1px solid #ccc; }
    .print-header { border-bottom: 2px solid #000; margin-bottom: 12px; padding-bottom: 6px; }
}
