:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ec;
  --text: #17212b;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #e6f4f2;
  --danger: #c2410c;
  --danger-soft: #fdf0e9;
  --warning: #b45309;
  --warning-soft: #fef6e4;
  --success: #15803d;
  --success-soft: #e9f7ee;
  --info-soft: #eaf2fb;
  --sidebar: #0d2b2a;
  --sidebar-ink: #cfe3e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1417;
    --surface: #161d21;
    --surface-2: #1b2328;
    --border: #2a343a;
    --text: #e6edf0;
    --muted: #93a3ad;
    --primary: #2bb3a5;
    --primary-ink: #04201d;
    --primary-soft: #133331;
    --danger: #fb8a5b;
    --danger-soft: #3a2018;
    --warning: #f5b454;
    --warning-soft: #362a14;
    --success: #4ade80;
    --success-soft: #15301f;
    --info-soft: #172a3a;
    --sidebar: #0a1112;
    --sidebar-ink: #b6cbc8;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Arabic", Tahoma, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .6em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.ic { width: 20px; height: 20px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: embed; }

/* ===== Layout ===== */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex: none; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; font-weight: 700; font-size: 1.05rem; color: #fff; }
.brand .ic { width: 26px; height: 26px; color: #5eead4; }
.sidebar nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--sidebar-ink); font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active { background: rgba(94,234,212,.14); color: #fff; }
.sidebar nav a .badge { margin-inline-start: auto; background: #f97316; color: #fff; border-radius: 99px; font-size: .72rem; padding: 0 7px; }
.sidebar-user { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); color: #fff; font-weight: 600; }
.sidebar-user small { display: block; color: var(--sidebar-ink); font-weight: 400; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 1.2rem; margin: 0; flex: 1; }
.icon-btn { background: none; border: 0; color: var(--text); padding: 6px; border-radius: 8px; cursor: pointer; position: relative; display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .dot { position: absolute; top: 0; left: 0; background: #f97316; color: #fff; font-size: .65rem; border-radius: 99px; padding: 0 5px; }
.menu-btn { display: none; }
.content { padding: 24px; max-width: 1280px; width: 100%; }
.backdrop { display: none; }

@media (max-width: 900px) {
  .sidebar { position: fixed; inset-block: 0; right: 0; transform: translateX(100%); transition: transform .2s; z-index: 20; }
  .sidebar.open { transform: none; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 15; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
}

/* ===== Cards & grid ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.35rem; font-weight: 700; margin-top: 4px; }
.stat .value small { font-size: .85rem; font-weight: 500; display: block; }
.stat.danger .value { color: var(--danger); }
.stat.success .value { color: var(--success); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) {
  .grid2, .grid3, .cols { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 1.08rem; }
  .table-wrap table { min-width: 560px; }
  .table-wrap td { white-space: nowrap; }
  .table-wrap td.desc { white-space: normal; min-width: 200px; }
  .card { padding: 14px; }
}

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 10px 8px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; background: var(--surface-2); }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

/* ===== Badges / amounts ===== */
.amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.amt.neg { color: var(--danger); }
.amt.pos { color: var(--success); }
.amt.zero { color: var(--success); font-weight: 500; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: .78rem; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.tag.green { background: var(--success-soft); color: var(--success); border-color: transparent; }
.tag.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag.amber { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.tag.teal { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

/* ===== Forms ===== */
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; font-weight: 500; margin-bottom: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px; width: 100%; min-height: 40px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px 4px; margin: 0 0 14px; }
legend { padding: 0 6px; font-weight: 600; font-size: .9rem; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.inline-form label { margin-bottom: 0; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters > * { width: auto; min-width: 150px; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  padding: 8px 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; min-height: 40px; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.sm { padding: 3px 10px; min-height: 30px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn .ic { width: 17px; height: 17px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.link-btn { background: none; border: 0; color: var(--danger); cursor: pointer; font: inherit; font-size: .85rem; padding: 0; }

/* ===== Alerts ===== */
.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--info-soft); }
.alert.success { background: var(--success-soft); color: var(--success); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.warning { background: var(--warning-soft); color: var(--warning); }

/* ===== Property structure ===== */
.floor { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; overflow: hidden; }
.floor-head { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--surface-2); flex-wrap: wrap; }
.floor-head b { flex: 1; }
.units-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; padding: 12px; }
.unit-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface); display: block; color: var(--text); }
.unit-card:hover { border-color: var(--primary); text-decoration: none; }
.unit-card .u-name { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.unit-card .u-tenant { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.unit-card.vacant { border-style: dashed; }
.unit-card.overdue { border-color: var(--danger); }

/* ===== Notifications ===== */
.notif { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.notif:last-child { border-bottom: 0; }
.notif .n-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 8px; flex: none; background: var(--border); }
.notif.unread .n-dot { background: #f97316; }
.notif .n-body { white-space: pre-line; color: var(--muted); font-size: .88rem; }

/* ===== Auth ===== */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.auth-card.wide { max-width: 640px; }
.auth-card h1 { font-size: 1.3rem; text-align: center; }
.steps li { margin-bottom: 6px; }

.statement td.desc { min-width: 180px; }
.row-credit td { color: var(--success); }
details summary { cursor: pointer; font-weight: 600; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; direction: ltr; unicode-bidi: embed; word-break: break-all; }
@media print {
  .sidebar, .topbar, .no-print, .btn { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; }
}
