/* Тема берётся из Telegram (CSS-переменные Telegram.WebApp), с фолбэками */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --danger: #e0504f;
  --success: #31a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 12px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.muted { color: var(--hint); font-size: 14px; }

.header h1 { margin: 4px 0; font-size: 22px; }
h1 { font-size: 22px; margin: 8px 0; }
h2 { font-size: 15px; color: var(--hint); margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: 0.04em; }

.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }

.card {
  background: var(--secondary-bg);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
}
.card:active { opacity: 0.75; }

.card .title { font-weight: 600; margin-bottom: 2px; }
.card .sub { font-size: 14px; color: var(--hint); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 6px;
}
.badge.paid { background: var(--success); color: #fff; }
.badge.unpaid { background: var(--danger); color: #fff; }

.summary {
  background: var(--secondary-bg);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  line-height: 1.5;
}

button {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin: 6px 0;
  background: var(--secondary-bg);
  color: var(--text);
}
button.primary { background: var(--button); color: var(--button-text); }
button.success { background: var(--success); color: #fff; }
button.danger { background: var(--danger); color: #fff; }
button.lesson-toggle { font-size: 14px; padding: 8px; margin: 0; border-radius: 9px; }
button.mark-paid { background: var(--success); color: #fff; }
button.mark-unpaid { background: transparent; color: var(--hint); border: 1px solid var(--hint); }

.row-buttons { display: flex; gap: 8px; }
.row-buttons button { flex: 1; }

.lesson-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.lesson-row .info { flex: 1; }
.lesson-row .date { font-weight: 600; }
.lesson-toggle { width: auto; min-width: 96px; }

/* Календарь */
.calendar { background: var(--secondary-bg); border-radius: 12px; padding: 8px; margin-bottom: 6px; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.cal-head button {
  width: 40px; margin: 0; padding: 6px; font-size: 18px;
  background: transparent; color: var(--text); font-weight: 700;
}
.cal-head span { font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--hint); padding: 4px 0; }
.cal-day {
  text-align: center; padding: 9px 0; border-radius: 9px;
  background: var(--bg); cursor: pointer; font-size: 14px;
}
.cal-day.empty { background: transparent; cursor: default; }
.cal-day.today { outline: 1.5px solid var(--button); }
.cal-day.selected { background: var(--button); color: var(--button-text); font-weight: 700; }
.cal-day:active { opacity: 0.7; }

label { display: block; font-size: 13px; color: var(--hint); margin: 12px 4px 4px; }

input[type="text"], input[type="number"], input[type="time"], select {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 16px;
}

#toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 10;
  max-width: 90%;
  text-align: center;
}

/* Вкладки */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 6px 0;
}
.tab {
  flex: 1;
  margin: 0;
  padding: 10px 4px;
  border-radius: 10px;
  font-size: 14px;
  background: var(--secondary-bg);
  color: var(--hint);
  font-weight: 600;
}
.tab.active { background: var(--button); color: var(--button-text); }

button.ghost {
  background: transparent;
  color: var(--link);
  border: 1px solid var(--link);
  font-weight: 500;
}

.lesson-row .actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lesson-row .actions .lesson-toggle,
.lesson-row .actions .lesson-edit,
.lesson-row .actions .lesson-delete {
  width: auto;
  min-width: 52px;
  margin: 0;
  padding: 6px 10px;
  font-size: 14px;
}
.lesson-row .actions .lesson-edit { background: var(--secondary-bg); }
.lesson-row .actions .lesson-delete { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.small { font-size: 13px; }
