/* ============================================================
   دستیار — سیستم بصری
   الهام از Todoist: سایدبار گرم و روشن، صفحهٔ سفید، خط‌های نازک به‌جای جعبه،
   یک رنگ تأکید (قرمز-نارنجی) برای کار اصلی و جای فعلی. بقیهٔ رنگ‌ها فقط
   جایی می‌آیند که معنا دارند: وضعیت، اولویت، سررسید.

   قاعده: هر اندازه، فاصله و رنگی از توکن‌های همین بالا می‌آید. اگر چیزی غلط
   به نظر می‌رسد، توکن را درست کنید نه نمونه را.
   ============================================================ */

@font-face {
  font-family: Vazirmatn;
  src: url('/fonts/Vazirmatn.woff2') format('woff2-variations');
  font-weight: 300 800;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* سطوح */
  --bg: #ffffff;
  --sidebar: #fcfaf8;
  --surface: #ffffff;          /* کارت، مودال، پنل */
  --surface-2: #faf9f8;        /* پرکردن‌های آرام: پای جدول، ناحیه‌های فرورفته */
  --hover: #f4f2f0;            /* زیر ماوس: ردیف، آیتم منو */
  --fill: #f1efed;             /* دکمهٔ معمولی */
  --fill-hover: #e8e5e2;
  --border: #ededed;
  --border-strong: #d9d9d9;    /* لبهٔ ورودی‌ها */
  --control: #b9b9b9;          /* لبهٔ چک‌باکس */

  /* متن — سه درجه، همه با کنتراست قابل‌قبول روی سفید */
  --text: #202020;
  --text-2: #555555;
  --muted: #737373;            /* ۴.۷:۱ روی سفید */
  --faint: #c4c4c4;            /* فقط تزئین: خط تیرهٔ خانهٔ خالی */

  /* تأکید */
  --accent: #dc4c3e;
  --accent-hover: #c53727;
  --accent-soft: #ffefe5;
  --accent-text: #b8392b;      /* متن تأکیدی روی سطح روشن */
  --on-accent: #ffffff;

  /* هیوهای معنایی — پیل‌ها و تاریخ‌ها از همین‌ها ساخته می‌شوند */
  --h-red: #d1453b;
  --h-orange: #e07a00;
  --h-amber: #b88a00;
  --h-green: #058527;
  --h-teal: #0f8a86;
  --h-blue: #246fe0;
  --h-indigo: #4f5bd5;
  --h-violet: #692ec2;
  --h-pink: #c63b80;
  --h-slate: #707070;

  --pill-bg: 12%;
  --pill-text: 78%;

  /* تایپوگرافی — یک مقیاس کوچک */
  --fs-xs: 12px;     /* سرستون، شمارنده، راهنما */
  --fs-sm: 13px;     /* خانه‌های جدول، متن دوم */
  --fs: 14px;        /* متن اصلی، ورودی، عنوان ردیف */
  --fs-lg: 16px;     /* عنوان مودال و بخش */
  --fs-xl: 20px;     /* عنوان صفحه */

  /* فاصله — مقیاس ۴ */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s8: 32px;
  --s10: 40px;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .12);
  --ring: color-mix(in srgb, var(--accent) 55%, transparent);
  --toast-bg: #2b2b2b;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #1f1f1f;
    --sidebar: #262626;
    --surface: #262626;
    --surface-2: #2a2a2a;
    --hover: #2f2f2f;
    --fill: #333333;
    --fill-hover: #3d3d3d;
    --border: #333333;
    --border-strong: #474747;
    --control: #6b6b6b;

    --text: #ececec;
    --text-2: #bdbdbd;
    --muted: #949494;
    --faint: #4a4a4a;

    --accent: #de4c4a;
    --accent-hover: #e8655f;
    --accent-soft: #3a2624;
    --accent-text: #ff8f80;
    --on-accent: #ffffff;

    --h-red: #ff7066;
    --h-orange: #ff9a3d;
    --h-amber: #e8c04a;
    --h-green: #4cc06d;
    --h-teal: #44c2b9;
    --h-blue: #6fa3ff;
    --h-indigo: #8f97ff;
    --h-violet: #b28cff;
    --h-pink: #f27fb5;
    --h-slate: #a3a3a3;

    --pill-bg: 18%;
    --pill-text: 88%;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .55);
    --toast-bg: #3a3a3a;
  }
}

/* ============================================================ پایه */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, 'Segoe UI', Tahoma, sans-serif;
  font-size: var(--fs);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 700; line-height: 1.4; margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

.i { flex: none; display: block; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.en { direction: ltr; unicode-bidi: isolate; font-family: 'Segoe UI', system-ui, sans-serif; font-size: .95em; }
.dash { color: var(--faint); user-select: none; }
.spacer { margin-inline-start: auto; }
.row { display: flex; gap: var(--s2); align-items: center; }
.hint { color: var(--muted); font-size: var(--fs-xs); line-height: 1.7; }

.kbd {
  font-family: ui-monospace, 'Cascadia Mono', monospace;
  font-size: 11px;
  line-height: 1.6;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--muted);
  background: var(--surface);
  direction: ltr;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================ چیدمان */

.app { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.main { padding: var(--s8) var(--s10) 96px; min-width: 0; }

/* ============================================================ سایدبار */

.sidebar {
  background: var(--sidebar);
  padding: var(--s3) var(--s2);
  display: flex;
  flex-direction: column;
  gap: 1px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s2) var(--s3); }
.logo-mark { display: grid; flex: none; filter: drop-shadow(0 1px 2px rgba(197, 55, 39, .25)); }
.brand b { font-size: 15px; font-weight: 700; display: block; line-height: 1.3; }
.brand .sub { color: var(--muted); font-size: var(--fs-xs); line-height: 1.3; }

.nav-label {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: var(--s4) var(--s2) var(--s1);
}

.nav-group { display: flex; flex-direction: column; gap: 1px; }

.nav-item, .quick-open {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: 34px;
  padding: 0 var(--s2);
  border-radius: var(--radius-sm);
  border: 0;
  background: transparent;
  width: 100%;
  text-align: start;
  color: var(--text);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-item:hover, .quick-open:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item .ico {
  width: 22px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 16px;
  line-height: 1;
  color: var(--muted);
}
.nav-item.active .ico { color: var(--accent-text); }
.nav-item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.nav-item .count {
  margin-inline-start: auto;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.nav-item.active .count { color: var(--accent-text); }
.nav-item .grip { order: 9; margin-inline-start: 2px; }
.nav-item:hover .grip { opacity: .6; }

.quick-open { color: var(--muted); margin-bottom: var(--s1); }
.quick-open .ico { width: 22px; display: grid; place-items: center; }
.quick-open .kbd { margin-inline-start: auto; }

/* ============================================================ سرصفحه */

.page-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s5); flex-wrap: wrap; }
.page-head > .page-title { display: flex; align-items: center; gap: var(--s2); min-width: 0; flex: 1 1 260px; }
.page-head h1 { font-size: var(--fs-xl); overflow: hidden; text-overflow: ellipsis; }
.page-head .desc { color: var(--muted); font-size: var(--fs-sm); margin: 0; }
.page-head .actions { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.page-icon { font-size: 22px; line-height: 1; width: 32px; display: grid; place-items: center; flex: none; color: var(--muted); }

/* ============================================================ دکمه */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 var(--s3);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--fill);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background .12s, color .12s, border-color .12s;
}
.btn:hover { background: var(--fill-hover); }
.btn:active:not(:disabled) { transform: translateY(.5px); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.danger { background: transparent; color: var(--h-red); }
.btn.danger:hover { background: color-mix(in srgb, var(--h-red) 10%, transparent); }
.btn.danger-fill { background: var(--h-red); color: #fff; }
.btn.danger-fill:hover { background: color-mix(in srgb, var(--h-red) 85%, #000); }
.btn.icon { width: 32px; padding: 0; }
.btn.sm { height: 28px; padding: 0 var(--s2); font-size: var(--fs-xs); }
.btn.sm.icon { width: 28px; padding: 0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary .kbd {
  background: rgba(255, 255, 255, .18);
  border-color: rgba(255, 255, 255, .28);
  color: inherit;
}

/* ============================================================ ورودی */

.input, .select, .textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  transition: border-color .12s, box-shadow .12s;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--control); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--muted);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 7%, transparent);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--border);
  cursor: not-allowed;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.8; }
.input.short { max-width: 160px; }

.search-box { position: relative; width: 220px; }
.search-box .i { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-box .input { min-height: 32px; padding-inline-start: 32px; background: var(--surface-2); border-color: var(--border); }
.search-box .input:focus { background: var(--surface); }

/* ============================================================ فرم */

.field label, .field-label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text);
}
.req { color: var(--h-red); }
.field .hint { margin-top: var(--s1); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }

.check { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; font-size: var(--fs); }
.check-main { font-weight: 500; padding: 2px 0; }

/* چک‌باکس — همه‌جای برنامه یکی */
.tick,
.check input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1.5px solid var(--control);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  flex: none;
  transition: background .14s, border-color .14s, transform .1s;
}
.tick:hover, .check input[type="checkbox"]:hover { border-color: var(--text-2); }
.tick:active, .check input[type="checkbox"]:active { transform: scale(.9); }
.tick:checked, .check input[type="checkbox"]:checked { background: var(--h-green); border-color: var(--h-green); }
.tick::after, .check input[type="checkbox"]::after {
  content: '';
  position: absolute;
  inset-inline-start: 5px;
  top: 1.5px;
  width: 4.5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  opacity: 0;
}
.tick:checked::after, .check input[type="checkbox"]:checked::after { opacity: 1; }
.tick:disabled, .check input[type="checkbox"]:disabled { cursor: default; opacity: .55; }

/* «انجام شد»: دایره، مثل Todoist. زیر ماوس تیکش کم‌رنگ پیدا می‌شود. */
.tick.round, .check .tick.round { border-radius: 50%; border-color: var(--muted); }
.tick.round::after, .check .tick.round::after { inset-inline-start: 5px; top: 2px; border-color: var(--muted); }
.tick.round:hover:not(:checked)::after, .check .tick.round:hover:not(:checked)::after { opacity: .5; }
.tick.round:checked, .check .tick.round:checked { border-color: var(--h-green); }
.tick.round:checked::after, .check .tick.round:checked::after { border-color: #fff; }

/* ============================================================ پیل */

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 var(--s2);
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 500;
  white-space: nowrap;
  background: color-mix(in srgb, var(--hue, var(--h-slate)) var(--pill-bg), transparent);
  color: color-mix(in srgb, var(--hue, var(--h-slate)) var(--pill-text), var(--text));
  border: 1px solid transparent;
}
.pills { display: inline-flex; flex-wrap: wrap; gap: var(--s1); vertical-align: middle; }
td .pills { flex-wrap: nowrap; }   /* در جدول، ردیف‌ها هم‌ارتفاع بمانند */
.pill[role="button"] { cursor: pointer; }
.pill[role="button"]:hover { border-color: color-mix(in srgb, var(--hue, var(--h-slate)) 40%, transparent); }

/* پیل انتخابی در فرم */
.pick {
  height: 28px;
  padding: 0 var(--s3);
  cursor: pointer;
  background: transparent;
  color: var(--text-2);
  border-color: var(--border-strong);
  transition: background .13s, color .13s, border-color .13s;
}
.pick:hover { border-color: color-mix(in srgb, var(--hue) 55%, transparent); color: var(--text); }
.pick.on {
  background: color-mix(in srgb, var(--hue) var(--pill-bg), transparent);
  color: color-mix(in srgb, var(--hue) var(--pill-text), var(--text));
  border-color: color-mix(in srgb, var(--hue) 55%, transparent);
  font-weight: 600;
}
.pick-group { display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  display: inline-block;
  margin-inline-start: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.8;
}

/* ============================================================ تاریخ */

.date { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.date-rel { font-size: var(--fs-xs); color: var(--muted); }
.date.overdue, .date.overdue .date-rel { color: var(--h-red); }
.date.today, .date.today .date-rel { color: var(--h-green); }
.date.tomorrow, .date.tomorrow .date-rel { color: var(--h-orange); }
.date.week, .date.week .date-rel { color: var(--h-violet); }

/* ============================================================ کارت و جدول */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-wrap { overflow-x: auto; }
/* جدول اصلی خودش اسکرول می‌خورد تا سرستون و جمع همیشه دیده شوند */
.table-wrap.scroll-y { max-height: calc(100vh - 170px); overflow: auto; }

table { width: 100%; border-collapse: separate; border-spacing: 0; white-space: nowrap; }

th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 38px;
  padding: 0 var(--s3);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 500;
  text-align: start;
  user-select: none;
}
th.sortable { cursor: pointer; transition: color .12s; }
th.sortable:hover { color: var(--text); }
th .sort-mark { color: var(--accent-text); margin-inline-start: var(--s1); font-size: 10px; }

td {
  height: 44px;
  padding: var(--s1) var(--s3);
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--fs-sm);
  text-align: start;
  vertical-align: middle;
  background: var(--surface);
}
th:first-child, td:first-child { padding-inline-start: var(--s4); }
th:last-child, td:last-child { padding-inline-end: var(--s2); }
tbody tr:last-child > td { border-bottom: 0; }

tbody tr[data-id] { cursor: pointer; }
tbody tr[data-id]:hover > td { background: var(--hover); }
tbody tr[data-id]:focus-visible { outline: none; }
tbody tr[data-id]:focus-visible > td { background: var(--hover); box-shadow: inset 0 1px 0 var(--ring), inset 0 -1px 0 var(--ring); }

td.title-cell { color: var(--text); font-size: var(--fs); max-width: 420px; }
td.wide { white-space: normal; min-width: 220px; max-width: 340px; line-height: 1.65; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.link-cell { display: inline-flex; align-items: center; gap: var(--s1); }
.cell-text { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  height: 40px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-bottom: 0;
}
.sum-label { color: var(--muted); font-size: var(--fs-xs); margin-inline-end: 6px; }
.sum-value { color: var(--text); font-weight: 700; }

/* ستون‌های ابتدایی تا «عنوان» موقع اسکرول افقی سر جا می‌مانند.
   افست‌ها در JS اندازه گرفته می‌شوند و با تغییر اندازه دوباره حساب می‌شوند. */
td.frozen, th.frozen { position: sticky; z-index: 3; }
th.frozen { z-index: 4; }
tfoot td.frozen { z-index: 4; }
.frozen-last::after {
  content: '';
  position: absolute;
  inset-block: 0;
  inset-inline-end: -8px;
  width: 8px;
  background: linear-gradient(to left, rgba(0, 0, 0, .06), transparent);
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.table-wrap.scrolled .frozen-last::after { opacity: 1; }

/* ردیف‌های تمام‌شده: خط روی عنوان، بقیه کم‌رنگ */
tbody tr.struck .title-cell .cell-text {
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--muted) 70%, transparent);
  color: var(--muted);
}
tbody tr.struck > td { color: var(--muted); }
tbody tr.struck .pill, tbody tr.struck .date { opacity: .55; }
tbody tr.struck .date, tbody tr.struck .date .date-rel { color: var(--muted); }
tbody tr.struck .mono { opacity: .7; }

.row-actions { white-space: nowrap; width: 1%; }
.row-actions .btn { opacity: 0; transition: opacity .12s, background .12s, color .12s; }
tbody tr:hover .row-actions .btn,
tbody tr:focus-within .row-actions .btn,
.row-actions .btn:focus-visible { opacity: 1; }
@media (hover: none) { .row-actions .btn { opacity: .7; } }

.table-meta { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s3); color: var(--muted); font-size: var(--fs-xs); }

/* ============================================================ درخت */

.cell-tree { display: flex; align-items: center; min-height: 28px; }
.rail { width: 24px; flex: none; }

.twisty {
  width: 22px;
  height: 22px;
  margin-inline-end: 2px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex: none;
  transition: background .12s, color .12s;
}
.twisty:hover { background: var(--fill-hover); color: var(--text); }
.twisty-space { width: 24px; flex: none; }

.kid-count {
  display: inline-block;
  min-width: 20px;
  margin-inline-end: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.7;
  text-align: center;
  font-variant-numeric: tabular-nums;
  flex: none;
}

.grip { color: var(--muted); opacity: 0; cursor: grab; margin-inline-end: 2px; flex: none; transition: opacity .12s; display: grid; place-items: center; }
tr:hover .grip, .field-row:hover .grip { opacity: .6; }
[draggable="true"] { -webkit-user-drag: element; }
.dragging { opacity: .4; }

tbody tr.drop-into > td { background: var(--accent-soft) !important; }
tbody tr.drop-before > td { box-shadow: inset 0 2px 0 var(--accent); }
tbody tr.drop-after > td { box-shadow: inset 0 -2px 0 var(--accent); }

/* ============================================================ حالت خالی */

.empty { padding: 56px var(--s5); text-align: center; color: var(--muted); }
.empty .big { font-size: 32px; display: flex; justify-content: center; margin-bottom: var(--s2); opacity: .55; }
.empty .title { color: var(--text); font-weight: 600; margin-bottom: var(--s1); }
.empty .actions { margin-top: var(--s4); display: flex; gap: var(--s2); justify-content: center; }

/* ============================================================ مودال */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px var(--s4);
  overflow-y: auto;
  z-index: 100;
  animation: fade-in .14s ease;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 96px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop-in .16s cubic-bezier(.2, .9, .3, 1.1);
}
.modal.wide { max-width: 760px; }
.modal.narrow { max-width: 420px; }
.modal-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s3) var(--s3) var(--s5); border-bottom: 1px solid var(--border); flex: none; }
.modal-head h2 { font-size: var(--fs-lg); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); overflow-y: auto; flex: 1; }
.modal-foot { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s5); border-top: 1px solid var(--border); flex: none; }
.confirm-text { color: var(--text-2); margin: 0; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px) scale(.985); }
  to { opacity: 1; transform: none; }
}

/* ============================================================ فهرست فیلدها */

.field-list { display: flex; flex-direction: column; gap: 6px; }
.field-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.field-row:hover { border-color: var(--border-strong); background: var(--surface-2); }
.field-row .meta { color: var(--muted); font-size: var(--fs-xs); line-height: 1.5; }
.field-row .code { font-family: ui-monospace, 'Cascadia Mono', monospace; font-size: 11.5px; direction: ltr; unicode-bidi: isolate; }

.section { border-top: 1px solid var(--border); padding-top: var(--s4); }
.section-title { font-weight: 600; font-size: var(--fs); margin-bottom: var(--s2); }

/* ============================================================ تاریخ و تقویم */

.date-wrap { position: relative; display: flex; gap: var(--s1); align-items: center; }
.date-wrap .input { max-width: 150px; }
.date-wrap .input[type="time"] { max-width: 120px; }
.calendar {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  width: 264px;
  padding: var(--s3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 60;
}
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s2); }
.cal-head b { font-size: var(--fs-sm); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-grid span { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0; }
.cal-grid button {
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  height: 32px;
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.cal-grid button:hover { background: var(--hover); color: var(--text); }
.cal-grid button.today { color: var(--accent-text); font-weight: 700; }
.cal-grid button.sel { background: var(--accent); color: var(--on-accent); }

/* ============================================================ کاشی‌ها */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--s3); }
.tile {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color .12s;
}
.tile:hover { border-color: var(--border-strong); }
.tile h3 { font-size: var(--fs); font-weight: 600; }
.tile p { margin: 0 0 var(--s3); color: var(--muted); font-size: var(--fs-sm); flex: 1; }
.tile .btn, .tile .pill { align-self: flex-start; }

/* ============================================================ انتخاب آیکون */

.icon-picker { position: relative; display: inline-block; }
.icon-preview { width: 44px; height: 36px; padding: 0; justify-content: center; background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-2); }
.icon-panel {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  width: 300px;
  max-height: 300px;
  overflow-y: auto;
  padding: var(--s3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 70;
}
.icon-group-title { color: var(--muted); font-size: 11px; font-weight: 600; margin: var(--s2) 2px var(--s1); }
.icon-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.icon-cell { border: 0; background: transparent; border-radius: var(--radius-sm); height: 34px; display: grid; place-items: center; color: var(--text-2); cursor: pointer; }
.icon-cell:hover { background: var(--hover); color: var(--text); }
.icon-cell.sel { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent); }

/* آیکونِ خطیِ موجودیت و فضا، کنار اسمشان */
.ent-ico { display: inline-grid; place-items: center; flex: none; line-height: 0; }
.with-ico { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; vertical-align: middle; }
.with-ico .ent-ico { color: var(--muted); }
.act-ico { display: inline-grid; place-items: center; color: var(--muted); }
.act.structural .act-ico { color: var(--accent-text); }
.formula-err, .formula-val { display: inline-flex; align-items: center; gap: 4px; }

/* ============================================================ دستیار */

/* دکمه و پنجرهٔ دستیار سمت چپِ صفحه (انتهای خط)، تا روی سایدبار نیفتند */
#chat-toggle {
  position: fixed;
  bottom: var(--s6);
  inset-inline-end: var(--s6);
  z-index: 80;
  height: 40px;
  padding: 0 var(--s4);
  display: flex;
  gap: var(--s2);
  align-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: background .12s;
}
#chat-toggle:hover { background: var(--accent-hover); }

#chat {
  position: fixed;
  bottom: var(--s6);
  inset-inline-end: var(--s6);
  width: 400px;
  max-width: calc(100vw - 48px);
  height: min(640px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  z-index: 81;
}
#chat header { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s2) var(--s2) var(--s4); border-bottom: 1px solid var(--border); }
#chat header b { font-size: var(--fs); }
#chat header .ico { color: var(--accent); display: grid; }
.chat-log { flex: 1; overflow-y: auto; padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.msg { max-width: 88%; font-size: var(--fs-sm); line-height: 1.8; }
.msg.user {
  align-self: flex-start;
  background: var(--fill);
  color: var(--text);
  padding: 6px var(--s3);
  border-radius: var(--radius-lg);
  border-end-start-radius: 4px;
  white-space: pre-wrap;
}
.msg.assistant { align-self: flex-end; width: 100%; white-space: pre-wrap; color: var(--text-2); }
.msg.thinking { color: var(--muted); }
.msg .error { color: var(--h-red); }

.act {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-top: 6px;
  padding: var(--s1) var(--s2) var(--s1) var(--s3);
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-2);
  white-space: normal;
}
.act.structural { border-inline-start: 3px solid var(--accent); }
.act .undo { margin-inline-start: auto; }

.chat-input { border-top: 1px solid var(--border); padding: var(--s2); display: flex; gap: var(--s2); align-items: flex-end; }
.chat-input textarea {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  resize: none;
  line-height: 1.7;
}
.chat-input textarea:focus { outline: none; border-color: var(--muted); }
.chat-input .btn { height: 40px; }

.notice {
  padding: var(--s3);
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: 1.85;
}

/* ============================================================ توست */

#toasts {
  position: fixed;
  bottom: var(--s6);
  inset-inline: 0;
  margin-inline: auto;
  width: max-content;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  z-index: 200;
  pointer-events: none;
}
#toasts > * { pointer-events: auto; }
.toast {
  display: flex;
  align-items: center;
  gap: var(--s3);
  max-width: 400px;
  padding: 10px var(--s4);
  border-radius: var(--radius);
  background: var(--toast-bg);
  color: #f5f5f5;
  font-size: var(--fs-sm);
  box-shadow: var(--shadow);
  animation: slide-in .18s ease;
}
.toast.err { border-inline-start: 3px solid #ff6b5e; }
.toast-action {
  margin-inline-start: auto;
  border: 0;
  background: transparent;
  color: #ff9d8f;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}
@keyframes slide-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============================================================ فرمول و جمع */

.formula-val { color: var(--text); font-weight: 500; }
.formula-err { color: var(--h-red); font-size: var(--fs-xs); cursor: help; }
.formula-expr { color: var(--muted); font-size: var(--fs-xs); font-family: ui-monospace, 'Cascadia Mono', monospace; }
.negative { color: var(--h-red); }

/* ============================================================ تنظیمات */

.settings-card { padding: 0 var(--s5); }
.setting-row { display: flex; align-items: center; gap: var(--s4); padding: var(--s4) 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .select { max-width: 200px; }
.info-card { margin-top: var(--s4); padding: var(--s4) var(--s5); }
.scope-card { margin-bottom: var(--s4); padding: var(--s4) var(--s5); }
.exceptions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1); margin-top: var(--s1); }
.exceptions .tag { margin: 0; border: 0; cursor: pointer; font: inherit; font-size: 11px; font-weight: 600; }
.exceptions .tag:hover { background: var(--fill-hover); }

/* ============================================================ بخش تاشو و صفحهٔ رکورد */

.fold-card + .fold-card { margin-top: var(--s4); }
.fold-top { display: flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s3) var(--s1) var(--s2); }
.fold-head {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: start;
  cursor: pointer;
}
.fold-head:hover { background: var(--hover); }
.fold-arrow { color: var(--muted); display: grid; flex: none; }
.fold-title { font-weight: 600; font-size: var(--fs); flex: none; }
.fold-sub { color: var(--muted); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold-actions { flex: none; }
.fold-body { border-top: 1px solid var(--border); }
.fold-body > .detail-grid, .fold-body > .detail-foot { padding: var(--s5); }
.fold-body > .detail-foot { padding-top: 0; }

.modal-body .fold { border-top: 1px solid var(--border); padding-top: var(--s2); }
.modal-body .fold-top { padding: 0; }
.modal-body .fold-body { border-top: 0; padding: var(--s2) var(--s2) 0; display: flex; flex-direction: column; gap: var(--s2); }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s4) var(--s5); }
.detail-grid .span-2 { grid-column: 1 / -1; }

/* ============================================================ نوار بارگذاری */

#loading {
  position: fixed;
  top: 0;
  inset-inline: 0;
  height: 2px;
  background: var(--accent);
  /* transform-origin مقدار منطقی ندارد؛ برنامه همیشه راست‌به‌چپ است */
  transform-origin: right;
  transform: scaleX(0);
  opacity: 0;
  z-index: 300;
  transition: transform .3s ease, opacity .25s;
  pointer-events: none;
}
#loading.on { opacity: 1; transform: scaleX(.75); transition-duration: 1.4s; }
#loading.done { opacity: 0; transform: scaleX(1); transition-duration: .18s; }

/* ============================================================ جستجوگر سریع */

.palette-overlay { padding-top: 12vh; }
.palette {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: pop-in .16s cubic-bezier(.2, .9, .3, 1.1);
}
.palette-top { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); color: var(--muted); }
.palette-input { flex: 1; border: 0; background: transparent; outline: none; font-size: 15px; color: var(--text); }
.palette-input:focus-visible { outline: none; }
.palette-input::placeholder { color: var(--muted); }
.palette-list { max-height: 54vh; overflow-y: auto; padding: 6px; }
.palette-row { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--radius-sm); cursor: pointer; color: var(--text); }
.palette-row.active { background: var(--hover); }
.palette-row .ico { width: 22px; display: grid; place-items: center; flex: none; color: var(--muted); }
.palette-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-hint { margin-inline-start: auto; padding-inline-start: var(--s3); color: var(--muted); font-size: var(--fs-xs); flex: none; }
.palette-empty { padding: 28px; text-align: center; color: var(--muted); font-size: var(--fs-sm); }
.palette-foot { display: flex; gap: var(--s4); padding: var(--s2) var(--s4); border-top: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: var(--fs-xs); }

/* ============================================================ فضای کار در سایدبار */

.nav-space { font-weight: 600; }
.nav-space .count { font-weight: 400; }
.nav-toggle {
  width: 18px;
  height: 18px;
  margin-inline-end: -4px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex: none;
}
.nav-toggle:hover { background: var(--fill-hover); color: var(--text); }
/* خط راهنمای عمودی: موجودیت‌های یک فضا زیر سرتیترش آویزان دیده می‌شوند */
.nav-space-block + .nav-space-block { margin-top: 2px; }
.nav-group.nested {
  margin-inline-start: 18px;
  padding-inline-start: 6px;
  border-inline-start: 1px solid var(--border-strong);
}
.nav-divider { border: 0; border-top: 1px solid var(--border); margin: var(--s3) var(--s2) 0; }
/* دکمه‌های ساختن: کم‌رنگ‌تر از آیتم‌های فهرست، چون «جا» نیستند، «کار»ند */
.nav-actions { margin-top: var(--s2); }
.nav-create { color: var(--muted); }
.nav-create:hover { color: var(--text); }
.nav-create .ico { color: var(--accent-text); }
.nav-group[hidden] { display: none; }
.nav-empty {
  margin: 2px var(--s2) var(--s1);
  padding: var(--s1) var(--s2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: var(--fs-xs);
}
.nav-space.drop-target { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }

.crumb {
  display: inline-block;
  padding: 0;
  margin-bottom: 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-xs);
  cursor: pointer;
}
.crumb:hover { color: var(--accent-text); text-decoration: underline; }

/* ============================================================ صفحهٔ خانه */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s3); margin-bottom: var(--s5); }
.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: start;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.stat:hover { border-color: var(--border-strong); background: var(--surface-2); }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.3; color: var(--text); }
.stat-label { font-size: var(--fs-xs); color: var(--muted); }
.stat.overdue .stat-value { color: var(--h-red); }
.stat.today .stat-value { color: var(--h-green); }
.stat.done .stat-value { color: var(--h-green); }

.home-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: var(--s4); align-items: start; }
.home-col { display: flex; flex-direction: column; gap: var(--s4); min-width: 0; }

.card-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s3) var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
.card-head h2 { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs); font-weight: 600; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card-head h2 .i { color: var(--muted); }
.card-head .count { color: var(--muted); font-size: var(--fs-xs); }
.card-body { padding: var(--s4); }

/* دستورکار — فهرستی مثل Todoist، نه جدول */
.agenda-section + .agenda-section { border-top: 1px solid var(--border); }
.agenda-title {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  margin: 0;
  padding: var(--s3) var(--s4) var(--s1);
  font-size: var(--fs-sm);
  font-weight: 700;
}
.agenda-title.overdue { color: var(--h-red); }
.agenda-title.today { color: var(--h-green); }
.agenda-title .count { color: var(--muted); font-weight: 400; font-size: var(--fs-xs); }
.agenda-list { padding: 0 var(--s2) var(--s2); }
.agenda-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 48px;
  padding: 6px var(--s2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s, opacity .25s;
}
.agenda-row:hover, .agenda-row:focus-visible { background: var(--hover); outline: none; }
.agenda-row.done { opacity: .45; }
.agenda-row.done .agenda-text { text-decoration: line-through; }
.agenda-dot { width: 18px; height: 18px; flex: none; display: grid; place-items: center; }
.agenda-dot::after { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.agenda-main { flex: 1; min-width: 0; }
.agenda-text { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agenda-meta { display: flex; align-items: center; gap: var(--s2); color: var(--muted); font-size: var(--fs-xs); line-height: 1.6; }
.agenda-meta .pill { height: 18px; font-size: 11px; padding: 0 6px; }
.agenda-col { white-space: nowrap; }
.agenda-row .date { font-size: var(--fs-xs); flex: none; }
.agenda-more {
  margin: var(--s1) var(--s2);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-text);
  font-size: var(--fs-xs);
  cursor: pointer;
}
.agenda-more:hover { text-decoration: underline; }

/* گزارش */
.report-title { font-weight: 600; display: flex; align-items: center; flex-wrap: wrap; gap: var(--s1); }
.report-when { font-size: var(--fs-xs); margin-bottom: var(--s3); }
.report-chips { display: flex; flex-wrap: wrap; gap: var(--s1); margin-bottom: var(--s3); }
.report-text { white-space: pre-wrap; color: var(--text-2); line-height: 1.9; font-size: var(--fs-sm); }
.report-list { margin-top: var(--s3); }
.report-list-title { font-size: var(--fs-xs); font-weight: 600; color: var(--muted); }
.report-list ul { margin: var(--s1) 0 0; padding-inline-start: var(--s5); color: var(--text-2); font-size: var(--fs-sm); }
.report-history { display: flex; flex-direction: column; gap: var(--s3); }
.report-history .fold-card + .fold-card { margin-top: 0; }

/* نماهای سنجاق‌شده */
.widget-list { padding: var(--s1) var(--s2); }
.widget-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: 40px;
  padding: var(--s1) var(--s2);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.widget-row:hover, .widget-row:focus-visible { background: var(--hover); outline: none; }
.widget-row + .widget-row { border-top: 1px solid var(--border); }
.widget-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.widget-row.struck .widget-title { text-decoration: line-through; color: var(--muted); }
.widget-cells { display: flex; align-items: center; gap: var(--s2); flex: none; font-size: var(--fs-xs); color: var(--text-2); }
.widget-cell .pill { height: 20px; font-size: 11px; }
.widget-foot { display: flex; flex-wrap: wrap; gap: var(--s4); padding: var(--s2) var(--s4); border-top: 1px solid var(--border); background: var(--surface-2); font-size: var(--fs-sm); }

.home-hint { padding: var(--s4); }
.home-hint .title { display: flex; align-items: center; gap: var(--s2); font-weight: 600; margin-bottom: var(--s1); }
.home-hint p { margin: 0 0 var(--s3); color: var(--muted); font-size: var(--fs-sm); }

/* چیدمان با کشیدن: دستگیره بالای هر کارت، فقط زیر ماوس */
.home-card { position: relative; }
.home-col { min-height: 80px; }
.card-grip {
  position: absolute;
  top: -1px;
  inset-inline: 0;
  margin-inline: auto;
  width: 40px;
  height: 14px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0 0 6px 6px;
  background: var(--fill);
  color: var(--muted);
  cursor: grab;
  opacity: 0;
  z-index: 3;
  transition: opacity .12s;
}
.card-grip .i { transform: rotate(90deg); }
.home-card:hover > .card-grip, .card-grip:focus-visible { opacity: 1; }
.card-grip:active { cursor: grabbing; }
@media (hover: none) { .card-grip { opacity: .7; } }
.home-card.dragging { opacity: .45; }
.home-grid.arranging .home-col {
  outline: 2px dashed var(--border-strong);
  outline-offset: 4px;
  border-radius: var(--radius-lg);
}

/* برنامهٔ امروز */
.schedule-day { padding: var(--s2) var(--s2) 0; font-size: var(--fs-xs); font-weight: 600; color: var(--muted); }
.schedule-time { flex: none; min-width: 64px; font-size: var(--fs-sm); color: var(--accent-text); font-weight: 600; }
.agenda-title .i { color: var(--muted); }

@media (max-width: 1100px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ============================================================ اتصال‌ها */

.section-heading { font-size: var(--fs-lg); font-weight: 700; margin: var(--s8) 0 var(--s3); }
.integration-body { display: flex; flex-direction: column; gap: var(--s4); }
.integration-setup, .integration-sync { display: flex; flex-direction: column; gap: var(--s4); }
.steps { margin: 0; padding-inline-start: var(--s5); display: flex; flex-direction: column; gap: var(--s2); color: var(--text-2); font-size: var(--fs-sm); line-height: 1.9; }
.copyable {
  display: inline-block;
  padding: 2px var(--s2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: ui-monospace, 'Cascadia Mono', monospace;
  font-size: 12px;
  user-select: all;
  overflow-wrap: anywhere;
}
.push-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); }
.push-row { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); }
.push-row + .push-row { border-top: 1px solid var(--border); }
.push-row .select { max-width: 200px; }
.error-text { color: var(--h-red); }

/* ============================================================ ورود و ثبت‌نام */

body.auth-mode .app { grid-template-columns: minmax(0, 1fr); }
body.auth-mode .sidebar { display: none; }
body.auth-mode .main { padding: 0; }

.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
  padding: var(--s8) var(--s4);
  background:
    radial-gradient(1200px 500px at 50% -10%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
    var(--sidebar);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: var(--s8) var(--s8) var(--s6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; justify-content: center; margin-bottom: var(--s4); }
.auth-card h1 { font-size: 22px; text-align: center; }
.auth-sub { color: var(--muted); text-align: center; font-size: var(--fs-sm); margin: var(--s1) 0 var(--s6); }
.auth-form { display: flex; flex-direction: column; gap: var(--s4); }
.auth-form .input { min-height: 42px; }
.auth-submit { height: 42px; font-size: var(--fs); margin-top: var(--s1); }
.auth-error {
  padding: var(--s2) var(--s3);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--h-red) 10%, transparent);
  color: var(--h-red);
  font-size: var(--fs-sm);
}
.auth-link { border: 0; background: none; padding: 0; color: var(--accent-text); font-weight: 600; cursor: pointer; }
.auth-link:hover { text-decoration: underline; }
.auth-link.small { align-self: flex-start; font-weight: 500; font-size: var(--fs-xs); margin-top: calc(-1 * var(--s2)); }
.auth-switch { color: var(--muted); font-size: var(--fs-sm); margin: 0; }
.auth-done { display: flex; flex-direction: column; align-items: center; gap: var(--s3); text-align: center; color: var(--text-2); }
.auth-done .i { color: var(--h-green); }

/* ============================================================ کاربر و منو */

.brand .spacer { margin-inline-start: auto; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 150px;
  height: 30px;
  padding: 0 6px 0 4px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.user-chip:hover { background: var(--hover); }
.user-chip .user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); }
.user-chip .tag { margin: 0; }
.avatar {
  width: 24px;
  height: 24px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--hue, var(--h-blue)) 18%, var(--surface));
  color: color-mix(in srgb, var(--hue, var(--h-blue)) 85%, var(--text));
  font-size: 12px;
  font-weight: 700;
}
.menu-pop {
  position: fixed;
  z-index: 150;
  min-width: 220px;
  padding: var(--s1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: pop-in .14s ease;
}
.menu-pop hr { border: 0; border-top: 1px solid var(--border); margin: var(--s1) 0; }
.menu-head { display: flex; flex-direction: column; padding: var(--s2) var(--s3); line-height: 1.5; }
.menu-head .muted { font-size: var(--fs-xs); }
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: 100%;
  min-height: 34px;
  padding: 0 var(--s3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: start;
  cursor: pointer;
}
.menu-item:hover { background: var(--hover); }
.menu-item .i { color: var(--muted); }
.menu-item.danger, .menu-item.danger .i { color: var(--h-red); }

/* ============================================================ زبانه‌ها و پنل مدیریت */

.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--border); margin-bottom: var(--s5); overflow-x: auto; }
.tab {
  height: 38px;
  padding: 0 var(--s3);
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--accent-text); border-bottom-color: var(--accent); }
.admin-body { display: flex; flex-direction: column; gap: var(--s3); }
.admin-body .stats { margin-bottom: 0; }
.stat.static { cursor: default; }
.stat.static:hover { background: var(--surface); border-color: var(--border); }
.mail-body {
  margin: var(--s3) 0 0;
  padding: var(--s3);
  background: var(--surface-2);
  border-radius: var(--radius);
  white-space: pre-wrap;
  font-family: inherit;
  font-size: var(--fs-sm);
  color: var(--text-2);
  overflow-wrap: anywhere;
}

/* ============================================================ خوشامد */

.onboard {
  max-width: 760px;
  margin: 6vh auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--s3);
}
.onboard h1 { font-size: 26px; }
.onboard-sub { color: var(--text-2); max-width: 520px; margin: 0 0 var(--s4); }
.onboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--s3); width: 100%; }
.onboard-choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s2);
  padding: var(--s5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  text-align: start;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.onboard-choice:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.onboard-choice.primary { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }
.onboard-ico { font-size: 22px; color: var(--accent-text); display: grid; }
.onboard-title { font-weight: 700; font-size: var(--fs-lg); }
.onboard-text { color: var(--muted); font-size: var(--fs-sm); line-height: 1.8; }

/* چیدنِ اولیه با دستیار */
.onboard-chat { max-width: 680px; margin-top: 3vh; text-align: start; align-items: stretch; }
.onboard-chat h1 { text-align: center; }
.onboard-chat-log {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  min-height: 160px;
  max-height: 52vh;
  overflow-y: auto;
  padding: var(--s4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.onboard-chat-log .msg { font-size: var(--fs); }
.onboard-examples { display: flex; flex-wrap: wrap; gap: 6px; }
.onboard-examples .pick { --hue: var(--accent); height: auto; min-height: 28px; padding: 4px var(--s3); white-space: normal; text-align: start; }
.onboard-input { display: flex; gap: var(--s2); align-items: flex-end; }
.onboard-input .textarea { flex: 1; resize: none; }
.onboard-title .tag { margin-inline-start: var(--s2); vertical-align: middle; }

/* ============================================================ اشتراک و پلن‌ها */

.menu-plan { margin-top: var(--s1); }
.current-plan { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.plan-name { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: var(--s2); }
.usage { display: flex; flex-direction: column; gap: var(--s2); max-width: 420px; }
.usage-label { font-size: var(--fs-sm); color: var(--text-2); }
.usage-bar { height: 6px; border-radius: 999px; background: var(--fill); overflow: hidden; }
.usage-bar span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.period-toggle { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--radius); background: var(--fill); }
.period-toggle .tab { height: 30px; border: 0; margin: 0; border-radius: calc(var(--radius) - 2px); }
.period-toggle .tab.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm, 0 1px 2px rgb(0 0 0 / .08)); }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s4); }
.plan-card {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.plan-card.featured {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 3%, var(--surface));
  box-shadow: var(--shadow);
}
.plan-card > .btn { margin-top: auto; justify-content: center; }
.plan-title { font-size: var(--fs-lg); font-weight: 700; }
.plan-price { font-size: 24px; font-weight: 700; }
.plan-price .muted { font-size: var(--fs-sm); font-weight: 400; }
.plan-desc { margin: 0; color: var(--text-2); font-size: var(--fs-sm); line-height: 1.8; }
.plan-features { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); font-size: var(--fs-sm); }
.plan-features li { display: flex; align-items: center; gap: var(--s2); }
.plan-features li.yes .i { color: var(--h-green); }
.plan-features li.no { color: var(--muted); }
.plan-features li.no .i { color: var(--muted); }

.upgrade { display: flex; flex-direction: column; align-items: center; gap: var(--s3); text-align: center; }
.upgrade .plan-features { align-self: stretch; text-align: start; }
.upgrade-ico {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--accent-text);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.upgrade-text { margin: 0; font-weight: 600; }
.upgrade-notice { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s2); }

/* ربات تلگرام و بله */
.plan-features.levels { flex-direction: row; flex-wrap: wrap; gap: var(--s2) var(--s4); }
.link-steps { display: flex; flex-direction: column; gap: var(--s2); }
.link-steps p { margin: 0; }

/* مصرف و هزینه: نمودار ستونی ساده */
.usage-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 180px;
  padding-top: var(--s2);
  direction: ltr;              /* زمان از چپ به راست، مثل محور نمودار */
}
.usage-col {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
}
.usage-fill {
  width: 100%;
  max-width: 28px;
  border-radius: 4px 4px 0 0;
  background: color-mix(in srgb, var(--accent) 75%, transparent);
  transition: background .12s;
}
.usage-col:hover .usage-fill { background: var(--accent); }
.usage-x { font-size: 10px; color: var(--muted); line-height: 1; }

/* پنل مدیریت: ویرایش پلن */
.plan-editor { display: flex; flex-direction: column; gap: var(--s4); }
.check-grid { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s4); }
.card-body > b { font-size: var(--fs); }
.admin-body .card-body { display: flex; flex-direction: column; gap: var(--s3); }

/* ============================================================ واکنش‌گرا */

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  /* سایدبار یک نوار افقیِ اسکرول‌خور بالای صفحه می‌شود، نه یک صفحه فهرست */
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: var(--s1);
    padding: var(--s2) var(--s3);
    overflow-x: auto;
    overflow-y: hidden;
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
  }
  .sidebar .brand { padding: 0 var(--s1) 0 var(--s2); }
  .sidebar .brand > div, .nav-label, .nav-item .count, .nav-item .grip,
  .quick-open .kbd, .quick-open span:not(.ico) { display: none; }
  .nav-group { flex-direction: row; gap: var(--s1); }
  .nav-item, .quick-open { width: auto; flex: none; white-space: nowrap; margin: 0; padding: 0 var(--s3); }

  .main { padding: var(--s5) var(--s4) 96px; }
  .grid-2 { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .search-box { width: 100%; }
  .page-head .actions { width: 100%; }
  .page-head .actions .search-box { flex: 1; }
  .table-wrap.scroll-y { max-height: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* در نوار افقیِ موبایل، فضاها و موجودیت‌هایشان پشت هم می‌آیند */
  .nav-group.nested { margin-inline-start: 0; padding-inline-start: 0; border-inline-start: 0; }
  .nav-space-block { display: contents; }
  .nav-group[hidden] { display: flex; }
  .nav-toggle, .nav-empty, .nav-divider { display: none; }
}
