:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #1c2321;
  --muted: #6b726f;
  --line: #e4e1da;
  --brand: #0f5c4d;
  --brand-ink: #ffffff;
  --brand-soft: #e3efeb;
  --brand-dark: #0b4a3e;
  --brand-paper: #e3efeb;   /* لون فاتح ثابت للمستندات (سندات/كشوف) */
  --brand-text: #0f5c4d;    /* لون النص والروابط بلون الهوية */
  --surface-2: #faf9f6;
  --hover: #fbfaf7;
  --field: #d6d2c9;
  --label: #3a4240;
  --chip-bg: #eeece7;
  --ghost-line: #cfd9d5;
  --ok: #1f7a4d;
  --ok-soft: #e2f3e9;
  --warn: #a8650b;
  --warn-soft: #fbf0dc;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 4px 16px rgba(20, 30, 25, .04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 "Tajawal", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
}
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; margin: 0; font-weight: 800; }
h2 { font-size: 18px; margin: 0 0 14px; font-weight: 700; }
h3 { margin: 0; font-size: 17px; }
.muted { color: var(--muted); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 48px; }
.mt { margin-top: 12px; }

/* Header */
.top { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 10; }
.top-inner { display: flex; align-items: center; gap: 14px; min-height: 60px; }
.brand { color: #fff; font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo, .auth-logo {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: #fff; color: var(--brand-text); font-weight: 800;
}
.auth-lang { display: flex; justify-content: flex-end; padding-top: 16px; }
.auth-lang .lang-switch { padding: 6px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }

/* Page head */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.crumbs { margin: 0 0 4px !important; font-size: 14px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* Cards */
.card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.empty { text-align: center; padding: 48px 20px; }
.two-col { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 18px; }
.two-col .card { margin-bottom: 0; }
.two-col + * { margin-top: 18px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border-top: 4px solid var(--line); }
.stat span { display: block; color: var(--muted); font-size: 14px; }
.stat b { display: block; font-size: 22px; font-weight: 800; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.stat.good { border-top-color: var(--ok); }
.stat.bad { border-top-color: var(--bad); }
.stat.warn { border-top-color: var(--warn); }
.stat.net { border-top-color: var(--brand); background: var(--brand-soft); }
.stats.five { grid-template-columns: repeat(5, minmax(0,1fr)); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: -6px 0 18px; }
.progress i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.mini-bar { display: inline-block; width: 60px; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; vertical-align: middle; margin-inline-end: 6px; }
.mini-bar i { display: block; height: 100%; background: var(--ok); }
.mini-bar.wide { flex: 1; width: auto; height: 8px; }
.mini-bar.wide i { background: var(--warn); }
.cat-bars { display: grid; gap: 12px; }
.cat-row { display: flex; align-items: center; gap: 12px; }
.cat-row span { width: 150px; flex-shrink: 0; }
.cat-row b { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Building cards */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 18px; }
.bcard { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; color: var(--ink); box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.bcard:hover { border-color: var(--brand); text-decoration: none; transform: translateY(-2px); }
.bcard p { margin: 4px 0 12px; font-size: 14px; }
.bcard-stats { display: flex; gap: 14px; font-size: 14px; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-y { max-height: 420px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--hover); }
tr.dim td { color: var(--muted); }
.pos { color: var(--ok); }
.neg { color: var(--bad); font-weight: 600; }
.contact a { margin-inline-end: 6px; }
.wa { color: #128c4b; font-size: 13px; }
.row-actions > * { display: inline-block; vertical-align: middle; margin: 0 0 0 6px; }

td.meters > span { display: block; font-size: 13px; line-height: 1.8; white-space: nowrap; }
.payer { font-weight: 700; }
.payer.tenant { color: var(--brand-text); }
.payer.owner { color: var(--warn); }
.meter-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px 14px; margin: 0; background: var(--surface-2); }
.meter-box legend { font-weight: 700; padding: 0 6px; }
.meter-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.receipt-links { white-space: nowrap; font-size: 13px; }
.receipt-links a { margin-inline-start: 6px; padding: 2px 8px; border: 1px solid var(--ghost-line); border-radius: 6px; }
.receipt-links a:hover { background: var(--brand-soft); text-decoration: none; }
.net-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 2px solid var(--brand); border-radius: var(--radius); padding: 16px 22px; margin-bottom: 18px; }
.net-box div { display: flex; flex-direction: column; }
.net-box span { color: var(--muted); font-size: 14px; }
.net-box b { font-size: 22px; font-variant-numeric: tabular-nums; }
.net-box .op { font-size: 26px; color: var(--muted); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--chip-bg); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 8px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

/* Forms */
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; color: var(--label); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--field); border-radius: 9px;
  padding: 9px 12px; min-height: 42px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid p { margin: 0; font-size: 13px; }
.stack { display: grid; gap: 14px; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { min-width: 200px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px; }
.filters input { flex: 1; min-width: 200px; width: auto; }
.filters select { width: auto; min-width: 160px; }

.pay-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; width: 270px; }
.pay-form input[type=number] { width: 110px; }
.pay-form input[type=date] { width: 145px; }
.pay-form select { width: 145px; }
.pay-form .btn { width: 110px; }
.pay-form input, .pay-form select { min-height: 36px; padding: 6px 8px; font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap;
  background: var(--brand); color: var(--brand-ink); border: 1px solid var(--brand);
  border-radius: 9px; padding: 9px 18px; min-height: 42px;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--brand-text); border-color: var(--ghost-line); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.small { padding: 4px 12px; min-height: 34px; font-size: 14px; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--bad); border-color: #ebc9c6; }
.btn.danger.ghost:hover { background: var(--bad-soft); }
.wa-btn { background: #128c4b; border-color: #128c4b; }

.monthbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.monthbar form { margin: 0; }
.monthbar input { width: auto; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: #c6e5d3; }
.flash.bad { background: var(--bad-soft); color: var(--bad); border-color: #f0cbc7; }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: #f0dbb5; }

.danger-zone { border-color: #f0d6d3; }

/* Auth */
.auth { min-height: 80vh; display: grid; place-items: center; }
.auth .card { width: 100%; max-width: 400px; padding: 32px; text-align: center; }
.auth .stack { text-align: start; margin-top: 18px; }
.auth-logo { width: 54px; height: 54px; font-size: 26px; background: var(--brand); color: #fff; border-radius: 14px; margin-bottom: 12px; }

/* Report */
.report-title { display: none; }

/* Receipt */
.receipt-page { background: #eceae4; padding: 24px 16px; }
.receipt { max-width: 640px; margin: 0 auto; background: #fff; border: 2px solid var(--brand); border-radius: 14px; padding: 28px; }
.receipt-tools { max-width: 640px; margin: 0 auto 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.receipt .en { display: block; font-size: .78em; color: var(--muted); font-weight: 500; }
.receipt-amount .en { color: var(--brand-text); font-size: .6em; }
.receipt-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px dashed var(--line); padding-bottom: 16px; }
.receipt-head h1 { color: var(--brand-text); }
.receipt-head p { margin: 0; color: var(--muted); }
.receipt-no { text-align: end; color: var(--muted); }
.receipt-no b { color: var(--ink); font-size: 18px; }
.receipt-amount { font-size: 30px; font-weight: 800; text-align: center; background: var(--brand-paper); color: var(--brand-text); border-radius: 10px; padding: 14px; margin: 20px 0; }
.receipt dl { display: grid; grid-template-columns: 150px 1fr; gap: 12px; margin: 0 0 32px; }
.receipt dt { color: var(--muted); }
.receipt dd { margin: 0; font-weight: 700; border-bottom: 1px dotted #ccc; }
.sign { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.sign div { flex: 1; color: var(--muted); }
.sign .line { display: block; border-bottom: 1px solid #999; height: 44px; }
.receipt.bilingual dt .en { text-align: right; }

/* Mobile */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .two-col { grid-template-columns: minmax(0,1fr); }
  .two-col .card { margin-bottom: 18px; }
  .stats.five { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .meter-grid { grid-template-columns: 1fr; }
  .net-box .op { display: none; }
}
@media (max-width: 600px) {
  h1 { font-size: 22px; }
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
  .stat b { overflow-wrap: anywhere; }
  .stat b { font-size: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .monthbar .btn { padding: 6px 10px; font-size: 13px; }
  .receipt dl { grid-template-columns: 1fr; gap: 4px; }
}

@media print {
  .top, .no-print, .monthbar, .filters, .btn { display: none !important; }
  body, .receipt-page { background: #fff; font-size: 12px; }
  main.wrap { padding: 0; max-width: none; }
  .card, .stat { box-shadow: none; break-inside: avoid; }
  .report-title { display: block; text-align: center; margin-bottom: 14px; }
  .report-title h2 { font-size: 20px; margin: 0; }
  .stats, .stats.five { grid-template-columns: repeat(4, 1fr); }
  th { position: static; }
  .stat.net { background: none; }
  a { color: inherit; }
  .receipt { border-width: 1px; }
}

/* Receipt ledger (v4) */
.ledger { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.ledger td { padding: 7px 4px; border-bottom: 1px dotted #ccc; white-space: normal; }
.ledger td:last-child { text-align: end; font-weight: 700; white-space: nowrap; }
.ledger tr.total td { border-top: 2px solid #1c2321; border-bottom: 1px solid #1c2321; font-weight: 800; }
.ledger tr.paid td { color: #1f7a4d; }
.ledger tr.after td { font-weight: 800; font-size: 1.08em; background: #e2f3e9; color: #1f7a4d; }
.ledger tr.after.owe td { background: #fbe7e5; color: #b3261e; }
.ledger .en { display: block; }
.alloc-title { font-size: 15px; margin: 4px 0 6px; color: var(--brand); }
.ledger.alloc td { font-size: 14px; }
.kind { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 99px; margin-inline-start: 6px; vertical-align: middle; }
.kind .en { display: inline; margin-inline-start: 4px; }
.kind.arrears { background: #fbf0dc; color: #a8650b; }
.kind.current { background: var(--brand-paper); color: var(--brand); }
.kind.advance { background: #e2f3e9; color: #1f7a4d; }
td.alloc { white-space: normal; font-size: 13px; color: var(--muted); min-width: 180px; }
details summary { cursor: pointer; font-size: 14px; }
.receipt.bilingual .ledger td:first-child .en { text-align: right; }
.receipt.bilingual .ledger td:last-child .en { text-align: left; }
.kind .en::before { content: "· "; }

/* v5: invoices, owner statements */
.ledger.items th { text-align: start; font-size: 12px; color: #6b726f; padding: 6px 4px; border-bottom: 1px solid #1c2321; background: none; }
.ledger.items td:not(:first-child) { text-align: end; }
.ledger.items td { font-size: 14px; }
.ledger .sub { display: block; font-size: 12px; color: #6b726f; font-weight: 500; }
.ledger .pending { text-align: center !important; color: #a8650b; font-weight: 700; background: #fbf0dc; }
.invoice-note { font-size: 14px; color: #3a4240; background: #faf9f6; border-radius: 8px; padding: 10px 12px; }
.invoice-note .en { display: block; }
.office-phone { display: block; font-size: 13px; color: #6b726f; }
.receipt-head p .en { display: block; }
.app-ledger { max-width: 640px; }
.app-ledger td { border-bottom-color: var(--line); }
.app-ledger tr.after td { background: var(--ok-soft); color: var(--ok); }
.app-ledger tr.after.owe td { background: var(--bad-soft); color: var(--bad); }
tr.selected td { background: var(--brand-soft); }
.row-actions { white-space: nowrap; }

/* v6: WhatsApp dialog + unit picker */
.wa-modal { position: fixed; inset: 0; z-index: 50; background: rgba(10, 15, 13, .55); display: grid; place-items: center; padding: 16px; }
.wa-modal[hidden] { display: none; }
.wa-panel { width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; background: var(--surface); color: var(--ink); border-radius: 14px; padding: 20px; display: grid; gap: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.wa-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.wa-head h2 { margin: 0; font-size: 18px; }
.wa-panel textarea { font-size: 14px; line-height: 1.6; resize: vertical; }
.wa-hint { margin: 0; font-size: 13px; }
.wa-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.wa-actions .btn { flex: 1 1 150px; }
.receipt-page .wa-panel label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.receipt-page .wa-panel input, .receipt-page .wa-panel textarea { font: inherit; border: 1px solid #d6d2c9; border-radius: 9px; padding: 8px 12px; width: 100%; }

.unit-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.unit-picker .picked { grid-column: 1 / -1; font-size: 14px; padding: 10px 14px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-text); }
.unit-picker .picked.busy { background: var(--warn-soft); color: var(--warn); }
@media (max-width: 700px) { .unit-picker { grid-template-columns: minmax(0, 1fr); } }
.bcard .area { font-size: 12px; font-weight: 700; color: var(--brand-text); text-transform: none; }

/* v7: owner statement units table */
.receipt.wide { max-width: 900px; }
.receipt-page:has(.receipt.wide) .receipt-tools { max-width: 900px; }
.units-wrap { overflow-x: auto; margin-bottom: 14px; }
.units-table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; color: #1c2321; }
.units-table th { background: var(--brand); color: #fff; font-weight: 700; padding: 7px 6px; text-align: center; border: 1px solid var(--brand-dark); font-size: 12.5px; line-height: 1.35; }
.units-table th .en { display: block; font-size: 10.5px; color: rgba(255,255,255,.78); font-weight: 500; }
.units-table td { padding: 7px 6px; border: 1px solid #e4e1da; text-align: center; white-space: nowrap; background: #fff; }
.units-table td.name { text-align: start; white-space: normal; min-width: 110px; }
.units-table td.hl, .units-table th.hl { background: var(--brand-paper); }
.units-table th.hl { background: var(--brand-dark); }
.units-table td.warn { color: #a8650b; font-weight: 700; }
.units-table td.due { color: #b3261e; font-weight: 800; background: #fbe7e5; }
.units-table td.ok { color: #1f7a4d; font-weight: 800; }
.units-table tr.vacant td { color: #9aa29f; background: #faf9f6; font-style: italic; }
.units-table tbody tr:nth-child(even):not(.vacant) td:not(.hl):not(.due) { background: #fcfbf9; }
.units-table tfoot td { font-weight: 800; background: #f0eee9; border-top: 2px solid #1c2321; }
.units-table td .en { display: block; font-size: 11px; color: #6b726f; }
@media print { .units-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; } .units-table td.due, .units-table td.hl, .units-table tfoot td { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
.owner-units { margin-top: 18px; }

/* v8: users, permissions, office identity */
.hidden-perm { display: none !important; }
.logo-img { object-fit: contain; background: #fff; padding: 3px; }
.brand .logo-img { width: 38px; height: 38px; border-radius: 9px; }
.auth-logo.logo-img { width: 88px; height: 88px; border-radius: 16px; display: inline-block; border: 1px solid var(--line); }
.top nav .who { color: rgba(255,255,255,.75); font-size: 13px; padding: 8px 6px; white-space: nowrap; }
.doc-logo { display: block; max-height: 64px; max-width: 180px; object-fit: contain; margin-bottom: 8px; }
.receipt-head .office-name { display: block; color: #1c2321; }
.receipt-head .office-line { display: block; font-size: 12.5px; color: #6b726f; }
.brand-setup { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.logo-box { display: grid; gap: 10px; justify-items: start; }
.logo-preview { max-width: 200px; max-height: 120px; object-fit: contain; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: #fff; }
.logo-empty { width: 200px; height: 100px; display: grid; place-items: center; border: 2px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: 14px; }
@media (max-width: 800px) { .brand-setup { grid-template-columns: minmax(0, 1fr); } }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px 18px; margin: 12px 0; }
.presets { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; margin: 2px; border-radius: 99px; background: var(--brand-soft); color: var(--brand-text); white-space: nowrap; }
td.perm-cell { white-space: normal; max-width: 420px; }

/* v9: PDF tools */
.receipt-tools { align-items: center; }
.receipt-tools .tool-group { display: inline-flex; gap: 6px; flex-wrap: wrap; padding-inline-end: 10px; margin-inline-end: 4px; border-inline-end: 1px solid #d6d2c9; }
.receipt-tools .tool-group:last-child { border: 0; }
.receipt-tools button[disabled] { opacity: .7; cursor: progress; }
.pdf-status { max-width: 640px; margin: -4px auto 12px; padding: 10px 14px; border-radius: 10px; font-size: 14px; background: #fbf0dc; color: #a8650b; }
.receipt-page:has(.receipt.wide) .pdf-status { max-width: 900px; }
.pdf-status.ok { background: #e2f3e9; color: #1f7a4d; }
.pdf-status.bad { background: #fbe7e5; color: #b3261e; }
.pdf-mode .receipt { box-shadow: none; }

/* v10: الوضع الليلي — يُطبّق على صفحات البرنامج فقط (المستندات تبقى بيضاء للطباعة) */
html[data-theme="dark"] {
  --bg: #111715; --surface: #1a211f; --surface-2: #202825; --hover: #232c29; --ink: #e5ebe8; --muted: #97a39e;
  --line: #2c3632; --field: #3a4640; --label: #c9d2ce; --chip-bg: #28322e; --ghost-line: #3a4640;
  --ok: #5cc48f; --ok-soft: #173326; --warn: #e3a64a; --warn-soft: #3a2c14; --bad: #f07a70; --bad-soft: #3c1c1a;
  --brand-soft: #173a32; --brand-text: #5fbfa6; --shadow: none; color-scheme: dark;
}
html[data-theme="dark"] .flash.ok, html[data-theme="dark"] .flash.bad, html[data-theme="dark"] .flash.warn { border-color: var(--line); }
html[data-theme="dark"] .danger-zone { border-color: #4a2523; }
html[data-theme="dark"] .btn.danger.ghost { border-color: #5a2a27; }
html[data-theme="dark"] .ledger td { border-bottom-color: var(--line); }
html[data-theme="dark"] .ledger tr.total td { border-color: var(--muted); }
html[data-theme="dark"] .note { background: var(--warn-soft); color: var(--warn); }
html[data-theme="dark"] input[type=date], html[data-theme="dark"] input[type=month] { color-scheme: dark; }
html[data-theme="dark"] .bcard:hover { border-color: var(--brand-text); }
html[data-theme="dark"] .auth-logo:not(.logo-img) { background: var(--brand); }
@media (prefers-color-scheme: dark) {
html[data-theme="auto"] {
  --bg: #111715; --surface: #1a211f; --surface-2: #202825; --hover: #232c29; --ink: #e5ebe8; --muted: #97a39e;
  --line: #2c3632; --field: #3a4640; --label: #c9d2ce; --chip-bg: #28322e; --ghost-line: #3a4640;
  --ok: #5cc48f; --ok-soft: #173326; --warn: #e3a64a; --warn-soft: #3a2c14; --bad: #f07a70; --bad-soft: #3c1c1a;
  --brand-soft: #173a32; --brand-text: #5fbfa6; --shadow: none; color-scheme: dark;
}
html[data-theme="auto"] .flash.ok, html[data-theme="auto"] .flash.bad, html[data-theme="auto"] .flash.warn { border-color: var(--line); }
html[data-theme="auto"] .danger-zone { border-color: #4a2523; }
html[data-theme="auto"] .btn.danger.ghost { border-color: #5a2a27; }
html[data-theme="auto"] .ledger td { border-bottom-color: var(--line); }
html[data-theme="auto"] .ledger tr.total td { border-color: var(--muted); }
html[data-theme="auto"] .note { background: var(--warn-soft); color: var(--warn); }
html[data-theme="auto"] input[type=date], html[data-theme="auto"] input[type=month] { color-scheme: dark; }
html[data-theme="auto"] .bcard:hover { border-color: var(--brand-text); }
html[data-theme="auto"] .auth-logo:not(.logo-img) { background: var(--brand); }
}

/* زر الوضع الليلي */
.mode-btn { background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 16px; line-height: 1.4; }
.mode-btn:hover { background: rgba(255,255,255,.12); }
.auth-lang { gap: 8px; }
.auth-lang .mode-btn { color: var(--ink); border-color: var(--line); background: var(--surface); }

/* إعدادات المظهر */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; font-size: 12px; color: var(--muted); }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch i { width: 44px; height: 44px; border-radius: 12px; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.swatch input:checked + i { box-shadow: 0 0 0 3px var(--ink); }
.swatch input:focus-visible + i { outline: 2px solid var(--brand-text); outline-offset: 3px; }
.custom-color { display: flex; align-items: center; gap: 10px; }
.custom-color input[type=color] { width: 56px; height: 44px; padding: 2px; cursor: pointer; }
.theme-preview { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px; border-radius: 10px; border: 1px dashed var(--line); }
.theme-preview .bar { flex: 1 1 100%; height: 34px; border-radius: 8px; background: var(--brand); color: #fff; display: flex; align-items: center; padding-inline: 12px; font-weight: 700; }
.quickbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 14px; }
.quickbar select { width: auto; min-width: 220px; flex: 1 1 220px; }
.quickbar .btn { flex: 0 0 auto; }
.note { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; background: var(--warn-soft); color: var(--warn); }

/* v11: العقود والتجديد والبطاقة الشخصية */
.nav-badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: #e5484d; color: #fff; font-size: 12px; font-weight: 800; line-height: 20px; text-align: center; margin-inline-start: 4px; }
.lease-alert { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px; border-radius: 12px; margin-bottom: 16px; border: 1px solid var(--line); }
.lease-alert small { display: block; margin-top: 2px; opacity: .85; }
.lease-alert.expired { background: var(--bad-soft); color: var(--bad); }
.lease-alert.expiring { background: var(--warn-soft); color: var(--warn); }
.lease-alert.done { background: var(--ok-soft); color: var(--ok); }
.lease-alert .actions { margin: 0; }
.lease-card tr.has-due td { background: var(--bad-soft); }
tr.hl-row td { background: var(--ok-soft); }
.nowrap { white-space: nowrap; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.doc-item { display: flex; flex-direction: column; gap: 4px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); min-width: 0; }
.doc-item small { overflow-wrap: anywhere; }
.doc-item .actions { margin-top: 4px; gap: 6px; }
.doc-item form { margin: 0; }
.doc-thumb { display: grid; place-items: center; height: 110px; border-radius: 8px; overflow: hidden; background: var(--chip-bg); }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pdf-icon { font-weight: 800; font-size: 22px; color: #b3261e; background: #fff; border: 2px solid #b3261e; border-radius: 6px; padding: 8px 10px; }
.upload-box { padding: 12px; border: 1px dashed var(--ghost-line); border-radius: 12px; background: var(--surface-2); }
.upload-box input[type=file], .inline-form input[type=file] { padding: 8px; }
.small-note { font-size: 13px; margin-top: 8px; }
.units-table td.date { font-size: 12.5px; }
.units-table td.date.warn { background: #fff4e0; }
.units-table td .lease-flag { display: block; font-size: 10.5px; font-weight: 700; }
@media print { .units-table td.date.warn { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* عقد الإيجار */
.receipt.contract { max-width: 760px; }
.receipt-tools:has(+ .pdf-status + .receipt.contract) { max-width: 760px; }
.receipt.contract dl { margin-bottom: 16px; grid-template-columns: 170px 1fr; gap: 8px 12px; }
.receipt.contract .alloc-title { margin: 18px 0 8px; color: var(--brand-text); font-size: 16px; border-inline-start: 4px solid var(--brand); padding-inline-start: 8px; }
.receipt.contract .ledger { margin-bottom: 8px; }
.contract-note { background: var(--brand-paper); border-radius: 8px; padding: 10px 12px; margin: 14px 0; font-size: 14px; }
.contract-note .en { display: block; }
.clauses { margin: 0 0 12px; padding-inline-start: 22px; line-height: 1.75; font-size: 14px; }
.clauses li { margin-bottom: 6px; break-inside: avoid; }
.clauses li .en { display: block; font-size: .85em; color: #555; text-align: left; }
.clauses.en-block { text-align: left; }
.sign.three { margin-top: 30px; }
.sign.three .line { height: 56px; }
@media (max-width: 600px) { .receipt.contract dl { grid-template-columns: 1fr; } }
html[data-theme="dark"] .units-table td.date.warn { background: #fff4e0; }
.units-table td.date { line-height: 1.35; }
.units-table td.date .d-from, .units-table td.date .d-to { display: block; }
.units-table td.date .d-to::before { content: "↓ "; color: #9aa29f; font-size: 10px; }

/* ===================== v12: الواجهة التفاعلية ===================== */
:root { --ease: cubic-bezier(.2,.7,.2,1); --sky-op: .085; --sky-far-op: .05; --grid-op: .035; }
html[data-theme="dark"] { --sky-op: .16; --sky-far-op: .09; --grid-op: .05; }
@media (prefers-color-scheme: dark) { html[data-theme="auto"] { --sky-op: .16; --sky-far-op: .09; --grid-op: .05; } }

/* الخلفية: شبكة مخطط هندسي خفيفة + خط أفق مبانٍ */
body.app { position: relative; min-height: 100vh; }
body.app::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(color-mix(in srgb, var(--brand) calc(var(--grid-op) * 100%), transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--brand) calc(var(--grid-op) * 100%), transparent) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,.9), rgba(0,0,0,.25) 55%, rgba(0,0,0,.6));
          mask-image: linear-gradient(to bottom, rgba(0,0,0,.9), rgba(0,0,0,.25) 55%, rgba(0,0,0,.6));
}
.scenery { position: fixed; inset: auto 0 0 0; height: 280px; z-index: 0; pointer-events: none; }
.scenery i { position: absolute; inset: 0; background: var(--brand); }
.scenery .far { opacity: var(--sky-far-op); bottom: 26px;
  -webkit-mask: url(skyline-far.svg) repeat-x bottom / auto 100%; mask: url(skyline-far.svg) repeat-x bottom / auto 100%; }
.scenery .near { opacity: var(--sky-op);
  -webkit-mask: url(skyline.svg) repeat-x bottom / auto 92%; mask: url(skyline.svg) repeat-x bottom / auto 92%; }
html[data-theme="dark"] .scenery i { background: var(--brand-text); }
@media (prefers-color-scheme: dark) { html[data-theme="auto"] .scenery i { background: var(--brand-text); } }
body.app > main, body.app > .wrap, body.app > header { position: relative; z-index: 1; }
body.auth-page .scenery { height: 46vh; }
body.auth-page { --sky-op: .14; --sky-far-op: .08; }

/* الشريط العلوي */
.top { box-shadow: 0 6px 24px -12px rgba(0,0,0,.45); overflow: hidden; }
.top::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: #fff; opacity: .07;
  -webkit-mask: url(skyline.svg) repeat-x bottom / auto 260%; mask: url(skyline.svg) repeat-x bottom / auto 260%; }
.top > * { position: relative; z-index: 1; }
.top-bar { display: flex; align-items: center; gap: 14px; min-height: 58px; }
.top-tools { margin-inline-start: auto; display: flex; align-items: center; gap: 6px; }
.top-tools .lang-switch, .tool-btn, .top-tools .mode-btn {
  display: inline-flex; align-items: center; justify-content: center; height: 36px; min-width: 36px; padding: 0 10px; border-radius: 10px;
  color: #fff; border: 1px solid rgba(255,255,255,.28); background: rgba(255,255,255,.06); font-size: 14px; font-weight: 600;
  transition: background .2s var(--ease), transform .2s var(--ease), border-color .2s;
}
.top-tools .lang-switch:hover, .tool-btn:hover, .top-tools .mode-btn:hover { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.5); text-decoration: none; transform: translateY(-1px); }
.top-tools .mode-btn { font-size: 16px; padding: 0; width: 36px; }
.who { display: inline-flex; align-items: center; gap: 6px; color: rgba(255,255,255,.88); font-size: 13.5px; padding: 0 8px; white-space: nowrap; }
.who .ico { width: 18px; height: 18px; opacity: .8; }
.who em { font-style: normal; font-size: 11.5px; background: rgba(255,255,255,.18); padding: 1px 8px; border-radius: 99px; }
.brand { transition: opacity .2s; }
.brand:hover { opacity: .9; }
.brand .logo { transition: transform .35s var(--ease); }
.brand:hover .logo { transform: rotate(-6deg) scale(1.06); }

/* التبويبات */
.tabs { background: rgba(0,0,0,.14); border-top: 1px solid rgba(255,255,255,.08); }
.tabs-inner { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; scroll-behavior: smooth; padding-top: 6px; padding-bottom: 6px; }
.tabs-inner::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px 6px 12px; border-radius: 12px; flex-shrink: 0;
  color: rgba(255,255,255,.8); font-size: 14px; font-weight: 600; white-space: nowrap; isolation: isolate;
  transition: color .2s var(--ease), background .25s var(--ease), transform .2s var(--ease);
}
.tab::after { content: ""; position: absolute; inset-inline: 14px; bottom: 2px; height: 2px; border-radius: 2px; background: #fff; transform: scaleX(0); transition: transform .3s var(--ease); }
.tab:hover { color: #fff; background: rgba(255,255,255,.1); text-decoration: none; }
.tab:hover::after { transform: scaleX(1); }
.tab:active { transform: scale(.97); }
.tab-ico { position: relative; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; background: rgba(255,255,255,.1); transition: transform .3s var(--ease), background .25s; }
.tab .ico { width: 18px; height: 18px; transition: transform .35s var(--ease); }
.tab:hover .tab-ico { transform: translateY(-2px); background: rgba(255,255,255,.2); }
.tab:hover .ico { transform: scale(1.12) rotate(-4deg); }
.tab.active { color: var(--brand-text); background: var(--surface); box-shadow: 0 6px 18px -8px rgba(0,0,0,.45); }
.tab.active::after { display: none; }
.tab.active .tab-ico { background: var(--brand); color: #fff; }
.tab .nav-badge { position: absolute; top: -6px; inset-inline-end: -8px; margin: 0; min-width: 18px; line-height: 18px; font-size: 11px; padding: 0 5px; box-shadow: 0 0 0 2px var(--brand); animation: pulse 2.2s infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@media (max-width: 700px) {
  .top-bar { gap: 8px; }
  .brand { font-size: 16px; gap: 8px; min-width: 0; }
  .brand-name { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; }
  .top-tools { gap: 4px; }
  .top-tools .lang-switch, .tool-btn { padding: 0 8px; min-width: 34px; height: 34px; font-size: 13px; }
  .top-tools .mode-btn { width: 34px; height: 34px; }
  .who { padding: 0 2px; }
  .who-name, .who em { display: none; }
  .tab { flex-direction: column; gap: 2px; padding: 6px 8px; font-size: 11.5px; min-width: 70px; }
  .tab::after { display: none; }
  .tab-ico { width: 32px; height: 28px; }
}

/* أيقونات عامة */
.ico { width: 18px; height: 18px; flex-shrink: 0; vertical-align: -3px; }
.btn .ico { width: 17px; height: 17px; }
h2 > .ico { width: 20px; height: 20px; color: var(--brand-text); margin-inline-end: 4px; vertical-align: -3px; }

/* تفاعل العناصر */
.btn { position: relative; overflow: hidden; transition: transform .15s var(--ease), box-shadow .2s var(--ease), background .2s, filter .2s; }
.btn:hover { box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--brand) 70%, transparent); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn .ripple { position: absolute; border-radius: 50%; transform: scale(0); background: currentColor; opacity: .25; animation: ripple .6s var(--ease); pointer-events: none; }
@keyframes ripple { to { transform: scale(4); opacity: 0; } }
:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 2px; }
.card { transition: box-shadow .25s var(--ease), border-color .25s; }
.card:hover { box-shadow: 0 2px 4px rgba(20,30,25,.05), 0 12px 32px -12px rgba(20,30,25,.18); }
.stat { position: relative; overflow: hidden; transition: transform .25s var(--ease), box-shadow .25s var(--ease); }
.stat:hover { transform: translateY(-3px); box-shadow: 0 14px 30px -16px rgba(20,30,25,.35); }
.stat::after { content: ""; position: absolute; inset-inline-end: -18px; bottom: -30px; width: 80px; height: 80px; border-radius: 50%; background: var(--brand); opacity: .045; transition: transform .4s var(--ease); }
.stat:hover::after { transform: scale(1.25); }
.bcard { position: relative; overflow: hidden; transition: border-color .2s, transform .25s var(--ease), box-shadow .25s var(--ease); }
.bcard::before { content: ""; position: absolute; inset: auto 0 0 0; height: 70px; background: var(--brand); opacity: .07; pointer-events: none;
  -webkit-mask: url(skyline.svg) repeat-x bottom / auto 100%; mask: url(skyline.svg) repeat-x bottom / auto 100%; transition: opacity .3s, transform .5s var(--ease); }
.bcard:hover { box-shadow: 0 16px 34px -18px rgba(20,30,25,.4); transform: translateY(-4px); }
.bcard:hover::before { opacity: .16; transform: translateX(-12px); }
tbody tr { transition: background .15s; }
.progress i, .mini-bar i { transition: width 1s var(--ease); }
.flash { animation: slideIn .4s var(--ease); }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } }

/* ظهور تدريجي للمحتوى */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
main.wrap > * { animation: rise .45s var(--ease) both; }
main.wrap > *:nth-child(2) { animation-delay: .04s; } main.wrap > *:nth-child(3) { animation-delay: .08s; }
main.wrap > *:nth-child(4) { animation-delay: .12s; } main.wrap > *:nth-child(5) { animation-delay: .16s; }
main.wrap > *:nth-child(n+6) { animation-delay: .2s; }
.stats > .stat { animation: rise .5s var(--ease) both; }
.stats > .stat:nth-child(2) { animation-delay: .06s; } .stats > .stat:nth-child(3) { animation-delay: .12s; }
.stats > .stat:nth-child(4) { animation-delay: .18s; } .stats > .stat:nth-child(5) { animation-delay: .24s; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* صفحة الدخول */
body.auth-page .auth .card { backdrop-filter: blur(6px); background: color-mix(in srgb, var(--surface) 88%, transparent); box-shadow: 0 30px 60px -30px rgba(0,0,0,.35); }

/* اتفاقيات الملاك */
.type-cards { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.type-card { position: relative; display: grid; gap: 6px; padding: 18px; border: 2px solid var(--line); border-radius: 14px; cursor: pointer; transition: border-color .2s, background .2s, transform .2s var(--ease); }
.type-card:hover { border-color: var(--ghost-line); transform: translateY(-2px); }
.type-card input { position: absolute; opacity: 0; pointer-events: none; }
.type-card:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.type-card:has(input:checked)::after { content: "✓"; position: absolute; top: 12px; inset-inline-end: 14px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #fff; font-size: 13px; font-weight: 800; }
.type-card:has(input:focus-visible) { outline: 2px solid var(--brand-text); outline-offset: 2px; }
.type-card b { font-size: 16px; }
.type-card small { color: var(--muted); line-height: 1.6; }
.type-ico { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--brand); color: #fff; }
.type-ico .ico { width: 24px; height: 24px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.check-chip { display: flex !important; flex-direction: row !important; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 500 !important; transition: background .15s, border-color .15s; }
.check-chip:hover { background: var(--hover); }
.check-chip:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.check-chip input { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); flex-shrink: 0; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip { font: inherit; font-size: 12.5px; padding: 4px 10px; border-radius: 99px; border: 1px dashed var(--ghost-line); background: var(--surface-2); color: var(--ink); cursor: pointer; transition: background .15s, transform .15s; }
.tag-chip:hover { background: var(--brand-soft); transform: translateY(-1px); }
.tag-chip code { color: var(--brand-text); font-size: 12px; }
.clause-box { display: grid; gap: 8px; }
.clause-box textarea { font-size: 14px; line-height: 1.8; }
.clause-box .btn { justify-self: start; }
.sticky-actions { position: sticky; bottom: 12px; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; box-shadow: 0 16px 40px -18px rgba(0,0,0,.4); }
.agr-strip { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.agr-strip-main { display: flex; gap: 12px; align-items: center; }
.agr-strip-main b { display: block; }
.type-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 99px; background: var(--brand-soft); color: var(--brand-text); }
.type-pill.lease { background: var(--warn-soft); color: var(--warn); }
.type-pill .ico { width: 14px; height: 14px; }
.chip-link { display: inline-block; padding: 2px 10px; margin: 2px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; }
.small-b { font-size: 16px !important; line-height: 1.5; }
.doc-preview { padding: 0; overflow: hidden; background: #eceae4; }
.doc-preview .receipt { margin: 18px auto; }
.services-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 4px 18px; font-size: 14px; }
.services-list .en { display: block; font-size: .85em; color: #555; }
.draft-mark { display: inline-block; margin-top: 4px; padding: 1px 10px; border: 1px dashed #b3261e; color: #b3261e; border-radius: 6px; font-weight: 700; }
.receipt.agreement .contract-note:first-of-type { font-weight: 500; }
@media (max-width: 700px) { .type-cards, .services-list { grid-template-columns: 1fr; } .sticky-actions { position: static; } }

@media print {
  .scenery, body.app::before, .top::after { display: none !important; }
}
@media (min-width: 701px) and (max-width: 1320px) {
  .tab { padding: 6px 8px; gap: 6px; font-size: 13.5px; }
  .tab-ico { width: 26px; height: 26px; }
  .tabs-inner { gap: 2px; }
}
