/* مَعالِم — قماش التطريز: كل عادة منجزة غُرزة */

:root {
  color-scheme: dark;
  --fabric: #201C2B;
  --patch: #2A2536;
  --patch-2: #332D41;
  --seam: #463E55;
  --seam-soft: #3A3347;
  --hole: #1A1723;
  --linen: #F1E8DA;
  --ash: #B0A595;
  --strike: #9A90A4;
  --bright: #FFF8F0;

  --crimson: #EE6477;
  --crimson-solid: #BE2E44;
  --saffron: #E3A63B;
  --olive: #9DB35A;
  --teal: #3FA89C;
  --indigo: #8090E6;
  --rose: #E685A6;

  --ok: #A7C96B;
  --warn: #E3A63B;
  --bad: #FF7A6B;
  --focus: #E3A63B;

  --display: "Reem Kufi", "Noto Kufi Arabic", "Segoe UI", system-ui, sans-serif;
  --body: "Readex Pro", "Noto Sans Arabic", "Segoe UI", system-ui, -apple-system, sans-serif;

  --fs-xs: 12px;
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 19px;
  --fs-xl: 24px;
  --fs-2xl: 32px;

  --r-patch: 8px;
  --r-ctl: 6px;
  --rail: 220px;
  --tabbar: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--fabric); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--fabric);
  /* ثقوب قماش الإيتامين */
  background-image: radial-gradient(rgba(241, 232, 218, 0.045) 1px, transparent 1.3px);
  background-size: 7px 7px;
  color: var(--linen);
  font-family: var(--body);
  font-size: var(--fs-md);
  line-height: 1.65;
  font-weight: 400;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: 0.4; }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-family: var(--display); font-weight: 600; line-height: 1.3; text-wrap: balance; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; }
.ico { flex: none; display: block; }
.sr { position: absolute; inset-inline-start: 0; top: 0; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ash); }

/* ───────── الهيكل ───────── */

.app { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); }
.rail { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: 8px; padding-inline: 16px;
  background: color-mix(in srgb, var(--fabric) 92%, transparent);
  backdrop-filter: blur(6px);
  border-block-end: 1px solid var(--seam-soft);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-size: 26px; font-weight: 700; color: var(--bright); text-decoration: none; line-height: 1; }
.brand-mark { color: var(--crimson); }
.top-tools { display: flex; align-items: center; gap: 4px; }

main {
  width: 100%; max-width: 1100px; min-width: 0;
  margin-inline: auto;
  padding-inline: 16px;
  padding-block: 20px calc(var(--tabbar) + 96px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-block-end: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--patch);
  border-block-start: 1px solid var(--seam-soft);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 44px; font-size: 11px; color: var(--ash); text-decoration: none;
}
.tab[aria-current="page"] { color: var(--linen); }
.tab[aria-current="page"] .ico { color: var(--crimson); }

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--ash); padding-inline: 8px; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.sync[data-state="pending"]::before, .sync[data-state="connecting"]::before { background: var(--saffron); }
.sync[data-state="offline"]::before { background: var(--bad); }

.offline-bar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding-block: 10px; padding-inline: 16px;
  background: var(--saffron); color: #231B10;
  font-size: var(--fs-sm); font-weight: 500;
}

@media (min-width: 901px) {
  .app { grid-template-columns: var(--rail) minmax(0, 1fr); }
  .topbar, .tabbar { display: none; }
  .rail {
    display: flex; flex-direction: column; gap: 28px;
    position: sticky; top: 0; height: 100vh;
    padding-block: 28px; padding-inline: 16px;
    border-inline-end: 1px solid var(--seam-soft);
    background: color-mix(in srgb, var(--hole) 55%, transparent);
  }
  .rail .brand { font-size: 34px; padding-inline: 8px; }
  .rail nav { display: grid; gap: 2px; }
  .rail-foot { margin-block-start: auto; display: grid; gap: 8px; }
  main { padding-inline: 40px; padding-block: 36px 64px; }
}
.navlink {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding-inline: 10px;
  border-radius: var(--r-ctl);
  color: var(--ash); text-decoration: none; font-weight: 500;
}
.navlink:hover { color: var(--linen); background: var(--patch); }
.navlink[aria-current="page"] { color: var(--linen); background: var(--patch); }
.navlink[aria-current="page"] .ico { color: var(--crimson); }

/* ───────── عناصر عامة ───────── */

.panel { background: var(--patch); border: 1px solid var(--seam-soft); border-radius: var(--r-patch); padding: 16px; min-width: 0; }
.panel > h2, .sec-head h2 { font-size: var(--fs-lg); }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-block-end: 12px; }
.sec-head .meta { font-size: var(--fs-sm); color: var(--ash); }
.stack { display: grid; gap: 16px; }
.page-title { font-size: var(--fs-2xl); color: var(--bright); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-block-end: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding-inline: 16px;
  border-radius: var(--r-ctl);
  background: var(--patch-2); border: 1px solid var(--seam);
  color: var(--linen); font-weight: 500; font-size: var(--fs-sm);
  text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--ash); }
.btn-primary { background: var(--crimson-solid); border-color: var(--crimson-solid); color: var(--bright); }
.btn-primary:hover:not(:disabled) { background: #C52F43; border-color: #C52F43; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ash); }
.btn-ghost:hover:not(:disabled) { color: var(--linen); border-color: var(--seam); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--bad) 60%, transparent); color: var(--bad); }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r-ctl); color: var(--ash); }
.icon-btn:hover:not(:disabled) { color: var(--linen); background: var(--patch-2); }

.field { display: grid; gap: 6px; font-size: var(--fs-sm); color: var(--ash); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px;
  padding-inline: 12px; padding-block: 8px;
  background: var(--hole); border: 1px solid var(--seam); border-radius: var(--r-ctl);
  color: var(--linen); font-size: var(--fs-md);
}
.input:focus { outline: none; border-color: var(--focus); }
.input::placeholder { color: var(--strike); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ash) 50%), linear-gradient(135deg, var(--ash) 50%, transparent 50%); background-position: 14px 50%, 19px 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-inline-start: 12px; padding-inline-end: 30px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding-inline: 12px;
  border: 1px solid var(--seam); border-radius: var(--r-ctl);
  color: var(--ash); font-size: var(--fs-sm); background: transparent;
}
.chip:hover { color: var(--linen); }
.chip[aria-pressed="true"] { background: var(--linen); border-color: var(--linen); color: var(--fabric); font-weight: 500; }
.chip[data-dim="true"] { opacity: 0.55; }
@media (pointer: coarse) { .chip { min-height: 44px; } }

.seg { display: inline-flex; border: 1px solid var(--seam); border-radius: var(--r-ctl); overflow: hidden; }
.seg button { min-height: 40px; padding-inline: 14px; color: var(--ash); font-size: var(--fs-sm); }
.seg button + button { border-inline-start: 1px solid var(--seam); }
.seg button[aria-pressed="true"] { background: var(--patch-2); color: var(--linen); }
@media (pointer: coarse) { .seg button { min-height: 44px; } }

.note-line { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--r-ctl); background: var(--patch-2); font-size: var(--fs-sm); }
.note-line .ico { margin-block-start: 2px; color: var(--saffron); }
.note-line.warn { background: color-mix(in srgb, var(--saffron) 14%, var(--patch)); }
.note-line.bad { background: color-mix(in srgb, var(--bad) 12%, var(--patch)); }
.note-line.bad .ico { color: var(--bad); }

/* ثنائي «قيمة ووصف» مخيط في شريط واحد */
.strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px; background: var(--seam-soft);
  border: 1px solid var(--seam-soft); border-radius: var(--r-patch); overflow: hidden;
}
.strip > div { background: var(--patch); padding-block: 12px; padding-inline: 14px; display: grid; gap: 2px; align-content: start; min-width: 0; }
.strip .v { font-family: var(--display); font-size: var(--fs-xl); font-weight: 600; color: var(--bright); line-height: 1.25; font-variant-numeric: tabular-nums; }
.strip .l { font-size: var(--fs-xs); color: var(--ash); }
.strip .d { font-size: var(--fs-xs); display: inline-flex; align-items: center; gap: 3px; color: var(--ash); }
.strip .d.up { color: var(--ok); }
.strip .d.down { color: var(--bad); }
.strip.n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.strip.n5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.strip.n6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1000px) { .strip.n5 { grid-template-columns: repeat(6, minmax(0, 1fr)); } .strip.n5 > div { grid-column: span 2; } .strip.n5 > div:nth-child(n+4) { grid-column: span 3; } }
@media (max-width: 700px) { .strip.n4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .strip.n6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strip.n5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strip.n5 > div, .strip.n5 > div:nth-child(n+4) { grid-column: auto; }
  .strip.n5 > div:first-child { grid-column: 1 / -1; }
}

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.chart-box { min-width: 0; }
.chart-box .chart { display: block; height: auto; }
.chart-wide { min-width: 640px; }
.nodata { display: flex; align-items: center; gap: 12px; padding: 20px; border: 1px dashed var(--seam); border-radius: var(--r-ctl); color: var(--ash); font-size: var(--fs-sm); }

/* ───────── الغُرزة ───────── */
.stitch-svg path { fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; }

/* ───────── شاشة اليوم ───────── */

.today { display: grid; gap: 20px; }
@media (min-width: 1100px) {
  .today { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); column-gap: 28px; align-items: start; }
  .today .dayhead, .today .finish-wrap, .today .today-alerts { grid-column: 1 / -1; }
  .today .side { display: grid; gap: 20px; }
}
.side { display: grid; gap: 20px; }

.dayhead { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; align-items: start; }
.dh-title { display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: end; }
.dh-wd { grid-column: 1 / -1; font-family: var(--display); font-size: var(--fs-lg); color: var(--ash); font-weight: 500; }
.dh-num { font-family: var(--display); font-weight: 700; font-size: clamp(72px, 19vw, 112px); line-height: 0.86; color: var(--bright); font-variant-numeric: tabular-nums; }
.dh-my { display: grid; padding-block-end: 8px; }
.dh-month { font-family: var(--display); font-size: var(--fs-xl); font-weight: 600; line-height: 1.2; }
.dh-hijri { font-size: var(--fs-sm); color: var(--ash); }
.dh-nav { display: flex; gap: 4px; }
.back-today { font-size: var(--fs-sm); }

.progress-row { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-block-start: 6px; }
.stitches { display: flex; gap: 3px; flex-wrap: wrap; }
.stitches i { width: 18px; height: 18px; display: grid; place-items: center; color: var(--hc); }
.stitches i::before { content: ""; width: 3px; height: 3px; border-radius: 50%; background: var(--seam); }
.stitches i.on::before { display: none; }
.progress-txt { display: inline-flex; align-items: baseline; gap: 8px; font-size: var(--fs-sm); color: var(--ash); }
.progress-txt b { font-family: var(--display); font-size: var(--fs-lg); color: var(--bright); font-weight: 600; }

.today-alerts { display: grid; gap: 8px; }

.habit-list { display: grid; gap: 8px; }
.habit {
  --hc: var(--crimson);
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 12px;
  width: 100%; min-height: 60px; padding-block: 8px; padding-inline: 10px 12px;
  background: var(--patch); border: 1px solid var(--seam-soft); border-radius: var(--r-patch);
  text-align: start; color: var(--linen);
  transition: background-color 140ms ease-out, border-color 140ms ease-out;
}
.habit:hover { border-color: var(--seam); }
.habit[aria-pressed="true"] { background: color-mix(in srgb, var(--hc) 17%, var(--patch)); border-color: color-mix(in srgb, var(--hc) 75%, transparent); }
.habit-ico { width: 38px; height: 38px; display: grid; place-items: center; border-radius: var(--r-ctl); color: var(--hc); background: color-mix(in srgb, var(--hc) 13%, transparent); }
.habit-name { font-weight: 500; overflow-wrap: anywhere; }
.habit-streak { display: inline-flex; align-items: center; gap: 3px; font-size: var(--fs-sm); color: var(--saffron); font-variant-numeric: tabular-nums; }
.stitch-box { width: 32px; height: 32px; display: grid; place-items: center; border: 1.5px dashed var(--seam); border-radius: 4px; color: var(--hc); transition: border-color 140ms; }
.stitch-box path { stroke-dasharray: 16; stroke-dashoffset: 16; transition: stroke-dashoffset 110ms ease-out; }
[aria-pressed="true"] > .stitch-box { border-style: solid; border-color: var(--hc); }
[aria-pressed="true"] > .stitch-box path { stroke-dashoffset: 0; }
[aria-pressed="true"] > .stitch-box path + path { transition-delay: 100ms; }
.empty-habits { display: grid; gap: 12px; justify-items: start; padding: 20px; border: 1px dashed var(--seam); border-radius: var(--r-patch); color: var(--ash); }

.task-add { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; margin-block-end: 8px; }
.task-add select.input { width: auto; font-size: var(--fs-sm); }
.task-list { display: grid; }
.task { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto auto; align-items: center; gap: 4px; min-height: 48px; border-block-end: 1px solid var(--seam-soft); background: var(--patch); }
.task:last-child { border-block-end: 0; }
.grip { width: 28px; height: 44px; display: grid; place-items: center; color: var(--strike); cursor: grab; touch-action: none; }
.tbox { width: 44px; height: 44px; display: grid; place-items: center; --hc: var(--olive); }
.tbox .stitch-box { width: 24px; height: 24px; }
.ttext { padding-block: 10px; overflow-wrap: anywhere; line-height: 1.45; }
.task.done .ttext { color: var(--strike); text-decoration: line-through; text-decoration-color: var(--ash); text-decoration-thickness: 1.5px; }
.tag { font-size: var(--fs-xs); color: var(--ash); border: 1px solid var(--seam); border-radius: 4px; padding-inline: 6px; line-height: 20px; white-space: nowrap; }
.carried { font-size: var(--fs-xs); color: var(--strike); }
.tdel { width: 44px; height: 44px; display: grid; place-items: center; color: var(--ash); opacity: 0; }
.task:hover .tdel, .task:focus-within .tdel, .task.armed .tdel { opacity: 1; }
.tdel:hover { color: var(--bad); }
@media (hover: none) { .grip { display: none; } .task { grid-template-columns: auto minmax(0, 1fr) auto auto; } }
.dragging { opacity: 0.85; outline: 1.5px dashed var(--saffron); outline-offset: -2px; position: relative; z-index: 2; }
.task-count { margin-block-start: 10px; font-size: var(--fs-sm); color: var(--ash); }
.carry { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-block-end: 10px; }

.mind { container-type: inline-size; }
.mind-rows { display: grid; gap: 14px; }
.mind-row { display: grid; gap: 2px; }
.mind-label { display: flex; justify-content: space-between; font-size: var(--fs-sm); }
.mind-label span:last-child { color: var(--ash); font-variant-numeric: tabular-nums; }
.scale { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); }
.dot { min-height: 44px; min-width: 0; display: grid; place-items: center; color: var(--mc); }
.dot i { width: 22px; height: 22px; display: grid; place-items: center; }
.dot i::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: var(--seam); }
.dot.on i::before { display: none; }
.dot .stitch-svg { display: none; }
.dot.on .stitch-svg { display: block; opacity: var(--k); }
.dot:hover i::before { background: var(--ash); }
.dot .dnum { text-decoration: none; font-size: 11px; line-height: 1; font-style: normal; color: var(--ash); opacity: .55; font-variant-numeric: tabular-nums; margin-block-start: 3px; }
.dot.on .dnum { color: var(--mc); opacity: 1; font-weight: 600; }
.dot:hover .dnum { opacity: 1; }
@container (max-width: 440px) { .scale { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.mind-score { margin-block-start: 12px; font-size: var(--fs-sm); color: var(--ash); }
.mind-score b { color: var(--bright); font-family: var(--display); font-size: var(--fs-lg); font-weight: 600; }

.an-empty { margin-block-end: 14px; }
.an-empty h2 { font-family: var(--display); font-size: var(--fs-lg); margin-block-end: 8px; }
.an-empty p { color: var(--ash); font-size: var(--fs-sm); line-height: 1.7; }
.an-empty b { color: var(--linen); }
.an-empty ul { margin-block: 10px; padding-inline-start: 18px; display: grid; gap: 4px; color: var(--ash); font-size: var(--fs-sm); }
.an-empty .btn { margin-block-start: 12px; }

.note-field { width: 100%; resize: none; overflow: hidden; min-height: 52px; padding: 14px 16px; background: transparent; border: 1px dashed var(--seam); border-radius: var(--r-patch); color: var(--linen); line-height: 1.6; }
.note-field:focus { outline: none; border-style: solid; border-color: var(--focus); }
.note-field::placeholder { color: var(--strike); }

.finish-wrap { position: sticky; bottom: calc(var(--tabbar) + 12px + env(safe-area-inset-bottom)); z-index: 10; }
@media (min-width: 901px) { .finish-wrap { bottom: 20px; } }
.finish {
  width: 100%; min-height: 58px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border-radius: var(--r-patch);
  background: var(--crimson-solid); color: var(--bright);
  font-family: var(--display); font-size: var(--fs-lg); font-weight: 600;
}
.finish:hover { background: #C52F43; }
.finish.done { background: var(--patch-2); color: var(--linen); border: 1px solid var(--olive); }

.summary { display: grid; gap: 16px; }
.summary h2 { font-size: var(--fs-xl); color: var(--bright); }
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--seam-soft); border-radius: var(--r-ctl); overflow: hidden; }
.sum-grid > div { background: var(--patch-2); padding: 12px; display: grid; }
.sum-grid b { font-family: var(--display); font-size: var(--fs-xl); font-weight: 600; color: var(--bright); }
.sum-grid span { font-size: var(--fs-xs); color: var(--ash); }

/* ───────── الشهر ───────── */

.picker { display: flex; align-items: center; gap: 4px; }
.picker h1 { font-size: var(--fs-2xl); color: var(--bright); min-width: 0; padding-inline: 4px; }
.month-layout { display: grid; gap: 20px; }

.mgrid-wrap { background: var(--patch); border: 1px solid var(--seam-soft); border-radius: var(--r-patch); }
table.mgrid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.mgrid th, .mgrid td { padding: 0; text-align: center; border-block-end: 1px solid var(--seam-soft); }
.mgrid tr:last-child td { border-block-end: 0; }
.mgrid .hn {
  position: sticky; inset-inline-start: 0; z-index: 1;
  background: var(--patch); text-align: start;
  padding-inline: 10px 8px; min-width: 108px; max-width: 150px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-inline-end: 1px solid var(--seam-soft);
  font-size: var(--fs-sm); font-weight: 400;
}
.mgrid .hn .ico { display: inline-block; vertical-align: -4px; margin-inline-end: 6px; color: var(--hc); }
.mgrid thead th { height: 26px; font-weight: 600; }
.mgrid .dn { color: var(--wc); }
.mgrid .dl { color: var(--ash); font-weight: 400; font-size: 10px; }
.mgrid td.c { width: 3.2%; min-width: 22px; height: 30px; }
.mgrid td.c a { display: grid; place-items: center; height: 30px; color: var(--wc); text-decoration: none; }
.mgrid td.c a::before { content: ""; width: 3px; height: 3px; border-radius: 50%; background: var(--seam); }
.mgrid td.c a.on::before { display: none; }
.mgrid td.c a:hover { background: var(--patch-2); }
.mgrid td.dead, .mgrid th.dead { background: var(--hole); }
.mgrid .today-col { box-shadow: inset 2px 0 0 var(--linen), inset -2px 0 0 var(--linen); }
.mgrid thead .today-col { box-shadow: inset 2px 0 0 var(--linen), inset -2px 0 0 var(--linen), inset 0 2px 0 var(--linen); }
.mgrid tbody tr:last-child .today-col { box-shadow: inset 2px 0 0 var(--linen), inset -2px 0 0 var(--linen), inset 0 -2px 0 var(--linen); }
.mgrid tfoot td, .mgrid tfoot th { border-block-start: 1px solid var(--seam); height: 30px; color: var(--ash); }
.mgrid .bar { display: block; margin-inline: auto; width: 8px; height: 22px; background: var(--patch-2); border-radius: 2px; position: relative; overflow: hidden; }
.mgrid .bar i { position: absolute; inset-inline: 0; bottom: 0; background: var(--teal); }
@media (pointer: coarse) { .mgrid td.c { min-width: 44px; } .mgrid td.c a { height: 44px; } }

.weeks { display: grid; gap: 12px; }
.wk { background: var(--patch); border: 1px solid var(--seam-soft); border-radius: var(--r-patch); padding-block: 10px; padding-inline: 4px; }
.wk h3 { font-size: var(--fs-md); padding-inline: 10px; margin-block-end: 6px; display: flex; gap: 8px; align-items: center; }
.wk h3 i { width: 10px; height: 10px; border-radius: 2px; background: var(--wc); }
.wk-grid { display: grid; grid-template-columns: minmax(70px, 1fr) repeat(7, minmax(0, 34px)); align-items: center; }
.wk-day { min-height: 44px; display: grid; place-items: center; align-content: center; line-height: 1.1; text-decoration: none; border-radius: 4px; }
.wk-day b { color: var(--wc); font-weight: 600; font-size: var(--fs-sm); }
.wk-day small { color: var(--ash); font-size: 10px; }
.wk-day.is-today { outline: 2px solid var(--linen); outline-offset: -2px; }
.wk-ico { display: flex; align-items: center; gap: 6px; height: 26px; color: var(--hc); overflow: hidden; padding-inline-start: 4px; }
.wk-ico b { font-size: 11px; font-weight: 500; color: var(--ash); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wk-cell { height: 26px; display: grid; place-items: center; color: var(--wc); }
.wk-cell::before { content: ""; width: 3px; height: 3px; border-radius: 50%; background: var(--seam); }
.wk-cell.on::before { display: none; }
.wk-cell.dead { background: var(--hole); }
.wk-cell.dead::before { display: none; }

.habit-side { display: grid; gap: 14px 28px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.hs-row { display: grid; gap: 4px; }
.hs-top { display: flex; justify-content: space-between; gap: 8px; font-size: var(--fs-sm); }
.hs-top span:last-child { color: var(--ash); font-variant-numeric: tabular-nums; white-space: nowrap; }
.databar { height: 6px; background: var(--patch-2); border-radius: 3px; overflow: hidden; }
.databar i { display: block; height: 100%; background: var(--hc, var(--teal)); border-radius: 3px; }
.spark-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 6px; }
.spark-row .spark { flex: 1; max-width: 100%; height: 40px; }

/* ───────── الأسبوع ───────── */

.wboard { display: grid; gap: 10px; }
@media (min-width: 901px) {
  .wboard { grid-template-columns: repeat(7, minmax(128px, 1fr)); min-width: 920px; }
}
.dcard { background: var(--patch); border: 1px solid var(--seam-soft); border-radius: var(--r-patch); overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.dcard.drop { outline: 2px dashed var(--saffron); outline-offset: -2px; }
.dcard-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-block: 8px; padding-inline: 12px; background: var(--dc); color: var(--dc-ink, var(--bright)); text-decoration: none; min-height: 44px; }
.dcard-head b { font-family: var(--display); font-weight: 600; }
.dcard-head span { font-size: var(--fs-xs); opacity: 0.9; }
.dcard.is-today { border-color: var(--linen); }
.dcard-body { padding: 10px; display: grid; gap: 8px; flex: 1; align-content: start; }
.dcard-ring { display: flex; align-items: center; gap: 10px; font-size: var(--fs-xs); color: var(--ash); }
.dcard .task { background: transparent; min-height: 40px; grid-template-columns: auto minmax(0, 1fr) auto; font-size: var(--fs-sm); }
.dcard .task[draggable="true"] { cursor: grab; }
.dcard .tbox { width: 36px; height: 40px; }
.dcard-foot { font-size: var(--fs-xs); color: var(--ash); padding-block: 8px; padding-inline: 12px; border-block-start: 1px solid var(--seam-soft); }
.dcard-add .input { min-height: 38px; font-size: var(--fs-sm); padding-inline: 8px; }
.dcard summary { list-style: none; cursor: pointer; }
.dcard summary::-webkit-details-marker { display: none; }
@media (max-width: 900px) {
  .dcard-head .chev { transition: transform 150ms; }
  details[open] .dcard-head .chev { transform: rotate(180deg); }
}

/* ───────── التحليل ───────── */

.period-bar { position: sticky; top: 0; z-index: 15; padding-block: 10px; margin-block-end: 16px; background: color-mix(in srgb, var(--fabric) 94%, transparent); backdrop-filter: blur(6px); display: grid; gap: 8px; }
@media (max-width: 900px) { .period-bar { top: 61px; } }
.period-custom { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.period-custom .field { flex: 1 1 140px; }
.an-grid { display: grid; gap: 20px; }
@media (min-width: 700px) { .an-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; } }
.an-two > * + * { margin-block-start: 20px; }
@media (min-width: 700px) { .an-two > * + * { margin-block-start: 0; } }

.pv-controls { display: grid; gap: 12px; }
.pv-group { display: grid; gap: 6px; }
.pv-group > span { font-size: var(--fs-xs); color: var(--ash); }
.saved { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.saved .chip { display: inline-flex; align-items: center; gap: 4px; padding-inline-end: 4px; }
.saved .chip .x { width: 28px; height: 28px; display: grid; place-items: center; color: var(--ash); }
.pv-out { margin-block-start: 16px; display: grid; gap: 12px; }
.pv-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
table.pv { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.pv th, .pv td { padding-block: 8px; padding-inline: 10px; border-block-end: 1px solid var(--seam-soft); text-align: center; white-space: nowrap; }
.pv th:first-child, .pv td:first-child { text-align: start; position: sticky; inset-inline-start: 0; background: var(--patch); z-index: 1; }
.pv thead th { color: var(--ash); font-weight: 500; font-size: var(--fs-xs); }
.pv thead th button { min-height: 36px; color: inherit; display: inline-flex; gap: 4px; align-items: center; }
.pv thead th button[aria-sort] { color: var(--linen); }
.pv tfoot td, .pv td.tot { background: var(--patch-2); font-weight: 600; }
.pv tfoot td:first-child { background: var(--patch-2); }
.pv td.heat { color: var(--bright); }

.trend-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.trend { display: grid; gap: 6px; padding: 12px; border: 1px solid var(--seam-soft); border-radius: var(--r-ctl); background: var(--patch-2); }
.trend-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.trend-top b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state { font-size: var(--fs-xs); border-radius: 4px; padding-inline: 6px; line-height: 20px; white-space: nowrap; }
.state.up { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.state.flat { color: var(--ash); background: var(--patch); }
.state.down { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.trend .spark { width: 100%; height: 36px; }
.trend-bot { font-size: var(--fs-xs); color: var(--ash); display: flex; justify-content: space-between; }

.heat-wrap .hcell { cursor: pointer; }
.heat-wrap .chart { display: block; }
body:has(#offline:not([hidden])) .period-bar { top: 44px; }
@media (max-width: 900px) { body:has(#offline:not([hidden])) .period-bar { top: 0; position: static; } }
.legend { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; font-size: var(--fs-xs); color: var(--ash); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 5px; vertical-align: -1px; background: var(--c); }

table.plain { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.plain th, .plain td { padding-block: 9px; padding-inline: 8px; border-block-end: 1px solid var(--seam-soft); text-align: start; white-space: nowrap; }
.plain th { color: var(--ash); font-weight: 500; font-size: var(--fs-xs); }
.plain td small { color: var(--ash); display: block; font-size: var(--fs-xs); }

.insight { font-size: var(--fs-md); line-height: 1.8; max-width: 62ch; }
.caution { font-size: var(--fs-xs); color: var(--ash); display: flex; gap: 6px; align-items: flex-start; }
.matrix { display: grid; gap: 2px; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.matrix div { min-height: 36px; display: grid; place-items: center; padding-inline: 4px; border-radius: 3px; text-align: center; }
.matrix .mh { color: var(--ash); }

.report { display: grid; gap: 20px; }
.report-prose { display: grid; gap: 8px; max-width: 64ch; font-size: var(--fs-md); line-height: 1.9; }
.rank { display: grid; gap: 6px; }
.rank li { display: flex; justify-content: space-between; gap: 10px; padding-block: 6px; border-block-end: 1px solid var(--seam-soft); }
.notes-list { display: grid; gap: 10px; }
.notes-list li { display: grid; gap: 2px; padding-inline-start: 12px; border-inline-start: 2px dashed var(--seam); }
.notes-list small { color: var(--ash); }

/* ───────── البيانات والإعدادات ───────── */

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px 20px; }
.kv div { display: grid; }
.kv dt { font-size: var(--fs-xs); color: var(--ash); }
.kv dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.form-row .field { flex: 1 1 180px; }
.backup-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-block: 10px; border-block-end: 1px solid var(--seam-soft); }
.backup-list li:last-child { border-block-end: 0; }
.backup-meta { display: grid; }
.backup-meta small { color: var(--ash); font-size: var(--fs-xs); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 40%, var(--seam-soft)); }
.preview { display: grid; gap: 6px; padding: 12px; border-radius: var(--r-ctl); background: var(--patch-2); font-size: var(--fs-sm); }
.radio-row { display: grid; gap: 8px; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--seam); border-radius: var(--r-ctl); cursor: pointer; }
.radio input { margin-block-start: 5px; accent-color: var(--crimson-solid); }
.radio small { display: block; color: var(--ash); font-size: var(--fs-xs); }
.radio:has(input:checked) { border-color: var(--linen); }

.hlist { display: grid; }
.hrow { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 8px; align-items: center; min-height: 56px; border-block-end: 1px solid var(--seam-soft); background: var(--patch); }
.hrow:last-child { border-block-end: 0; }
.hrow .habit-ico { width: 34px; height: 34px; }
.hrow-name { display: grid; min-width: 0; }
.hrow-name small { color: var(--ash); font-size: var(--fs-xs); }
@media (hover: none) { .hrow .grip { display: grid; } }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 44px; height: 44px; border-radius: var(--r-ctl); display: grid; place-items: center; border: 2px solid transparent; }
.swatch i { width: 26px; height: 26px; border-radius: 4px; background: var(--c); }
.swatch[aria-pressed="true"] { border-color: var(--linen); }
.icons-pick { display: grid; grid-template-columns: repeat(auto-fill, 44px); gap: 4px; }
.icons-pick button { width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--r-ctl); color: var(--ash); border: 1px solid transparent; }
.icons-pick button[aria-pressed="true"] { color: var(--linen); border-color: var(--linen); background: var(--patch-2); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.switch input { width: 22px; height: 22px; accent-color: var(--crimson-solid); }

/* ───────── طبقات عائمة ───────── */

.dlg {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 20px; border-radius: 10px;
  background: var(--patch); color: var(--linen); border: 1px solid var(--seam);
}
.dlg::backdrop { background: rgba(14, 11, 20, 0.72); }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-block-start: 16px; }

#toast {
  position: fixed; z-index: 60; inset-inline: 16px; bottom: calc(var(--tabbar) + 88px + env(safe-area-inset-bottom));
  max-width: 460px; margin-inline: auto;
  padding: 12px 16px; border-radius: var(--r-ctl);
  background: var(--linen); color: var(--fabric); font-size: var(--fs-sm); font-weight: 500;
}
#toast[data-kind="warn"] { background: var(--saffron); color: #231B10; }
@media (min-width: 901px) { #toast { bottom: 96px; inset-inline-start: calc(var(--rail) + 16px); } }
#tip {
  position: fixed; z-index: 70; pointer-events: none;
  max-width: 260px; padding: 5px 9px; border-radius: 4px;
  background: var(--linen); color: var(--fabric); font-size: var(--fs-xs); line-height: 1.5;
}

.boot { display: grid; place-items: center; gap: 12px; min-height: 50vh; color: var(--ash); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-property: color, background-color, border-color !important; transition-duration: 1ms !important; animation: none !important; }
  .stitch-box path { stroke-dashoffset: 0 !important; }
  [aria-pressed="false"] > .stitch-box path { opacity: 0; }
}

/* عناصر الشبكة لا تتمدد أعرض من أعمدتها؛ التمرير الأفقي داخل حاوياته فقط */
.stack > *, .an-grid > *, .month-layout > *, .today > *, .side > *, .an-two > * { min-width: 0; }
.dcard .ttext { overflow-wrap: break-word; word-break: normal; hyphens: auto; }
@media (min-width: 901px) { .wboard { grid-template-columns: repeat(7, minmax(150px, 1fr)); min-width: 1080px; } }
.scroll-x, .panel, .dcard, .task-add, .field { position: relative; }
.chip { min-width: 44px; }
.dcard-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-block: 0; min-height: 44px; }
.dcard-foot a { min-height: 44px; display: inline-flex; align-items: center; }
@media (pointer: coarse) {
  .pv thead th button { min-height: 44px; min-width: 44px; }
  .grip { width: 44px; }
}

/* ───────── الإصدار الثاني: الأهداف والعادات الرقمية والتراجع ───────── */
.habit-main { display: grid; gap: 1px; min-width: 0; }
.goal { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--ash); font-variant-numeric: tabular-nums; }
.goal.met { color: var(--ok); }
.habit-count { cursor: default; grid-template-columns: auto minmax(0, 1fr) auto auto; }
.habit-count.met { background: color-mix(in srgb, var(--hc) 17%, var(--patch)); border-color: color-mix(in srgb, var(--hc) 75%, transparent); }
.habit-count.met .habit-ico { background: transparent; }
.habit-sub { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--ash); }
.habit-sub b { color: var(--linen); font-weight: 600; }
.countbar { flex: 1; max-width: 120px; height: 5px; border-radius: 3px; background: var(--patch-2); overflow: hidden; }
.countbar i { display: block; height: 100%; background: var(--hc); }
.stepper { display: flex; gap: 4px; }
.step { width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--r-ctl); border: 1px solid var(--seam); color: var(--ash); background: transparent; }
.step.plus { color: var(--bright); background: color-mix(in srgb, var(--hc) 35%, var(--patch)); border-color: var(--hc); }
.step:hover:not(:disabled) { border-color: var(--ash); }
.off-group { display: grid; gap: 8px; margin-block-start: 10px; }
.off-toggle { justify-self: start; }
.off-toggle[aria-expanded="true"] .ico { transform: rotate(180deg); }
#toast { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#toast[hidden] { display: none; }
.toast-action { min-height: 36px; padding-inline: 12px; border-radius: var(--r-ctl); background: var(--fabric); color: var(--linen); font-weight: 600; font-size: var(--fs-sm); }
@media (max-width: 400px) { .habit-count { grid-template-columns: auto minmax(0, 1fr) auto; } .habit-count .habit-streak { display: none; } }

/* خانات الشهر أزرار تعليم مباشرة */
.mgrid td.c .mc { display: grid; place-items: center; width: 100%; height: 30px; color: var(--wc); }
.mgrid td.c .mc::before, .wk-cell::before { content: ""; width: 3px; height: 3px; border-radius: 50%; background: var(--seam); }
.mgrid td.c .mc.on::before, .wk-cell.on::before, .wk-cell.dead::before, .mc.future::before, .wk-cell.future::before { display: none; }
.mgrid td.c .mc:hover { background: var(--patch-2); }
.mc.off, .wk-cell.off { background-image: repeating-linear-gradient(135deg, transparent 0 4px, rgba(241, 232, 218, 0.05) 4px 5px); }
.mgrid .dn a { color: inherit; text-decoration: none; display: grid; place-items: center; min-height: 26px; }
.mgrid .dn a:hover { text-decoration: underline; }
@media (pointer: coarse) { .mgrid td.c .mc { height: 44px; min-width: 44px; } .mgrid .dn a { min-height: 44px; } }
.wk { padding-block: 4px; }
.wk-head { width: 100%; min-height: 48px; display: flex; align-items: center; gap: 8px; padding-inline: 10px; text-align: start; font-size: var(--fs-md); }
.wk-head i { width: 10px; height: 10px; border-radius: 2px; background: var(--wc); flex: none; }
.wk-head b { font-family: var(--display); font-weight: 600; }
.wk-head span { font-size: 13px; }
.wk-head .wk-count { margin-inline-start: auto; }
.wk-head .ico { transition: transform 150ms; color: var(--ash); }
.wk-head[aria-expanded="true"] .ico { transform: rotate(180deg); }
.wk-grid { padding-block-end: 8px; }
.wk-cell { height: 44px; display: grid; place-items: center; color: var(--wc); border-radius: 4px; }
button.wk-cell:hover { background: var(--patch-2); }
.hs-row .goal { margin-block-start: 2px; }
.ai-list { display: grid; gap: 10px; max-width: 70ch; }
.ai-list li { position: relative; padding-inline-start: 22px; line-height: 1.8; }
.ai-list li::before { content: ""; position: absolute; inset-inline-start: 2px; top: 0.7em; width: 10px; height: 10px; background:
  linear-gradient(45deg, transparent 43%, var(--saffron) 43% 57%, transparent 57%),
  linear-gradient(-45deg, transparent 43%, var(--saffron) 43% 57%, transparent 57%); }
.insight-panel[aria-busy="true"] .ai-list li:last-child::after { content: "▍"; color: var(--saffron); margin-inline-start: 2px; }
.days-pick { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; max-width: 360px; }
.days-pick button { min-height: 44px; border-radius: var(--r-ctl); border: 1px solid var(--seam); color: var(--ash); font-weight: 600; }
.days-pick button[aria-pressed="true"] { background: var(--linen); color: var(--fabric); border-color: var(--linen); }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip { display: inline-flex; align-items: center; border: 1px solid var(--seam); border-radius: var(--r-ctl); }
.tag-chip button:first-child { min-height: 40px; padding-inline: 12px; }
.tag-chip .x { width: 36px; min-height: 40px; display: grid; place-items: center; color: var(--ash); border-inline-start: 1px solid var(--seam); }
.tag-chip .x:hover { color: var(--bad); }
.habit-form [hidden] { display: none !important; }

/* بوابة الدخول */
.signin { max-width: 420px; margin-inline: auto; margin-block-start: 8vh; display: grid; gap: 14px; }
.signin-title { font-family: var(--display); font-size: var(--fs-xl); display: flex; align-items: center; gap: 8px; }
.signin-title .ico { color: var(--crimson); }
.signin-lead { font-size: var(--fs-sm); line-height: 1.7; }
.signin-form { display: grid; gap: 12px; }
.signin-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.signin-foot { font-size: var(--fs-xs); line-height: 1.7; border-block-start: 1px solid var(--seam-soft); padding-block-start: 12px; }

/* السمة hidden تسبق أي display صريح */
/* الصفحة داخل Claude كانت تأخذ هذه القاعدة من غلافها. النسخة المستقلة تحتاجها
   بنفسها، وإلا تجاهلَ display الصريح (مثل .offline-bar) السمةَ وبقي العنصر ظاهراً. */
[hidden] { display: none !important; }
