:root {
  --bg: #f6f5f2; --surface: #fff; --ink: #1d1d1b; --muted: #74726c; --line: #e6e3dc;
  --accent: #1f5f8b; --accent-soft: #e5eef5; --good: #1e7a4c; --bad: #b3261e; --warn-bg: #fff4dc;
  --bar: #9dbad0; --bar-hi: #1f5f8b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514; --surface: #1e1e1c; --ink: #ecebe6; --muted: #9a978f; --line: #2f2e2b;
    --accent: #7fb3d9; --accent-soft: #1d2a33; --good: #6fcf97; --bad: #f28b82; --warn-bg: #3a3020;
    --bar: #36536a; --bar-hi: #7fb3d9;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 "IBM Plex Sans Arabic", system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.good { color: var(--good); } .bad { color: var(--bad); } .strong { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; text-align: left; direction: ltr; white-space: nowrap; }

.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-in { display: flex; align-items: center; gap: 20px; min-height: 58px; flex-wrap: wrap; padding-block: 8px; }
.brand { font-weight: 700; color: var(--ink); } .brand span { color: var(--muted); font-weight: 500; }
nav { display: flex; gap: 4px; }
nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sync { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; }

button { font: inherit; background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 7px 14px; cursor: pointer; }
@media (prefers-color-scheme: dark) { button { color: #0f1a22; } }
button.link { background: none; color: var(--muted); padding: 0; font-size: 12px; }
button.link:hover { color: var(--bad); }
select, input { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }

main { padding-block: 20px 60px; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 16px; margin: 0 0 12px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.btn-ghost { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
details.card summary { cursor: pointer; list-style: none; } details.card summary h2 { display: inline; }
details.card[open] summary { margin-bottom: 12px; }
.flash { background: var(--accent-soft); color: var(--accent); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.alert { background: var(--warn-bg); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.alert a { margin-inline: 3px; }
.empty { color: var(--muted); text-align: center; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi b { font-size: 21px; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi.main { background: var(--accent-soft); border-color: transparent; } .kpi.main b { color: var(--accent); }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: start; font-weight: 500; color: var(--muted); font-size: 13px; padding: 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); }
tfoot td { font-weight: 600; border-bottom: 0; }
tr.dim td { color: var(--muted); }
table.compact { max-width: 420px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--warn-bg); }

.chart { display: flex; align-items: flex-end; gap: 3px; height: 180px; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; }
.bar-col i { display: block; width: 100%; background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-col:hover i { background: var(--bar-hi); }
.bar-col em { font-style: normal; font-size: 10px; color: var(--muted); }
.bar-col.off em { opacity: .5; }

body.center { min-height: 100vh; display: grid; place-items: center; }
.login { width: min(360px, 92vw); display: flex; flex-direction: column; gap: 14px; }
.login label { display: flex; flex-direction: column; gap: 6px; }

@media (max-width: 640px) {
  .sync .muted { display: none; }
  .kpi b { font-size: 18px; }
  .chart { height: 130px; gap: 2px; }
  .bar-col em { font-size: 8px; }
}

/* ---- اليومية (نفس ألوان الشيت) ---- */
:root { --band: #4472c4; --band-dark: #1f4e78; --band-soft: #d9e1f2; --fixed-bg: #f7f9fd; }
@media (prefers-color-scheme: dark) { :root { --band: #3b5f9e; --band-dark: #1d3a57; --band-soft: #25324a; --fixed-bg: #1b2230; } }
.wrap.wide { max-width: 1440px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head .btn-ghost { font-size: 20px; padding: 4px 16px; }
.sheet-title { text-align: center; }
.sheet-title h1 { background: var(--band-dark); color: #fff; padding: 6px 22px; border-radius: 8px; font-size: 19px; }
.day-pick { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; background: var(--band-soft); border-radius: 8px; padding: 4px 10px; font-weight: 600; }
.day-pick input { padding: 2px 6px; border: 0; background: transparent; font-weight: 600; }

.totals-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.totals-bar div { background: var(--band); color: #fff; border-radius: 10px; padding: 8px 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.totals-bar .net { background: #5b9bd5; }
@media (prefers-color-scheme: dark) { .totals-bar .net { background: #2f5f8a; } }
.totals-bar b { font-size: 20px; color: #fff; }
.totals-bar b.bad { color: #ffd4d0; }

.sheet-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 330px; gap: 14px; align-items: start; }
.book { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 14px; }
.band { margin: 0; background: var(--band); color: #fff; padding: 7px 12px; font-size: 15px; text-align: center; }
.band.dark { background: var(--band-dark); }
.book table { width: 100%; border-collapse: collapse; }
.book th { background: var(--band-soft); color: var(--ink); font-weight: 600; padding: 5px 10px; font-size: 13px; }
.book td { padding: 0; border-bottom: 1px solid var(--line); }
.book td:first-child { padding-inline: 10px; }
.book tr.fixed td:first-child { background: var(--fixed-bg); font-size: 14px; white-space: nowrap; }
.book tr.islam td:first-child { white-space: normal; padding-block: 6px; }
.book tr.islam td:first-child small { display: block; color: var(--muted); font-size: 11px; line-height: 1.5; }
.book input { width: 100%; border: 0; border-radius: 0; background: transparent; padding: 8px 10px; }
.book input:focus { outline: 2px solid var(--band); outline-offset: -2px; background: var(--surface); }
.book input.amt { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; width: 120px; }
.book td:last-child { width: 1%; border-inline-start: 1px solid var(--line); }
.book tr.free td:first-child { padding: 0; position: relative; }
.book tr.free .tag { display: block; font-size: 11px; color: var(--muted); background: none; padding: 0 10px 4px; margin-top: -4px; pointer-events: none; }
.book tr.free .tag:empty { display: none; }
.book tfoot td { background: var(--band-soft); font-weight: 700; padding: 7px 10px; }
.book tfoot td.num { text-align: left; }
.book [data-islam]::placeholder { color: var(--accent); opacity: .75; }
.hint { background: var(--band-soft); color: var(--ink); font-size: 11px; padding: 2px 8px; margin-inline-start: 6px; border-radius: 99px; }
.note { display: flex; flex-direction: column; gap: 4px; padding: 10px; font-size: 13px; color: var(--muted); }
.book.count, table.count input { text-align: center; }
table.count td { padding: 0 10px; } table.count td:nth-child(2) { padding: 0; border-inline: 1px solid var(--line); }
table.count input { width: 100%; text-align: center; }
.insta-actual { display: flex; align-items: center; justify-content: space-between; padding: 0 0 0 0; border-top: 1px solid var(--line); }
.insta-actual span { padding-inline: 10px; font-size: 14px; font-weight: 600; }
.insta-actual input { width: 140px; border-inline-start: 1px solid var(--line); }
.report dl { display: grid; grid-template-columns: 1fr auto; margin: 0; }
.report dt, .report dd { margin: 0; padding: 6px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.report dt { color: var(--muted); }
.report .sep { border-top: 2px solid var(--band-soft); }
.report .strong { font-weight: 700; color: var(--ink); font-size: 16px; }

.save-bar { position: sticky; bottom: 0; z-index: 4; display: flex; align-items: center; gap: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px 12px 0 0; padding: 10px 16px; box-shadow: 0 -4px 16px rgba(0,0,0,.06); }
.save-bar div { display: flex; flex-direction: column; }
.save-bar span { font-size: 12px; color: var(--muted); }
.save-bar b { font-size: 18px; }
.save-bar button { margin-inline-start: auto; padding: 10px 36px; font-weight: 700; }
.sublinks { font-size: 14px; }

@media (max-width: 1150px) { .sheet-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .side { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; } .side .book { margin: 0; } }
@media (max-width: 760px) {
  .sheet-grid, .side { grid-template-columns: 1fr; }
  .totals-bar { gap: 6px; }
  .totals-bar div { flex-direction: column; align-items: flex-start; padding: 6px 10px; gap: 0; }
  .totals-bar span { font-size: 12px; } .totals-bar b { font-size: 16px; }
  .book tr.fixed td:first-child { white-space: normal; }
  .book input.amt { width: 100px; }
  .save-bar { gap: 12px; } .save-bar button { padding: 10px 20px; }
}
tr.today td { background: var(--accent-soft); }
table.ledger td, table.ledger th { padding: 7px 6px; font-size: 14px; }
.settings .row-2 { max-width: 520px; }
.settings > button { padding: 10px 28px; }

@media (max-width: 640px) {
  .row-2 { grid-template-columns: 1fr; }
  nav { overflow-x: auto; max-width: 100%; }
  nav a { white-space: nowrap; }
}

/* ---- الإعدادات وعناصر عامة ---- */
.c { text-align: center; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }
textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
table.grid td { padding: 4px; border-bottom: 0; }
table.grid th { padding: 4px 6px; }
table.grid input:not([type=checkbox]), table.grid select { width: 100%; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-2 label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
@media (max-width: 640px) { .row-2 { grid-template-columns: 1fr; } }

.book small.sys { display: block; font-size: 11px; color: var(--muted); line-height: 1.4; }
.book small.sys b { font-weight: 600; margin-inline-start: 4px; }
.book tr.fixed td:first-child:has(small.sys) { padding-block: 5px; }

details.tg { font-size: 11px; color: var(--muted); margin-top: 2px; }
details.tg summary { cursor: pointer; }
details.tg summary b { margin-inline-start: 4px; }
details.tg ul { list-style: none; margin: 4px 0; padding: 0; }
details.tg li { display: flex; gap: 8px; align-items: center; padding: 2px 0; }
details.tg li.off .num { text-decoration: line-through; }
details.tg .link { font-size: 11px; }
.tg-warn { margin: 0; padding: 8px 10px; font-size: 12px; background: var(--warn-bg); }

.sys-missing { margin: 0; padding: 8px 10px; font-size: 12px; background: var(--warn-bg); display: flex; flex-direction: column; gap: 4px; }
.sys-missing div { display: flex; gap: 8px; align-items: center; }
.sys-missing .link { color: var(--accent); font-size: 12px; }
.hint.bad-hint { background: var(--warn-bg); color: var(--bad); }

/* ---- الموبايل: هيدر وعنوان أصغر ---- */
@media (max-width: 640px) {
  .top-in { gap: 6px 10px; min-height: 0; padding-block: 8px; }
  .brand { order: 1; }
  .sync { order: 2; margin-inline-start: auto; }
  .sync button { padding: 5px 10px; font-size: 13px; }
  nav { order: 3; width: 100%; justify-content: space-between; }
  nav a { padding: 5px 10px; font-size: 14px; }
  .sheet-head { gap: 8px; margin-bottom: 10px; }
  .sheet-head .btn-ghost { padding: 4px 10px; font-size: 18px; }
  .sheet-title h1 { font-size: 15px; padding: 5px 12px; }
  .day-pick { flex-wrap: nowrap; gap: 6px; padding: 3px 8px; font-size: 13px; }
  .day-pick span { white-space: nowrap; }
  .day-pick input { font-size: 13px; width: 125px; }
  main { padding-block: 12px 40px; }
}

.who { font-size: 13px; color: var(--muted); white-space: nowrap; }
.saved-by { text-align: center; font-size: 12px; color: var(--muted); margin: -6px 0 10px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
tr.warn-row td { background: var(--warn-bg); }
tr.new-user td { background: var(--accent-soft); }
@media (max-width: 640px) { .who { order: 2; } }
