/* ===== الألوان (فاتح) ===== */
:root {
  color-scheme: light;
  --bg: #eef2f8; --card: #ffffff; --text: #162033; --muted: #5a6779;
  --line: #d3dbe8; --line-strong: #b9c5d8;
  --brand: #2563eb; --brand-dark: #1d4ed8; --on-brand: #ffffff;
  --input-bg: #ffffff; --readonly-bg: #eef2f8;
  --th-bg: #e4ecfa; --th-text: #1e3a6e; --stripe: #f5f8fd; --hover: #e9f1ff; --tfoot-bg: #e4ecfa;
  --talent: #7c3aed; --decor: #d97706;
  --good: #0f7a46; --bad: #c62828;
  --pill-bg: #e8edf5; --pill-talent-bg: #ede9fe; --pill-talent: #5b21b6; --pill-decor-bg: #fef3c7; --pill-decor: #92400e; --pill-shared-bg: #dbeefe; --pill-shared: #075985;
  --done-bg: #e8f7ef; --done-line: #9fd8b9;
  --shadow: 0 1px 2px rgba(22, 32, 51, .06), 0 4px 14px rgba(22, 32, 51, .06);
  --head-from: #1e3a8a; --head-to: #2563eb;
}
/* ===== داكن ===== */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1420; --card: #172030; --text: #e7ecf5; --muted: #9baabf;
  --line: #2b384c; --line-strong: #3d4d66;
  --brand: #5b9bff; --brand-dark: #7db0ff; --on-brand: #0b1220;
  --input-bg: #0f1724; --readonly-bg: #1c2739;
  --th-bg: #22324d; --th-text: #cfe0ff; --stripe: #1b2638; --hover: #263753; --tfoot-bg: #22324d;
  --talent: #a78bfa; --decor: #fbbf24;
  --good: #4ade80; --bad: #ff7b7b;
  --pill-bg: #263248; --pill-talent-bg: #2e2552; --pill-talent: #c4b5fd; --pill-decor-bg: #4a3512; --pill-decor: #fcd34d; --pill-shared-bg: #12364d; --pill-shared: #7dd3fc;
  --done-bg: #12301f; --done-line: #25663f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
  --head-from: #14213d; --head-to: #1e3a7a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1420; --card: #172030; --text: #e7ecf5; --muted: #9baabf;
    --line: #2b384c; --line-strong: #3d4d66;
    --brand: #5b9bff; --brand-dark: #7db0ff; --on-brand: #0b1220;
    --input-bg: #0f1724; --readonly-bg: #1c2739;
    --th-bg: #22324d; --th-text: #cfe0ff; --stripe: #1b2638; --hover: #263753; --tfoot-bg: #22324d;
    --talent: #a78bfa; --decor: #fbbf24;
    --good: #4ade80; --bad: #ff7b7b;
    --pill-bg: #263248; --pill-talent-bg: #2e2552; --pill-talent: #c4b5fd; --pill-decor-bg: #4a3512; --pill-decor: #fcd34d; --pill-shared-bg: #12364d; --pill-shared: #7dd3fc;
    --done-bg: #12301f; --done-line: #25663f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
    --head-from: #14213d; --head-to: #1e3a7a;
  }
}

* { box-sizing: border-box; }
body { margin: 0; font-family: 'Cairo', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; transition: background .2s, color .2s; }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 20px; } h3 { font-size: 16px; }
.hidden { display: none !important; }

/* ===== الشريط العلوي والتبويبات ===== */
.topbar { background: linear-gradient(135deg, var(--head-from), var(--head-to)); color: #fff; padding: 12px 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; box-shadow: 0 2px 10px rgba(0, 0, 0, .25); }
.brand { font-weight: 700; font-size: 19px; margin-inline-end: auto; letter-spacing: .2px; }
.who { color: rgba(255, 255, 255, .85); font-size: 13px; }
.topbar button { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .28); color: #fff; }
.topbar button:hover { background: rgba(255, 255, 255, .26); }
.tabs { display: flex; gap: 6px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; box-shadow: var(--shadow); }
.tab { border: 1px solid transparent; background: none; padding: 8px 18px; font: inherit; cursor: pointer; color: var(--muted); border-radius: 999px; white-space: nowrap; }
.tab:hover { background: var(--hover); color: var(--text); }
.tab.active { background: var(--brand); color: var(--on-brand); font-weight: 700; }
main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 40px; }

/* ===== الكروت والنماذج ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--input-bg); color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
input[readonly] { background: var(--readonly-bg); }
.wide { grid-column: 1 / -1; }

button { font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--card); padding: 8px 14px; color: var(--text); transition: background .15s, border-color .15s; }
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-weight: 700; }
button.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
button.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
button.small { padding: 4px 11px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ===== الجداول (حدود واضحة + تظليل صفوف) ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--line-strong); border-radius: 10px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); border-inline-end: 1px solid var(--line); text-align: start; white-space: nowrap; }
th:last-child, td:last-child { border-inline-end: 0; }
td.wrap { white-space: normal; min-width: 170px; }
thead th { background: var(--th-bg); color: var(--th-text); font-weight: 700; border-bottom: 2px solid var(--line-strong); position: sticky; top: 0; }
tbody tr:nth-child(even) td { background: var(--stripe); }
tbody tr:hover td { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; background: var(--tfoot-bg); border-top: 2px solid var(--line-strong); border-bottom: 0; }
.card > table, .card > .table-wrap + table { margin-top: 12px; }
.card > table { border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.pos { color: var(--good); font-weight: 700; } .neg { color: var(--bad); font-weight: 700; }

/* ===== كروت الأرباح ===== */
.stat { border-top: 6px solid var(--line-strong); }
.stat.talent { border-top-color: var(--talent); } .stat.decor { border-top-color: var(--decor); } .stat.total { border-top-color: var(--brand); }
.stat h3 { margin-bottom: 10px; font-size: 17px; }
.stat .row { display: flex; justify-content: space-between; padding: 4px 0; color: var(--muted); }
.stat .row b { color: var(--text); font-variant-numeric: tabular-nums; }
.stat .bar { height: 8px; border-radius: 99px; background: var(--pill-bg); overflow: hidden; margin: 8px 0 4px; }
.stat .bar i { display: block; height: 100%; border-radius: 99px; background: var(--good); }
.stat .bar i.over { background: var(--bad); }
.stat .bar-note { font-size: 12px; color: var(--muted); }
.stat .net { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line-strong); font-size: 20px; display: flex; justify-content: space-between; font-weight: 700; }

.pill { display: inline-block; padding: 2px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--pill-bg); }
.pill.talent { background: var(--pill-talent-bg); color: var(--pill-talent); } .pill.decor { background: var(--pill-decor-bg); color: var(--pill-decor); } .pill.shared { background: var(--pill-shared-bg); color: var(--pill-shared); }

/* ===== المصروفات الثابتة ===== */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
button.tpl { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; padding: 12px 14px; text-align: start; border-radius: 12px; border: 1px solid var(--line-strong); }
button.tpl:hover { border-color: var(--brand); background: var(--hover); transform: translateY(-1px); }
button.tpl span:first-of-type { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
button.tpl.done { background: var(--done-bg); border-color: var(--done-line); }
button.tpl em { color: var(--good); font-style: normal; font-size: 12px; font-weight: 600; }

.note { color: var(--muted); font-size: 13px; }
.center-box { max-width: 400px; margin: 8vh auto; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; }
hr { border: 0; border-top: 1px solid var(--line); }

#toast { position: fixed; bottom: 20px; inset-inline: 0; margin: auto; width: fit-content; max-width: 90vw; background: #101828; color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; box-shadow: var(--shadow); border: 1px solid rgba(255, 255, 255, .15); }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); color: #fff; }

@media (max-width: 600px) { main { padding: 12px 10px 30px; } .card { padding: 13px; } .topbar { padding: 10px 12px; } .tabs { padding: 8px 10px; } }
