/* الگوی صالح — shared styles. Tokens mirror design-system/MASTER.md */
/* Vazirmatn loads from each page <head> without blocking first paint (see <link media="print" onload>) */

:root {
  /* colour — brand values measured from assets/logo.png */
  --mint-500: #2cd48c;
  --mint-700: #0b7a4e;
  --mint-100: #ddf7eb;
  --navy-600: #003098;
  --navy-700: #00267a;
  --navy-800: #0a1f4d;
  --navy-500: #3a4f7a;
  --navy-400: #56648a;
  --navy-100: #e6ecf7;
  --paper: #f4f7f6;
  --line: rgba(var(--ink-rgb), .10);
  --line-strong: rgba(var(--ink-rgb), .16);
  --amber-700: #9a5b00;
  --amber-100: #fff1d6;
  --red-700: #b42318;
  --red-100: #fde7e5;

  /* type */
  --font: "Vazirmatn", system-ui, sans-serif;
  --fs-display: 2.25rem;
  --fs-h1: 1.75rem;
  --fs-h2: 1.25rem;
  --fs-h3: 1.0625rem;
  --fs-body: 1rem;
  --fs-small: .875rem;
  --fs-micro: .8125rem;

  /* space */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px;
  --s-6: 32px; --s-7: 48px; --s-8: 64px; --s-9: 96px;

  /* radius */
  --r-sm: 10px; --r-md: 14px; --r-lg: 22px; --r-xl: 30px; --r-full: 999px;

  /* surfaces as channels so themes can swap them (see css/appearance.css) */
  --surface: #fff;
  --surface-rgb: 255, 255, 255;
  --ink-rgb: 10, 31, 77;
  --shadow-rgb: 10, 31, 77;
  --primary-rgb: 0, 48, 152;
  --accent-rgb: 44, 212, 140;
  --accent-soft-rgb: 221, 247, 235;
  --rim-rgb: 255, 255, 255;
  --on-primary: #fff;

  /* adjustable from the appearance panel (js/theme.js) */
  --glass-a: .58;          /* pane opacity: lower = clearer glass */
  --glass-blur-px: 22px;
  --orn-k: 1;              /* ornament strength multiplier */
  --tile-size: 132px;

  /* glass */
  --glass-bg: rgba(var(--surface-rgb), var(--glass-a));
  --glass-bg-strong: rgba(var(--surface-rgb), min(.96, calc(var(--glass-a) + .2)));
  --glass-blur: blur(var(--glass-blur-px)) saturate(170%);
  --glass-edge: rgba(var(--surface-rgb), .85);
  --shadow-pane: 0 1px 1px rgba(var(--shadow-rgb), .04), 0 10px 30px -14px rgba(var(--shadow-rgb), .16);
  --shadow-lift: 0 2px 4px rgba(var(--shadow-rgb), .06), 0 18px 40px -18px rgba(var(--shadow-rgb), .24);
  --glass-inner: inset 0 1px 0 rgba(var(--rim-rgb), .9), inset 0 -1px 0 rgba(var(--ink-rgb), .05);

  /* motion */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  --sidebar-w: 248px;
  color-scheme: light;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.85;
  color: var(--navy-800);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
a { color: var(--navy-600); text-underline-offset: .3em; text-decoration-thickness: 1px; }
img, svg { display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: rgba(var(--accent-rgb), .32); color: var(--navy-800); }
input, textarea { caret-color: var(--navy-600); }
:focus-visible { outline: 2px solid var(--navy-600); outline-offset: 2px; border-radius: var(--r-sm); }
* { scrollbar-width: thin; scrollbar-color: rgba(var(--ink-rgb), .22) transparent; }
.num { font-variant-numeric: tabular-nums; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 24px; height: 24px; }
[dir="rtl"] .icon--dir { transform: scaleX(-1); }

/* ---------- the ground: paper + eslimi tile + colour fields ---------- */
.ground {
  position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none;
  background: var(--paper);
}
.ground::before { /* faint eslimi tile — p20-02 */
  content: ""; position: absolute; inset: -40px;
  background: var(--navy-800);
  opacity: calc(.045 * var(--orn-k));
  -webkit-mask: var(--orn-tile) 0 0 / var(--tile-size) var(--tile-size) repeat;
          mask: var(--orn-tile) 0 0 / var(--tile-size) var(--tile-size) repeat;
}
.ground::after { /* colour fields the glass refracts */
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(38rem 30rem at 88% 6%, rgba(var(--accent-rgb), calc(.20 * var(--field-k, 1))), transparent 70%),
    radial-gradient(34rem 28rem at 6% 96%, rgba(var(--primary-rgb), calc(.12 * var(--field-k, 1))), transparent 70%);
}

/* ---------- glass ---------- */
.glass {
  position: relative;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
          backdrop-filter: var(--glass-blur);
  border: 1px solid rgba(var(--rim-rgb), calc(.55 * var(--rim-o, 1)));
  border-radius: var(--r-lg);
  box-shadow: var(--glass-inner), var(--shadow-pane);
}
.glass::before { /* specular rim: bright top-start, fading to the bottom-end */
  content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(200deg, rgba(var(--rim-rgb), .95), rgba(var(--rim-rgb), .15) 38%, rgba(var(--rim-rgb), 0) 60%, rgba(var(--rim-rgb), .45));
  opacity: var(--rim-o, 1);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}
.glass--strong { background: var(--glass-bg-strong); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: rgba(var(--surface-rgb), .96); }
}
@media (prefers-reduced-transparency: reduce) {
  .glass { background: rgba(var(--surface-rgb), .97); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

/* ---------- ornament primitives (all aria-hidden) ---------- */
.orn { display: block; background: currentColor; pointer-events: none; -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; -webkit-mask-position: center; mask-position: center; }
.orn--fan { -webkit-mask-image: var(--orn-fan); mask-image: var(--orn-fan); aspect-ratio: 1184 / 600; }
.orn--fan-solid { -webkit-mask-image: var(--orn-fan-solid); mask-image: var(--orn-fan-solid); aspect-ratio: 1184 / 600; }
.orn--shamseh { -webkit-mask-image: var(--orn-shamseh); mask-image: var(--orn-shamseh); aspect-ratio: 1; }
.orn--divider { -webkit-mask-image: var(--orn-divider); mask-image: var(--orn-divider); aspect-ratio: 739 / 1081; }

/* lachak (لچک): each corner has its own motif or none, chosen in «تنظیمات ظاهر» (js/theme.js sets
   --orn-lachak-tl/tr/bl/br). Which panes get them: «روی کدام قاب‌ها» (html[data-lachak-scope]). */
:root {
  --orn-ink: var(--mint-700);       /* deeper brand colour, so line ornaments read on light glass */
  --lk-size: 64px;
  --lk-tl: var(--orn-lachak-tl); --lk-tr: var(--orn-lachak-tr);
  --lk-bl: var(--orn-lachak-bl); --lk-br: var(--orn-lachak-br);
}
.lachak, html[data-lachak-scope="all"] main .glass { position: relative; }
.lachak::after, html[data-lachak-scope="all"] main .glass::after {
  content: ""; position: absolute; inset: 9px; pointer-events: none; z-index: 0;
  background: var(--orn-ink); opacity: min(1, calc(.75 * var(--orn-k)));
  -webkit-mask:
    var(--lk-tl) left top / var(--lk-size) var(--lk-size) no-repeat,
    var(--lk-tr) right top / var(--lk-size) var(--lk-size) no-repeat,
    var(--lk-bl) left bottom / var(--lk-size) var(--lk-size) no-repeat,
    var(--lk-br) right bottom / var(--lk-size) var(--lk-size) no-repeat;
          mask:
    var(--lk-tl) left top / var(--lk-size) var(--lk-size) no-repeat,
    var(--lk-tr) right top / var(--lk-size) var(--lk-size) no-repeat,
    var(--lk-bl) left bottom / var(--lk-size) var(--lk-size) no-repeat,
    var(--lk-br) right bottom / var(--lk-size) var(--lk-size) no-repeat;
}
/* small panes get smaller corners */
html[data-lachak-scope="all"] main .glass:not(.lachak) { --lk-size: 44px; }
.lachak > *, html[data-lachak-scope="all"] main .glass > * { position: relative; z-index: 1; }
/* top corners on: the first line of the pane steps in so the start corner never sits on a heading */
html[data-lachak-top] :is(.lachak, html[data-lachak-scope="all"] main .glass) > :first-child:not(.orn) {
  padding-inline-start: calc(var(--lk-size) * .9);
}
@media (max-width: 639.98px) { :root { --lk-size: 48px; } }

/* divider: hairline — sar-toranj — hairline */
.divider { display: flex; align-items: center; gap: var(--s-3); color: var(--orn-ink); }
.divider .orn { opacity: min(1, var(--orn-k)); }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: linear-gradient(to left, transparent, rgba(var(--accent-rgb), .55) 35%, rgba(var(--accent-rgb), .55) 70%, transparent); }
.divider::after { transform: scaleX(-1); }
.divider .orn { width: 34px; transform: rotate(90deg); }
.divider--plain::before, .divider--plain::after { background: var(--line); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: 0 var(--s-5);
  border: 1px solid transparent; border-radius: var(--r-md);
  font-size: var(--fs-small); font-weight: 600; line-height: 1; text-decoration: none; white-space: nowrap;
  transition: transform 160ms var(--ease-out), background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}
.btn:active { transform: scale(.97); }
/* button colour is a token so «رنگ دکمه» can swap it (css/controls.css) */
:root { --btn: var(--navy-600); --btn-fg: var(--on-primary); }
.btn--primary { background-color: var(--btn); color: var(--btn-fg); box-shadow: inset 0 1px 0 rgba(var(--surface-rgb), .18), 0 6px 16px -8px color-mix(in srgb, var(--btn) 55%, transparent); }
.btn--primary:hover { background-color: color-mix(in srgb, var(--btn) 86%, #000); }
.btn--quiet { background: rgba(var(--surface-rgb), .6); border-color: var(--line); color: var(--navy-800); }
.btn--quiet:hover { background: var(--surface); border-color: var(--line-strong); }
.btn--ghost { background: transparent; color: var(--navy-600); padding-inline: var(--s-3); }
.btn--ghost:hover { background: rgba(var(--primary-rgb), .06); }
.btn--lg { min-height: 52px; padding-inline: var(--s-6); font-size: var(--fs-body); border-radius: 16px; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: var(--r-full); background: transparent; color: var(--navy-500);
  transition: background-color 150ms ease, transform 160ms var(--ease-out), color 150ms ease;
}
.icon-btn:hover { background: rgba(var(--ink-rgb), .06); color: var(--navy-800); }
.icon-btn:active { transform: scale(.94); }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--r-full); font-size: var(--fs-micro); font-weight: 500; line-height: 1.8; white-space: nowrap; }
.chip--mint { background: var(--mint-100); color: var(--mint-700); }
.chip--amber { background: var(--amber-100); color: var(--amber-700); }
.chip--red { background: var(--red-100); color: var(--red-700); }
.chip--navy { background: var(--navy-100); color: var(--navy-600); }
.chip--line { border: 1px solid var(--line-strong); color: var(--navy-500); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint-500); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .25); }

/* ---------- form fields ---------- */
.field { display: grid; gap: 6px; }
.field label { font-size: var(--fs-small); font-weight: 500; color: var(--navy-500); }
.input {
  width: 100%; min-height: 50px; padding: 0 var(--s-4);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: rgba(var(--surface-rgb), .72);
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}
.input::placeholder { color: var(--navy-400); }
.input:hover { border-color: rgba(var(--ink-rgb), .28); }
.input:focus { outline: none; background: var(--surface); border-color: var(--navy-600); box-shadow: 0 0 0 4px rgba(var(--primary-rgb), .12); }
.input-wrap { position: relative; }
.input-wrap .input { padding-inline-end: 52px; }
.input-wrap .icon-btn { position: absolute; inset-inline-end: 3px; inset-block-start: 3px; }
.input[dir="ltr"] { text-align: right; }
.input[dir="ltr"]:placeholder-shown { direction: rtl; }

/* ---------- segmented control (sliding glass thumb) ---------- */
.segmented {
  --count: 3; --index: 0;
  position: relative; display: grid; grid-template-columns: repeat(var(--count), minmax(0, 1fr));
  padding: 4px; border-radius: var(--r-full);
  background: rgba(var(--shadow-rgb), .06); box-shadow: inset 0 1px 2px rgba(var(--shadow-rgb), .06);
}
.segmented__thumb {
  position: absolute; inset-block: 4px; inset-inline-start: 4px;
  width: calc((100% - 8px) / var(--count));
  border-radius: var(--r-full); background: var(--surface);
  box-shadow: 0 1px 2px rgba(var(--shadow-rgb), .08), 0 4px 12px -4px rgba(var(--shadow-rgb), .18), inset 0 1px 0 var(--surface);
  transform: translateX(calc(var(--index) * -100%));
  transition: transform 240ms var(--ease-out);
}
[dir="ltr"] .segmented__thumb { transform: translateX(calc(var(--index) * 100%)); }
.segmented button {
  position: relative; z-index: 1; min-height: 42px; border: 0; background: none; border-radius: var(--r-full);
  font-size: var(--fs-small); font-weight: 500; color: var(--navy-500); white-space: nowrap; padding-inline: 8px;
  transition: color 180ms ease;
}
@media (max-width: 639.98px) { .segmented button { font-size: var(--fs-micro); } }
.segmented button[aria-checked="true"], .segmented button[aria-selected="true"] { color: var(--navy-800); font-weight: 600; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: 0; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 16px; align-self: start; margin: 16px; margin-inline-end: 0;
  height: calc(100dvh - 32px); display: flex; flex-direction: column; padding: var(--s-5) var(--s-4);
  border-radius: var(--r-xl);
}
.brand { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-2) var(--s-5); text-decoration: none; color: inherit; }
.brand img { width: 46px; height: auto; }
.brand strong { display: block; font-size: 1.0625rem; font-weight: 800; color: var(--navy-600); line-height: 1.4; }
.brand span { display: block; font-size: .75rem; color: var(--navy-400); line-height: 1.5; }
.nav { display: grid; gap: 2px; margin-top: var(--s-2); }
.nav a {
  display: flex; align-items: center; gap: var(--s-3); min-height: 44px; padding: 0 var(--s-3);
  border-radius: var(--r-md); color: var(--navy-500); text-decoration: none; font-size: .9375rem; font-weight: 500;
  transition: background-color 150ms ease, color 150ms ease;
}
.nav a:hover { background: rgba(var(--surface-rgb), .7); color: var(--navy-800); }
.nav a[aria-current="page"] { background: var(--surface); color: var(--navy-600); font-weight: 600; box-shadow: 0 1px 2px rgba(var(--shadow-rgb), .06), 0 6px 14px -8px rgba(var(--shadow-rgb), .18); }
.nav a[aria-current="page"] .icon { color: var(--navy-600); }
.sidebar__foot { margin-top: auto; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-2) 0; border-top: 1px solid var(--line); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--navy-100); color: var(--navy-600); font-weight: 700; font-size: .9375rem; }
.avatar--sm { width: 32px; height: 32px; font-size: .8125rem; }
.avatar--mint { background: var(--mint-100); color: var(--mint-700); }
.who { min-width: 0; line-height: 1.5; }
.who strong { display: block; font-size: var(--fs-small); font-weight: 600; }
.who span { display: block; font-size: .75rem; color: var(--navy-400); }

.main { min-width: 0; overflow-x: clip; padding: var(--s-6) var(--s-7) var(--s-8); }
.container { max-width: 1180px; margin-inline: auto; }

/* topbar (mobile brand + page actions) */
.topbar { display: none; }

/* bottom tab bar (mobile) */
.tabbar { display: none; }

@media (max-width: 1023.98px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .main { padding: var(--s-4) var(--s-5) calc(104px + env(safe-area-inset-bottom)); }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-5); }
  .topbar .brand { padding: 0; }
  .topbar .brand img { width: 38px; }
  .tabbar {
    position: fixed; z-index: 20; inset-inline: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); padding: 6px; border-radius: 26px; /* as many items as the menu has */
  }
  .tabbar a {
    display: grid; justify-items: center; gap: 2px; padding: 6px 0 4px; border-radius: 20px;
    color: var(--navy-500); text-decoration: none; font-size: .8125rem; font-weight: 500; line-height: 1.5; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
    transition: background-color 150ms ease, color 150ms ease;
  }
  .tabbar a[aria-current="page"] { background: var(--surface); color: var(--navy-600); font-weight: 600; box-shadow: 0 1px 2px rgba(var(--shadow-rgb), .06); }
}
@media (max-width: 639.98px) {
  .main { padding-inline: var(--s-4); }
  :root { --fs-display: 1.75rem; --fs-h1: 1.5rem; }
}

/* ---------- page heading ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-5); flex-wrap: wrap; margin-bottom: var(--s-6); }
.page-head h1 { font-size: var(--fs-h1); font-weight: 700; line-height: 1.35; }
.page-head p { color: var(--navy-500); font-size: .9375rem; margin-top: 2px; }

/* ---------- sections ---------- */
.section + .section { margin-top: var(--s-7); }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-4); }
.section__head h2 { font-size: var(--fs-h2); font-weight: 600; }
.section__head a { font-size: var(--fs-small); font-weight: 500; text-decoration: none; }
.section__head a:hover { text-decoration: underline; }
.muted { color: var(--navy-500); }
.meta { color: var(--navy-400); font-size: var(--fs-small); }

/* rows: the default container for lists — not cards */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-4) var(--s-2); border-top: 1px solid var(--line); }
.rows > .row:first-child { border-top: 0; }
.row__main { flex: 1; min-width: 0; }
.row__title { display: block; font-size: var(--fs-h3); font-weight: 600; line-height: 1.6; }
.row__meta { display: block; color: var(--navy-400); font-size: var(--fs-small); line-height: 1.7; }
a.row { color: inherit; text-decoration: none; border-radius: var(--r-md); transition: background-color 150ms ease; }
a.row:hover { background: rgba(var(--surface-rgb), .7); }

/* thin progress bar */
.bar { display: block; position: relative; height: 6px; border-radius: var(--r-full); background: rgba(var(--ink-rgb), .08); overflow: hidden; }
.bar > span { position: absolute; inset-block: 0; inset-inline-start: 0; width: var(--v, 0%); border-radius: inherit; background: var(--mint-500); }

/* ---------- entrance: one authored moment ---------- */
/* entrance effects live in css/motion.css; glass styles in css/glass.css */
@media (prefers-reduced-motion: reduce) { /* stop movement in transitions; colour changes stay */
  *, *::before, *::after { transition-property: background-color, color, border-color, opacity !important; }
}
.brand span span { white-space: nowrap; }

/* «کنار عنوان‌ها هم»: a small sar-toranj leads each section heading */
html[data-divider-heads] :is(.section__head h2, .toolbar h2, .attend__head h2, .day h2, .classes h2, .sessions__head h2)::before {
  content: ""; display: inline-block; width: 14px; height: 20px; margin-inline-end: 10px; vertical-align: -3px;
  background: var(--orn-ink); opacity: min(1, var(--orn-k));
  -webkit-mask: var(--orn-divider) center / contain no-repeat; mask: var(--orn-divider) center / contain no-repeat;
}
/* lachak panes that hold a table: room above and below so corners frame the table instead of sitting on it */
html[data-lachak-top] .lachak:has(> table) { padding-block-start: calc(var(--lk-size) * .5); }
html[data-lachak-bottom] .lachak:has(> table) { padding-block-end: calc(var(--lk-size) * .5); }
html:is([data-lachak-tr], [data-lachak-br]) .lachak:has(> table) :is(th, td):first-child { padding-inline-start: calc(var(--lk-size) * .55); }
