:root {
  --bg: #f4f6f8; --panel: #ffffff; --ink: #1f2933; --muted: #64748b; --line: #e2e8f0; --line-strong: #cbd5e1;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e6f4f2; --side: #102a2a; --side-ink: #cfe3e0; --side-hover: #18403d;
  --danger: #b42318; --danger-soft: #fdecea; --warn: #b54708; --warn-soft: #fff4e5; --ok: #067647; --ok-soft: #e7f6ec; --info-soft: #eaf2ff;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 16px; margin: 0 0 10px; } h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); } .right { text-align: right; } .center { text-align: center; } .nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* ---- Layout ---- */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.layout.collapsed { grid-template-columns: 0 1fr; }
.sidebar { background: var(--side); color: var(--side-ink); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.layout.collapsed .sidebar { overflow: hidden; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; color: #fff; font-weight: 700; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--side-ink); }
.menu-search { margin: 0 12px 8px; width: calc(100% - 24px); background: #183936; border: 1px solid #23504c; color: #fff; border-radius: 6px; padding: 7px 10px; }
.menu-search::placeholder { color: #8fb3ae; }
.nav-group > button { all: unset; box-sizing: border-box; cursor: pointer; display: flex; width: 100%; align-items: center; justify-content: space-between; padding: 9px 16px; font-weight: 600; color: #e9f5f3; }
.nav-group > button:hover { background: var(--side-hover); }
.nav-group .chev { transition: transform .15s; opacity: .7; }
.nav-group.open .chev { transform: rotate(90deg); }
.nav-items { display: none; padding-bottom: 6px; }
.nav-group.open .nav-items { display: block; }
.nav-section { padding: 8px 16px 2px 28px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #7fa7a1; }
.nav-items a { display: flex; justify-content: space-between; padding: 6px 16px 6px 28px; color: var(--side-ink); font-size: 13px; border-left: 3px solid transparent; }
.nav-items a:hover { background: var(--side-hover); color: #fff; }
.nav-items a.active { border-left-color: #5eead4; background: var(--side-hover); color: #fff; }
.nav-items a .star { opacity: 0; cursor: pointer; color: #fcd34d; }
.nav-items a:hover .star, .nav-items a .star.on { opacity: 1; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 20px; position: sticky; top: 0; z-index: 20; }
.topbar .crumbs { color: var(--muted); font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumbs b { color: var(--ink); }
.content { padding: 20px; flex: 1; }
.footer { padding: 10px 20px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); background: var(--panel); }

/* ---- Components ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card.tight { padding: 0; }
.card > .card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -16px -16px 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.card.tight > .card-head { margin: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: #f4b4ad; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.link { border: none; background: none; color: var(--brand); padding: 2px 4px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { all: unset; cursor: pointer; padding: 6px; border-radius: 6px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: #eef2f6; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #eef2f6; color: #334155; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); } .badge.info { background: var(--info-soft); color: #1d4ed8; }

/* forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.span-2 { grid-column: span 2; } .field.span-3 { grid-column: span 3; } .field.span-all { grid-column: 1 / -1; }
.field > label { font-size: 12px; font-weight: 600; color: #475569; }
.field > label .req { color: var(--danger); }
.field.check { flex-direction: row; align-items: center; gap: 8px; padding-top: 18px; }
.field.check > label { order: 2; font-weight: 500; color: var(--ink); font-size: 13px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 9px; background: #fff; min-height: 34px; }
.input:focus { outline: 2px solid #99f6e4; border-color: var(--brand); }
.input[readonly], .input:disabled { background: #f8fafc; color: #475569; }
textarea.input { min-height: 64px; resize: vertical; }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.field .hint { font-size: 11px; color: var(--muted); }
.field.invalid .input { border-color: var(--danger); }
.combo { position: relative; }
.combo-list { position: absolute; z-index: 60; top: 100%; left: 0; right: 0; min-width: 260px; max-height: 280px; overflow-y: auto; background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.12); margin-top: 2px; }
.combo-list div { padding: 6px 10px; cursor: pointer; font-size: 13px; }
.combo-list div.hl, .combo-list div:hover { background: var(--brand-soft); }
.combo-list div.disabled { color: var(--muted); cursor: default; background: none; }

/* grid */
.grid-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.grid-toolbar .grow { flex: 1; }
.grid-toolbar .input { width: auto; min-width: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-strong); background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip .dot { width: 10px; height: 10px; border-radius: 3px; border: 1px solid rgba(0,0,0,.15); }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.table-wrap { overflow: auto; max-height: calc(100vh - 260px); }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.grid th { position: sticky; top: 0; background: #f8fafc; z-index: 2; text-align: left; font-weight: 600; color: #475569; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; }
table.grid th.num, table.grid td.num { text-align: right; }
table.grid td { padding: 7px 10px; border-bottom: 1px solid #eef2f6; vertical-align: top; white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
table.grid tbody tr:hover td { background: #f1f8f7 !important; }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid tfoot td { font-weight: 700; background: #f8fafc; border-top: 2px solid var(--line-strong); position: sticky; bottom: 0; }
table.grid tr.bold td { font-weight: 700; } table.grid tr.group td { background: #f8fafc; font-weight: 700; }
table.grid td.actions { white-space: nowrap; text-align: right; }
.grid-foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; color: var(--muted); font-size: 12px; gap: 8px; flex-wrap: wrap; }
.pager { display: flex; gap: 4px; align-items: center; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* lines editor */
table.lines { width: 100%; border-collapse: collapse; font-size: 13px; }
table.lines th { text-align: left; font-size: 12px; color: #475569; padding: 6px; border-bottom: 1px solid var(--line); background: #f8fafc; white-space: nowrap; }
table.lines td { padding: 4px; border-bottom: 1px solid #eef2f6; vertical-align: middle; }
table.lines .input { min-height: 30px; padding: 5px 7px; }
table.lines tfoot td { font-weight: 700; padding: 8px 6px; }
.balance-ok { color: var(--ok); } .balance-bad { color: var(--danger); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: start center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: min(640px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(1100px, 100%); } .modal.xwide { width: min(1400px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; max-height: calc(100vh - 200px); overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

/* toast */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #0f172a; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; font-size: 13px; }
.toast.error { background: var(--danger); } .toast.ok { background: var(--ok); }

/* login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: linear-gradient(150deg, #0b3b37 0%, #0f766e 55%, #14b8a6 100%); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.login-art h2 { font-size: 34px; line-height: 1.15; margin: 0 0 12px; max-width: 460px; }
.login-art p { max-width: 420px; opacity: .85; line-height: 1.6; }
.login-form { display: grid; place-items: center; padding: 24px; }
.login-box { width: min(360px, 100%); }
.login-box h1 { font-size: 24px; margin-bottom: 4px; }
.login-box .field { margin-top: 14px; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 18px; padding: 10px; }

/* dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding: 10px 0 0; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; font-size: 11px; color: var(--muted); }
.bars .bar span.b { width: 100%; max-width: 42px; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* tree (chart of accounts) */
.tree { font-size: 13px; }
.tree-node { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.tree-node:hover { background: #f1f5f9; } .tree-node.sel { background: var(--brand-soft); }
.tree-node .tog { width: 16px; text-align: center; color: var(--muted); }
.tree-children { margin-left: 16px; border-left: 1px dashed var(--line-strong); padding-left: 4px; }
.split { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: 16px; align-items: start; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { all: unset; cursor: pointer; padding: 8px 12px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; font-size: 13px; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.dropdown { position: relative; }
.dropdown-menu { position: absolute; right: 0; top: 100%; margin-top: 4px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.12); min-width: 200px; z-index: 50; padding: 4px; }
.dropdown-menu a, .dropdown-menu button { all: unset; display: block; box-sizing: border-box; width: 100%; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--ink); }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: #f1f5f9; }
.summary-row { display: flex; gap: 24px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); background: #fbfcfd; }
.summary-row div { display: flex; flex-direction: column; } .summary-row span { font-size: 11px; color: var(--muted); } .summary-row b { font-variant-numeric: tabular-nums; }
.alert { padding: 10px 12px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); margin-bottom: 12px; font-size: 13px; }
.alert.info { background: var(--info-soft); color: #1d4ed8; } .alert.danger { background: var(--danger-soft); color: var(--danger); }
.mobile-only { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 90; width: 260px; left: 0; transform: translateX(-100%); transition: transform .2s; }
  .layout.menu-open .sidebar { transform: none; }
  .layout.collapsed { grid-template-columns: 1fr; }
  .mobile-only { display: inline-grid; }
  .grid-toolbar label.nowrap { white-space: normal; flex-wrap: wrap; }
  .grid-toolbar .input { max-width: 100%; }
  .content { padding: 12px; }
  .login { grid-template-columns: 1fr; } .login-art { display: none; }
  .two-col, .split { grid-template-columns: 1fr; }
  .form-grid.cols-2, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .field.span-2, .field.span-3 { grid-column: auto; }
}
@media print {
  .sidebar, .topbar, .footer, .grid-toolbar, .page-head .actions, .no-print { display: none !important; }
  .layout { display: block; } .content { padding: 0; } .card { box-shadow: none; border: none; }
  .table-wrap { max-height: none; overflow: visible; }
}
