@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-var.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --line: #e6e4de;
  --line-strong: #d6d3cb;
  --text: #191919;
  --text-2: #5f5e5a;
  --text-3: #8f8d86;
  --accent: #2370cd;
  --accent-soft: #e3eefb;
  --accent-ink: #ffffff;
  --now: #dc3c3d;
  --good: #0a8a1f;
  --good-soft: #e3f3e5;
  --warn: #b77900;
  --shadow: 0 1px 2px rgba(20, 20, 15, .06), 0 4px 16px rgba(20, 20, 15, .06);
  --shadow-lg: 0 12px 40px rgba(20, 20, 15, .18);
  --radius: 14px;
  --radius-sm: 10px;
  --slot-h: 48px;
  --c-1: #257de0; --c-2: #f47230; --c-3: #00b894; --c-4: #f2a600;
  --c-5: #ee7fac; --c-6: #008a17; --c-7: #6a4ce2; --c-8: #ec4647;
  --c-neutral: #8f8d86;
  --ev-tint: 14%;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121212; --surface: #1b1b1b; --surface-2: #242424; --line: #2c2c2c; --line-strong: #3a3a3a;
    --text: #efefef; --text-2: #b4b4b4; --text-3: #7d7d7d;
    --accent: #338ced; --accent-soft: #1a2c44; --accent-ink: #ffffff;
    --now: #eb6263; --good: #0aac23; --good-soft: #15301a; --warn: #d28e05;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
    --c-1: #338ced; --c-2: #e76624; --c-3: #00a888; --c-4: #d28e05;
    --c-5: #e24d8b; --c-6: #0aac23; --c-7: #9887ef; --c-8: #eb6263; --c-neutral: #7d7d7d;
    --ev-tint: 22%;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212; --surface: #1b1b1b; --surface-2: #242424; --line: #2c2c2c; --line-strong: #3a3a3a;
  --text: #efefef; --text-2: #b4b4b4; --text-3: #7d7d7d;
  --accent: #338ced; --accent-soft: #1a2c44; --accent-ink: #ffffff;
  --now: #eb6263; --good: #0aac23; --good-soft: #15301a; --warn: #d28e05;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
  --c-1: #338ced; --c-2: #e76624; --c-3: #00a888; --c-4: #d28e05;
  --c-5: #e24d8b; --c-6: #0aac23; --c-7: #9887ef; --c-8: #eb6263; --c-neutral: #7d7d7d;
  --ev-tint: 22%;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Vazirmatn", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px; line-height: 1.5;
  font-feature-settings: "ss01";
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* ---------------------------------------------------------------- shell */
.app { max-width: 980px; margin: 0 auto; min-height: 100%; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  padding: 12px 16px 8px;
}
.topbar-row { display: flex; align-items: center; gap: 8px; }
.title-block { flex: 1; min-width: 0; }
.title-block h1 { font-size: 20px; font-weight: 750; margin: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-block .sub { font-size: 12.5px; color: var(--text-3); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface); box-shadow: var(--shadow); color: var(--text-2);
}
.icon-btn:active { transform: scale(.96); }
.pill {
  height: 32px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.content { padding: 4px 16px 24px; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { max-width: 520px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0 8px; font-size: 11.5px; color: var(--text-3); font-weight: 600; }
.tab svg { width: 23px; height: 23px; }
.tab.active { color: var(--accent); }

/* ---------------------------------------------------------------- week strip */
.strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
.strip button {
  border-radius: 12px; padding: 6px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 1px;
  color: var(--text-2);
}
.strip .wd { font-size: 11px; color: var(--text-3); }
.strip .dn { font-size: 17px; font-weight: 700; line-height: 1.25; }
.strip .dots { height: 5px; display: flex; gap: 2px; }
.strip .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--text-3); opacity: .7; }
.strip button.today .dn { color: var(--accent); }
.strip button.sel { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.strip button.sel .wd, .strip button.sel .dn { color: var(--accent-ink); }
.strip button.sel .dots i { background: var(--accent-ink); }

/* ---------------------------------------------------------------- day summary */
.daysum {
  display: flex; align-items: center; gap: 14px; margin: 6px 0 14px; padding: 12px 14px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.ring { width: 46px; height: 46px; flex: none; }
.ring circle { fill: none; stroke-width: 5; }
.ring .track { stroke: var(--surface-2); }
.ring .val { stroke: var(--good); stroke-linecap: round; transition: stroke-dasharray .5s; }
.ring text { font-size: 12px; font-weight: 700; fill: var(--text); text-anchor: middle; dominant-baseline: central; }
.daysum .facts { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.daysum .facts b { display: block; font-size: 17px; color: var(--text); font-weight: 750; }
.nextup { font-size: 13px; margin-top: 2px; color: var(--text-2); }
.nextup b { color: var(--text); }

/* ---------------------------------------------------------------- timeline */
.timeline {
  position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; touch-action: pan-y;
}
.slot { height: var(--slot-h); display: flex; border-top: 1px solid var(--line); }
.slot:first-child { border-top: 0; }
.slot.half { border-top-style: dashed; border-top-color: color-mix(in srgb, var(--line) 70%, transparent); }
.slot .lbl { width: 52px; flex: none; font-size: 11.5px; color: var(--text-3); padding: 3px 10px 0 0; text-align: right; }
.slot .cell { flex: 1; border-right: 1px solid var(--line); }
.slot .cell:active { background: var(--accent-soft); }
.slot.past .cell { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.events { position: absolute; top: 0; bottom: 0; right: 52px; left: 6px; pointer-events: none; }
.ev {
  position: absolute; pointer-events: auto; overflow: hidden; text-align: right;
  border-radius: 9px; padding: 5px 9px 5px 6px;
  background: color-mix(in srgb, var(--ec) var(--ev-tint), var(--surface));
  border-right: 4px solid var(--ec);
  box-shadow: 0 0 0 2px var(--surface);
  transition: transform .12s;
}
.ev:active { transform: scale(.985); }
.ev .t { font-size: 13.5px; font-weight: 650; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev .m { font-size: 11.5px; color: var(--text-2); white-space: nowrap; }
.ev.short { padding-top: 2px; padding-bottom: 2px; display: flex; gap: 6px; align-items: center; }
.ev.short .m { order: 2; }
.ev.done { opacity: .62; }
.ev.done .t { text-decoration: line-through; text-decoration-thickness: 1.5px; }
.ev.skipped { opacity: .45; border-right-style: dashed; }
.ev .badge { position: absolute; left: 6px; top: 5px; font-size: 12px; }
.ev.hi .t::after { content: " ‼"; color: var(--now); }
.nowline { position: absolute; right: 46px; left: 0; height: 2px; background: var(--now); z-index: 3; pointer-events: none; }
.nowline::before { content: ""; position: absolute; right: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--now); }

.fab {
  position: fixed; z-index: 25; left: 18px; bottom: calc(86px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent);
}
.fab svg { width: 26px; height: 26px; }
@media (min-width: 1000px) { .fab { left: calc(50% - 470px); } }

/* ---------------------------------------------------------------- week grid */
.wk { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.wk-head { display: grid; grid-template-columns: 34px repeat(7, 1fr); border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.wk-head button { padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--text-3); }
.wk-head button b { font-size: 15px; color: var(--text); }
.wk-head button.today b { color: var(--accent); }
.wk-body { position: relative; display: grid; grid-template-columns: 34px repeat(7, 1fr); }
.wk-hours div { height: calc(var(--wk-h) * 2); font-size: 10px; color: var(--text-3); text-align: center; padding-top: 1px; border-top: 1px solid var(--line); }
.wk-col { position: relative; border-right: 1px solid var(--line); background-image: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px calc(var(--wk-h) * 2)); }
.wk-col.today { background-color: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.wk-ev {
  position: absolute; right: 2px; left: 2px; border-radius: 5px; overflow: hidden; padding: 1px 3px;
  font-size: 10px; line-height: 1.25; font-weight: 600;
  background: color-mix(in srgb, var(--ec) var(--ev-tint), var(--surface)); border-right: 3px solid var(--ec);
  box-shadow: 0 0 0 1px var(--surface);
}
.wk-ev.done { opacity: .55; }

/* ---------------------------------------------------------------- cards & widgets */
.section-title { font-size: 13px; font-weight: 700; color: var(--text-2); margin: 20px 2px 10px; }
.grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .grid { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; }
.card h3 { margin: 0 0 8px; font-size: 13.5px; font-weight: 700; color: var(--text-2); }
.stat .v { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.stat .u { font-size: 14px; color: var(--text-2); font-weight: 600; margin-inline-start: 4px; }
.stat .d { font-size: 12.5px; font-weight: 700; margin-inline-start: 8px; }
.stat .d.up { color: var(--good); } .stat .d.down { color: var(--now); }
.stat .h { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .6s; }
.bar-fill.warn { background: var(--warn); } .bar-fill.crit { background: var(--now); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .sub { font-size: 12.5px; color: var(--text-3); }
.badge-s { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.check { width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--line-strong); display: grid; place-items: center; flex: none; }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: right; font-weight: 700; color: var(--text-2); font-size: 12px; padding: 6px 6px; border-bottom: 1px solid var(--line-strong); }
table.t td { padding: 8px 6px; border-bottom: 1px solid var(--line); }
.tbl-wrap { overflow-x: auto; }
.note-md p { margin: 0 0 8px; } .note-md h1, .note-md h2, .note-md h3 { font-size: 15px; margin: 8px 0 6px; } .note-md ul { padding-inline-start: 18px; margin: 4px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--text-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; }
.chart svg { width: 100%; display: block; overflow: visible; }
.chart .axis text { font-size: 10.5px; fill: var(--text-3); }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; }
.tip {
  position: fixed; z-index: 90; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 6px 10px; border-radius: 8px; font-size: 12.5px; box-shadow: var(--shadow-lg); white-space: nowrap;
  transform: translate(50%, calc(-100% - 10px)); opacity: 0; transition: opacity .12s;
}
.tip.on { opacity: 1; }
.board-card { display: flex; align-items: center; gap: 12px; text-align: right; width: 100%; }
.board-card .ic { width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 22px; flex: none; }
.empty { text-align: center; padding: 40px 20px; color: var(--text-3); }
.empty .big { font-size: 40px; margin-bottom: 6px; }

/* ---------------------------------------------------------------- sheet */
.backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .38); opacity: 0; transition: opacity .2s; }
.backdrop.on { opacity: 1; }
.sheet {
  position: fixed; z-index: 61; inset: auto 0 0 0; max-width: 560px; margin: 0 auto;
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: var(--shadow-lg);
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto;
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet.on { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line-strong); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 19px; font-weight: 750; }
.field { margin-top: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-2); font-weight: 650; margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; border: 1.5px solid var(--line); background: var(--surface-2); border-radius: 12px;
  padding: 11px 12px; outline: none; font-size: 16px;
}
.input:focus { border-color: var(--accent); background: var(--surface); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 7px 12px; border-radius: 99px; background: var(--surface-2); font-size: 13.5px; font-weight: 600; color: var(--text-2); border: 1.5px solid transparent; }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.chip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 6px; background: var(--ec); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.actions.three { grid-template-columns: repeat(3, 1fr); }
.btn { height: 48px; border-radius: 14px; font-weight: 700; font-size: 15px; background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--good-soft); color: var(--good); }
.btn.danger { color: var(--now); }
.btn.wide { grid-column: 1 / -1; }
.btn:active { transform: scale(.98); }
.kv { display: flex; gap: 8px; align-items: center; color: var(--text-2); font-size: 14px; margin-top: 6px; }
.warnbox { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--now) 12%, var(--surface)); font-size: 13.5px; }

.toast {
  position: fixed; z-index: 95; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; transition: all .2s; box-shadow: var(--shadow-lg); white-space: nowrap;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.login { min-height: 80vh; display: grid; place-items: center; text-align: center; padding: 24px; }
.login .logo { font-size: 54px; }
.skeleton { height: 420px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
