/* Report site — right-to-left, mobile first, no external resources. */
:root {
  --bg: #f6f5ef;
  --surface: #ffffff;
  --surface-2: #f0efe6;
  --text: #1d2320;
  --muted: #5d6a63;
  --border: #dcdfd6;
  --accent: #1f6f43;
  --accent-soft: #e2f0e8;
  --due: #b3261e;
  --owed: #1b7a3a;
  --warn-bg: #fff3cf;
  --warn-text: #6b4e00;
  --shadow: 0 1px 2px rgba(20, 30, 25, .08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121613;
    --surface: #1a201c;
    --surface-2: #232b26;
    --text: #e8ede9;
    --muted: #9ba8a0;
    --border: #2d372f;
    --accent: #5cc48c;
    --accent-soft: #1d3327;
    --due: #ff8f86;
    --owed: #74d493;
    --warn-bg: #3a3116;
    --warn-text: #f3d77a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

h1 { font-size: 1.45rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

main { max-width: 1200px; margin: 0 auto; padding: 1rem 16px 2rem; }

.muted { color: var(--muted); }
.neg { color: var(--due); }

/* ── side menu (phone: slide-in drawer) ──────────────── */
.ic { width: 20px; height: 20px; fill: currentColor; flex: none; }

.menu-toggle { position: absolute; opacity: 0; pointer-events: none; }

.brand {
  display: flex; align-items: center; gap: .6rem; min-width: 0;
  font-weight: 800; font-size: 1.05rem; color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-logo { width: 36px; height: 36px; flex: none; object-fit: contain; border-radius: 10px; background: #fff; }
.brand-mark {
  width: 36px; height: 36px; flex: none; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: #fff;
}
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Phone top bar: ☰ + name. */
.mbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem 12px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(20, 30, 25, .06);
}
.burger, .side-close {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  border-radius: 12px; cursor: pointer; color: var(--text);
}
.burger:hover, .side-close:hover { background: var(--surface-2); }
.burger .ic, .side-close .ic { width: 24px; height: 24px; }

/* The menu itself: a drawer from the right on phones… */
.side {
  position: fixed; top: 0; bottom: 0; inset-inline-start: 0; z-index: 40;
  width: min(290px, 86vw);
  display: flex; flex-direction: column; gap: .75rem;
  padding: .9rem .75rem;
  background: var(--surface); border-inline-end: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(0, 0, 0, .18);
  transform: translateX(105%); transition: transform .22s ease;
  overflow-y: auto;
}
.menu-toggle:checked ~ .side { transform: none; }
.scrim {
  position: fixed; inset: 0; z-index: 30; background: rgba(10, 16, 13, .45);
  opacity: 0; pointer-events: none; transition: opacity .22s ease;
}
.menu-toggle:checked ~ .scrim { opacity: 1; pointer-events: auto; }

.side-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 0 .25rem .5rem; border-bottom: 1px solid var(--border); }

.nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem .85rem; border-radius: 12px; color: var(--muted); font-weight: 600;
  transition: background-color .15s, color .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--accent); color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent); }

.me { display: flex; align-items: center; gap: .4rem; padding-top: .6rem; border-top: 1px solid var(--border); }
.me-name {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: .4rem;
  padding: .45rem .7rem; border-radius: 999px; background: var(--surface-2);
  color: var(--muted); font-size: .9rem;
}
.me-name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout { margin: 0; }
.side .logout button[type="submit"] {
  display: flex; align-items: center; gap: .3rem;
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: .4rem .8rem; font: inherit; font-size: .9rem; cursor: pointer;
}
.side .logout button[type="submit"]:hover { color: var(--due); border-color: var(--due); background: none; }

@media (prefers-color-scheme: dark) {
  .nav a.on, .brand-mark { color: #0c1a12; }
}

/* …and a fixed side menu on wider screens. */
@media (min-width: 900px) {
  .mbar, .scrim, .side-close { display: none; }
  .side {
    width: 250px; transform: none; transition: none;
    box-shadow: none; z-index: 10;
  }
  .side ~ main, .side ~ .foot { margin-inline-start: 250px; }
}
/* ── reports hub ─────────────────────────────────────── */
.report-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.report-card {
  display: flex; align-items: center; gap: .9rem; padding: 1rem 1.1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); color: var(--text);
  transition: border-color .15s, transform .15s;
}
.report-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }
.rc-icon {
  width: 48px; height: 48px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.rc-icon .ic { width: 26px; height: 26px; }
.rc-text { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.rc-title { font-weight: 700; }
.rc-desc { color: var(--muted); font-size: .88rem; }

.foot { text-align: center; color: var(--muted); font-size: .9rem; padding: 1rem 16px 2rem; display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.credit { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .35rem 1rem; font-size: .88rem; }
.credit-name { display: inline-flex; align-items: center; gap: .35rem; font-weight: 700; }
.credit-name img { border-radius: 6px; }
.credit-tel { display: inline-flex; align-items: center; gap: .25rem; color: var(--muted); }
.credit-tel .ic { width: 16px; height: 16px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: .4rem; margin-bottom: .25rem; }
.login-brand img { width: 72px; height: 72px; object-fit: contain; }
.login-brand strong { font-size: 1.25rem; }
.back { margin: 0 0 .75rem; }

/* ── cards ───────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin: 0 0 1.25rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: .75rem .9rem; box-shadow: var(--shadow);
}
.stat .lbl { color: var(--muted); font-size: .88rem; }
.stat .val { font-size: 1.3rem; font-weight: 700; margin-top: .15rem; word-break: break-word; }
.stat .unit { font-size: .8rem; font-weight: 400; color: var(--muted); }
@media (min-width: 900px) { .stats.four { grid-template-columns: repeat(4, 1fr); } }
.stat.due .val, .stat.warn .val { color: var(--due); }
.stat.owed .val, .stat.good .val { color: var(--owed); }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem; margin: 0 0 1.25rem; box-shadow: var(--shadow);
}
.panel .table-wrap { border: 0; border-radius: 0; }
.cols { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
@media (min-width: 900px) { .cols { grid-template-columns: 1fr 1fr; } }

.notice { background: var(--surface-2); border-radius: 10px; padding: .75rem 1rem; margin: 0 0 1rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.bad { background: var(--warn-bg); color: var(--due); }

/* ── numbers and balances ────────────────────────────── */
.num { direction: ltr; unicode-bidi: isolate; display: inline-block; font-variant-numeric: tabular-nums; }
td.num, th.num { display: table-cell; text-align: right; white-space: nowrap; }
.bal .note { font-size: .85rem; margin-inline-start: .15rem; }
.bal.due { color: var(--due); }
.bal.owed { color: var(--owed); }
.bal.zero { color: var(--muted); }
td.due { color: var(--due); font-weight: 600; }
.est { font-size: .78rem; color: var(--muted); }

.chip {
  display: inline-block; font-size: .8rem; font-weight: 600; padding: .05rem .6rem;
  border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.settled { background: var(--accent-soft); color: var(--accent); }
.chip.open { background: var(--warn-bg); color: var(--warn-text); }
.chip.est { background: var(--warn-bg); color: var(--warn-text); }

/* ── tables ──────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  margin: 0 0 1.25rem;
}
.tbl { border-collapse: collapse; width: 100%; min-width: 460px; }
.tbl th, .tbl td { padding: .55rem .8rem; text-align: right; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th { background: var(--surface-2); font-weight: 600; white-space: nowrap; font-size: .92rem; }
.tbl th a { color: var(--text); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--accent-soft); }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); border-bottom: 0; }
.tbl .c-desc { min-width: 12rem; }
.tbl td.c-date, .tbl td.c-type, .tbl td.c-voucher, .tbl td.c-no, .tbl td.c-bal, .tbl td.c-label { white-space: nowrap; }
.tbl .row-opening td { color: var(--muted); font-style: italic; }

/* ── lists and definition lists ──────────────────────── */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li + li { border-top: 1px solid var(--border); }
.rows a {
  display: grid; grid-template-columns: 1fr auto; gap: 0 1rem; padding: .6rem .25rem; color: var(--text);
}
.rows a:hover { background: var(--accent-soft); text-decoration: none; }
.rows .t { font-weight: 600; }
.rows .s { grid-column: 1; color: var(--muted); font-size: .9rem; }
.rows .v { grid-column: 2; grid-row: 1 / span 2; align-self: center; text-align: end; }

.info { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .6rem 1.5rem; }
.info > div { display: flex; flex-direction: column; }
.info dt { color: var(--muted); font-size: .85rem; }
.info dd { margin: 0; font-weight: 600; }
.info.stacked { grid-template-columns: 1fr; gap: 0; max-width: 520px; }
.info.stacked > div { flex-direction: row; justify-content: space-between; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.info.stacked > div:last-child { border-bottom: 0; }
.info.stacked .total { font-size: 1.15rem; }

/* ── forms ───────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem .9rem; margin: 0 0 1rem; }
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .88rem; color: var(--muted); }
.filters label.check { flex-direction: row; align-items: center; gap: .4rem; color: var(--text); font-size: 1rem; padding-bottom: .55rem; }
input, select, button { font: inherit; }
input[type="text"], input[type="search"], input[type="password"], input[type="date"], select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: .5rem .65rem; min-height: 2.6rem; max-width: 100%;
}
input[type="search"] { min-width: 12rem; }
button[type="submit"] {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: .5rem 1.2rem; min-height: 2.6rem; cursor: pointer; font-weight: 600;
}
@media (prefers-color-scheme: dark) { button[type="submit"] { color: #0c1a12; } }
.reset { align-self: center; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1.25rem; }
.chip.on { background: var(--accent); color: #fff; }
a.chip { background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 400; }
a.chip:hover { text-decoration: none; background: var(--surface-2); }
a.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { a.chip.on { color: #0c1a12; } }

.login { max-width: 360px; margin: 2rem auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.25rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .9rem; }
.login label { display: flex; flex-direction: column; gap: .25rem; }
.login input { width: 100%; }

@media print {
  .mbar, .side, .scrim, .filters, .chips, .foot, .logout { display: none; }
  .side ~ main { margin: 0 auto; }
  .report-card { box-shadow: none; }
  body { background: #fff; color: #000; }
  .table-wrap { overflow: visible; }
}
