/* عقاراتي — واجهة متجاوبة (موبايل أولاً) */
:root {
  --brand: #0f5f5c;
  --brand-600: #0b4b48;
  --brand-50: #e7f2f1;
  --gold: #c8932f;
  --ink: #17212b;
  --muted: #6a7682;
  --line: #e4e8ec;
  --bg: #f3f5f7;
  --card: #ffffff;
  --pos: #12804a;
  --neg: #c62828;
  --radius: 14px;
  --sidebar-w: 264px;
  --bottom-h: 64px;
  --bs-primary: #0f5f5c;
  --bs-primary-rgb: 15, 95, 92;
  --bs-link-color: #0f5f5c;
  --bs-link-color-rgb: 15, 95, 92;
  --bs-link-hover-color: #0b4b48;
  --bs-body-font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --bs-body-color: #17212b;
  --bs-border-color: #e4e8ec;
  --bs-success: #12804a;
  --bs-success-rgb: 18, 128, 74;
  --bs-danger-rgb: 198, 40, 40;
}

html { -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--bs-body-font-family); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
a { text-decoration: none; }
.text-success { color: var(--pos) !important; }
.text-danger { color: var(--neg) !important; }

/* أزرار */
.btn { border-radius: 10px; font-weight: 500; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-600); --bs-btn-hover-border-color: var(--brand-600); --bs-btn-active-bg: var(--brand-600); --bs-btn-active-border-color: var(--brand-600); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand); --bs-btn-active-border-color: var(--brand); }
.btn-success { --bs-btn-bg: var(--pos); --bs-btn-border-color: var(--pos); --bs-btn-hover-bg: #0e6a3d; --bs-btn-hover-border-color: #0e6a3d; }
.btn-light { --bs-btn-bg: #eef1f4; --bs-btn-border-color: #eef1f4; --bs-btn-hover-bg: #e2e7ec; --bs-btn-hover-border-color: #e2e7ec; }
.form-control, .form-select { border-radius: 10px; border-color: #d8dee4; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(15, 95, 92, .15); }
.form-label { font-size: .86rem; font-weight: 500; color: #3d4954; margin-bottom: .3rem; }
.form-label.req::after { content: ' *'; color: var(--neg); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.page-link { color: var(--brand); }
.active > .page-link, .page-link.active { background: var(--brand); border-color: var(--brand); }
.progress-bar.bg-success { background: var(--pos) !important; }

/* الهيكل */
.sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar-w); background: #0d2b2f; color: #fff; flex-direction: column; padding: 18px 14px; z-index: 1030; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.12rem; padding: 4px 8px 18px; }
.brand:hover { color: #fff; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg, #14837e, #0f5f5c); display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 1.15rem; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
.brand-mark.lg { width: 64px; height: 64px; border-radius: 18px; font-size: 1.9rem; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav .nav-link { display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,.72); padding: 10px 12px; border-radius: 10px; font-weight: 500; }
.side-nav .nav-link i { font-size: 1.1rem; width: 22px; text-align: center; }
.side-nav .nav-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.side-nav .nav-link.active { color: #fff; background: rgba(20, 131, 126, .55); box-shadow: inset 3px 0 0 var(--gold); }
.side-user { margin-top: auto; padding: 14px 12px 4px; border-top: 1px solid rgba(255,255,255,.1); color: #fff; }
.drawer { background: #0d2b2f; color: #fff; width: 290px !important; }
.drawer .offcanvas-header { padding-bottom: 0; }
.drawer .side-user { margin-top: 12px; }

.main { min-height: 100vh; }
@media (min-width: 992px) { .main { margin-inline-start: var(--sidebar-w); } }
.topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: 8px; height: 60px; padding: 0 14px; padding-top: env(safe-area-inset-top); background: rgba(255,255,255,.92); backdrop-filter: saturate(160%) blur(10px); -webkit-backdrop-filter: saturate(160%) blur(10px); border-bottom: 1px solid var(--line); }
.topbar-title { font-size: 1.08rem; font-weight: 700; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; font-size: 1.35rem; color: var(--ink); }
.icon-btn:hover { background: #eef1f4; color: var(--ink); }
.content { padding: 16px; max-width: 1400px; }
@media (min-width: 992px) { .content { padding: 22px 26px; } }

.bottom-nav { position: fixed; inset-inline: 0; bottom: 0; z-index: 1025; display: grid; grid-template-columns: repeat(5, 1fr); 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); box-shadow: 0 -4px 18px rgba(16, 24, 40, .05); }
.bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: #7a8692; font-size: .72rem; font-weight: 500; }
.bottom-nav a i { font-size: 1.3rem; }
.bottom-nav a.active { color: var(--brand); }
.bottom-nav a.active i { transform: translateY(-1px); }
@media (max-width: 991.98px) { .main:not(.main-guest) .content { padding-bottom: calc(var(--bottom-h) + 24px + env(safe-area-inset-bottom)); } }

/* البطاقات */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; }
.card-header > span > i, .card-header > span i.bi:first-child { color: var(--brand); margin-inline-end: 4px; }
.card-footer { background: #fafbfc; border-top: 1px solid var(--line); }
.list-group-item { border-color: var(--line); }

.page-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.section-title { font-size: 1rem; font-weight: 700; margin: 6px 0 12px; color: #2b3640; }
.period-form { display: flex; gap: 6px; align-items: center; font-weight: 400; }
.period-form .form-control { min-width: 0; }
@media (max-width: 575.98px) { .period-form { width: 100%; } .period-form .form-control { flex: 1; } }
.main, .content { min-width: 0; }
.fin-table td { word-break: break-word; }

.hero-card { background: linear-gradient(135deg, #0f5f5c 0%, #0d4643 60%, #12302f 100%); color: #fff; border-radius: 18px; padding: 18px 18px 14px; box-shadow: 0 10px 30px -12px rgba(15, 95, 92, .55); }
.hero-label { font-size: .85rem; opacity: .8; }
.hero-value { font-size: 1.9rem; font-weight: 700; line-height: 1.25; letter-spacing: -.5px; }
.hero-value small { font-size: .9rem; opacity: .75; font-weight: 500; }
.hero-sub { font-size: .75rem; opacity: .65; }
.hero-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.15); }
.hero-grid > div { display: flex; flex-direction: column; }
.hero-grid span { font-size: .75rem; opacity: .75; }
.hero-grid b { font-size: 1.02rem; font-weight: 600; }
@media (min-width: 768px) { .hero-grid { grid-template-columns: repeat(4, 1fr); } .hero-value { font-size: 2.2rem; } }
.hero-card.slim .hero-value { font-size: 1.7rem; }

.kpi { padding: 14px; color: var(--ink); display: block; }
a.kpi:hover { border-color: #cfd8df; color: var(--ink); }
.kpi-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--brand-50); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem; margin-bottom: 8px; }
.kpi-icon.bg-gold { background: #fbf1de; color: #a8761d; }
.kpi-icon.bg-rose { background: #fdecec; color: #b42323; }
.kpi-icon.bg-sky { background: #e8f1fb; color: #1d5fa8; }
.kpi-label { font-size: .78rem; color: var(--muted); }
.kpi-value { font-size: 1.22rem; font-weight: 700; }

.mini-stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; height: 100%; display: flex; flex-direction: column; }
.mini-stat span { font-size: .76rem; color: var(--muted); }
.mini-stat b { font-size: 1.1rem; font-weight: 700; }
.mini-stat small { font-size: .74rem; color: var(--muted); }
.mini-stat.accent { background: var(--brand-50); border-color: #cfe4e2; }
.mini-stat.good b { color: var(--pos); }
.mini-stat.bad b { color: var(--neg); }
.mini-stat.warn { background: #fff8eb; border-color: #f3e0b5; }
.mini-stat.warn b { color: #9a6200; }

.stat-strip { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.stat-strip::-webkit-scrollbar { display: none; }
.stat-strip > div { flex: 1 0 auto; min-width: 128px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; display: flex; flex-direction: column; }
.stat-strip span { font-size: .74rem; color: var(--muted); white-space: nowrap; }
.stat-strip b { font-size: 1.02rem; font-weight: 700; white-space: nowrap; }
.stat-strip small { font-size: .72rem; color: var(--muted); white-space: nowrap; }

.quick-tile { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; color: var(--ink); font-weight: 600; }
.quick-tile i { font-size: 1.3rem; color: var(--brand); }
.quick-tile:hover { border-color: var(--brand); color: var(--brand); }

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

/* الشارات */
.badge { font-weight: 600; border-radius: 7px; padding: .38em .6em; }
.badge-soft-primary { background: var(--brand-50); color: var(--brand); }
.badge-soft-success { background: #e4f4ea; color: #0f6b3e; }
.badge-soft-danger { background: #fdeaea; color: #ad1f1f; }
.badge-soft-warning { background: #fff3d6; color: #8a5a00; }
.badge-soft-info { background: #e5f0fb; color: #1b5796; }
.badge-soft-secondary { background: #eef1f4; color: #4f5b66; }
.code-chip { display: inline-block; font-size: .74rem; font-weight: 600; background: #eef1f4; color: #3c4852; border-radius: 6px; padding: 1px 6px; direction: ltr; unicode-bidi: isolate; }

.acc-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 8px; background: #9aa5b1; vertical-align: middle; }
.acc-dot.type-cash { background: var(--brand); } .acc-dot.type-bank { background: #1d5fa8; } .acc-dot.type-exchange { background: #7b4bc2; } .acc-dot.type-profit { background: var(--gold); }
.acc-card { border-top: 4px solid #9aa5b1; overflow: hidden; }
.acc-card.type-cash { border-top-color: var(--brand); } .acc-card.type-bank { border-top-color: #1d5fa8; } .acc-card.type-exchange { border-top-color: #7b4bc2; } .acc-card.type-profit { border-top-color: var(--gold); }
.acc-card.inactive { opacity: .6; }
.acc-type { font-size: .78rem; color: var(--muted); }
.acc-name { font-weight: 700; font-size: 1.05rem; }
.acc-balance { font-size: 1.55rem; font-weight: 700; margin: 8px 0 6px; }
.acc-balance small { font-size: .8rem; color: var(--muted); font-weight: 500; }
.acc-flow { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); flex-wrap: wrap; }

/* الفلاتر */
.filter-bar .card-body { padding: 12px; }
.filter-bar .form-label { font-size: .78rem; color: var(--muted); }
.filter-count { position: absolute; top: -6px; inset-inline-end: -6px; background: var(--gold); color: #fff; border-radius: 10px; font-size: .68rem; min-width: 18px; height: 18px; line-height: 18px; text-align: center; padding: 0 4px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: .84rem; color: #3d4954; cursor: pointer; }
.chip.active, .btn-check:checked + .chip { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-del button { border: 0; background: transparent; padding: 0; color: #9aa5b1; line-height: 1; }
.chip-del button:hover { color: var(--neg); }
@media (max-width: 767.98px) { .chip-row:not(.chip-pick) { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; } .chip-row::-webkit-scrollbar { display: none; } .chip { white-space: nowrap; } }

.seg { display: flex; gap: 6px; background: #eef1f4; padding: 4px; border-radius: 12px; }
.seg .btn { flex: 1; border: 0; border-radius: 9px; color: #4f5b66; font-weight: 600; padding: 9px 6px; }
.seg .btn-check:checked + .btn { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(16, 24, 40, .1); }
.seg.seg-wrap { flex-wrap: wrap; }
.seg.seg-wrap .btn { flex: 1 0 auto; }
.seg-tabs { gap: 6px; background: #eef1f4; padding: 4px; border-radius: 12px; flex-wrap: nowrap; }
.seg-tabs .nav-item { flex: 1; }
.seg-tabs .nav-link { color: #4f5b66; font-weight: 600; text-align: center; border-radius: 9px; padding: 9px 6px; font-size: .9rem; }
.seg-tabs .nav-link.active { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(16, 24, 40, .1); }

.soft-box { background: #f6f8fa; border: 1px dashed #d5dce2; border-radius: 12px; padding: 12px; }
.calc-box { display: flex; gap: 8px; flex-wrap: wrap; background: var(--brand-50); border-radius: 12px; padding: 10px 12px; height: 100%; align-items: center; }
.calc-box > div { flex: 1 0 auto; display: flex; flex-direction: column; }
.calc-box span { font-size: .75rem; color: var(--muted); }
.calc-box b { font-size: 1.05rem; }
.notes-box { background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: .9rem; white-space: normal; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0 0 10px; font-size: .92rem; }
.details dt { color: var(--muted); font-weight: 500; }
.details dd { margin: 0; }

.form-page .card-body { padding: 16px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 575.98px) {
  .form-actions { position: sticky; bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(243,245,247,0), var(--bg) 30%); padding: 14px 0 6px; z-index: 5; }
  .form-actions .btn { flex: 1; }
}

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state i { font-size: 2.6rem; color: #b7c2cc; display: block; margin-bottom: 8px; }

/* الجداول */
.table { --bs-table-hover-bg: #f7f9fa; margin: 0; }
.table > :not(caption) > * > * { padding: .7rem .8rem; border-bottom-color: var(--line); }
.table thead th { font-size: .78rem; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
.table tfoot td { background: #f6f8fa; font-weight: 600; }
.row-overdue > td { background: #fff7f7 !important; }
.list-card { overflow: hidden; }

@media (max-width: 767.98px) {
  .list-card { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .list-card > .card-header { background: transparent; border: 0; padding: 4px 2px 10px; }
  .card .table-rc { margin: 0; }
  .table-rc thead { display: none; }
  .table-rc, .table-rc tbody, .table-rc tfoot, .table-rc tr, .table-rc td { display: block; width: 100%; }
  .table-rc tr { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; padding: 8px 12px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
  .card:not(.list-card) .table-rc tr { border-inline: 0; border-radius: 0; margin: 0; box-shadow: none; border-top: 0; }
  .table-rc td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0 !important; border: 0 !important; text-align: start !important; background: transparent !important; }
  .table-rc td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .78rem; font-weight: 500; flex-shrink: 0; }
  .table-rc td > * { text-align: end; }
  .table-rc td.rc-title { display: block; font-weight: 600; font-size: .98rem; padding-bottom: 8px !important; margin-bottom: 4px; border-bottom: 1px dashed var(--line) !important; }
  .table-rc td.rc-title > * { text-align: start; }
  .table-rc td.rc-actions { justify-content: flex-end; padding-top: 8px !important; gap: 6px; }
  .table-rc td.rc-actions:empty { display: none; }
  .table-rc tr.rc-empty td { justify-content: center; }
  .table-rc tfoot tr { background: var(--brand-50); border-color: #cfe4e2; }
  .table-rc tfoot td:empty { display: none; }
  .table-rc .d-none.d-md-table-cell { display: none !important; }
  /* نسخة مضغوطة: عمودان داخل كل بطاقة */
  .table-rc.rc-compact tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; }
  .table-rc.rc-compact td { flex-direction: column; align-items: flex-start; gap: 0; padding: 3px 0 !important; }
  .table-rc.rc-compact td[data-label]::before { font-size: .72rem; }
  .table-rc.rc-compact td.rc-title, .table-rc.rc-compact td.rc-actions, .table-rc.rc-compact tr.rc-empty td { grid-column: 1 / -1; }
  .table-rc.rc-compact td.rc-actions { flex-direction: row; align-items: center; }
  .table-rc.rc-compact tfoot tr { display: flex; justify-content: space-between; }
}

/* المرفقات */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.file-item { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fafbfc; }
.file-item img, .file-icon { width: 100%; aspect-ratio: 1; object-fit: cover; display: flex; align-items: center; justify-content: center; font-size: 2rem; color: #c0392b; }
.file-name { font-size: .7rem; padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.file-del { position: absolute; top: 4px; inset-inline-end: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; display: flex; align-items: center; justify-content: center; padding: 0; }

/* التقارير */
.fin-table td { padding: .6rem 1rem; }
.fin-table tr.grp td { background: #fafbfc; font-size: .78rem; color: var(--muted); font-weight: 600; }
.fin-table tr.sub td { font-weight: 600; background: #f6f8fa; }
.fin-table tr.total td { font-weight: 700; font-size: 1.05rem; background: var(--brand-50); color: var(--brand-600); border-bottom: 0; }
.bar-row { margin-bottom: 10px; }
.bar { height: 7px; background: #eef1f4; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar span { display: block; height: 100%; background: var(--gold); border-radius: 4px; }

/* الدخول */
body.guest { min-height: 100vh; background: radial-gradient(1200px 600px at 100% -10%, #d7ebe9 0%, transparent 60%), var(--bg); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 28px 24px; box-shadow: 0 20px 50px -24px rgba(15, 95, 92, .35); }

/* الطباعة */
.print-page { background: #e9edf0; }
.print-toolbar { display: flex; gap: 8px; justify-content: center; padding: 14px; }
.print-sheet { background: #fff; max-width: 820px; margin: 0 auto 30px; padding: 28px; border-radius: 6px; box-shadow: 0 4px 20px rgba(0,0,0,.08); }
.print-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; border-bottom: 2px solid var(--brand); padding-bottom: 12px; margin-bottom: 18px; }
.print-brand { font-weight: 700; font-size: 1.2rem; color: var(--brand); }
.print-title { font-size: 1.15rem; font-weight: 700; margin: 0; }
.receipt-amount { background: var(--brand-50); border-radius: 10px; padding: 14px; display: flex; justify-content: space-between; align-items: center; }
.receipt-amount b { font-size: 1.5rem; color: var(--brand-600); }
.sign-row { display: flex; justify-content: space-between; margin-top: 50px; text-align: center; }
.sign-row > div { width: 40%; border-top: 1px solid #999; padding-top: 6px; font-size: .9rem; }
.sign-row span { color: var(--muted); font-size: .8rem; }

@media print {
  body, .print-page { background: #fff !important; }
  .sidebar, .topbar, .bottom-nav, .page-actions, .no-print, .filter-bar, .alert .btn-close, .rc-actions, .print-toolbar { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0 !important; max-width: none; }
  .print-sheet { box-shadow: none; padding: 0; margin: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .hero-card { color: #000; background: #fff !important; border: 1px solid #ccc; box-shadow: none; }
  a { color: inherit !important; }
}
