/* ============================================================
   Журнал репетитора — стили
   Принцип: спокойный нейтральный фон, белые карточки, один акцентный
   цвет, оценки — мягкой подложкой с цветной цифрой (так 3 на жёлтом
   читается не хуже, чем 5 на зелёном).
   ============================================================ */

/* ---------- Токены ----------
   --fb-* — собственная палитра для обычного браузера (светлая и тёмная).
   Внутри Telegram вместо неё берутся --tg-theme-*: приложение красится
   в тему пользователя Telegram. */
:root {
  color-scheme: light dark;

  --fb-bg: #ffffff;          /* карточки */
  --fb-bg2: #f2f3f7;         /* фон страницы, поля ввода */
  --fb-text: #16181d;
  --fb-hint: #7d828c;
  --fb-accent: #3b63e0;
  --fb-accent-text: #ffffff;
  --fb-danger: #d93a3a;
  --line: rgba(20, 24, 33, .07);
  --shadow: 0 1px 2px rgba(20, 24, 33, .04), 0 6px 20px rgba(20, 24, 33, .05);

  /* Оценки: насыщенный цвет — для цифры, подложка — он же на 14% */
  --g1: #d63b3b;
  --g2: #e0631c;
  --g3: #b97a0b;
  --g4: #3f9b4f;
  --g5: #1d8a5f;
  --tint: 14%;

  --seg-active: #ffffff;   /* выбранная вкладка переключателя */

  /* Пастельные плитки на главной ученика: фон и цвет текста */
  --tile-mint: #dcf3ec;   --tile-mint-text: #135e48;
  --tile-peach: #fde6dc;  --tile-peach-text: #8a3b1d;
  --tile-lilac: #e4e5f6;  --tile-lilac-text: #333a86;
  --tile-sand: #fbf0d6;   --tile-sand-text: #7a5a10;

  --radius: 16px;
  --radius-sm: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #1c1d21;
    --fb-bg2: #111214;
    --fb-text: #eceef2;
    --fb-hint: #8d929c;
    --fb-accent: #6d8cf5;
    --fb-danger: #f06464;
    --line: rgba(255, 255, 255, .07);
    --shadow: none;
    --seg-active: #3b3d44;
    --tile-mint: #183a31;   --tile-mint-text: #a6e8d2;
    --tile-peach: #42271d;  --tile-peach-text: #f8c4ad;
    --tile-lilac: #282a4a;  --tile-lilac-text: #c3c7f5;
    --tile-sand: #3d3219;   --tile-sand-text: #f0d698;
    --g1: #f07171;
    --g2: #f5904f;
    --g3: #e9b949;
    --g4: #6cc47b;
    --g5: #4cc493;
    --tint: 20%;
  }
}

:root {
  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --bg2: var(--tg-theme-secondary-bg-color, var(--fb-bg2));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --btn: var(--tg-theme-button-color, var(--fb-accent));
  --btn-text: var(--tg-theme-button-text-color, var(--fb-accent-text));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --accent-soft: color-mix(in srgb, var(--btn) 12%, transparent);
}

/* ---------- Основа ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Атрибут hidden должен прятать всегда. Без этого правила display: flex у .row
   и других классов перебивает hidden, и спрятанный элемент остаётся на экране. */
[hidden] { display: none !important; }

/* Сдвиг экрана при переходе не должен давать горизонтальную прокрутку */
html { overflow-x: clip; }

body {
  margin: 0 auto;
  max-width: 560px;          /* на компьютере не растягиваемся на весь экран */
  padding: 20px 16px calc(40px + env(safe-area-inset-bottom));
  background: var(--bg2);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1 {
  font-size: 30px; line-height: 1.15; font-weight: 700; letter-spacing: -.02em;
  margin: 4px 0 6px; word-break: break-word;
}
h2 {
  font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--hint); margin: 28px 4px 8px;
}

.hint { color: var(--hint); margin: 0 0 16px; }
.center { text-align: center; }
.small { font-size: 13px; }

/* ---------- Поля и кнопки ---------- */
input, button { font: inherit; color: inherit; border: 0; border-radius: var(--radius-sm); }

input, textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  background: var(--bg2);
  color: var(--text);
  outline: none;
  transition: box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--hint); opacity: .85; }
input:focus, textarea:focus { box-shadow: 0 0 0 2px var(--btn); }
textarea { font: inherit; border: 0; border-radius: var(--radius-sm); resize: vertical; min-height: 80px; line-height: 1.4; }
input[type="date"] { min-height: 44px; }

button {
  min-height: 48px;
  padding: 12px 18px;
  background: var(--btn);
  color: var(--btn-text);
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
button:active { opacity: .75; transform: scale(.98); }
button:disabled { opacity: .4; }

.secondary { background: var(--accent-soft); color: var(--btn); }

.link-btn,
.back-btn,
.icon-btn,
.danger-link { background: none; min-height: 0; }
.link-btn { color: var(--btn); padding: 6px 2px; font-size: 16px; font-weight: 500; }
/* margin-top 6px: кнопка на 22px от верха, чтобы не попадать под размытую
   полосу у верхнего края экрана iPhone (Safari размывает её при прокрутке) */
.back-btn { color: var(--btn); padding: 4px 0; margin: 2px 0 10px; font-size: 17px; font-weight: 500; }
.icon-btn { color: var(--hint); padding: 8px; font-size: 15px; opacity: .7; }
.danger-link { display: block; margin: 28px auto 0; padding: 10px; color: var(--danger); font-weight: 500; }

/* ---------- Раскладка ---------- */
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.grow { flex: 1; min-width: 0; }

.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.title-row h1 { margin: 0; }

.card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

/* ---------- Списки ---------- */
.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--bg); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.list:empty { display: none; }
.list li {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px;
  padding: 10px 14px;
  position: relative;
}
/* Разделитель — с отступом слева, как в системных списках iOS */
.list li + li::before {
  content: ''; position: absolute; top: 0; left: 14px; right: 0;
  border-top: 1px solid var(--line);
}
.list li.clickable { cursor: pointer; transition: background .15s; }
.list li.clickable:active { background: var(--bg2); }
.list li.clickable::after { content: '›'; color: var(--hint); font-size: 22px; line-height: 1; opacity: .6; }

.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--hint); font-size: 13px; margin-top: 1px; }

/* ---------- Оценки ---------- */
/* Кружок с оценкой: мягкая подложка + цветная цифра */
.badge {
  flex: none;
  min-width: 40px; height: 40px; padding: 0 9px;
  border-radius: 20px;
  display: grid; place-items: center;
  font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--g, var(--hint));
  background: color-mix(in srgb, var(--g, var(--hint)) var(--tint), transparent);
}
/* Цвет по оценке. Без data-g (нет оценок) — серый, запасное значение в var(--g, …) */
[data-g="1"] { --g: var(--g1); }
[data-g="2"] { --g: var(--g2); }
[data-g="3"] { --g: var(--g3); }
[data-g="4"] { --g: var(--g4); }
[data-g="5"] { --g: var(--g5); }

/* Кнопки 1–5: тот же приём, цифра крупная */
.grades-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
.grades-row button {
  min-height: 56px; padding: 0;
  font-size: 22px; font-weight: 700;
  color: var(--g);
  background: color-mix(in srgb, var(--g) var(--tint), transparent);
}
.grades-row [data-v="1"] { --g: var(--g1); }
.grades-row [data-v="2"] { --g: var(--g2); }
.grades-row [data-v="3"] { --g: var(--g3); }
.grades-row [data-v="4"] { --g: var(--g4); }
.grades-row [data-v="5"] { --g: var(--g5); }
.grade-card .hint { margin: 10px 0 0; }

/* ---------- Всплывающее сообщение ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(22, 24, 29, .92); color: #fff;
  padding: 11px 18px; border-radius: 999px;
  font-size: 15px; font-weight: 500; white-space: nowrap;
  max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Экран входа ---------- */
.login { max-width: 380px; margin: 9vh auto 0; text-align: center; }
.login-icon {
  width: 72px; height: 72px; margin: 0 auto 16px;
  display: grid; place-items: center;
  font-size: 38px; border-radius: 20px;
  background: var(--bg); box-shadow: var(--shadow);
}
.login h1 { font-size: 28px; }
.login .hint { margin: 12px 0 0; min-height: 1.45em; }
.login-card { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 14px; text-align: left; }
.login-error { color: var(--danger); font-size: 14px; margin: 0 2px; }

/* Переключатель «Репетитор / Ученик» */
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
  padding: 3px; margin: 22px 0 0;
  background: color-mix(in srgb, var(--hint) 16%, transparent);
  border-radius: var(--radius-sm);
}
.segmented button {
  min-height: 38px; padding: 6px;
  background: none; color: var(--text);
  border-radius: 9px; font-size: 15px; font-weight: 500;
  transform: none;
}
.segmented button[aria-selected="true"] {
  background: var(--seg-active); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

/* ---------- Добавление ученика ---------- */
.add-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

/* ---------- Карточка ученика ---------- */
#student-stats { margin-bottom: 18px; }

/* Только что выданные логин и пароль */
.credentials { margin-bottom: 14px; background: var(--accent-soft); box-shadow: none; }
.credentials-title { font-weight: 600; margin-bottom: 10px; }
.credentials dl {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 14px;
  margin: 0 0 12px; padding: 12px 14px;
  background: var(--bg); border-radius: var(--radius-sm);
}
.credentials dt { color: var(--hint); }
.credentials dd { margin: 0; font: 600 17px/1.45 ui-monospace, "SF Mono", Menlo, monospace; word-break: break-all; }
.credentials button { width: 100%; }
.credentials .hint { margin: 10px 2px 0; }

.access .row { align-items: center; }
.access-row b { font-weight: 600; }

/* ---------- Экран ученика ---------- */
#me-hello { margin-bottom: 16px; }
.me-summary { display: flex; align-items: center; gap: 16px; padding: 18px; }
.me-avg {
  width: 68px; height: 68px; flex: none;
  border-radius: 50%; display: grid; place-items: center;
  font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--g, var(--hint));
  background: color-mix(in srgb, var(--g, var(--hint)) var(--tint), transparent);
}
.me-avg-label { font-weight: 600; font-size: 17px; }

/* ---------- Главная ученика ---------- */
.home-top { display: flex; justify-content: flex-end; min-height: 32px; }
.home-hello { font-size: 32px; margin: 6px 0 10px; }

/* Цитата под приветствием: спокойная, без кавычек-украшений */
.quote { margin: 0 0 24px; }
.quote blockquote { margin: 0; font-size: 17px; line-height: 1.4; color: var(--hint); }
.quote figcaption { margin-top: 4px; font-size: 13px; color: var(--hint); opacity: .8; }
.quote figcaption:empty { display: none; }
.quote figcaption::before { content: '— '; }

/* Плитки-разделы: 2 в ряд, эмодзи — как иллюстрация, срезанная краем */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  --tile-bg: var(--tile-mint); --tile-text: var(--tile-mint-text);
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  min-height: 168px; padding: 16px;
  border-radius: 20px;
  background: var(--tile-bg); color: var(--tile-text);
  text-align: left; font-weight: 400;
}
button.tile { cursor: pointer; }
.tile-mint  { --tile-bg: var(--tile-mint);  --tile-text: var(--tile-mint-text); }
.tile-peach { --tile-bg: var(--tile-peach); --tile-text: var(--tile-peach-text); }
.tile-lilac { --tile-bg: var(--tile-lilac); --tile-text: var(--tile-lilac-text); }
.tile-sand  { --tile-bg: var(--tile-sand);  --tile-text: var(--tile-sand-text); }
.tile-title { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.tile-info { font-size: 13px; line-height: 1.45; opacity: .85; position: relative; z-index: 1; }
.tile-info b { font-weight: 700; }
.tile-emoji {
  position: absolute; right: -10px; bottom: -14px;
  font-size: 76px; line-height: 1;
  transform: rotate(-12deg);
  opacity: .9; pointer-events: none;
}
/* Подсказка «можно нажать» — внизу слева, эмодзи занимает правый угол */
.tile-more { margin-top: auto; padding-top: 8px; font-size: 13px; font-weight: 600; position: relative; z-index: 1; }

#screen-my-grades h1 { margin-bottom: 16px; }

/* ---------- Домашние задания ---------- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 28px 4px 8px; }
.section-head h2 { margin: 0; }

.task-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.task-form .row { align-items: stretch; }
.field-row { display: flex; align-items: center; gap: 12px; }
.field-row span { color: var(--hint); flex: none; }
.field-row input { flex: 1; }

/* Кнопка выбора фото: <label> с <input type=file> внутри, выглядит как кнопка */
.file-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 16px; border-radius: var(--radius-sm);
  font-weight: 600; cursor: pointer; flex: none;
}
.file-btn:active { opacity: .75; }

.task-text { margin: 0; white-space: pre-wrap; word-break: break-word; }
.task-text:empty { display: none; }
.eyebrow { color: var(--hint); font-size: 15px; margin: 0; }

/* Статус задания: строка из «таблеток» */
.status-line { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 16px; }
.status-line:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--hint) 14%, transparent); color: var(--hint);
}
.chip-accent { background: var(--accent-soft); color: var(--btn); }
.chip-danger { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
.chip-ok { background: color-mix(in srgb, var(--g5) var(--tint), transparent); color: var(--g5); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--btn); flex: none; }
.hw { margin-top: 2px; }

/* Фото: сетка квадратных превью, ✕ — удалить своё */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.task-form .photo-grid { margin-top: 0; }
.photo {
  position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  background: var(--bg2); cursor: zoom-in;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-del {
  position: absolute; top: 4px; right: 4px;
  width: 28px; height: 28px; min-height: 0; padding: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 14px; line-height: 28px;
}
.photo.uploading img { opacity: .4; }

.review-card { display: flex; align-items: flex-start; gap: 12px; }

/* Фото на весь экран */
.lightbox {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, .9); cursor: zoom-out;
  animation: fade-in .15s ease-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
@keyframes fade-in { from { opacity: 0; } }

/* Карточка «Включить уведомления» на главной ученика */
.push-card { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.push-title { font-weight: 600; }
.push-card button { min-height: 40px; padding: 8px 14px; flex: none; }

/* Счётчик новых на плитке */
.tile-badge {
  position: absolute; top: 14px; right: 14px;
  min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--tile-text); color: var(--tile-bg);
  font-size: 13px; font-weight: 700;
}

/* ---------- Переходы между экранами ----------
   Анимируем только появляющийся экран: лёгкий сдвиг + проявление.
   Сдвиг 14px меньше бокового отступа страницы (16px) — горизонтальной прокрутки не будет.
   Направление выбирает show() в app.js по «глубине» экрана. */
.enter-forward { animation: enter-forward .22s cubic-bezier(.2, .8, .2, 1); }
.enter-back    { animation: enter-back .22s cubic-bezier(.2, .8, .2, 1); }
.enter-fade    { animation: enter-fade .2s ease-out; }
@keyframes enter-forward { from { opacity: 0; transform: translateX(14px); } }
@keyframes enter-back    { from { opacity: 0; transform: translateX(-14px); } }
@keyframes enter-fade    { from { opacity: 0; } }

/* «Уменьшение движения» в настройках — никаких анимаций */
@media (prefers-reduced-motion: reduce) {
  .enter-forward, .enter-back, .enter-fade, .lightbox, #toast { animation: none; }
}


/* ---------- Типы оценок ---------- */
.title-actions { display: flex; gap: 14px; align-items: baseline; }

/* Выбор типа перед баллом: «таблетки», выбранная — акцентная */
.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.cat-chip {
  min-height: 34px; padding: 6px 12px; border-radius: 999px;
  background: var(--bg2); color: var(--text);
  font-size: 14px; font-weight: 500;
}
.cat-chip[aria-checked="true"] { background: var(--btn); color: var(--btn-text); font-weight: 600; }
.cat-chip-add { background: none; color: var(--btn); padding-inline: 8px; }

/* Средние по типам под именем ученика */
.cat-stats { display: flex; flex-wrap: wrap; gap: 6px; margin: -8px 0 18px; }
.cat-stats:empty { display: none; }

/* Ученик: карточки по типам — 2 в ряд, нажатие фильтрует историю */
.cat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cat-card {
  display: grid; grid-template-columns: 1fr auto; row-gap: 2px; align-items: center;
  text-align: left; padding: 12px 14px; border-radius: var(--radius);
  background: var(--bg); color: var(--text); box-shadow: var(--shadow);
  font-weight: 400;
}
.cat-card[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--btn); }
/* Сверху эмодзи и средний балл, ниже — название целиком и количество */
.cat-card-emoji { font-size: 26px; line-height: 1; }
.cat-card .badge { min-width: 38px; height: 38px; font-size: 15px; }
.cat-card-name { grid-column: 1 / -1; margin-top: 8px; font-weight: 600; font-size: 15px; line-height: 1.25; }
.cat-card-count { grid-column: 1 / -1; color: var(--hint); font-size: 12px; }

/* Экран «Типы оценок» */
.cat-emoji { min-height: 0; width: 40px; height: 40px; padding: 0; border-radius: 12px; background: var(--bg2); font-size: 20px; }
.category-form { align-items: center; }
.emoji-input { flex: none !important; width: 56px; text-align: center; font-size: 20px; padding-inline: 4px; }
