:root {
    color-scheme: light;
    --ink: #13213a;
    --ink-soft: #5f6b7e;
    --navy: #12213f;
    --navy-2: #1b315d;
    --header-blue: #285a9f;
    --blue: #315efb;
    --blue-soft: #e8eeff;
    --coral: #f05b47;
    --amber: #d98600;
    --green: #16815f;
    --paper: #ffffff;
    --canvas: #f2f5fa;
    --line: #dfe5ef;
    --shadow: 0 18px 50px rgba(18, 33, 63, 0.09);
    --radius: 22px;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--canvas);
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background: var(--canvas);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.eyebrow {
    margin: 0 0 2px;
    color: inherit;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.11em;
    line-height: 1.2;
    text-transform: uppercase;
    opacity: 0.68;
}

.error-state button {
    min-height: 54px;
    margin-top: 6px;
    border: 0;
    border-radius: 15px;
    color: #fff;
    background: var(--blue);
    font-weight: 850;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(49, 94, 251, 0.23);
}

.error-state button:hover {
    background: #234be1;
}

.error-state button:focus-visible,
.refresh-button:focus-visible,
.logout-link:focus-visible {
    outline: 3px solid rgba(49, 94, 251, 0.35);
    outline-offset: 3px;
}

.form-error {
    margin: 0;
    color: #b3261e;
    font-size: 0.875rem;
    font-weight: 700;
}

/* Schedule */
.app-page {
    background: var(--canvas);
}

.app-shell {
    width: 100%;
    min-height: 100vh;
}

.sticky-header {
    position: sticky;
    z-index: 50;
    top: 0;
    padding-bottom: 10px;
    background: var(--header-blue);
    box-shadow: 0 8px 24px rgba(18, 33, 63, 0.16);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(100%, 920px);
    min-height: 92px;
    margin: 0 auto;
    padding: max(18px, env(safe-area-inset-top)) 18px 14px;
    color: #fff;
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 13px;
}

.brand-logo {
    display: block;
    flex: 0 0 auto;
    width: 58px;
    height: 58px;
    padding: 3px;
    border-radius: 50%;
    background: #fff;
    object-fit: contain;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
}

/* Сумісність, якщо на сервері випадково залишився старий index.php. */
.brand-mark {
    display: block;
    flex: 0 0 auto;
    width: 58px;
    height: 58px;
    overflow: hidden;
    border-radius: 50%;
    color: transparent;
    background: #fff url("logo.png?v=3.0.0") center / calc(100% - 6px) no-repeat;
    font-size: 0;
    line-height: 0;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
}

.topbar h1 {
    margin: 0;
    font-size: 1.65rem;
    letter-spacing: -0.04em;
    line-height: 1.08;
}

.topbar__updated {
    margin: 5px 0 0;
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.72rem;
    font-weight: 650;
    line-height: 1.2;
}

.topbar__date {
    margin-left: 0;
    padding: 7px 14px;
    border-left: 1px solid rgba(255, 255, 255, 0.24);
    color: #fff;
    text-align: right;
}

.week-switcher {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-left: auto;
}

.week-switcher__button {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    cursor: pointer;
}

.week-switcher__button[hidden] {
    display: none;
}

.week-switcher__button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.week-switcher__button:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.35);
    outline-offset: 2px;
}

.week-switcher__button svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.topbar__weekday,
.topbar__date-value {
    margin: 0;
    white-space: nowrap;
}

.topbar__weekday {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1.15;
    text-transform: uppercase;
}

.topbar__date-value {
    margin-top: 3px;
    font-size: 1.32rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.logout-link,
.refresh-button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 13px;
    cursor: pointer;
}

.logout-link {
    margin-left: 14px;
    color: rgba(255, 255, 255, 0.78);
    background: rgba(255, 255, 255, 0.1);
}

.logout-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
}

.logout-link svg,
.refresh-button svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.schedule-main {
    width: min(calc(100% - 24px), 880px);
    margin: 0 auto;
    padding-bottom: max(30px, env(safe-area-inset-bottom));
}

.weekday-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 7px;
    width: min(calc(100% - 24px), 880px);
    margin: 0 auto;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
}

.weekday-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    min-height: 44px;
    padding: 7px 8px;
    border: 0;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.76);
    background: transparent;
    font-size: 0.78rem;
    font-weight: 800;
    cursor: pointer;
    transition: color 150ms ease, background 150ms ease, transform 150ms ease;
}

.weekday-button:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.weekday-button:active {
    transform: translateY(1px);
}

.weekday-button.is-active {
    color: var(--navy);
    background: #fff;
    box-shadow: 0 8px 20px rgba(4, 13, 32, 0.18);
}

.weekday-button.is-today:not(.is-active) {
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.38);
}

.weekday-button__short {
    display: none;
}

.weekday-button__date {
    display: grid;
    place-items: center;
    min-width: 24px;
    height: 24px;
    border-radius: 8px;
    color: inherit;
    background: rgba(255, 255, 255, 0.1);
    font-size: 0.7rem;
}

.weekday-button.is-active .weekday-button__date {
    color: var(--blue);
    background: var(--blue-soft);
}

.date-panel {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    min-height: 126px;
    padding: 24px 20px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.98);
    box-shadow: var(--shadow);
}

.date-panel__weekday {
    margin: 0 0 3px;
    color: var(--blue);
    font-size: 0.9rem;
    font-weight: 850;
}

.date-panel__date {
    margin: 0;
    font-size: clamp(1.45rem, 7vw, 2.15rem);
    font-weight: 900;
    letter-spacing: -0.045em;
    line-height: 1.15;
}

.sync-control {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.sync-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 7px 10px;
    border-radius: 999px;
    color: var(--ink-soft);
    background: #f4f6fa;
    font-size: 0.75rem;
    font-weight: 800;
    white-space: nowrap;
}

.sync-status__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #8290a6;
}

.sync-status[data-state="ready"] {
    color: var(--green);
    background: #eaf7f2;
}

.sync-status[data-state="ready"] .sync-status__dot {
    background: var(--green);
}

.sync-status[data-state="warning"] {
    color: #8a5900;
    background: #fff3d9;
}

.sync-status[data-state="warning"] .sync-status__dot {
    background: var(--amber);
}

.sync-status[data-state="error"] {
    color: #a62b23;
    background: #ffe9e7;
}

.sync-status[data-state="error"] .sync-status__dot {
    background: var(--coral);
}

.refresh-button {
    flex: 0 0 auto;
    color: var(--blue);
    background: var(--blue-soft);
}

.refresh-button:hover {
    background: #dce5ff;
}

.refresh-button:disabled {
    cursor: wait;
}

.refresh-button.is-loading svg {
    animation: spin 0.9s linear infinite;
}

.schedule-section {
    margin-top: 16px;
}

.schedule-list {
    display: grid;
    gap: 12px;
}

.lesson-card {
    position: relative;
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    min-height: 142px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: 0 10px 32px rgba(18, 33, 63, 0.055);
}

.lesson-card::before {
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    content: "";
    background: var(--blue);
}

.lesson-card--weekly::before {
    background: var(--coral);
}

.lesson-card--lecture::before {
    background: #8b5cf6;
}

.lesson-card--current {
    border-color: rgba(49, 94, 251, 0.45);
    box-shadow: 0 16px 38px rgba(49, 94, 251, 0.13);
}

.lesson-card--completed {
    opacity: 0.76;
}

.lesson-card__time {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 22px 8px;
    border-right: 1px solid var(--line);
    color: var(--ink);
    background: #f8faff;
    text-align: center;
}

.lesson-card__time strong {
    font-size: 1.12rem;
    font-weight: 900;
    letter-spacing: -0.025em;
}

.lesson-card__time span {
    margin-top: 3px;
    color: var(--ink-soft);
    font-size: 0.72rem;
    font-weight: 700;
}

.lesson-card--weekly .lesson-card__time {
    background: #fff7f4;
}

.lesson-card--lecture .lesson-card__time {
    color: #6d28d9;
    background: #f5f3ff;
}

.lesson-card__body {
    min-width: 0;
    padding: 18px 17px 17px;
}

.lesson-card__meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 10px;
}

.period-badge,
.source-label,
.now-badge {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 0.73rem;
    font-weight: 850;
    line-height: 1.2;
}

.period-badge {
    color: var(--blue);
    background: var(--blue-soft);
}

.lesson-card--weekly .period-badge {
    color: #b83d2e;
    background: #ffe9e4;
}

.lesson-card--lecture .period-badge {
    color: #6d28d9;
    background: #ede9fe;
}

.source-label {
    color: var(--ink-soft);
    background: #f2f4f8;
}

.now-badge {
    color: #fff;
    background: var(--green);
}

.lesson-card__title {
    margin: 0 0 14px;
    overflow-wrap: anywhere;
    font-size: clamp(1.15rem, 5.4vw, 1.45rem);
    font-weight: 900;
    letter-spacing: -0.025em;
    line-height: 1.2;
}

.lesson-details {
    display: grid;
    gap: 7px;
    margin: 0;
}

.lesson-details__row {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 8px;
}

.lesson-details dt,
.lesson-details dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.lesson-details dt {
    color: var(--ink-soft);
    font-size: 0.76rem;
    font-weight: 750;
}

.lesson-details dd {
    color: #35425a;
    font-size: 0.88rem;
    font-weight: 700;
}

.empty-state,
.error-state {
    padding: 42px 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: 0 10px 32px rgba(18, 33, 63, 0.055);
    text-align: center;
}

.empty-state__icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin: 0 auto 16px;
    border-radius: 16px;
    color: var(--green);
    background: #eaf7f2;
    font-size: 1.45rem;
    font-weight: 900;
}

.empty-state h2,
.error-state h2 {
    margin: 0 0 6px;
    font-size: 1.25rem;
}

.empty-state p,
.error-state p {
    margin: 0;
    color: var(--ink-soft);
}

/* Встановлення на домашній екран */
.pwa-install {
    position: fixed;
    z-index: 1000;
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    left: 14px;
    display: flex;
    align-items: flex-start;
    gap: 13px;
    width: min(calc(100% - 28px), 430px);
    margin: 0 auto;
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 24px 70px rgba(18, 33, 63, 0.28);
}

.pwa-install[hidden] {
    display: none;
}

.pwa-install__logo {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    object-fit: contain;
}

.pwa-install__content {
    min-width: 0;
}

.pwa-install h2 {
    margin: 0 0 4px;
    font-size: 1rem;
    line-height: 1.2;
}

.pwa-install p {
    margin: 0;
    color: var(--ink-soft);
    font-size: 0.78rem;
    line-height: 1.35;
}

.pwa-install .pwa-install__instructions {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    color: var(--ink);
    background: var(--blue-soft);
    font-weight: 750;
}

.pwa-install__actions {
    display: flex;
    gap: 7px;
    margin-top: 12px;
}

.pwa-install__actions button {
    min-height: 40px;
    padding: 0 13px;
    border: 0;
    border-radius: 11px;
    font-size: 0.78rem;
    font-weight: 850;
    cursor: pointer;
}

.pwa-install__primary {
    color: #fff;
    background: var(--blue);
}

.pwa-install__secondary {
    color: var(--ink-soft);
    background: #eef1f6;
}

.error-state button {
    min-height: 48px;
    padding: 0 20px;
    margin-top: 20px;
}

/* Loading */
.lesson-card--skeleton::before {
    background: #d8deea;
}

.lesson-card--skeleton .lesson-card__body {
    display: grid;
    align-content: start;
    gap: 13px;
}

.skeleton {
    border-radius: 8px;
    background: linear-gradient(90deg, #edf0f5 20%, #f8f9fb 40%, #edf0f5 60%);
    background-size: 300% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton--time {
    width: 45px;
    height: 20px;
    margin: 28px auto;
}

.skeleton--small {
    width: 110px;
    height: 24px;
}

.skeleton--title {
    width: 76%;
    height: 25px;
}

.skeleton--line {
    width: 68%;
    height: 14px;
}

.skeleton--short {
    width: 48%;
}

@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 520px) {
    .app-page {
        background: var(--canvas);
    }

    .sticky-header {
        padding-bottom: 6px;
    }

    .topbar {
        min-height: 68px;
        padding: max(7px, env(safe-area-inset-top)) 9px 5px;
    }

    .topbar__brand {
        gap: 8px;
    }

    .brand-logo,
    .brand-mark {
        width: 43px;
        height: 43px;
        padding: 2px;
        box-shadow: 0 5px 14px rgba(0, 0, 0, 0.16);
    }

    .brand-mark {
        padding: 0;
        background-size: calc(100% - 4px);
    }

    .topbar .eyebrow {
        margin-bottom: 0;
        font-size: 0.61rem;
    }

    .topbar h1 {
        font-size: 1.32rem;
        line-height: 1;
    }

    .topbar__updated {
        margin-top: 3px;
        font-size: 0.61rem;
    }

    .topbar__date {
        padding: 3px 4px;
        border-left: 0;
    }

    .week-switcher {
        gap: 2px;
    }

    .topbar__weekday {
        font-size: 0.54rem;
    }

    .topbar__date-value {
        margin-top: 2px;
        font-size: 0.88rem;
    }

    .week-switcher__button {
        width: 27px;
        height: 32px;
        border-radius: 9px;
    }

    .week-switcher__button svg {
        width: 17px;
        height: 17px;
    }

    .logout-link {
        width: 36px;
        height: 36px;
        margin-left: 6px;
        border-radius: 11px;
    }

    .logout-link svg {
        width: 18px;
        height: 18px;
    }

    .schedule-main {
        width: calc(100% - 12px);
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .weekday-nav {
        width: calc(100% - 12px);
        gap: 3px;
        padding: 4px;
        border-radius: 13px;
    }

    .weekday-button {
        flex-direction: column;
        gap: 1px;
        min-height: 40px;
        padding: 3px 2px;
        border-radius: 9px;
    }

    .weekday-button__full {
        display: none;
    }

    .weekday-button__short {
        display: inline;
        font-size: 0.72rem;
    }

    .weekday-button__date {
        height: 15px;
        min-width: 20px;
        background: transparent;
        font-size: 0.59rem;
    }

    .schedule-section {
        margin-top: 7px;
    }

    .schedule-list {
        gap: 6px;
    }

    .lesson-card {
        grid-template-columns: 60px minmax(0, 1fr);
        min-height: 0;
        border-radius: 16px;
    }

    .lesson-card::before {
        width: 4px;
    }

    .lesson-card__time {
        justify-content: flex-start;
        padding: 12px 5px 9px;
    }

    .lesson-card__time strong {
        font-size: 0.95rem;
    }

    .lesson-card__time span {
        margin-top: 0;
        font-size: 0.63rem;
    }

    .lesson-card__body {
        padding: 9px 11px;
    }

    .lesson-card__meta {
        gap: 4px;
        margin-bottom: 5px;
    }

    .period-badge,
    .source-label,
    .now-badge {
        min-height: 20px;
        padding: 3px 6px;
        border-radius: 6px;
        font-size: 0.63rem;
    }

    .lesson-card__title {
        margin-bottom: 6px;
        font-size: clamp(1rem, 4.7vw, 1.16rem);
        line-height: 1.12;
    }

    .lesson-details {
        gap: 3px;
    }

    .lesson-details__row {
        grid-template-columns: 65px minmax(0, 1fr);
        gap: 5px;
    }

    .lesson-details dt {
        font-size: 0.67rem;
    }

    .lesson-details dd {
        font-size: 0.76rem;
    }

    .empty-state,
    .error-state {
        padding: 24px 16px;
        border-radius: 17px;
    }

    .pwa-install {
        gap: 10px;
        padding: 13px;
        border-radius: 17px;
    }

    .pwa-install__logo {
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 520px) and (max-height: 720px) {
    .source-label {
        display: none;
    }

    .lesson-card__body {
        padding-block: 7px;
    }

    .lesson-card__time {
        padding-top: 10px;
    }
}

@media (min-width: 700px) {
    .topbar {
        min-height: 108px;
        padding-inline: 20px;
    }

    .schedule-main {
        width: min(calc(100% - 40px), 880px);
    }

    .date-panel {
        align-items: center;
        min-height: 142px;
        padding: 28px 30px;
    }

    .lesson-card {
        grid-template-columns: 112px minmax(0, 1fr);
        min-height: 148px;
    }

    .lesson-card__time {
        padding-top: 25px;
    }

    .lesson-card__time strong {
        font-size: 1.35rem;
    }

    .lesson-card__body {
        padding: 21px 26px;
    }

    .lesson-details__row {
        grid-template-columns: 92px minmax(0, 1fr);
    }

}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
