@font-face { font-family: "NotoSansAr"; src: url("/static/fonts/NotoSansArabic-Regular.ttf"); }
@font-face { font-family: "NotoSansAr"; font-weight: 700; src: url("/static/fonts/NotoSansArabic-Bold.ttf"); }

:root {
  color-scheme: light;
  --bg: #f5f5f3; --surface: #fcfcfb; --surface-2: #f0efec; --border: #dddcd7;
  --text: #0b0b0b; --text-2: #52514e; --muted: #807e78;
  --accent: #2a78d6; --accent-ink: #ffffff;
  --series-1: #2a78d6; --series-2: #eb6834;
  --good: #0a7d3c; --good-bg: #e3f4ea; --warn: #9a6200; --warn-bg: #fdf1d8; --bad: #b42318; --bad-bg: #fde7e5;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8d84;
    --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926;
    --good: #5fd08f; --good-bg: #16301f; --warn: #f0b440; --warn-bg: #33270f; --bad: #ff8a80; --bad-bg: #3a1a17;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #33332f;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8d84;
  --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926;
  --good: #5fd08f; --good-bg: #16301f; --warn: #f0b440; --warn-bg: #33270f; --bad: #ff8a80; --bad-bg: #3a1a17;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, "NotoSansAr", "Segoe UI", sans-serif; }
[dir="rtl"] body { font-family: "NotoSansAr", system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 16px; margin: 22px 0 10px; }
.num, td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

header.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; white-space: nowrap; }
.brand img { height: 28px; }
header nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
header nav a { color: var(--text-2); padding: 6px 10px; border-radius: 6px; }
header nav a.on, header nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.tools { display: flex; gap: 12px; white-space: nowrap; }
.menu-btn { display: none; background: none; border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 4px 10px; font-size: 18px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
.flash { background: var(--good-bg); color: var(--good); padding: 8px 12px; border-radius: 8px; margin-bottom: 14px; }

.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.bar .grow { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 12px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat .lbl { color: var(--text-2); font-size: 12px; }
.stat .big { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.tbl-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: start; font-weight: 600; color: var(--text-2); background: var(--surface-2); padding: 7px 10px; font-size: 12px; white-space: nowrap; }
table.t td { padding: 7px 10px; border-top: 1px solid var(--border); vertical-align: top; }
table.t tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
table.t tfoot td { font-weight: 700; background: var(--surface-2); }
table.t td.neg, .neg { color: var(--bad); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.paid { background: var(--good-bg); color: var(--good); }
.pill.sent, .pill.invoiced, .pill.partial { background: var(--warn-bg); color: var(--warn); }
.pill.cancelled { text-decoration: line-through; }
.pill.expected { background: var(--surface-2); }
.alert { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }

input, select, textarea, button { font: inherit; color: var(--text); }
input, select, textarea { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; min-width: 0; }
textarea { width: 100%; min-height: 70px; }
button, .btn { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer; color: var(--text); display: inline-block; white-space: nowrap; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); }
.btn:hover { text-decoration: none; }
form.inline { display: inline; }

.form { display: grid; grid-template-columns: 220px minmax(0, 520px); gap: 10px 16px; align-items: center; }
.form label { color: var(--text-2); }
.form input:not([type=checkbox]), .form select, .form textarea { width: 100%; }
.form .actions { grid-column: 2; display: flex; gap: 8px; margin-top: 8px; }

.login { max-width: 340px; margin: 12vh auto; }
.login input { width: 100%; margin: 8px 0 12px; }

/* chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 260px; overflow: visible; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .b1 { fill: var(--series-1); } .chart .b2 { fill: var(--series-2); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: color-mix(in srgb, var(--text) 6%, transparent); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 6px; vertical-align: -1px; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); display: none; white-space: nowrap; z-index: 5; }
.tip b { display: block; margin-bottom: 4px; }

@media (max-width: 900px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2 { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: block; margin-inline-start: auto; }
  header.top { flex-wrap: wrap; }
  header nav, .tools { display: none; width: 100%; }
  body.nav-open header nav, body.nav-open .tools { display: flex; }
  .form { grid-template-columns: minmax(0, 1fr); }
  .form .actions { grid-column: 1; }
}
@media print { header.top, .bar, .noprint { display: none !important; } body { background: #fff; } }
