/* فونت Vazirmatn از خود پروژه بارگذاری می‌شود (بدون CDN) — مجوز: OFL، فایل public/fonts/OFL.txt */
@font-face {
  font-family: 'Vazirmatn';
  src: url('/static/fonts/Vazirmatn-variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #e6f4f1;
  --bg: #f4f6f7;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #5f6b76;
  --border: #dde3e7;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok-soft: #e7f6ec;
  --warn: #92600a;
  --radius: 14px;
  --nav-h: 64px;
  --font: 'Vazirmatn', Tahoma, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.8;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
body.bare { padding-bottom: 0; }
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.5; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; line-height: 1.6; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 2px; border-radius: 6px; }

/* ---------- ساختار ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .5rem 1rem;
  background: var(--primary); color: #fff;
  min-height: 56px;
}
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.who { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.who-name { display: flex; flex-direction: column; line-height: 1.3; font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-name small { font-weight: 400; opacity: .85; font-size: .75rem; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.5); }

.container { max-width: 960px; margin: 0 auto; padding: 1rem; }
.bare .container { display: grid; place-items: center; min-height: 100vh; }

.nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: var(--nav-h); gap: 0; font-size: .8rem; color: var(--muted); padding: .25rem;
}
.nav a:hover { text-decoration: none; }
.nav a.on { color: var(--primary-dark); font-weight: 700; box-shadow: inset 0 3px 0 var(--primary); }
.nav .ico { font-size: 1.25rem; line-height: 1.4; }

@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .nav {
    position: sticky; top: 56px; bottom: auto; inset-inline: 0;
    justify-content: flex-start; gap: .25rem; padding: 0 1rem;
    border-top: 0; border-bottom: 1px solid var(--border);
  }
  .nav a { flex: 0 0 auto; flex-direction: row; gap: .4rem; min-height: 48px; padding: 0 1rem; font-size: .95rem; box-shadow: none !important; }
  .nav a.on { border-bottom: 3px solid var(--primary); }
}

/* ---------- کارت و چیدمان ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.narrow { max-width: 520px; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.grid .card { margin-bottom: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-bottom: 1rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.class-head { margin-bottom: .75rem; }
.class-head .back { display: inline-block; font-size: .9rem; margin-bottom: .25rem; }
.class-card h2 a { color: var(--text); }
.class-card .stat { margin: .25rem 0 .75rem; }
.card-actions { display: grid; gap: .5rem; }
.empty-state { text-align: center; padding: 2rem 1rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 .75rem; }
.chip { background: var(--primary-soft); border-radius: 999px; padding: .1rem .85rem; font-size: .9rem; }

.tabs { display: flex; gap: .25rem; overflow-x: auto; margin: 0 0 1rem; padding-bottom: 2px; scrollbar-width: thin; }
.tabs a { flex: 0 0 auto; padding: .45rem 1rem; border-radius: 999px; background: var(--card); border: 1px solid var(--border); color: var(--text); min-height: 44px; display: inline-flex; align-items: center; }
.tabs a:hover { text-decoration: none; background: var(--primary-soft); }
.tabs a.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list.compact .list-row { padding: .35rem 0; }
.row-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.row-actions form { margin: 0; }

/* ---------- دکمه‌ها ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .4rem 1.1rem;
  font: inherit; font-weight: 600; font-size: .95rem; line-height: 1.4;
  color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer; text-align: center;
}
.btn:hover { text-decoration: none; background: var(--primary-soft); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8e1a10; }
.btn-ghost { background: transparent; }
.btn-small { min-height: 38px; padding: .2rem .8rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn.disabled, .btn[aria-disabled='true'] { opacity: .45; pointer-events: none; }

/* ---------- فرم ---------- */
.form { display: grid; gap: .9rem; }
.form label, .form .field { display: grid; gap: .3rem; font-weight: 600; font-size: .95rem; }
.form .label { font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--text); background: #fff;
  min-height: 46px; padding: .45rem .75rem; width: 100%;
  border: 1px solid #b9c3cb; border-radius: 10px;
}
textarea { resize: vertical; line-height: 1.7; }
input[type='radio'], input[type='checkbox'] { width: auto; min-height: 0; }
input[type='file'] { padding: .5rem; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: 2px solid var(--primary); outline-offset: 0; }
.datepick { display: grid; grid-template-columns: 1fr 2fr 1.4fr; gap: .4rem; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .75rem; }
.inline-form .datepick { min-width: min(100%, 320px); }

.flash { border-radius: 10px; padding: .7rem 1rem; margin-bottom: 1rem; border: 1px solid transparent; }
.flash-ok { background: var(--ok-soft); border-color: #b7e1c4; }
.flash-err { background: var(--danger-soft); border-color: #f4b8b1; color: #7a1a12; }
.flash-err ul { margin: .25rem 0 0; padding-inline-start: 1.25rem; }
.flash-secret { background: #fff8e1; border-color: #f0d98c; }
.creds { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: .5rem 0; }
.creds dt { color: var(--muted); } .creds dd { margin: 0; font-weight: 700; }
.creds code { font-size: 1.15rem; letter-spacing: .05em; user-select: all; }

/* ---------- جدول ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-inline: -.25rem; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .55rem .6rem; text-align: start; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { background: #f0f4f5; font-weight: 700; white-space: nowrap; }
.table tfoot th, .table tfoot td { background: #f0f4f5; font-weight: 700; }
.matrix .table th, .matrix .table td { white-space: nowrap; }
.matrix .sticky-col { position: sticky; inset-inline-start: 0; background: #fff; z-index: 1; box-shadow: -1px 0 0 var(--border); }
.matrix thead .sticky-col, .matrix tfoot .sticky-col { background: #f0f4f5; }

/* ---------- حضور و غیاب و نمره ---------- */
.date-nav { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.date-title { text-align: center; line-height: 1.5; display: flex; flex-direction: column; }
.att-tools { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.att-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .5rem; }
.att-row { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .75rem; display: grid; gap: .5rem; }
.att-name { font-weight: 600; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: .35rem; }
.seg-opt { position: relative; display: block; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg-opt span { display: flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font-size: .85rem; font-weight: 600; text-align: center; padding: 0 .2rem; }
.seg-opt input:focus-visible + span { outline: 3px solid #1d4ed8; outline-offset: 2px; }
.seg-opt.st-present input:checked + span { background: #d8f0e0; border-color: #2e7d4f; color: #14532d; }
.seg-opt.st-absent input:checked + span { background: #fde0dc; border-color: #c0392b; color: #7a1a12; }
.seg-opt.st-late input:checked + span { background: #fdf0cc; border-color: #b7791f; color: #6b4300; }
.seg-opt.st-excused input:checked + span { background: #dce9fb; border-color: #3b6fc4; color: #1a3d7c; }
.seg-opt input:checked + span::before { content: '✓ '; white-space: pre; }

.score-row .score-inputs { display: grid; grid-template-columns: 6.5rem 1fr; gap: .5rem; }
.score-input { text-align: center; font-weight: 700; }

.sticky-save { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + .5rem); padding: .5rem 0; z-index: 10; }
@media (min-width: 760px) { .sticky-save { bottom: .5rem; } }
.sticky-save .btn { box-shadow: 0 4px 14px rgba(0,0,0,.18); }

.badge { display: inline-flex; align-items: center; gap: .25rem; padding: 0 .65rem; border-radius: 999px; background: #eceff1; font-size: .8rem; font-weight: 600; }
.badge.st-present { background: #d8f0e0; color: #14532d; }
.badge.st-absent { background: #fde0dc; color: #7a1a12; }
.badge.st-late { background: #fdf0cc; color: #6b4300; }
.badge.st-excused { background: #dce9fb; color: #1a3d7c; }

.danger-zone { border-color: #f1c4be; }
.danger-zone h2 { color: var(--danger); }

/* ---------- ورود ---------- */
.login-card { width: min(100%, 420px); text-align: center; padding: 1.5rem 1.25rem; }
.login-card .form { text-align: start; margin-top: 1rem; }
.login-logo { font-size: 2.5rem; }

@media (max-width: 420px) {
  .container { padding: .75rem; }
  .seg-opt span { font-size: .78rem; }
  .datepick { grid-template-columns: 1fr 1.8fr 1.3fr; }
  .brand span:last-child { font-size: 1rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .tabs a { transition: background-color .15s; }
}
@media print {
  .topbar, .nav, .sticky-save, .btn { display: none !important; }
  body { background: #fff; padding: 0; }
  .card { border: 0; }
}
