:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f4f8);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #18202a);
  --muted: var(--tg-theme-hint-color, #7b8794);
  --accent: var(--tg-theme-button-color, #2688eb);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--muted) 18%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface));
  --danger: #e5484d;
  --shadow: 0 12px 36px rgba(21, 31, 45, .09);
  --safe-top: max(12px, var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(18px, var(--tg-content-safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 300px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 100% 0, color-mix(in srgb, var(--accent) 10%, transparent), transparent 32%),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, select { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.app-shell { max-width: 680px; margin: 0 auto; min-height: 100vh; padding: var(--safe-top) 14px calc(92px + var(--safe-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 2px 18px; }
.eyebrow, .section-label { margin: 0 0 4px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: -.025em; }
h1 { font-size: 27px; }
h2 { font-size: 22px; }
.icon-button, .secondary-button, .danger-button { border: 0; border-radius: 12px; padding: 10px 13px; font-weight: 700; cursor: pointer; }
.icon-button, .secondary-button { color: var(--accent); background: var(--accent-soft); }
.danger-button { color: var(--danger); background: color-mix(in srgb, var(--danger) 11%, var(--surface)); }

.week-card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 12px 10px 14px; box-shadow: var(--shadow); }
.week-nav { display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; margin-bottom: 10px; }
.week-nav p { margin: 0; text-align: center; font-size: 14px; font-weight: 700; }
.nav-button, .close-button { width: 38px; height: 38px; border: 0; border-radius: 50%; background: transparent; font-size: 30px; line-height: 1; cursor: pointer; }
.nav-button:active, .close-button:active { background: var(--accent-soft); }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day-button { min-width: 0; border: 0; border-radius: 15px; padding: 8px 2px 7px; background: transparent; cursor: pointer; }
.day-button .weekday { display: block; margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.day-button .day-number { display: grid; place-items: center; width: 32px; height: 32px; margin: auto; border-radius: 50%; font-size: 14px; font-weight: 800; }
.day-button .dot { display: block; width: 4px; height: 4px; margin: 4px auto 0; border-radius: 50%; background: transparent; }
.day-button.has-lessons .dot { background: var(--accent); }
.day-button.today .day-number { outline: 1.5px solid var(--accent); outline-offset: -2px; }
.day-button.selected { color: var(--accent-text); background: var(--accent); }
.day-button.selected .weekday { color: color-mix(in srgb, var(--accent-text) 75%, transparent); }
.day-button.selected .dot { background: var(--accent-text); }
.day-button.selected .day-number { outline: none; }

.summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 24px 2px 12px; }
.summary-copy { margin: 0; color: var(--muted); font-size: 14px; }
.lesson-list { display: grid; gap: 10px; }
.lesson-card { position: relative; width: 100%; display: grid; grid-template-columns: 61px 4px 1fr auto; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 18px; padding: 14px; color: var(--text); background: var(--surface); text-align: left; box-shadow: 0 6px 20px rgba(21, 31, 45, .045); cursor: pointer; }
.lesson-time strong { display: block; font-size: 16px; }
.lesson-time span { color: var(--muted); font-size: 12px; }
.lesson-accent { align-self: stretch; border-radius: 4px; background: var(--accent); }
.lesson-info strong { display: block; margin-bottom: 5px; font-size: 16px; }
.lesson-info span { color: var(--muted); font-size: 13px; }
.lesson-chevron { color: var(--muted); font-size: 22px; }
.badge { display: inline-flex; align-items: center; gap: 5px; margin-top: 7px; padding: 4px 7px; border-radius: 8px; color: #ab6400; background: rgba(255, 196, 9, .13); font-size: 11px; font-weight: 700; }
.empty-state { padding: 40px 22px; border: 1px dashed var(--line); border-radius: 20px; color: var(--muted); text-align: center; }
.empty-state .empty-icon { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 18px; color: var(--accent); background: var(--accent-soft); font-size: 26px; }
.empty-state strong { display: block; margin-bottom: 6px; color: var(--text); }
.empty-state p { margin: 0; font-size: 14px; line-height: 1.45; }

.fab { position: fixed; right: max(18px, calc((100vw - 660px) / 2)); bottom: calc(18px + var(--safe-bottom)); z-index: 4; border: 0; border-radius: 18px; padding: 14px 18px; color: var(--accent-text); background: var(--accent); box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 38%, transparent); font-weight: 800; cursor: pointer; }
.fab span { margin-right: 4px; font-size: 19px; }
.primary-button { border: 0; border-radius: 14px; padding: 13px 18px; color: var(--accent-text); background: var(--accent); font-weight: 800; cursor: pointer; }
.primary-button:disabled { opacity: .55; cursor: wait; }
.primary-button.full { width: 100%; min-height: 50px; }

.loading-screen, .error-screen { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; padding: 30px; background: var(--bg); text-align: center; }
.loader-mark { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 21px; color: var(--accent-text); background: var(--accent); box-shadow: 0 12px 32px color-mix(in srgb, var(--accent) 35%, transparent); font-size: 28px; font-weight: 900; animation: breathe 1.4s ease-in-out infinite; }
.loading-screen p { color: var(--muted); }
.error-icon { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%; color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); font-size: 28px; font-weight: 900; }
.error-screen h2 { margin-top: 18px; }
.error-screen p { max-width: 320px; margin: 9px 0 22px; color: var(--muted); line-height: 1.45; }
@keyframes breathe { 50% { transform: scale(.94); opacity: .78; } }

.sheet-backdrop { position: fixed; inset: 0; z-index: 8; background: rgba(0, 0, 0, .38); backdrop-filter: blur(2px); }
.sheet { position: fixed; left: 50%; bottom: 0; z-index: 9; width: min(680px, 100%); max-height: 88vh; overflow-y: auto; transform: translateX(-50%); padding: 8px 18px calc(18px + var(--safe-bottom)); border-radius: 26px 26px 0 0; background: var(--surface); box-shadow: 0 -16px 50px rgba(0, 0, 0, .18); animation: rise .22s ease-out; }
@keyframes rise { from { transform: translate(-50%, 18px); opacity: .4; } }
.sheet-handle { width: 40px; height: 4px; margin: 0 auto 14px; border-radius: 3px; background: var(--line); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.close-button { font-size: 26px; }
form label { display: block; margin-bottom: 15px; color: var(--muted); font-size: 12px; font-weight: 700; }
input, select { width: 100%; min-height: 49px; margin-top: 7px; border: 1px solid var(--line); border-radius: 13px; padding: 0 13px; color: var(--text); background: var(--bg); outline: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-row { display: grid; grid-template-columns: 1.2fr 1fr; gap: 10px; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 7px; padding: 4px; border-radius: 14px; background: var(--bg); }
.segmented button { min-height: 40px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 800; cursor: pointer; }
.segmented button.active { color: var(--accent-text); background: var(--accent); }
.segmented.compact { margin: 0 0 16px; }
.form-note { margin: -2px 0 18px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.slot-list { display: grid; gap: 10px; }
.slot-day-title { margin: 12px 2px 3px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.slot-button { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; color: var(--text); background: var(--surface); font-weight: 700; cursor: pointer; }
.slot-button span:last-child { color: var(--accent); }
.slot-loading { padding: 32px; color: var(--muted); text-align: center; }
.detail-card { padding: 18px; border-radius: 18px; background: var(--bg); }
.detail-card .detail-time { margin: 0 0 8px; color: var(--accent); font-size: 14px; font-weight: 800; }
.detail-card h3 { margin: 0 0 12px; font-size: 21px; }
.detail-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.detail-meta div { padding: 10px; border-radius: 11px; background: var(--surface); }
.detail-meta span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 11px; }
.detail-meta strong { font-size: 13px; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 14px; }
.reschedule-form { margin-top: 16px; }
.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom)); z-index: 30; width: max-content; max-width: calc(100% - 32px); transform: translateX(-50%); padding: 12px 16px; border-radius: 13px; color: #fff; background: rgba(25, 30, 36, .92); box-shadow: var(--shadow); font-size: 13px; font-weight: 700; text-align: center; animation: toast-in .2s ease-out; }
@keyframes toast-in { from { transform: translate(-50%, 8px); opacity: 0; } }

@media (max-width: 370px) {
  .app-shell { padding-inline: 10px; }
  .day-button .day-number { width: 29px; height: 29px; }
  .summary { align-items: flex-start; }
  .secondary-button { font-size: 12px; }
  .lesson-card { grid-template-columns: 54px 3px 1fr auto; gap: 9px; padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; }
}
