/* «🏫 Ranch» — Telegram theme colours (`--tg-theme-*`, set by telegram-web-app.js) with light/dark fallbacks for a
   plain browser (the Mac). Phone first: 360 px base, 16 px side padding, 12 px cards. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #0f1419);
  --hint: var(--tg-theme-hint-color, #8a9099);
  --subtle: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --accent-soft: rgba(36, 129, 204, .12);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: rgba(127, 127, 127, .16);
  --fill: rgba(127, 127, 127, .12);
  --ok: #2fa66a;
  --warn: #e09b00;
  --radius: 12px;
  --pad: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 2px 10px rgba(16, 24, 40, .04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --bg2: var(--tg-theme-secondary-bg-color, #0e1621);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --hint: var(--tg-theme-hint-color, #7d8b99);
    --link: var(--tg-theme-link-color, #62bcf9);
    --accent: var(--tg-theme-button-color, #5288c1);
    --accent-soft: rgba(98, 188, 249, .14);
    --seg-on: rgba(255, 255, 255, .13);
    --shadow: none;
    color-scheme: dark;
  }
}

/* Telegram's own scheme wins over the system's (set from `Telegram.WebApp.colorScheme`) */
html[data-scheme="dark"] {
  --accent-soft: rgba(98, 188, 249, .14); --seg-on: rgba(255, 255, 255, .13); --shadow: none; color-scheme: dark;
}
html[data-scheme="light"] {
  --accent-soft: rgba(36, 129, 204, .12);
  --seg-on: var(--section);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 2px 10px rgba(16, 24, 40, .04);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}

button, input { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
img { display: block; }

#app { max-width: 600px; margin: 0 auto; min-height: 100vh; }

/* ---------------------------------------------------------------- shell */

.boot { display: grid; place-items: center; min-height: 70vh; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--fill); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: 52px; padding: 0 8px;
  background: var(--bg2);
  border-bottom: 1px solid var(--sep);
}
.topbar .brand { font-weight: 600; font-size: 16px; }
.topbar .back {
  border: 0; background: none; color: var(--link); font-size: 16px;
  padding: 8px; border-radius: 10px; cursor: pointer;
}
.topbar .back:hover { background: var(--fill); }

.screen { padding: 12px var(--pad) 32px; animation: enter .22s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.head { padding: 8px 2px 14px; }
.head h1 { margin: 0; font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; }
.head .sub { margin-top: 4px; color: var(--hint); font-size: 14px; }

h2.label {
  margin: 22px 4px 8px; font-size: 13px; font-weight: 600; color: var(--hint);
  text-transform: uppercase; letter-spacing: .04em;
}

.card {
  background: var(--section); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 12px; }
.pad { padding: 14px var(--pad); }

/* ---------------------------------------------------------------- home */

.hello { padding: 10px 2px 16px; }
.hello h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.hello .sub { color: var(--hint); margin-top: 2px; }

.stats { display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); gap: 8px; margin-bottom: 16px; }
.stat {
  min-width: 0; padding: 12px 14px;
  background: var(--section); border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 22px; line-height: 1.1; font-weight: 700; }
.stat span { display: block; margin-top: 2px; font-size: 12px; color: var(--hint); }
.stat.warn b { color: var(--warn); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex; flex-direction: column; gap: 10px; min-height: 104px; padding: 14px;
  background: var(--section); border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--text); cursor: pointer; transition: transform .12s ease;
}
.tile:active { transform: scale(.97); }
.tile .icon {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  font-size: 21px; background: var(--accent-soft);
}
.tile .name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.tile .meta { font-size: 12px; color: var(--hint); margin-top: -6px; }
.tile.wide { grid-column: span 2; flex-direction: row; align-items: center; min-height: 0; }
.tile.wide .meta { margin-top: 0; }

.foot { margin-top: 22px; text-align: center; color: var(--hint); font-size: 13px; }

/* ---------------------------------------------------------------- lists */

.list { background: var(--section); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px var(--pad);
  color: var(--text); position: relative; cursor: pointer; background: none; border: 0; width: 100%; text-align: left;
}
.row + .row::before, .kv + .kv::before, .phone + .phone::before, .parent .phone::before, .pinrow::before,
.lesson + .lesson::before, .check + .check::before {
  content: ""; position: absolute; top: 0; right: 0; left: var(--pad); border-top: 1px solid var(--sep);
}
.row + .row::before { left: 64px; }
.row.plain + .row.plain::before { left: var(--pad); }
.lesson + .lesson::before { left: 58px; }
.row:active { background: var(--fill); }
.row .body { flex: 1; min-width: 0; }
.row .title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .chev { color: var(--hint); opacity: .6; font-size: 18px; }
.row.static { cursor: default; }
.row.static:active { background: none; }
.row.selected { background: var(--accent-soft); }

.kv { display: flex; justify-content: space-between; gap: 16px; padding: 12px var(--pad); position: relative; }
.kv .k { color: var(--hint); }
.kv .v { text-align: right; font-weight: 500; word-break: break-word; }

/* ---------------------------------------------------------------- avatars */

.avatar {
  flex: 0 0 auto; position: relative; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; color: #fff; font-weight: 600; letter-spacing: .02em;
  background: linear-gradient(160deg, var(--a1, #72d5fd), var(--a2, #2a9ef1));
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ---------------------------------------------------------------- classes */

.classes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.klass {
  display: flex; flex-direction: column; gap: 4px; padding: 12px; min-height: 96px;
  background: var(--section); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text);
  cursor: pointer; transition: transform .12s ease;
}
.klass:active { transform: scale(.97); }
.klass .lbl { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.klass .who {
  font-size: 12px; color: var(--hint); line-height: 1.25; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.klass .num { margin-top: auto; font-size: 12px; color: var(--subtle); }
.bar { height: 4px; border-radius: 2px; background: var(--fill); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 2px; }

.picks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pick {
  display: grid; place-items: center; height: 48px; border-radius: 10px; background: var(--section);
  box-shadow: var(--shadow); color: var(--text); font-weight: 700; font-size: 16px;
}
.pick:active { transform: scale(.96); }
.caption { display: flex; align-items: center; gap: 10px; margin: 2px 2px 12px; font-size: 17px; font-weight: 600; }

/* ---------------------------------------------------------------- class: photo grid */

.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 8px; padding-top: 4px; }
.pupil {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  color: var(--text); cursor: pointer; min-width: 0;
}
.pupil:active .avatar { transform: scale(.95); }
.pupil .avatar { transition: transform .12s ease; box-shadow: var(--shadow); }
.pupil .nm { font-size: 13px; line-height: 1.2; max-width: 100%; overflow-wrap: anywhere; }
.pupil .nm small { display: block; color: var(--hint); font-size: 12px; }

/* ---------------------------------------------------------------- controls */

.seg {
  display: flex; gap: 2px; padding: 2px; margin-bottom: 14px;
  background: var(--fill); border-radius: 10px;
}
.seg button {
  flex: 1 1 auto; border: 0; background: none; padding: 7px 8px; border-radius: 8px;
  font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.seg button.on {
  background: var(--seg-on, var(--section)); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 600;
}

.search {
  position: relative; display: flex; align-items: center; height: 40px; padding: 0 12px 0 36px; margin-bottom: 14px;
  background: var(--fill); border-radius: 10px;
}
.search::before {
  content: ""; position: absolute; left: 13px; top: 12px; width: 10px; height: 10px;
  border: 2px solid var(--hint); border-radius: 50%;
}
.search::after {
  content: ""; position: absolute; left: 24px; top: 25px; width: 6px; height: 2px; border-radius: 1px;
  background: var(--hint); transform: rotate(45deg);
}
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; }
.search input::placeholder { color: var(--hint); }

.input {
  width: 100%; height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--sep);
  background: var(--bg); font-size: 17px; letter-spacing: .06em; outline: 0;
}
.input:focus { border-color: var(--accent); }
.input.bad { border-color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 18px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 15px;
  transition: opacity .15s ease, transform .1s ease;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.block { display: flex; width: 100%; }
.btn.soft { background: var(--accent-soft); color: var(--link); }
.btn.ghost { background: none; color: var(--link); padding: 0 8px; height: 36px; }
.btn.small { height: 32px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
.btn.danger { background: none; color: var(--danger); }
.btns { display: flex; gap: 10px; margin-top: 14px; }
.btns.sticky {
  position: sticky; bottom: 0; z-index: 5; margin: 14px calc(var(--pad) * -1) 0;
  padding: 10px var(--pad) calc(10px + env(safe-area-inset-bottom)); background: var(--bg2);
  border-top: 1px solid var(--sep);
}
.btns .btn { flex: 1; }

.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 12px;
  background: var(--fill); font-size: 12px; font-weight: 600; color: var(--subtle); white-space: nowrap;
}
.chip.ok { background: rgba(47, 166, 106, .14); color: var(--ok); }
.chip.warn { background: rgba(224, 155, 0, .16); color: var(--warn); }
.chip.bad { background: rgba(229, 72, 77, .13); color: var(--danger); }
.chip.accent { background: var(--accent-soft); color: var(--link); }

/* ---------------------------------------------------------------- student card */

.profile { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 6px 0 16px; }
.profile .avatar { box-shadow: 0 6px 24px rgba(0, 0, 0, .12); }
.profile h1 { margin: 14px 0 6px; font-size: 21px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
.profile .chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.profile .curator { margin-top: 8px; font-size: 13px; color: var(--hint); }
.profile .btn { margin-top: 10px; }

.parent { position: relative; }
.parent .who { font-weight: 600; }
.parent .rel { font-size: 13px; color: var(--hint); }
.phone { display: flex; align-items: center; gap: 12px; padding: 10px var(--pad); position: relative; }
.phone .num { flex: 1; font-size: 16px; font-variant-numeric: tabular-nums; }
.phone .num small { display: block; font-size: 12px; color: var(--hint); }
.pinrow { display: flex; align-items: center; gap: 8px; padding: 8px var(--pad) 10px; position: relative; }
.pinrow .body { flex: 1; min-width: 0; }
.pinrow small { display: block; font-size: 12px; color: var(--hint); }
.pinrow .acts { display: flex; gap: 2px; }
.pinfl {
  font-variant-numeric: tabular-nums; letter-spacing: .06em; font-weight: 600; font-size: 16px; white-space: nowrap;
}
.pinfl.hidden { color: var(--hint); letter-spacing: .02em; }
.pinfl-form { padding: 0 var(--pad) 14px; }
.pinfl-form .hint { font-size: 12px; color: var(--hint); margin-top: 6px; }
.pinfl-form .hint.bad { color: var(--danger); }

.secure { position: relative; }
.watermark {
  position: absolute; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; user-select: none;
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 34px 26px; padding: 10px;
  transform: rotate(-24deg) scale(1.4); opacity: .085; font-size: 13px; font-weight: 700; color: var(--text);
}
.watermark span { white-space: nowrap; }

/* ---------------------------------------------------------------- timetable */

.week { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.week .range { font-weight: 600; font-variant-numeric: tabular-nums; }
.week .nav {
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--fill); cursor: pointer;
  font-size: 18px; color: var(--text);
}
.days { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 14px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 0;
  border: 0; border-radius: 10px; background: var(--section); box-shadow: var(--shadow); cursor: pointer;
}
.day small { font-size: 11px; color: var(--hint); text-transform: uppercase; }
.day b { font-size: 16px; font-variant-numeric: tabular-nums; }
.day.today b { color: var(--link); }
.day.off { opacity: .5; }
.day.on { background: var(--accent); color: var(--accent-text); }
.day.on small, .day.on b { color: var(--accent-text); }

.lesson { display: flex; gap: 12px; padding: 12px var(--pad); position: relative; align-items: flex-start; }
.lesson .no {
  flex: 0 0 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--link); font-weight: 700; font-size: 14px;
}
.lesson .body { flex: 1; min-width: 0; }
.lesson .subj { font-weight: 600; }
.lesson .meta { font-size: 13px; color: var(--hint); margin-top: 1px; }
.lesson .meta a { color: var(--link); }
.lesson .time { font-size: 13px; color: var(--subtle); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lesson.now { background: var(--accent-soft); }

/* ---------------------------------------------------------------- imports and the picker */

.kinds .row .icon {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  font-size: 21px; background: var(--accent-soft);
}
.counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.counts .stat { min-width: 0; }
.progress { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; margin: 14px 0 6px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }
.lines { margin: 0; padding: 10px var(--pad) 12px 34px; font-size: 14px; }
.lines li + li { margin-top: 4px; }
.check { display: flex; align-items: center; gap: 10px; padding: 12px var(--pad); cursor: pointer; position: relative; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.check span { flex: 1; }

.picker { display: grid; grid-template-columns: 2fr 3fr; gap: 10px; align-items: start; }
.picker h3 {
  margin: 0 2px 8px; font-size: 13px; color: var(--hint); font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
}
.shots { display: grid; gap: 8px; }
.shot {
  position: relative; border: 0; padding: 0; border-radius: var(--radius); overflow: hidden; cursor: pointer;
  background: var(--fill); aspect-ratio: 3 / 4; box-shadow: var(--shadow); outline: 3px solid transparent;
  outline-offset: -3px; transition: outline-color .15s ease;
}
.shot img { width: 100%; height: 100%; object-fit: cover; }
.shot span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 5px;
  font-size: 11px; color: #fff; text-align: left; background: linear-gradient(transparent, rgba(0, 0, 0, .65));
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.shot.on { outline-color: var(--accent); }
.picker .search { margin-bottom: 8px; }
.picker .row { min-height: 48px; gap: 10px; padding: 6px 10px; }
.picker .row + .row::before { left: 52px; }

/* ---------------------------------------------------------------- states */

.skel { background: var(--fill); border-radius: 8px; position: relative; overflow: hidden; }
.skel::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .28), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.skel.circle { border-radius: 50%; }
.skel-line { height: 12px; margin: 6px 0; }

.empty { text-align: center; padding: 40px 24px; color: var(--hint); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.notice {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 12px;
  background: var(--accent-soft); font-size: 14px; line-height: 1.35;
}
.notice.bad { background: rgba(229, 72, 77, .1); }
.notice.warn { background: rgba(224, 155, 0, .12); }
.fail { text-align: center; padding: 48px 24px; }
.fail .big { font-size: 40px; }
.fail p { color: var(--hint); margin: 10px 0 18px; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px; background: rgba(28, 28, 30, .92); color: #fff; font-size: 14px;
  transition: opacity .2s ease, transform .2s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.sheet-bg {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .38);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease-out;
}
.sheet {
  width: 100%; max-width: 600px; max-height: 86vh; overflow-y: auto;
  padding: 8px var(--pad) calc(20px + env(safe-area-inset-bottom));
  background: var(--bg2); border-radius: 16px 16px 0 0; animation: rise .22s ease-out;
}
.sheet .grip { width: 36px; height: 5px; border-radius: 3px; background: var(--fill); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 19px; }
.sheet .sub { color: var(--hint); margin-bottom: 12px; font-size: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: .6; } }

.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login .big { font-size: 44px; }
.login p { color: var(--hint); }
.login .input { text-align: center; font-size: 24px; letter-spacing: .3em; margin: 8px 0 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (min-width: 520px) {
  .classes { grid-template-columns: repeat(4, 1fr); }
  .photos { grid-template-columns: repeat(4, 1fr); }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .tile.wide { grid-column: span 3; }
}
