/* ============ ПЕРЕМЕННЫЕ И ТЕМЫ ============ */
:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #1a1a1a);
    --hint: var(--tg-theme-hint-color, #8e8e93);
    --button: var(--tg-theme-button-color, #2f6fed);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
    --card-bg: var(--tg-theme-secondary-bg-color, #f7f7fa);
    --danger: #e53935; --warning: #f9a825; --success: #43a047;
}

body.theme-light { --bg: #ffffff; --text: #1a1a1a; --hint: #8e8e93; --button: #2f6fed; --secondary-bg: #f2f2f7; --card-bg: #f7f7fa; }
body.theme-dark { --bg: #171717; --text: #ffffff; --hint: #8e8e93; --button: #3b82f6; --secondary-bg: #2c2c2e; --card-bg: #1c1c1e; }
body.theme-newyear {
    --bg: #0f172a; --text: #f8fafc; --hint: #94a3b8; --button: #ef4444;
    --secondary-bg: #1e293b; --card-bg: #1e293b;
    background-image: radial-gradient(circle at top, #1e3a8a 0%, #0f172a 100%);
    background-attachment: fixed;
}

/* ============ ОБЩИЕ СТИЛИ ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0; padding: 0; height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg); color: var(--text);
    overflow: hidden;
    transition: background 0.3s, color 0.3s;
}
#app {
    display: flex; flex-direction: column; height: 100dvh;
    padding-top: env(safe-area-inset-top);
    position: relative; z-index: 2;
}

#topbar {
    padding: 14px 18px 10px;
    display: flex; justify-content: space-between;
    border-bottom: 1px solid rgba(128,128,128,0.15);
    align-items: center; position: relative; background: var(--bg);
}
#content {
    flex: 1; overflow-y: auto;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
    z-index: 2;
}

.loader {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding-top: 60px;
    color: var(--hint); gap: 14px;
}
.spinner {
    width: 34px; height: 34px;
    border: 3px solid var(--secondary-bg);
    border-top-color: var(--button);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.muted { color: var(--hint); font-size: 13px; }

/* ============ ПОСЕЩАЕМОСТЬ (кольцо) ============ */
.attendance { display: flex; align-items: center; gap: 16px; }
.ring { position: relative; width: 86px; height: 86px; flex-shrink: 0; }
.ring svg { transform: rotate(-90deg); }
.ring .center {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700;
}

/* ============ CHIP ============ */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 9px;
    border-radius: 999px;
    background: var(--secondary-bg);
    color: var(--text);
    line-height: 1.2;
    white-space: nowrap;
    border: 1px solid transparent;
    box-sizing: border-box;
}
.chip.excused {
    background: rgba(249, 168, 37, 0.18);
    color: #c47d00;
    border-color: rgba(249, 168, 37, 0.35);
}
.chip.unexcused {
    background: rgba(229, 57, 53, 0.15);
    color: #b71c1c;
    border-color: rgba(229, 57, 53, 0.35);
}
body.theme-dark .chip.excused {
    background: rgba(249, 168, 37, 0.22);
    color: #ffc233;
    border-color: rgba(249, 168, 37, 0.45);
}
body.theme-dark .chip.unexcused {
    background: rgba(229, 57, 53, 0.22);
    color: #ff6b68;
    border-color: rgba(229, 57, 53, 0.45);
}

/* ============ MARK-ROW ============ */
.mark-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
}

/* ============ ТАБЫ ДНЕЙ ============ */
.day-tabs {
    display: flex; gap: 6px;
    overflow-x: auto; padding-bottom: 10px; margin-bottom: 8px;
}
.day-tab {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--secondary-bg);
    border: none;
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    position: relative;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.day-tab.active { background: var(--button); color: white; }
.day-tab.is-today:not(.active) { box-shadow: inset 0 0 0 1.5px var(--button); }
.today-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--button);
    display: inline-block;
}
.day-tab.active .today-dot { background: white; }

/* ============ ПАРЫ ============ */
.lesson {
    display: flex; gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(128,128,128,0.12);
}
.lesson-num {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--secondary-bg);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
    flex-shrink: 0;
}

/* ============ ТАББАР ============ */
#tabbar {
    display: flex;
    border-top: 1px solid rgba(128,128,128,0.15);
    background: var(--bg);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 2;
}
.tab {
    flex: 1; border: none; background: transparent;
    color: var(--hint);
    padding: 8px 4px 10px;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    cursor: pointer;
}
.tab.active { color: var(--button); }
.tab-icon { font-size: 20px; }
.tab-label { font-size: 11px; font-weight: 600; }

/* ============ ФОРМЫ ============ */
select, input { color: var(--text); font-size: 16px; }
select option { background-color: var(--bg); color: var(--text); }

/* ============ СНЕГ И ЕЛКА ============ */
#winter-bg {
    position: fixed; inset: 0; z-index: 0;
    pointer-events: none; overflow: hidden; display: none;
}
body.theme-newyear #winter-bg { display: block; }
#snow-container {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none; z-index: 1; overflow: hidden;
}
.snowflake {
    position: absolute; top: -20px; color: #ffffff;
    opacity: 0.8;
    text-shadow: 0 0 5px rgba(255,255,255,0.5);
    animation: fall linear infinite;
    will-change: transform;
}
@keyframes fall {
    0% { transform: translateY(-10vh) translateX(0); }
    100% { transform: translateY(110vh) translateX(20px); }
}

#tree-container {
    position: absolute; bottom: -40px; left: 50%;
    transform: translateX(-50%);
    width: 320px; height: 420px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: flex-end;
    opacity: 0.35;
    filter: drop-shadow(0 0 20px rgba(16, 185, 129, 0.4));
}
.tree-star {
    font-size: 40px; line-height: 1; margin-bottom: -5px; z-index: 10;
    animation: star-pulse 2s infinite alternate;
}
@keyframes star-pulse {
    0% { transform: scale(1); filter: drop-shadow(0 0 10px gold); }
    100% { transform: scale(1.2); filter: drop-shadow(0 0 25px gold); }
}
.tree-body {
    width: 0; height: 0;
    border-left: 110px solid transparent;
    border-right: 110px solid transparent;
    border-bottom: 160px solid #064e3b;
    position: relative; margin-bottom: -20px;
}
.tree-body::before {
    content: ""; position: absolute; top: -90px; left: -85px;
    width: 0; height: 0;
    border-left: 85px solid transparent;
    border-right: 85px solid transparent;
    border-bottom: 120px solid #065f46;
}
.tree-body::after {
    content: ""; position: absolute; top: -150px; left: -55px;
    width: 0; height: 0;
    border-left: 55px solid transparent;
    border-right: 55px solid transparent;
    border-bottom: 85px solid #047857;
}
.tree-lights {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none; z-index: 5;
}
.light {
    position: absolute; width: 8px; height: 8px;
    border-radius: 50%; background: #fbbf24;
    box-shadow: 0 0 10px #fbbf24, 0 0 20px #fbbf24;
    animation: blink 1.5s infinite alternate;
}
@keyframes blink { 0% { opacity: 1; } 100% { opacity: 0.3; } }
.light:nth-child(3n) { background: #ef4444; box-shadow: 0 0 10px #ef4444; }
.light:nth-child(3n+1) { background: #3b82f6; box-shadow: 0 0 10px #3b82f6; }
.light:nth-child(3n+2) { background: #22c55e; box-shadow: 0 0 10px #22c55e; }

/* ============ ПЛАШКА ЗВОНКОВ ============ */
.bell-banner {
    background: var(--secondary-bg);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 15px;
    display: flex; align-items: center; justify-content: space-between;
    border-left: 4px solid var(--button);
    font-size: 13px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.bell-banner.break { border-left-color: var(--warning); }
.bell-time { font-weight: bold; font-size: 15px; color: var(--text); }

/* ============ ТОСТЫ ============ */
.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--card-bg);
    color: var(--text);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    max-width: 90vw;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-info { border-left: 4px solid var(--button); }

/* ============ ГЛАВНАЯ: плашка звонков ============ */
.home-bell {
    margin-top: 4px;
    margin-bottom: 14px;
    border-left-width: 4px;
}

/* ============ ГЛАВНАЯ: прогресс-бар ============ */
.attendance-progress { margin-top: 6px; }
.att-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.att-percent { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.att-percent.good { color: var(--success); }
.att-percent.warn { color: var(--warning); }
.att-percent.bad  { color: var(--danger); }
.att-target { margin-left: auto; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--secondary-bg); color: var(--hint); }
.att-target.good { background: rgba(67, 160, 71, 0.15); color: var(--success); }
.att-bar { position: relative; height: 12px; border-radius: 999px; background: var(--secondary-bg); overflow: hidden; }
.att-fill { height: 100%; border-radius: 999px; transition: width 0.6s ease; }
.att-fill.good { background: var(--success); }
.att-fill.warn { background: var(--warning); }
.att-fill.bad  { background: var(--danger); }
.att-target-line { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: 0.35; }
.att-stats { display: flex; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--hint); flex-wrap: wrap; }

/* ============ ГЛАВНАЯ: «Что нового» ============ */
.latest-card { padding: 14px 16px; }
.latest-card.empty { opacity: 0.8; }
.latest-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--hint); margin-bottom: 8px; }
.latest-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.latest-date { font-size: 13px; font-weight: 600; color: var(--hint); }
.latest-subject { font-size: 14px; font-weight: 600; color: var(--text); }

/* ============ РАСПИСАНИЕ: шапка с кнопками ============ */
.schedule-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.schedule-header-btns {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.day-jump-btn {
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--secondary-bg);
    color: var(--text);
    border: none;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.15s, opacity 0.2s;
    min-height: 32px;
    white-space: nowrap;
}
.day-jump-btn:active { transform: scale(0.95); }

/* «Сегодня» — заливная синяя, заметная */
#sched-today-btn {
    background: var(--button);
    color: white;
    box-shadow: 0 2px 8px rgba(47, 111, 237, 0.35);
}

/* «Завтра» — с синей обводкой */
#sched-tomorrow-btn {
    background: transparent;
    color: var(--button);
    border: 1.5px solid var(--button);
}

/* Активная кнопка (уже на этом дне) — слегка гаснет */
#sched-today-btn.is-active,
#sched-tomorrow-btn.is-active {
    opacity: 0.55;
    box-shadow: none;
}

/* ============ ПРОПУСКА: фильтры ============ */
.filters-row {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 10px;
    margin-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}
.filter-btn {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--secondary-bg);
    color: var(--text);
    border: none;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    min-height: 36px;
}
.filter-btn.active { background: var(--button); color: white; }

.marks-counter { font-size: 12px; margin-bottom: 8px; padding-left: 4px; }

.subject-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 10px;
}
.subject-count {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--secondary-bg);
    color: var(--hint);
}

/* ============ МОДАЛКИ ============ */
#settings-modal, #profile-modal {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.6); z-index: 1000;
    align-items: center; justify-content: center; padding: 20px;
}
.settings-content {
    width: 100%; max-width: 400px;
    background: var(--card-bg);
    border-radius: 14px; padding: 20px;
}

/* ============ АВТОРИЗАЦИЯ ============ */
#auth-screen {
    display: none; flex-direction: column; align-items: center;
    justify-content: center; height: 100vh; padding: 20px;
    text-align: center; z-index: 2; position: relative;
}
#auth-screen h2 { margin-bottom: 10px; }
#auth-screen p { color: var(--hint); margin-bottom: 30px; font-size: 14px; }
.auth-container { min-height: 44px; }

#btn-settings {
    background: transparent; border: none; font-size: 20px;
    cursor: pointer; padding: 5px;
}