/* =========================================================
   Кабінет репетитора — стилі
   Ідентичність: "робочий журнал репетитора" — чорнильно-синій,
   паперовий кремовий фон, латунно-золотий акцент.
   Шрифти навмисно системні (без зовнішніх CDN), щоб застосунок
   на 100% працював офлайн одразу після першого відкриття.
   ========================================================= */

:root {
  --ink: #1B2A4A;
  --ink-soft: #2E4066;
  --paper: #F4EFE3;
  --paper-raised: #FFFFFF;
  --gold: #C9A24B;
  --gold-soft: #E8D9B5;
  --rust: #B4472F;
  --forest: #3E7052;
  --line: #E3DCC9;
  --text: #2A2620;
  --text-muted: #766E5C;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(27, 42, 74, 0.08);

  --font-display: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { font-family: var(--font-display); color: var(--ink); margin: 0 0 4px; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.3rem; margin-bottom: 10px; }
h3.section-title { font-size: 1rem; margin: 22px 0 8px; color: var(--ink-soft); }
p { line-height: 1.5; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--ink);
  color: var(--paper);
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar__brand { display: flex; align-items: center; gap: 10px; }
.topbar__mark {
  width: 32px; height: 32px;
  border: 1.5px solid var(--gold);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 1rem;
}
.topbar__title { font-family: var(--font-display); font-size: 1.05rem; letter-spacing: 0.02em; }

/* ---------- Layout ---------- */
.app-main {
  flex: 1;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.view { display: none; }
.view--active { display: block; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

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

/* ---------- Bottom nav ---------- */
.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--paper-raised);
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.nav__item {
  flex: 1;
  border: none;
  background: none;
  padding: 9px 0 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-muted);
  font-size: 0.72rem;
}
.nav__item.is-active { color: var(--ink); font-weight: 600; }
.nav__icon { font-size: 1.2rem; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  width: 52px; height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--gold);
  color: var(--ink);
  font-size: 1.7rem;
  box-shadow: 0 4px 14px rgba(27,42,74,0.25);
  z-index: 15;
  line-height: 1;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
}
.btn--primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn--secondary { background: var(--gold-soft); color: var(--ink); border-color: var(--gold-soft); }
.btn--danger { background: var(--paper-raised); color: var(--rust); border-color: var(--rust); }
.btn--ghost { background: transparent; color: var(--paper); border-color: rgba(244,239,227,0.4); }
.btn--sm { padding: 7px 12px; font-size: 0.82rem; }
.btn--full { width: 100%; margin-top: 8px; }
.btn--icon { width: 34px; height: 34px; padding: 0; border-radius: 50%; }

/* ---------- Cards: students ---------- */
.card--student {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow);
}
.card--student__main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--ink); color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); flex-shrink: 0;
}
.card--student__name { font-weight: 600; }
.card--student__subject { font-size: 0.82rem; color: var(--text-muted); }

.balance { text-align: right; display: flex; flex-direction: column; }
.balance__label { font-size: 0.7rem; color: var(--text-muted); }
.balance__value { font-weight: 700; }
.balance--debt .balance__value { color: var(--rust); }
.balance--positive .balance__value { color: var(--forest); }
.balance--zero .balance__value { color: var(--text-muted); }
.balance--big { align-items: center; text-align: center; padding: 14px; background: var(--paper); border-radius: var(--radius); margin: 12px 0; }
.balance--big .balance__value { font-size: 1.6rem; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 40px 12px; color: var(--text-muted); }
.empty-state__hint { font-size: 0.85rem; }

/* ---------- Calendar ---------- */
.calendar__toolbar { margin-bottom: 12px; }
.calendar__mode-switch { display: flex; background: var(--line); border-radius: var(--radius-sm); padding: 3px; margin-bottom: 10px; }
.calendar__mode-switch button { flex: 1; border: none; background: none; padding: 7px 0; border-radius: 6px; font-size: 0.85rem; color: var(--text-muted); }
.calendar__mode-switch button.is-active { background: var(--paper-raised); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.calendar__nav { display: flex; align-items: center; justify-content: space-between; }
.calendar__label { font-family: var(--font-display); font-size: 1.05rem; color: var(--ink); text-transform: capitalize; }

.lesson-list { display: flex; flex-direction: column; gap: 8px; }
.lesson-row {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.lesson-row__time { font-family: var(--font-display); font-weight: 700; color: var(--ink); font-size: 0.95rem; line-height: 1.2; text-align: center; min-width: 44px; }
.lesson-row__time span { font-weight: 400; font-size: 0.75rem; color: var(--text-muted); }
.lesson-row__main { flex: 1; min-width: 0; }
.lesson-row__student { font-weight: 600; }
.lesson-row__subject { font-size: 0.8rem; color: var(--text-muted); }
.lesson-row__badges { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

.tag { font-size: 0.68rem; padding: 3px 8px; border-radius: 20px; white-space: nowrap; font-weight: 600; }
.tag--planned { background: #E4EBF5; color: var(--ink-soft); }
.tag--completed { background: #E1EEE5; color: var(--forest); }
.tag--cancelled { background: #F2E4E0; color: var(--rust); }
.tag--paid { background: #E1EEE5; color: var(--forest); }
.tag--unpaid { background: #F7EAD2; color: #8A6417; }
.tag--balance { background: var(--gold-soft); color: var(--ink); }
.tag-row { display: flex; gap: 6px; margin: 6px 0 14px; }

/* week grid */
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week-day { background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px; min-height: 120px; }
.week-day--today { border-color: var(--gold); }
.week-day__header { display: flex; flex-direction: column; align-items: center; font-size: 0.68rem; color: var(--text-muted); margin-bottom: 4px; }
.week-day__num { font-family: var(--font-display); font-size: 1rem; color: var(--ink); }
.week-day__lessons { display: flex; flex-direction: column; gap: 3px; }
.week-lesson { font-size: 0.62rem; padding: 3px 4px; border-radius: 5px; background: #E4EBF5; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.week-lesson.tag--completed { background: #E1EEE5; color: var(--forest); }
.week-lesson.tag--cancelled { background: #F2E4E0; color: var(--rust); opacity: 0.7; }
.week-day__add { border: 1px dashed var(--line); background: none; color: var(--text-muted); border-radius: 5px; font-size: 0.72rem; padding: 2px 0; margin-top: 2px; }

/* month grid */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month-grid--labels { margin-bottom: 4px; }
.month-grid__label { text-align: center; font-size: 0.7rem; color: var(--text-muted); font-weight: 600; }
.month-cell {
  aspect-ratio: 1;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative;
  font-size: 0.85rem;
}
.month-cell--muted { opacity: 0.35; }
.month-cell--today { border-color: var(--gold); border-width: 2px; }
.month-cell__num { font-family: var(--font-display); }
.month-cell__dot {
  position: absolute; bottom: 3px;
  font-size: 0.6rem; background: var(--gold); color: var(--ink);
  border-radius: 20px; padding: 0 5px; font-weight: 700;
}

/* ---------- Finance ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.stat-card { background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; grid-column: span 1; }
.stat-card:first-child { grid-column: span 2; }
.stat-card--warn { border-color: var(--rust); }
.stat-card__label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
.stat-card__value { font-family: var(--font-display); font-size: 1.5rem; color: var(--ink); }
.stat-card--warn .stat-card__value { color: var(--rust); }

.mini-list { display: flex; flex-direction: column; gap: 6px; }
.mini-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 0.88rem;
}
.mini-row--clickable { cursor: pointer; }
.money-plus { color: var(--forest); font-weight: 600; }
.money-minus { color: var(--rust); font-weight: 600; }

/* ---------- Settings ---------- */
.settings-card { background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.settings-card__hint { font-size: 0.85rem; color: var(--text-muted); margin: 4px 0 0; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; color: var(--ink-soft); font-weight: 600; }
.form input, .form select, .form textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  background: var(--paper);
  color: var(--text);
  font-weight: 400;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}
.form__row { display: flex; gap: 10px; }
.form__row label { flex: 1; }
.warning-box {
  background: #FBEFE4; border: 1px solid var(--rust); color: #7A3319;
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.82rem; line-height: 1.5;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(27,42,74,0.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
}
/* [hidden] має ту саму специфічність, що й .modal-overlay, тому без цього
   правила display:flex вище "перебиває" вбудоване display:none браузера,
   і невидимий (opacity:0) шар лишається клікабельним поверх усього застосунку. */
.modal-overlay[hidden] {
  display: none !important;
}
.modal-overlay--show { opacity: 1; }
.modal {
  background: var(--paper);
  width: 100%; max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  position: relative;
  transform: translateY(12px);
  transition: transform 0.2s ease;
}
.modal-overlay--show .modal { transform: translateY(0); }
.modal__close {
  position: absolute; top: 12px; right: 14px;
  border: none; background: none; font-size: 1.1rem; color: var(--text-muted);
  width: 30px; height: 30px;
}
.modal__actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; }
.modal__actions--wrap { flex-wrap: wrap; }
.modal__actions--wrap .btn { flex: 1; min-width: 140px; }

.detail__meta { color: var(--text-muted); font-size: 0.88rem; margin: 0 0 4px; }
.detail__notes { background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.88rem; }

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 18px; max-width: 480px; }
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 200; pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 30px;
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 88%;
  text-align: center;
}
.toast--show { opacity: 1; transform: translateY(0); }
.toast--success { background: var(--forest); }
.toast--error { background: var(--rust); }
.toast--warning { background: #8A6417; }

/* ---------- Accessibility ---------- */
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
