:root {
  --bg: #ECEFEA; --card: #FFFDF8; --card2: #F5F6F1; --ink: #1E2B33; --ink2: #4B5862; --mute: #6B747A;
  --line: #D6D9D2; --brand: #1C6B73; --brand-soft: #DCEAE8; --brand-ink: #FFFFFF;
  --crit: #B3261E; --crit-soft: #FBEBEB; --warn: #9A5B00; --warn-soft: #F9EEDA;
  --info: #1C6B73; --info-soft: #E3EFEE; --good: #2E7D4F; --good-soft: #E5F4E4;
  --client: #6A4FB3; --client-soft: #EFEDFF;
  --shadow: 0 1px 2px rgba(30,43,51,.06), 0 4px 14px rgba(30,43,51,.06);
  --r: 14px; --nav: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11181C; --card: #182126; --card2: #1E292F; --ink: #E7ECEA; --ink2: #B7C2C0; --mute: #8C9898;
    --line: #2B383E; --brand: #4FB0B8; --brand-soft: #1D3A3D; --brand-ink: #0D1518;
    --crit: #F28B82; --crit-soft: #3A1E1C; --warn: #F2B866; --warn-soft: #3A2C16;
    --info: #7FC7CD; --info-soft: #1A3235; --good: #81C995; --good-soft: #1B3324;
    --client: #B7A6F2; --client-soft: #2A2442;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11181C; --card: #182126; --card2: #1E292F; --ink: #E7ECEA; --ink2: #B7C2C0; --mute: #8C9898;
  --line: #2B383E; --brand: #4FB0B8; --brand-soft: #1D3A3D; --brand-ink: #0D1518;
  --crit: #F28B82; --crit-soft: #3A1E1C; --warn: #F2B866; --warn-soft: #3A2C16;
  --info: #7FC7CD; --info-soft: #1A3235; --good: #81C995; --good-soft: #1B3324;
  --client: #B7A6F2; --client-soft: #2A2442;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell ---------- */
.app { display: flex; min-height: 100vh; }
.side {
  width: var(--nav); flex: none; position: sticky; top: 0; height: 100vh;
  background: var(--card); border-inline-start: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; }
.brand b { display: block; font-size: 15px; }
.brand small { color: var(--mute); font-size: 12px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-radius: 10px;
  background: transparent; cursor: pointer; text-align: start; color: var(--ink2); font-size: 14.5px;
}
.nav-btn:hover { background: var(--card2); }
.nav-btn.on { background: var(--brand-soft); color: var(--ink); font-weight: 600; }
.nav-btn .badge { margin-inline-start: auto; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--mute); padding: 0 8px; }

.main { flex: 1; min-width: 0; padding: 22px 28px 96px; }
.wrap { max-width: 1060px; margin: 0 auto; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top h1 { font-size: 22px; margin: 0; font-weight: 700; }
.top .sub { color: var(--mute); font-size: 13.5px; }
.top .grow { flex: 1; }

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--mute); }
.sync::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.sync.saving::before, .sync.pending::before { background: var(--warn); }
.sync.error::before, .sync.offline::before { background: var(--crit); }

.bottom { display: none; }

/* ---------- primitives ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card h2 .count { color: var(--mute); font-weight: 500; font-size: 13px; }
.card h3 { font-size: 14.5px; margin: 14px 0 8px; }
.muted { color: var(--mute); }
.small { font-size: 13px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sp { flex: 1; }
.stack > * + * { margin-top: 14px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  border-radius: 10px; padding: 7px 12px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--card2); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.pri:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--crit); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--card2); color: var(--ink2); border: 1px solid var(--line); white-space: nowrap; }
.chip svg.i { width: 13px; height: 13px; }
.chip.bad { background: var(--crit-soft); color: var(--crit); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.chip.client { background: var(--client-soft); color: var(--client); border-color: transparent; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center; background: var(--crit); color: #fff; }
.badge.w { background: var(--warn); }

.bar { height: 6px; background: var(--card2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.bar.good > i { background: var(--good); }

input.f, select.f, textarea.f {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 10px; font-size: 14.5px;
}
textarea.f { min-height: 84px; resize: vertical; }
input.f:focus, select.f:focus, textarea.f:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
label.l { display: block; font-size: 13px; color: var(--ink2); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .help { font-size: 12px; color: var(--mute); margin-top: 3px; }
.unit { color: var(--mute); font-size: 12.5px; }

.seg { display: inline-flex; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 8px; cursor: pointer; font-size: 13.5px; color: var(--ink2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }

.empty { color: var(--mute); font-size: 14px; padding: 6px 0; }

/* ---------- hero ---------- */
.hero { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; }
.ring { width: 86px; height: 86px; }
.ring circle { fill: none; stroke-width: 9; }
.ring .t { stroke: var(--card2); }
.ring .v { stroke: var(--brand); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }
.ring text { fill: var(--ink); font-size: 20px; font-weight: 700; text-anchor: middle; dominant-baseline: central; font-family: inherit; }
.hero h2 { margin: 0; font-size: 19px; }
.hero .meta { color: var(--mute); font-size: 13.5px; }
.count-down { text-align: center; background: var(--brand-soft); border-radius: 12px; padding: 10px 14px; min-width: 150px; }
.count-down b { display: block; font-size: 26px; line-height: 1.2; }
.count-down span { font-size: 12.5px; color: var(--ink2); }

/* ---------- alerts ---------- */
.alert { display: flex; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--card2); border: 1px solid var(--line); cursor: pointer; text-align: start; width: 100%; }
.alert + .alert { margin-top: 8px; }
.alert .dot { width: 8px; flex: none; border-radius: 4px; background: var(--info); }
.alert.crit { background: var(--crit-soft); border-color: transparent; } .alert.crit .dot { background: var(--crit); }
.alert.warn { background: var(--warn-soft); border-color: transparent; } .alert.warn .dot { background: var(--warn); }
.alert.good { background: var(--good-soft); border-color: transparent; } .alert.good .dot { background: var(--good); }
.alert b { display: block; font-size: 14px; }
.alert p { margin: 2px 0 0; font-size: 13px; color: var(--ink2); white-space: pre-line; }
.alert .who { font-size: 11.5px; color: var(--mute); }

.persona { display: flex; flex-direction: column; }
.persona header { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.persona header b { display: block; }
.persona header small { color: var(--mute); font-size: 12.5px; line-height: 1.4; display: block; }

/* ---------- tasks ---------- */
.tasks { display: flex; flex-direction: column; }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 9px 2px; border-top: 1px solid var(--line); }
.tasks > .task:first-child { border-top: 0; }
.check {
  width: 22px; height: 22px; border-radius: 7px; border: 1.8px solid var(--mute); background: var(--card);
  flex: none; cursor: pointer; margin-top: 2px; display: grid; place-items: center; padding: 0;
}
.check svg.i { width: 14px; height: 14px; opacity: 0; stroke-width: 3; }
.task.is-done .check { background: var(--good); border-color: var(--good); color: #fff; }
.task.is-done .check svg.i { opacity: 1; }
.task.is-doing .check { border-color: var(--brand); box-shadow: inset 0 0 0 4px var(--brand-soft); }
.task.is-locked .check { border-style: dashed; }
.task-main { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-size: 14.5px; }
.task.is-done .task-title { color: var(--mute); text-decoration: line-through; text-decoration-color: var(--line); }
.task.is-locked .task-title { color: var(--ink2); }
.task-meta { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
.star { border: 0; background: transparent; cursor: pointer; color: var(--mute); padding: 2px; flex: none; }
.star.on { color: var(--warn); }
.star.on svg.i { fill: currentColor; }
.crit-mark { color: var(--crit); }

.sec-title { font-size: 13px; font-weight: 700; color: var(--ink2); margin: 16px 0 4px; display: flex; gap: 8px; align-items: center; }
.sec-title:first-child { margin-top: 0; }

/* ---------- journey ---------- */
.phase { padding: 0; overflow: hidden; }
.phase > summary { list-style: none; cursor: pointer; padding: 16px 18px; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; }
.phase > summary::-webkit-details-marker { display: none; }
.phase-letter { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; background: var(--card2); border: 1px solid var(--line); }
.phase[data-state="done"] .phase-letter { background: var(--good); color: #fff; border-color: transparent; }
.phase[data-state="active"] .phase-letter { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.phase h3 { margin: 0; font-size: 16px; }
.phase .pmeta { font-size: 12.5px; color: var(--mute); }
.phase-body { padding: 0 18px 16px; }
.stage { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 10px; background: var(--card); }
.stage.locked { background: var(--card2); }
.stage-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stage-head b { font-size: 14.5px; }
.stage .bar { margin: 8px 0 4px; }
.gatebox { background: var(--card2); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.gatebox li { margin: 2px 0; }
.gatebox ul { margin: 4px 0 0; padding-inline-start: 18px; }
.ok { color: var(--good); } .no { color: var(--crit); } .na { color: var(--mute); }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
.tbl th { color: var(--mute); font-weight: 600; font-size: 12.5px; }
.tbl td.n { font-variant-numeric: tabular-nums; white-space: nowrap; }
.scroll-x { overflow-x: auto; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; font-size: 14px; }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: end; white-space: nowrap; }
.kv .k { color: var(--ink2); }

/* ---------- week strip ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day { border: 1px solid var(--line); border-radius: 10px; padding: 6px 4px; text-align: center; background: var(--card); cursor: pointer; }
.day.today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.day.off { background: var(--card2); }
.day small { display: block; color: var(--mute); font-size: 11.5px; }
.day b { display: block; font-size: 16px; }
.day .n { font-size: 11.5px; color: var(--ink2); }
.day .mk { display: block; height: 4px; width: 18px; margin: 3px auto 0; border-radius: 2px; background: transparent; }
.day .mk.on { background: var(--crit); }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .ax { stroke: var(--line); }
.chart .lbl { fill: var(--mute); font-size: 11px; font-family: inherit; }
.chart .s1 { stroke: var(--brand); fill: none; stroke-width: 2.4; }
.chart .s2 { stroke: var(--mute); fill: none; stroke-width: 2; stroke-dasharray: 5 4; }
.chart .s3 { stroke: var(--crit); fill: none; stroke-width: 1.6; stroke-dasharray: 3 3; }
.chart .d1 { fill: var(--brand); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink2); flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; background: var(--brand); vertical-align: middle; margin-inline-end: 5px; border-radius: 2px; }
.legend i.s2 { background: var(--mute); }
.legend i.s3 { background: var(--crit); }

/* ---------- journal ---------- */
.entry { border-top: 1px solid var(--line); padding: 10px 0; }
.entry:first-child { border-top: 0; }
.entry p { margin: 4px 0 0; white-space: pre-wrap; }

/* ---------- dialog ---------- */
dialog.dlg { border: 0; padding: 0; border-radius: 16px; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog.dlg::backdrop { background: rgba(17,24,28,.45); }
.dlg-head { display: flex; align-items: flex-start; gap: 10px; padding: 16px 18px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); z-index: 1; }
.dlg-head h3 { margin: 0; font-size: 16.5px; flex: 1; }
.dlg-body { padding: 14px 18px 18px; }
.dlg-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; position: sticky; bottom: 0; background: var(--card); }
.how { background: var(--brand-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
pre.tpl { white-space: pre-wrap; font-family: inherit; margin: 0; }

.toast { position: fixed; bottom: 22px; inset-inline-start: 50%; transform: translateX(50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 100; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.on { opacity: 1; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(420px, 100%); }
.auth h1 { font-size: 20px; margin: 0 0 4px; }
.err { color: var(--crit); font-size: 13.5px; min-height: 20px; }

.fab { position: fixed; bottom: 26px; inset-inline-end: 26px; width: 52px; height: 52px; border-radius: 16px; border: 0; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; box-shadow: 0 8px 24px rgba(28,107,115,.35); cursor: pointer; z-index: 20; }
.fab svg.i { width: 24px; height: 24px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .side { display: none; }
  .main { padding: 14px 16px 96px; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .hero { grid-template-columns: auto 1fr; }
  .hero .count-down { grid-column: 1 / -1; }
  .top h1 { font-size: 19px; }
  .bottom {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
    background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom button { border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; color: var(--mute); padding: 4px 0; cursor: pointer; position: relative; }
  .bottom button.on { color: var(--brand); font-weight: 600; }
  .bottom button .badge { position: absolute; top: 0; inset-inline-end: calc(50% - 22px); transform: scale(.85); }
  .fab { bottom: calc(76px + env(safe-area-inset-bottom)); inset-inline-end: 16px; }
  .week { gap: 4px; }
  .day b { font-size: 14px; }
  .toast { bottom: 90px; }
}
@media print { .side, .bottom, .fab { display: none; } }
