@font-face {
  font-family: "Vazirmatn Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(fonts/vazirmatn-arabic-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: "Vazirmatn Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(fonts/vazirmatn-latin-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #17201e;
  --text-muted: #5b6965;
  --border: #dce3e0;
  --primary: #0f766e;
  --on-primary: #ffffff;
  --danger: #b42318;
  --warn: #a15c07;
  --ok: #15803d;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 14px rgb(0 0 0 / 0.05);
  --radius: 14px;
  --tabs-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1312;
    --surface: #171e1c;
    --surface-2: #202927;
    --text: #e7eeec;
    --text-muted: #98a7a2;
    --border: #28332f;
    --primary: #2dd4bf;
    --on-primary: #04211d;
    --danger: #f87171;
    --warn: #fbbf24;
    --ok: #4ade80;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn Variable", Tahoma, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  overscroll-behavior-y: none;
}
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, p { margin: 0; }

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px calc(var(--tabs-h) + 28px + env(safe-area-inset-bottom));
}

/* ───── هدر و ورودی سریع ───── */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 0 6px;
  background: var(--bg);
}
.top h1 { font-size: 22px; font-weight: 800; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--text-muted); }
.icon-btn:active { background: var(--surface-2); }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); padding: 6px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.dot.ok { background: var(--ok); }
.dot.busy { background: var(--primary); animation: pulse 1s infinite; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

.quick { position: sticky; top: calc(env(safe-area-inset-top) + 56px); z-index: 19; background: var(--bg); padding: 4px 0 10px; }
.quick-row { display: flex; gap: 8px; }
.quick input {
  flex: 1; min-width: 0; height: 50px; padding: 0 16px;
  border-radius: var(--radius); border: 1.5px solid var(--border);
  background: var(--surface); font-size: 16px; /* >=16 تا iOS زوم نکند */
}
.quick input:focus { outline: none; border-color: var(--primary); }
.add-btn { width: 50px; height: 50px; border-radius: var(--radius); background: var(--primary); color: var(--on-primary); display: grid; place-items: center; }
.add-btn:active { transform: scale(0.96); }

/* ───── چیپ‌ها ───── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.preview { min-height: 0; margin-top: 8px; }
.preview:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 10px; border-radius: 999px; font-size: 12.5px; line-height: 1.9;
  background: var(--surface-2); color: var(--text-muted); white-space: nowrap;
}
.chip.topic {
  color: hsl(var(--h) 65% 33%);
  background: hsl(var(--h) 60% 50% / 0.15);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chip.topic { color: hsl(var(--h) 75% 74%); background: hsl(var(--h) 60% 50% / 0.22); }
}
.chip.overdue { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); font-weight: 700; }
.chip.today { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); font-weight: 700; }
.chip.soon { color: var(--warn); }
.chip.hot { color: var(--danger); }

.topicbar { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.topicbar::-webkit-scrollbar { display: none; }
.pill { flex: none; padding: 5px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 14px; color: var(--text-muted); }
.pill[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }

/* ───── فهرست کارها ───── */
.section { margin-bottom: 20px; }
.section > h2 { font-size: 14px; font-weight: 700; color: var(--text-muted); margin: 6px 2px 8px; display: flex; align-items: baseline; gap: 8px; }
.section > h2 small { font-weight: 400; font-size: 12.5px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.task {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.task.is-overdue { border-inline-start: 4px solid var(--danger); }
.task.is-done .title { text-decoration: line-through; color: var(--text-muted); }
.check { flex: none; width: 28px; height: 28px; margin-top: 1px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; color: transparent; }
.check:active { border-color: var(--primary); }
.is-done .check { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.task .body { flex: 1; min-width: 0; text-align: start; cursor: pointer; }
.task .title { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.task .meta { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.mark-imp { color: var(--danger); font-size: 13px; font-weight: 800; }

.empty { text-align: center; color: var(--text-muted); padding: 40px 16px; }
.empty strong { display: block; font-size: 17px; color: var(--text); margin-bottom: 6px; }
details.fold > summary { cursor: pointer; color: var(--text-muted); font-size: 14px; padding: 8px 2px; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold[open] > summary { margin-bottom: 6px; }

/* ───── ماتریس ───── */
.matrix { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .matrix { grid-template-columns: 1fr 1fr; } }
.quad { background: var(--surface-2); border-radius: var(--radius); padding: 12px; }
.quad > h2 { font-size: 14px; margin-bottom: 8px; display: flex; justify-content: space-between; }
.quad > h2 small { color: var(--text-muted); font-weight: 400; }
.quad.do > h2 { color: var(--danger); }
.quad.plan > h2 { color: var(--primary); }

/* ───── نوار پایین ───── */
.tabs {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tabs button { display: grid; justify-items: center; gap: 1px; padding: 4px 0; font-size: 12px; color: var(--text-muted); min-height: 48px; }
.tabs button[aria-current="page"] { color: var(--primary); font-weight: 700; }

/* ───── شیت و فرم‌ها ───── */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / 0.45); }
.sheet {
  position: fixed; z-index: 41; inset-inline: 0; bottom: 0; max-height: 92dvh; overflow-y: auto;
  max-width: 760px; margin: 0 auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgb(0 0 0 / 0.25);
  animation: rise 0.2s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet h2 { font-size: 18px; margin-bottom: 14px; }
.sheet h3 { font-size: 15px; margin: 18px 0 8px; }
.sheet label { display: block; font-size: 13.5px; color: var(--text-muted); margin-bottom: 12px; }
.sheet input[type="text"], .sheet input[type="search"], .sheet input[type="password"], .sheet select, .sheet textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; min-height: 46px;
  border: 1.5px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text); font-size: 16px;
}
.sheet textarea { resize: vertical; }
.sheet input:focus, .sheet select:focus, .sheet textarea:focus { outline: none; border-color: var(--primary); }
.hint { font-size: 13px; color: var(--text-muted); margin: -4px 0 12px; min-height: 1.4em; }
.hint.err { color: var(--danger); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.seg button, .seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 9px 4px; border-radius: 12px; border: 1.5px solid var(--border); font-size: 14px; color: var(--text); }
.seg input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.check-row { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text) !important; }
.check-row input { width: 20px; height: 20px; accent-color: var(--primary); }
.btn { padding: 11px 18px; border-radius: 12px; min-height: 46px; font-weight: 700; background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions .primary { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.trow { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.trow .row input[type="range"] { flex: 1; min-width: 100px; accent-color: hsl(var(--h) 60% 45%); }
.swatch { width: 22px; height: 22px; border-radius: 50%; background: hsl(var(--h) 65% 48%); flex: none; }
.note { font-size: 13px; color: var(--text-muted); line-height: 1.8; }
.mono { direction: ltr; unicode-bidi: plaintext; font-family: ui-monospace, Menlo, Consolas, monospace; }

.toast {
  position: fixed; z-index: 60; inset-inline: 16px; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  max-width: 460px; margin: 0 auto; padding: 12px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.3); font-size: 15px;
}
.toast button { color: var(--primary); font-weight: 800; filter: brightness(1.25); }
[hidden] { display: none !important; }
