:root {
  /* Фолбэки на случай, если приложение открыли не в Telegram —
     сами переменные --tg-* дальше переопределяются из telegram.js
     значениями реальной темы пользователя */
  --tg-bg: #f2f2f7;
  --tg-text: #111111;
  --tg-hint: #8e8e93;
  --tg-link: #007aff;
  --tg-button: #007aff;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #ffffff;
  --tg-accent-soft: rgba(0, 122, 255, 0.14);
  --tg-accent-soft-strong: rgba(0, 122, 255, 0.22);

  --radius: 18px;
  --radius-sm: 12px;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px rgba(0, 0, 0, 0.05);
  --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.16);
}

[data-scheme='dark'] {
  --tg-bg: #000000;
  --tg-secondary-bg: #1c1c1e;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  overscroll-behavior-y: none;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: 90px; /* место под нижнюю навигацию */
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

#app {
  max-width: 560px;
  margin: 0 auto;
}

#page-content {
  padding: 18px 16px 28px;
  animation: page-in 0.22s ease;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1,
h2,
h3 {
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 23px;
  font-weight: 800;
}

h2 {
  font-size: 17px;
  font-weight: 700;
}

p {
  margin: 0 0 8px;
}

.hint {
  color: var(--tg-hint);
  font-size: 13px;
}

/* ---------- Карточки ---------- */

.card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 16px 17px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-card);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.card[onclick] {
  cursor: pointer;
}

.card[onclick]:active {
  transform: scale(0.985);
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.lesson-card {
  position: relative;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 15px 16px 15px 20px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.lesson-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--tg-link);
  border-radius: 0 4px 4px 0;
}

.lesson-time {
  font-weight: 800;
  font-size: 15px;
  color: var(--tg-link);
  margin-bottom: 5px;
  letter-spacing: -0.01em;
}

.lesson-subject {
  font-weight: 700;
  font-size: 16.5px;
  margin-bottom: 7px;
  letter-spacing: -0.01em;
}

.lesson-meta {
  color: var(--tg-hint);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px 14px;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  background: var(--tg-accent-soft);
  color: var(--tg-link);
}

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font-size: 15.5px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 46px; /* крупная зона нажатия */
  transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}

.btn-primary {
  background: var(--tg-button);
  color: var(--tg-button-text);
  width: 100%;
  box-shadow: 0 4px 14px var(--tg-accent-soft-strong);
}

.btn-primary:active {
  transform: scale(0.98);
  opacity: 0.92;
}

.btn-secondary {
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border: 1.5px solid rgba(128, 128, 128, 0.22);
}

.btn-secondary:active {
  transform: scale(0.98);
  background: var(--tg-accent-soft);
}

.btn-danger {
  background: rgba(255, 59, 48, 0.12);
  color: var(--red);
}

.btn-danger:active {
  transform: scale(0.98);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 9px 14px;
  font-size: 13px;
  min-height: 38px;
}

.btn-fab {
  position: fixed;
  right: 20px;
  bottom: 100px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--tg-button);
  color: var(--tg-button-text);
  font-size: 28px;
  font-weight: 400;
  border: none;
  box-shadow: var(--shadow-float), 0 0 0 6px var(--tg-accent-soft);
  z-index: 50;
  transition: transform 0.15s ease;
}

.btn-fab:active {
  transform: scale(0.92);
}

/* ---------- Нижняя навигация ---------- */

.nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--tg-secondary-bg);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.08);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0));
  z-index: 40;
}

[data-scheme='dark'] .nav-bar {
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 2px;
  background: none;
  border: none;
  border-radius: 16px;
  color: var(--tg-hint);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
}

.nav-item:active {
  transform: scale(0.92);
}

.nav-item .icon {
  font-size: 22px;
  line-height: 1;
  transition: transform 0.18s ease;
}

.nav-item.active {
  color: var(--tg-link);
  background: var(--tg-accent-soft);
}

.nav-item.active .icon {
  transform: translateY(-1px) scale(1.08);
}

/* ---------- Переключатель дней ---------- */

.day-switcher {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 4px 6px;
  margin: 0 -4px 16px;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
}

.day-tab {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
  border-radius: 9px;
  background: transparent;
  color: var(--tg-text);
  border: none;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.day-tab:active {
  transform: scale(0.94);
}

.day-tab.active {
  background: var(--tg-button);
  color: var(--tg-button-text);
  box-shadow: 0 2px 8px var(--tg-accent-soft-strong);
}

/* ---------- Табы (Активные/Выполненные и т.п.) ---------- */

.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  padding: 4px;
  box-shadow: var(--shadow-card);
}

.tab-bar .tab {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 9px;
  background: transparent;
  border: none;
  color: var(--tg-hint);
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.tab-bar .tab:active {
  transform: scale(0.96);
}

.tab-bar .tab.active {
  background: var(--tg-button);
  color: var(--tg-button-text);
  box-shadow: 0 2px 8px var(--tg-accent-soft-strong);
}

/* ---------- Формы ---------- */

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--tg-hint);
  margin-bottom: 6px;
  font-weight: 700;
}

input[type='text'],
input[type='date'],
input[type='time'],
input[type='datetime-local'],
textarea,
select {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(128, 128, 128, 0.25);
  background: var(--tg-bg);
  color: var(--tg-text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--tg-link);
  box-shadow: 0 0 0 3px var(--tg-accent-soft);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

.select-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.select-grid button,
.choice-list button {
  padding: 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(128, 128, 128, 0.22);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.select-grid button:active,
.choice-list button:active {
  transform: scale(0.97);
}

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.select-grid button.selected,
.choice-list button.selected {
  background: var(--tg-button);
  color: var(--tg-button-text);
  border-color: transparent;
  box-shadow: 0 2px 10px var(--tg-accent-soft-strong);
}

/* ---------- Progress bar статистики ---------- */

.progress-ring-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0 4px;
}

.progress-bar-track {
  width: 100%;
  height: 12px;
  border-radius: 10px;
  background: rgba(128, 128, 128, 0.16);
  overflow: hidden;
  margin: 12px 0;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--green), #30d158);
  transition: width 0.5s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: center;
  margin-top: 10px;
}

.stats-grid .stat-value {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.stats-grid .stat-label {
  font-size: 11px;
  color: var(--tg-hint);
  font-weight: 600;
}

/* ---------- Пустые состояния / загрузка ---------- */

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--tg-hint);
}

.empty-state .emoji {
  font-size: 42px;
  display: block;
  margin-bottom: 12px;
}

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(128, 128, 128, 0.13) 25%,
    rgba(128, 128, 128, 0.24) 37%,
    rgba(128, 128, 128, 0.13) 63%
  );
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius);
  height: 78px;
  margin-bottom: 10px;
}

@keyframes skeleton-loading {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* ---------- Модалка (форма добавления) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  animation: overlay-in 0.18s ease;
}

@keyframes overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-sheet {
  background: var(--tg-bg);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 24px 24px 0 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom, 0));
  animation: sheet-up 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
}

.modal-sheet::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 4px;
  background: rgba(128, 128, 128, 0.35);
  margin: 4px auto 14px;
}

@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-close {
  background: rgba(128, 128, 128, 0.14);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 16px;
  color: var(--tg-hint);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* ---------- Тосты ---------- */

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  padding: 11px 20px;
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.22s cubic-bezier(0.34, 1.4, 0.64, 1);
  max-width: 85vw;
  text-align: center;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

/* ---------- Шапка страницы ---------- */

.page-header {
  margin-bottom: 18px;
}

.section-title {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--tg-hint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 20px 0 9px;
}

.section-title:first-child {
  margin-top: 0;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid rgba(128, 128, 128, 0.13);
}

.list-item:last-child {
  border-bottom: none;
}

.icon-btn {
  background: rgba(128, 128, 128, 0.12);
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--tg-hint);
  padding: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background-color 0.15s ease;
  flex-shrink: 0;
}

.icon-btn:active {
  transform: scale(0.9);
  background: rgba(255, 59, 48, 0.15);
}

a {
  color: var(--tg-link);
}
