/* تخطيط: شريط جانبي على الكمبيوتر، شريط سفلي وبطاقات مكدسة على الجوال. هوية خضراء هادئة. */
:root {
  --bg: #F3F6F3;
  --surface: #FFFFFF;
  --surface-2: #EAF0EB;
  --line: #DCE5DE;
  --fg: #1E2A24;
  --muted: #5B6B63;
  --faint: #8A9A91;
  --primary: #0F5132;
  --primary-2: #198754;
  --primary-soft: #DDEFE3;
  --on-primary: #F4FBF6;
  --gold: #B38B12;
  --gold-soft: #F6EDCC;
  --red: #B54848;
  --red-soft: #F7E3E1;
  --orange: #C26A12;
  --orange-soft: #FBEBD8;
  --blue: #2563A6;
  --blue-soft: #E1ECF8;
  --hero: #0F5132;
  --hero-fg: #EEF7F1;
  --hero-muted: #A9CDB8;
  --shadow: 0 1px 2px rgba(15, 50, 30, .06), 0 6px 20px rgba(15, 50, 30, .05);
  --f-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --f-display: "Readex Pro", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --r: 16px;
  --r-sm: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1512; --surface: #151F1A; --surface-2: #1C2822; --line: #26352D;
    --fg: #E6EEE9; --muted: #A2B3A9; --faint: #74867B;
    --primary: #4CC08A; --primary-2: #5FD39C; --primary-soft: #183A29; --on-primary: #06140D;
    --gold: #E0BE52; --gold-soft: #3A3115; --red: #E58A85; --red-soft: #3B1F1E;
    --orange: #EBA25A; --orange-soft: #3A2814; --blue: #79AEEA; --blue-soft: #18283B;
    --hero: #123B28; --hero-fg: #EEF7F1; --hero-muted: #9CC7AF;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1512; --surface: #151F1A; --surface-2: #1C2822; --line: #26352D;
  --fg: #E6EEE9; --muted: #A2B3A9; --faint: #74867B;
  --primary: #4CC08A; --primary-2: #5FD39C; --primary-soft: #183A29; --on-primary: #06140D;
  --gold: #E0BE52; --gold-soft: #3A3115; --red: #E58A85; --red-soft: #3B1F1E;
  --orange: #EBA25A; --orange-soft: #3A2814; --blue: #79AEEA; --blue-soft: #18283B;
  --hero: #123B28; --hero-fg: #EEF7F1; --hero-muted: #9CC7AF;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { background: var(--bg); color: var(--fg); }
body { font-family: var(--f-body); font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
.num, .amt { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-2); }
:focus-visible { outline: 2px solid var(--primary-2); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; margin: 0; line-height: 1.3; }
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.12rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }

.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100%; }
.side { position: sticky; top: env(safe-area-inset-top, 0px); height: 100vh; padding-block: 24px; padding-inline: 16px; border-inline-end: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding-inline: 8px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); display: grid; place-items: center; color: var(--on-primary); flex: none; }
.brand b { font-family: var(--f-display); font-size: 1.2rem; display: block; line-height: 1.1; }
.brand small { color: var(--muted); font-size: .72rem; display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--fg); text-decoration: none; font-size: .93rem; }
.nav a svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav a.on svg { color: var(--primary); }
.nav .count { margin-inline-start: auto; background: var(--orange-soft); color: var(--orange); font-size: .72rem; padding: 0 7px; border-radius: 999px; font-weight: 600; }
.nav-sep { height: 1px; background: var(--line); margin: 6px 8px; }

main { min-width: 0; padding-block: 24px 110px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.wrap { max-width: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { color: var(--muted); font-size: .9rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head a, .link { font-size: .85rem; color: var(--primary-2); text-decoration: none; background: none; border: 0; cursor: pointer; padding: 0; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.hero { background: var(--hero); color: var(--hero-fg); border-radius: 20px; padding: 22px; display: grid; gap: 18px; }
.hero .hello { color: var(--hero-muted); font-size: .95rem; }
.hero-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.hero .lbl { font-size: .82rem; color: var(--hero-muted); letter-spacing: .01em; }
.hero .big { font-family: var(--f-display); font-size: clamp(1.9rem, 6vw, 2.6rem); font-weight: 600; line-height: 1.15; }
.hero .big small, .stat .v small { font-size: .45em; font-weight: 500; opacity: .75; margin-inline-start: 4px; }
.hero .avail .big { color: #FFE28A; }
.hero .neg { color: #FFB4AE !important; }
.hero-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; border-top: 1px solid rgba(255,255,255,.14); padding-top: 14px; }
.hero-strip .v { font-family: var(--f-display); font-size: 1.35rem; font-weight: 600; }
.hero button.calc { background: none; border: 0; color: var(--hero-muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 0; font-size: .82rem; justify-self: start; }
.breakdown { display: grid; gap: 4px; font-size: .88rem; background: rgba(0,0,0,.16); border-radius: 12px; padding: 12px 14px; }
.breakdown div { display: flex; justify-content: space-between; gap: 10px; }
.breakdown .tot { border-top: 1px solid rgba(255,255,255,.2); padding-top: 6px; margin-top: 4px; font-weight: 600; }

.ask { display: grid; gap: 10px; }
.ask-box { display: flex; gap: 8px; background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 6px; align-items: center; }
.ask-box:focus-within { border-color: var(--primary-2); }
.ask-box input { flex: 1; min-width: 0; border: 0; background: none; padding: 10px; outline: none; font-size: 1rem; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 4px 12px; font-size: .82rem; cursor: pointer; }
.chip:hover { border-color: var(--primary-2); color: var(--primary); }
.chip.on { background: var(--primary-soft); color: var(--primary); border-color: transparent; font-weight: 600; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 12px; padding: 10px 16px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; text-decoration: none; color: var(--fg); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.pri { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.btn.pri:hover { filter: brightness(1.07); background: var(--primary); }
.btn.big { width: 100%; padding: 14px; font-size: 1.05rem; border-radius: 14px; }
.btn.sm { padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn.danger { color: var(--red); border-color: var(--red-soft); }
.btn.ghost { border-color: transparent; background: none; }
.btn svg { width: 18px; height: 18px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-width: 0; }
.stat .k { color: var(--muted); font-size: .8rem; }
.stat .v { font-family: var(--f-display); font-size: 1.3rem; font-weight: 600; margin-top: 2px; }
.stat .s { color: var(--faint); font-size: .76rem; margin-top: 2px; }
.pos { color: var(--primary); } .neg { color: var(--red); } .warn { color: var(--orange); } .move { color: var(--blue); }

.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-top: 1px solid var(--line); min-width: 0; }
.item:first-child { border-top: 0; }
.item.tap { cursor: pointer; border-radius: 10px; padding-inline: 8px; margin-inline: -6px; }
.item.tap:hover { background: var(--surface-2); }
.ico { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); }
.ico svg { width: 18px; height: 18px; }
.ico.in { background: var(--primary-soft); color: var(--primary); }
.ico.out { background: var(--surface-2); color: var(--fg); }
.ico.move { background: var(--blue-soft); color: var(--blue); }
.ico.red { background: var(--red-soft); color: var(--red); }
.ico.orange { background: var(--orange-soft); color: var(--orange); }
.ico.gold { background: var(--gold-soft); color: var(--gold); }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .end { text-align: end; flex: none; font-weight: 600; font-variant-numeric: tabular-nums; }
.item .end small { display: block; color: var(--faint); font-weight: 400; font-size: .74rem; }
.day-h { font-size: .78rem; color: var(--faint); padding: 14px 2px 2px; font-weight: 600; letter-spacing: .02em; }

.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 1px 9px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--primary-soft); color: var(--primary); }
.pill.soon { background: var(--gold-soft); color: var(--gold); }
.pill.late { background: var(--red-soft); color: var(--red); }
.pill.open { background: var(--surface-2); color: var(--muted); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.orange { background: var(--orange-soft); color: var(--orange); }
.tag { font-size: .72rem; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 0 6px; white-space: nowrap; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 30%) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: .88rem; }
.bar-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.fill { height: 100%; background: var(--primary-2); border-radius: 999px; min-width: 2px; }
.fill.dim { background: var(--primary-soft); }
.fill.orange { background: var(--orange); }
.fill.red { background: var(--red); }
.fill.blue { background: var(--blue); }
.fill.gold { background: var(--gold); }
.bar-row .val { font-variant-numeric: tabular-nums; font-weight: 600; text-align: end; min-width: 64px; }
.bar-row .val small { color: var(--faint); font-weight: 400; }

.insight { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--surface-2); font-size: .92rem; }
.insight .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 8px; flex: none; background: var(--orange); }
.insight.repeat .dot { background: var(--blue); }
.insight.day .dot { background: var(--gold); }
.insight.review .dot { background: var(--red); }
.insight.good .dot { background: var(--primary-2); }

.progress { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--primary-2); border-radius: 999px; }

.empty { text-align: center; color: var(--muted); padding: 22px 10px; display: grid; gap: 10px; justify-items: center; font-size: .92rem; }
.empty svg { width: 34px; height: 34px; color: var(--faint); }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; font-size: .9rem; }
.banner.orange { background: var(--orange-soft); color: var(--fg); }
.banner.blue { background: var(--blue-soft); }
.banner.green { background: var(--primary-soft); }
.banner.red { background: var(--red-soft); }

/* نماذج */
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 5px; min-width: 0; }
.field label { font-size: .82rem; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; min-width: 0; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary-2); }
.field .hint { font-size: .76rem; color: var(--faint); }
.f2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.check { display: flex; gap: 8px; align-items: center; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary-2); }

/* لوح سفلي */
.sheet-bg { position: fixed; inset: 0; background: rgba(8, 20, 14, .45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: min(620px, 100%); max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 18px; padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: max(18px, env(safe-area-inset-right, 0px)); padding-bottom: max(22px, env(safe-area-inset-bottom, 0px)); display: grid; gap: 14px; box-shadow: 0 -8px 40px rgba(0,0,0,.2); }
.sheet-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.x { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; flex: none; }
.understood { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 6px; }
.understood .ln { display: flex; justify-content: space-between; gap: 10px; font-size: .92rem; }
.understood .ln span:first-child { color: var(--muted); }
.note { font-size: .84rem; color: var(--muted); display: flex; gap: 6px; }
.note::before { content: "•"; color: var(--primary-2); }

.toast { position: fixed; bottom: calc(86px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 60; font-size: .9rem; max-width: calc(100% - 32px); box-shadow: var(--shadow); }

.tabbar { display: none; }
.verdict { border-radius: 16px; padding: 18px; display: grid; gap: 6px; }
.verdict.green { background: var(--primary-soft); }
.verdict.yellow { background: var(--gold-soft); }
.verdict.red { background: var(--red-soft); }
.verdict .vt { font-family: var(--f-display); font-size: 1.25rem; font-weight: 600; }
.mini-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.mini-table td { padding: 7px 0; border-top: 1px solid var(--line); }
.mini-table td:last-child { text-align: end; font-variant-numeric: tabular-nums; font-weight: 600; }
.mini-table tr:first-child td { border-top: 0; }
.scroll-x { overflow-x: auto; }
.cmp { display: grid; gap: 10px; }
.stack { display: flex; height: 26px; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.stack > div { height: 100%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.path { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .88rem; }
.path b { background: var(--blue-soft); color: var(--blue); padding: 1px 8px; border-radius: 6px; font-weight: 600; }
.path i { color: var(--faint); font-style: normal; }
.acct-dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; flex: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  main { padding-block: 16px 104px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding-block: 6px max(8px, env(safe-area-inset-bottom, 0px)); padding-left: max(8px, env(safe-area-inset-left, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px)); }
  .tabbar a, .tabbar button { display: grid; justify-items: center; gap: 2px; font-size: .7rem; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; padding: 4px 0; }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar .on { color: var(--primary); font-weight: 600; }
  .tabbar .plus span { width: 46px; height: 46px; border-radius: 15px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; margin-top: -18px; box-shadow: var(--shadow); }
  .sheet-bg { align-items: flex-end; }
}
@media (max-width: 520px) {
  .g2.keep, .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .f2 { grid-template-columns: minmax(0, 1fr); }
  .hero { padding: 18px; }
  .hero-row { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .card { padding: 15px; }
  .bar-row { grid-template-columns: minmax(80px, 34%) minmax(0, 1fr) auto; }
}
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .22s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}

/* تسجيل الدخول */
.auth { max-width: 420px; margin: 8vh auto 0; display: grid; gap: 18px; }
.auth-brand { justify-content: center; }
body.signed-out .side, body.signed-out .tabbar { display: none; }
body.signed-out .app { grid-template-columns: minmax(0, 1fr); }
