:root {
  --bg: #f5f7f6;
  --card: #ffffff;
  --text: #17201e;
  --muted: #66736f;
  --line: #dfe5e3;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --good: #15803d;
  --bad: #c2410c;
  --bad-bg: #fff1e8;
  --good-bg: #e9f8ee;
  --mid-bg: #eef1f0;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1413;
    --card: #182120;
    --text: #e7eeec;
    --muted: #94a3a0;
    --line: #2a3533;
    --brand: #2dd4bf;
    --brand-ink: #062b27;
    --good: #4ade80;
    --bad: #fb923c;
    --bad-bg: #3a2216;
    --good-bg: #13301e;
    --mid-bg: #212b29;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 "IBM Plex Sans Arabic", system-ui, sans-serif;
  padding-bottom: 80px;
}
a { color: var(--brand); text-decoration: none; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }
h3 { margin: 0; font-size: 1rem; }
small { font-size: .82rem; }
.muted { color: var(--muted); }
.good { color: var(--good); }
.bad { color: var(--bad); }
code { background: var(--mid-bg); padding: 2px 6px; border-radius: 6px; font-size: .8rem; word-break: break-all; direction: ltr; display: inline-block; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--brand); color: var(--brand-ink);
}
.top .brand { color: var(--brand-ink); font-weight: 700; }
main { max-width: 760px; margin: 0 auto; padding: 12px 16px; }

.nav {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a { display: flex; flex-direction: column; align-items: center; padding: 8px 0 6px; font-size: .72rem; color: var(--muted); }
.nav a span { font-size: 1.25rem; line-height: 1.2; }
.nav a.on { color: var(--brand); font-weight: 700; }
@media (min-width: 900px) {
  body { padding-bottom: 0; padding-top: 0; }
  .nav { position: sticky; top: 52px; bottom: auto; max-width: 760px; margin: 0 auto; border: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
}

.subnav { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; }
.subnav a { padding: 6px 12px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); white-space: nowrap; color: var(--text); font-size: .9rem; }
.subnav a.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.flash { background: var(--good-bg); color: var(--good); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat.bad { background: var(--bad-bg); border-color: transparent; }
.stat.bad b { color: var(--bad); }
.stat em { font-style: normal; }

ul.tasks, ul.list, ul.meals, ul.pantry { list-style: none; padding: 0; margin: 0; }
.task { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.task.done { opacity: .65; }
.task.missed { background: var(--bad-bg); border-color: transparent; }
.task.late { border-color: var(--bad); border-width: 2px; }
.task-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.task-head .title { font-weight: 700; flex: 1; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; direction: ltr; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--mid-bg); }
.badge.red { background: var(--bad); color: #fff; }
.meals li { padding: 6px 0; border-bottom: 1px dashed var(--line); }

.list li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.list li > details { width: 100%; }
.list.compact li { padding: 8px 12px; }
.list li.inactive { opacity: .55; }
.list summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.list .pen { width: 100%; color: var(--bad); }
.right { margin-inline-start: auto; }
.penalty { justify-content: space-between; }

form { margin: 0; }
form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
form.inline input { flex: 1 1 110px; min-width: 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 10px; }
.grid .wide { grid-column: 1 / -1; }
.grid h2 { margin: .6rem 0 0; }
@media (max-width: 520px) { .grid { grid-template-columns: 1fr; } }
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--muted); }
label.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 0; }
fieldset.days { display: flex; flex-wrap: wrap; gap: 4px 14px; }
legend { font-size: .85rem; color: var(--muted); padding: 0 4px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; width: 100%;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; }
button, .btn {
  font: inherit; font-weight: 700; cursor: pointer; border: 0; border-radius: 10px;
  padding: 9px 16px; background: var(--brand); color: var(--brand-ink); display: inline-block;
}
button.ghost, .btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
button.link { background: none; color: var(--muted); padding: 4px 8px; font-weight: 400; text-decoration: underline; }
button.danger, .danger { color: var(--bad); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }

.ing-row { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 6px; margin-bottom: 6px; }

.day-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.slot { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }

.pantry { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { background: var(--good-bg); color: var(--text); font-weight: 400; padding: 5px 12px; border-radius: 99px; }
.pantry li.out .pill { background: var(--bad-bg); }

.chart { width: 100%; height: auto; display: block; direction: ltr; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; }
.chart .dot { fill: var(--brand); }
.chart .grid-line { stroke: var(--line); stroke-dasharray: 4 4; }
.chart .axis { fill: var(--muted); font-size: 11px; }

.heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 4px; }
.heat .cell { border-radius: 8px; padding: 4px; text-align: center; background: var(--mid-bg); line-height: 1.2; }
.heat .cell span { display: block; font-weight: 700; }
.heat .cell small { font-size: .7rem; color: var(--muted); }
.heat .cell.good { background: var(--good-bg); }
.heat .cell.bad { background: var(--bad-bg); }

.link-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; }

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
body.login .card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }
body.login h1 { margin: 0; text-align: center; }
.err { color: var(--bad); margin: 0; }
