:root, html[data-theme="light"] {
  --bg: #eef1f6;
  --card: #ffffff;
  --line: #e6e8ee;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --danger: #ef4444;
  --ok: #22c55e;
  --side: 280px;
  --sidebar: #ffffff;
  --profile: #f3f4f6;
  --nav-on: #eff6ff;
  --input: #ffffff;
  --surface: #f8fafc;
  --cell: #f3f4f6;
  --cell-line: #d1d5db;
  --shadow: 0 4px 16px rgba(15, 23, 42, .06);
  --side-shadow: -8px 0 30px rgba(15, 23, 42, .08);
  --err-bg: #fef2f2;
  --ok-bg: #f0fdf4;
  --ok-text: #15803d;
  --badge-bg: #eef2ff;
  --letter-bg: #dbeafe;
  --overlay: rgba(15, 23, 42, .35);
  --theme-track: #e5e7eb;
  --theme-knob: #ffffff;
}
html[data-theme="dark"] {
  --bg: #0f141c;
  --card: #171e2b;
  --line: #2a3444;
  --text: #e8edf5;
  --muted: #9aa4b2;
  --accent: #60a5fa;
  --danger: #f87171;
  --ok: #34d399;
  --sidebar: #151c27;
  --profile: #1e2836;
  --nav-on: rgba(96, 165, 250, .16);
  --input: #121820;
  --surface: #121820;
  --cell: #1e2836;
  --cell-line: #3b4658;
  --shadow: 0 4px 16px rgba(0, 0, 0, .28);
  --side-shadow: -8px 0 30px rgba(0, 0, 0, .35);
  --err-bg: #3f1d24;
  --ok-bg: #143322;
  --ok-text: #86efac;
  --badge-bg: #1e3a5f;
  --letter-bg: #1e3a5f;
  --overlay: rgba(0, 0, 0, .55);
  --theme-track: #2a3444;
  --theme-knob: #3b82f6;
}
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, Tahoma, sans-serif;
}
body.menu-open { overflow: hidden; }
img, video { max-width: 100%; height: auto; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; color: inherit; }
h1 { font-size: clamp(22px, 5vw, 30px); line-height: 1.4; margin: 8px 0 16px; font-weight: 800; }
h2 { font-size: clamp(16px, 4vw, 20px); line-height: 1.4; }
.section-title {
  color: var(--accent);
  font-weight: 800;
  margin: 8px 0 14px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}

.app { min-height: 100vh; }
[x-cloak] { display: none !important; }
.app-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 0;
}
.app-head .theme-toggle { margin-inline-start: auto; }
.app-main { padding: 8px 16px 40px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; color: var(--accent); font-size: 14px; font-weight: 600; }
.crumbs span { color: var(--muted); }

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 18px;
  margin-top: 14px;
  color: var(--text);
  box-shadow: var(--shadow);
}
.stat-card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}
.stat-card b { font-size: 22px; display: block; margin-top: 4px; }
.stat-ico {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.stat-ico svg { width: 22px; height: 22px; }
.stat-ico .nav-ico { background: none; width: auto; height: auto; }

.session-pick {
  display: block;
  width: 100%;
  text-align: right;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--line);
}
.session-pick b { color: var(--text); font-size: 18px; }
.session-pick .muted { color: var(--muted); }
.session-pick.is-on { outline: 2px solid var(--accent); }
.session-pick:disabled { opacity: .45; cursor: not-allowed; }
.price-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-top: 4px; }
.old-price { color: var(--muted); text-decoration: line-through; }
.sale-price { color: var(--accent); font-weight: 800; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}
.btn-p { background: var(--accent); color: #fff; }
.btn-g { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn-d { background: var(--danger); color: #fff; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.split { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.grow { flex: 1 1 180px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.page-head h1 { margin: 0; }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--text);
  font-family: inherit;
  min-height: 44px;
}
input.is-invalid, textarea.is-invalid, select.is-invalid { border-color: var(--danger); }
.terms-box {
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.9;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  margin: 12px 0;
  color: var(--text);
}
label { display: block; margin-top: 12px; font-size: 14px; color: var(--muted); }
.muted { color: var(--muted); }
.err { background: var(--err-bg); color: var(--danger); padding: 10px; border-radius: 12px; }
.ok { background: var(--ok-bg); color: var(--ok-text); padding: 10px; border-radius: 12px; }
.badge { display: inline-flex; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 800; background: var(--badge-bg); color: var(--accent); }
.grid { display: grid; gap: 12px; }
.grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
img.avatar { width: 112px; height: 112px; object-fit: cover; border-radius: 50%; }

.session-cells { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 10px; }
.session-cell {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 2px solid var(--cell-line);
  background: var(--cell);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
}
.session-cell.is-present { background: var(--ok); border-color: var(--ok); color: #fff; }
.session-cell.is-unexcused { background: var(--danger); border-color: var(--danger); color: #fff; }
.session-cell.is-excused { background: #9ca3af; border-color: #9ca3af; color: #fff; }
.session-cell.is-makeup:not(.is-present):not(.is-unexcused):not(.is-excused) {
  outline: 1px dashed #9ca3af;
  outline-offset: 2px;
}
.session-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.session-legend .session-cell { width: 12px; height: 12px; border-radius: 3px; margin-left: 6px; outline: none; font-size: 0; }
.weekdays { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  color: var(--text);
  font-size: 15px;
}
.check-line input { width: auto; min-height: 18px; }
.weekdays label { display: flex; align-items: center; gap: 6px; width: auto; margin: 0; color: var(--text); }
.weekdays input { width: auto; min-height: 18px; }
.date-row { align-items: stretch; }
.date-row input, .date-row select { flex: 1 1 28%; width: auto; min-width: 0; }
.date-row .btn { flex: 1 1 100%; }

.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: min(86vw, var(--side));
  height: 100%;
  background: var(--sidebar);
  box-shadow: var(--side-shadow);
  z-index: 50;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transform: translateX(110%);
  transition: transform .25s ease;
}
body.menu-open .sidebar { transform: translateX(0); }
.side-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #ef4444;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  margin-bottom: 14px;
}
.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.side-logo { margin-bottom: 0; }
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 0;
  border-radius: 999px;
  background: var(--theme-track);
  cursor: pointer;
  min-height: 0;
}
.theme-toggle span {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.theme-toggle svg { width: 15px; height: 15px; }
html[data-theme="light"] .theme-toggle .is-light,
html[data-theme="dark"] .theme-toggle .is-dark {
  background: var(--theme-knob);
  color: #fff;
}
html[data-theme="light"] .theme-toggle .is-light { color: #111827; }
.profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--profile);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 16px;
}
.profile-card img, .profile-letter {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.profile-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--letter-bg);
  color: var(--accent);
  font-weight: 800;
}
.profile-card b { display: block; font-size: 14px; }
.profile-card small { color: var(--muted); font-size: 12px; }
.side-nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.side-nav a,
.side-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: right;
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  min-height: 44px;
}
.side-nav a.is-on { background: var(--nav-on); color: var(--accent); }
.side-nav form { margin: 0; }
.nav-out { margin-top: auto; }
.nav-ico {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.nav-ico svg { width: 15px; height: 15px; }
.tone-blue { background: #3b82f6; }
.tone-red { background: #ef4444; }
.tone-green { background: #22c55e; }
.tone-yellow { background: #eab308; color: #1f2937; }
.stat-ico.tone-blue { background: #3b82f6; }
.stat-ico.tone-red { background: #ef4444; }
.stat-ico.tone-green { background: #22c55e; }
.stat-ico.tone-yellow { background: #eab308; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 40;
}
.drawer-backdrop[hidden] { display: none !important; }
.burger {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 10px;
  background: var(--card);
  box-shadow: var(--shadow);
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 0;
}
.burger span { display: block; width: 16px; height: 2px; background: var(--text); border-radius: 2px; }

.history-card h2 { margin: 0 0 4px; }
.kv-list {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.kv {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  background: var(--card);
}
.kv:nth-child(even) { background: var(--surface); }
.kv span { color: var(--muted); }
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0 8px;
}
.seg a {
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 800;
  box-shadow: var(--shadow);
}
.seg a.is-on {
  background: var(--nav-on);
  color: var(--accent);
  border-color: transparent;
}
.ins-open {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
}
.ins-shot {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 12px;
  background: var(--surface);
}
.ins-shot-lg {
  max-width: min(92vw, 720px);
  max-height: 82vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.ins-pdf {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}
.ins-pdf-frame {
  width: min(92vw, 720px);
  height: 82vh;
  background: var(--card);
  border: 0;
}
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.lightbox[hidden] { display: none !important; }
.lightbox-close {
  position: absolute;
  top: 16px;
  left: 16px;
  border: 0;
  border-radius: 12px;
  min-height: 40px;
  padding: 8px 14px;
  background: var(--card);
  color: var(--text);
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
}
.badge-ACTIVE { background: var(--nav-on); color: var(--accent); }
.badge-COMPLETED { background: var(--ok-bg); color: var(--ok-text); }
.badge-PENDING_PAYMENT { background: var(--profile); color: var(--muted); }
.badge-EXPIRED { background: var(--err-bg); color: var(--danger); }

@media (min-width: 960px) {
  body.has-nav .app { margin-right: var(--side); }
  body.has-nav .sidebar { transform: none; }
  body.has-nav .burger { display: none; }
  body.has-nav .drawer-backdrop { display: none !important; }
  .app-head, .app-main { padding-right: 28px; padding-left: 28px; }
  .grid-2 { grid-template-columns: 160px 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .date-row .btn { flex: 0 0 auto; }
  .actions-row .btn { flex: 1 1 auto; }
}
@media (min-width: 1200px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 959px) {
  .actions-row .btn { flex: 1 1 100%; }
  .split { align-items: stretch; }
  .split > .btn, .split > a.btn { width: 100%; }
  img.avatar { width: 88px; height: 88px; }
}
