/* نظام إعداد القوائم المالية — التنسيق العام (كحلي/أزرق/أبيض، Cairo، RTL) */
@font-face { font-family: "Cairo"; src: url("../fonts/Cairo-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Cairo"; src: url("../fonts/Cairo-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
:root {
  --navy: #1e3a5f; --navy-2: #16304f; --blue: #2c6e9b; --blue-2: #4a9d9c;
  --bg: #f2f5f9; --card: #ffffff; --line: #dde4ec; --txt: #1d2733; --muted: #68737f;
  --ok: #1e7a45; --warn: #9a6a00; --err: #b3372f; --orange: #b0653a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: "Cairo", "Segoe UI", Tahoma, sans-serif; background: var(--bg); color: var(--txt); font-size: 14px; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== هيكل لوحة التحكم ===== */
.admin { display: grid; grid-template-columns: 250px 1fr; grid-template-rows: auto 1fr; grid-template-areas: "top top" "side main"; min-height: 100vh; }
.demo-mode { grid-template-rows: auto auto 1fr; grid-template-areas: "banner banner" "top top" "side main"; }
.demo-banner { grid-area: banner; background: var(--orange); color: #fff; text-align: center; padding: 8px 12px; font-weight: 700; }
.demo-banner a { color: #fff; text-decoration: underline; margin-right: 10px; }
.topbar { grid-area: top; background: var(--navy); color: #fff; display: flex; align-items: center; gap: 14px; padding: 10px 18px; position: sticky; top: 0; z-index: 30; }
.topbar .brand { font-weight: 800; font-size: 16px; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.icon-btn { background: rgba(255,255,255,.12); border: 0; color: #fff; font-size: 18px; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; }
.sel { padding: 7px 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.1); color: #fff; font-family: inherit; max-width: 230px; }
.sel option { color: #1d2733; }
.ctx-forms { display: inline-flex; }
.user-box { text-align: left; line-height: 1.25; }
.user-box .u-name { display: block; font-weight: 700; font-size: 13px; }
.user-box .u-role { font-size: 11.5px; opacity: .8; }
.logout-link { color: #fff; background: rgba(255,255,255,.12); padding: 7px 16px; border-radius: 8px; }
.logout-link:hover { background: rgba(255,255,255,.22); text-decoration: none; }

.sidebar { grid-area: side; background: var(--navy-2); color: #cfd9e4; overflow-y: auto; padding: 12px 0 30px; transition: width .2s; }
.nav-group { margin-bottom: 4px; }
.nav-group-head { width: 100%; background: transparent; border: 0; color: #9fb3c8; font-family: inherit; font-size: 12px; font-weight: 700; padding: 10px 16px 6px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; letter-spacing: .3px; }
.nav-group.closed .nav-items { display: none; }
.nav-group.closed .chev { transform: rotate(-90deg); }
.nav-item { display: block; color: #dce6ef; padding: 8.5px 18px; font-size: 13.5px; border-left: 3px solid transparent; }
.nav-item:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav-item.active { background: rgba(255,255,255,.1); border-left-color: var(--blue-2); font-weight: 700; color: #fff; }
body.sb-collapsed .sidebar { display: none; }
body.sb-collapsed.admin { grid-template-columns: 0 1fr; }

.content { grid-area: main; padding: 22px 26px 50px; max-width: 1400px; width: 100%; }
.page-title { color: var(--navy); font-size: 21px; margin-bottom: 18px; padding-bottom: 10px; border-bottom: 2px solid var(--line); }

/* ===== عناصر عامة ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; }
.card h2 { color: var(--navy); font-size: 16px; margin-bottom: 10px; }
.card h3 { color: var(--navy); font-size: 14.5px; margin-bottom: 8px; }
.err-card { border-right: 4px solid var(--err); }
.details summary { cursor: pointer; font-weight: 700; color: var(--navy); padding: 4px 0; }
.card-body { padding-top: 12px; }
.sec { color: var(--navy); font-size: 15.5px; margin: 22px 0 10px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat-v { font-size: 17px; font-weight: 800; color: var(--navy); }
.stat-l { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat-h { font-size: 11.5px; color: var(--blue); margin-top: 4px; }
.stat.blue .stat-v { color: var(--blue); } .stat.green .stat-v { color: var(--ok); }
.stat.red .stat-v { color: var(--err); } .stat.orange .stat-v { color: var(--orange); } .stat.navy .stat-v { color: var(--navy); }
.ok-t { color: var(--ok); } .err-t { color: var(--err); }

.kpis { display: flex; flex-wrap: wrap; gap: 14px; }
.kpi { background: #f6f9fc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; min-width: 130px; }
.kpi b { display: block; font-size: 17px; color: var(--navy); }
.kpi span { font-size: 11.5px; color: var(--muted); }
.kpi.bad { background: #fdeeec; border-color: #f2c4bf; } .kpi.bad b { color: var(--err); }
.kpi.warn { background: #fdf6e3; border-color: #ecd9a8; } .kpi.warn b { color: var(--warn); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.chart-box { width: 100%; min-height: 200px; }
.chart-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 40px 10px; }

/* جداول */
.tbl-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 18px; }
.tbl-wrap.stmt { border: 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 640px; }
.data-table th { background: #eef3f8; color: var(--navy); text-align: right; padding: 10px 12px; border-bottom: 2px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
.data-table td { padding: 9px 12px; border-bottom: 1px solid #edf1f6; vertical-align: middle; }
.data-table tr:hover td { background: #f8fafc; }
.data-table .amount { text-align: left; direction: ltr; font-weight: 600; white-space: nowrap; }
.data-table .neg { color: var(--err); }
.data-table .center { text-align: center; }
.data-table .total-row td { background: #f0f5fa; font-weight: 800; color: var(--navy); border-top: 2px solid var(--navy); }
.data-table .section-row td { background: #e8eef5; font-weight: 700; color: var(--navy); }
.data-table .empty-row { text-align: center; color: var(--muted); padding: 24px; }
.hint-cell { color: var(--muted); font-size: 12px; }
.samples { font-size: 11.5px; color: var(--muted); max-width: 220px; }
.sort-link { color: inherit; }
.drill { font-size: 11px; background: #eef3f8; padding: 2px 8px; border-radius: 20px; margin-right: 6px; }
.tbl-tools { display: flex; gap: 8px; margin-bottom: 12px; }
.tbl-tools input[type=search] { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; min-width: 260px; font-family: inherit; }

/* شارات */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.b-ok { background: #e5f4ea; color: var(--ok); } .b-warn { background: #fdf3df; color: var(--warn); }
.b-err { background: #fdeeec; color: var(--err); } .b-info { background: #e8f1f8; color: var(--blue); }
.b-muted { background: #eceff3; color: var(--muted); }

/* أزرار ونماذج */
.btn { display: inline-block; background: var(--blue); color: #fff; border: 0; padding: 9px 20px; border-radius: 8px; font-size: 13.5px; font-family: inherit; cursor: pointer; text-decoration: none !important; }
.btn:hover { background: var(--navy); }
.btn.ghost { background: #eef2f7; color: var(--navy); }
.btn.ghost:hover { background: #dfe7f0; }
.btn.sm { padding: 5px 12px; font-size: 12px; }
.btn.wide { width: 100%; }
.actions-bar { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 18px; align-items: center; }
.form { max-width: 100%; }
.form-actions { margin-top: 14px; display: flex; gap: 8px; }
.fld { margin-bottom: 10px; }
.fld label { display: block; font-size: 12.5px; color: var(--muted); font-weight: 700; margin-bottom: 5px; }
.fld input, .fld select, .fld textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 13.5px; background: #fbfcfe; }
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: 2px solid rgba(44,110,155,.25); border-color: var(--blue); }
.fld textarea { min-height: 90px; }
.fld-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; }
.fld.wide { grid-column: 1 / -1; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.msg { padding: 11px 14px; border-radius: 9px; font-size: 13.5px; margin-bottom: 14px; }
.msg.err { background: #fdecea; color: var(--err); border: 1px solid #f2c4bf; }
.msg.ok { background: #e8f6ee; color: var(--ok); border: 1px solid #bfe5cd; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; }
.inline-form input[type=text] { padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; font-family: inherit; width: 160px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; }
.check-inline { display: inline-flex; align-items: center; gap: 5px; margin: 0 14px 6px 0; font-size: 13px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { padding: 8px 18px; border-radius: 8px 8px 0 0; background: #e8eef5; color: var(--navy); font-weight: 700; }
.tab.on { background: var(--navy); color: #fff; }
.perms-list { padding-right: 18px; margin: 10px 0; }
.perms-list li { margin: 6px 0; font-size: 12.5px; color: var(--muted); }
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.report-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; color: var(--navy); font-weight: 700; }
.report-card span { background: #eef3f8; padding: 3px 10px; border-radius: 16px; font-size: 11.5px; color: var(--blue); }
.report-card:hover { border-color: var(--blue); text-decoration: none; }

/* ===== صفحة الدخول ===== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg, var(--navy) 0%, #274b77 60%, var(--blue) 100%); padding: 20px; }
.login-box { background: #fff; border-radius: 16px; width: 100%; max-width: 420px; padding: 30px 32px; }
.login-head { text-align: center; margin-bottom: 20px; }
.login-head h1 { color: var(--navy); font-size: 20px; }
.login-head p { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.login-alt { margin-top: 14px; }
.login-note { font-size: 11px; color: var(--muted); margin-top: 16px; line-height: 1.8; }

/* ===== واجهة الزوار ===== */
.public { background: #fff; }
.p-header { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 40; box-shadow: 0 2px 14px rgba(22,48,79,.25); }
.p-header-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 18px; padding: 14px 22px; flex-wrap: wrap; }
.p-logo { font-weight: 800; font-size: 17px; }
.p-nav { display: flex; gap: 4px; flex-wrap: wrap; margin-right: auto; }
.p-nav a { color: #dbe6f0; padding: 7px 12px; border-radius: 8px; font-size: 13px; }
.p-nav a:hover { background: rgba(255,255,255,.1); text-decoration: none; color: #fff; }
.p-cta { background: var(--blue-2); color: #fff; padding: 9px 20px; border-radius: 8px; font-weight: 700; }
.p-cta:hover { background: #fff; color: var(--navy); }
.p-hero { background: linear-gradient(150deg, var(--navy) 30%, #2a5586); color: #fff; padding: 70px 22px 80px; }
.p-hero-in { max-width: 1180px; margin: 0 auto; display: grid; grid-template-columns: 1.15fr .85fr; gap: 40px; align-items: center; }
.p-hero h1 { font-size: 34px; line-height: 1.45; font-weight: 800; }
.p-hero p.lead { font-size: 16.5px; color: #c9d8e6; margin: 18px 0 26px; line-height: 2; }
.p-hero .hero-img { width: 100%; border-radius: 16px; box-shadow: 0 18px 50px rgba(0,0,0,.35); }
.p-section { max-width: 1180px; margin: 0 auto; padding: 55px 22px; }
.p-section h2 { color: var(--navy); font-size: 25px; margin-bottom: 8px; }
.p-section .sub { color: var(--muted); margin-bottom: 30px; max-width: 720px; line-height: 1.9; }
.p-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 18px; }
.p-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.p-card h3 { color: var(--navy); font-size: 15.5px; margin-bottom: 8px; }
.p-card p { color: var(--muted); font-size: 13px; line-height: 1.9; }
.p-num { display: inline-block; background: var(--navy); color: #fff; width: 34px; height: 34px; line-height: 34px; text-align: center; border-radius: 50%; font-weight: 800; margin-bottom: 12px; }
.p-alt { background: var(--bg); }
.p-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; }
.p-faq details { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin-bottom: 10px; }
.p-faq summary { font-weight: 700; color: var(--navy); cursor: pointer; }
.p-faq details p { color: var(--muted); font-size: 13.5px; line-height: 1.9; padding-top: 10px; }
.p-cta-band { background: var(--navy); color: #fff; text-align: center; padding: 60px 22px; }
.p-cta-band h2 { color: #fff; }
.p-cta-band p { color: #c9d8e6; margin: 10px 0 24px; }
.p-footer { background: var(--navy-2); color: #9fb3c8; padding: 34px 22px; font-size: 12.5px; }
.p-footer-in { max-width: 1180px; margin: 0 auto; display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.p-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 720px; }
.p-form .wide { grid-column: 1/-1; }
.p-form input, .p-form textarea { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px; font-family: inherit; }
.p-form textarea { min-height: 110px; }

/* تجاوب */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
  .p-hero-in { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .admin, .demo-mode.admin { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "banner" "top" "main"; }
  .admin:not(.demo-mode) { grid-template-rows: auto 1fr; grid-template-areas: "top" "main"; }
  .sidebar { display: none; position: fixed; top: 0; right: 0; width: 270px; height: 100vh; z-index: 70; grid-area: auto; overflow-y: auto; }
  body.sb-open .sidebar { display: block; box-shadow: -8px 0 30px rgba(0,0,0,.35); }
  .content { padding: 14px 12px 40px; }
  .page-title { font-size: 17px; }
  .fld-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .topbar .brand { font-size: 14px; }
  .ctx-forms { display: flex; width: 100%; min-width: 0; }
  .ctx-forms .sel { width: 100%; min-width: 0; text-overflow: ellipsis; }
  .ctx-forms .sel { flex: 1 1 auto; max-width: none; min-width: 0; }
  .user-box { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .data-table { min-width: 560px; }
  .p-hero h1 { font-size: 25px; }
  .p-form { grid-template-columns: 1fr; }
  .p-nav { display: none; }
}
