html {
    width: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
    background: #f5f5f7;
    color: #1d1d1f;
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto 1fr;
    gap: 20px;
    padding: 16px 20px 24px;
    min-height: 100vh;
    width: 100%;
    overflow-x: hidden;
}

#topNav {
    grid-column: 1 / -1;
    position: relative;
    z-index: 200;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 12px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(16px);
    min-width: 0;
}

body.dark-mode {
    background: #0e0f12;
    color: #f5f5f7;
}

#topNav .nav-title {
    justify-self: center;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    text-decoration: none;
    color: inherit;
    padding: 4px 10px;
    border-radius: 10px;
    transition: background-color 0.18s ease, box-shadow 0.18s ease;
}

#topNav .nav-title:hover {
    text-decoration: none;
    color: inherit;
    background: rgba(62, 133, 255, 0.14);
}

#topNav .nav-title:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(62, 133, 255, 0.28);
    background: rgba(62, 133, 255, 0.14);
}

#topNav .nav-menu {
    justify-self: start;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.7);
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
}

#topNav .nav-menu-icon {
    width: 20px;
    height: 20px;
}

#topNav .nav-action {
    justify-self: end;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.7);
    display: grid;
    place-items: center;
    cursor: pointer;
}

#topNav .nav-action-icon {
    width: 20px;
    height: 20px;
}

.nav-settings-control {
    position: relative;
    display: grid;
    justify-items: end;
}

.nav-actions-right {
    display: grid;
    grid-auto-flow: column;
    align-items: center;
    gap: 10px;
    justify-self: end;
}

.offline-sync-badge {
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 999px;
    background: rgba(10, 132, 255, 0.12);
    color: #0a57d4;
    font-size: 0.74rem;
    font-weight: 700;
    padding: 6px 10px;
    cursor: pointer;
}

.offline-sync-badge.is-offline {
    background: rgba(248, 107, 71, 0.13);
    color: #a74628;
}

.offline-sync-banner {
    position: fixed;
    left: 50%;
    top: 14px;
    transform: translateX(-50%) translateY(-10px);
    opacity: 0;
    pointer-events: none;
    z-index: 1200;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.12);
    font-size: 0.86rem;
    font-weight: 600;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.offline-sync-banner.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.sw-update-popup {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 1200;
    display: grid;
    gap: 8px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
}

.sw-update-popup button {
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    font-weight: 600;
    padding: 6px 10px;
    cursor: pointer;
}

.settings-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    padding: 8px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.16);
    display: none;
    z-index: 1000;
}

.settings-menu.is-open {
    display: grid;
    gap: 6px;
}

.settings-item {
    border: 0;
    border-radius: 10px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.04);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
}

.settings-item:hover {
    background: rgba(62, 133, 255, 0.18);
}

.settings-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.08);
    margin: 4px 2px;
}

.settings-toggle-indicator {
    width: 32px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: rgba(0, 0, 0, 0.1);
    position: relative;
}

.settings-toggle-indicator::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ffffff;
    transition: transform 0.2s ease;
}

body.dark-mode .settings-menu {
    background: rgba(28, 30, 35, 0.92);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.4);
}

body.dark-mode .settings-item {
    background: rgba(255, 255, 255, 0.06);
    color: #f5f5f7;
}

body.dark-mode .settings-item:hover {
    background: rgba(62, 133, 255, 0.26);
}

body.dark-mode .settings-divider {
    background: rgba(255, 255, 255, 0.08);
}

body.dark-mode .settings-toggle-indicator {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.15);
}

body.dark-mode .settings-toggle-indicator::after {
    transform: translateX(14px);
    background: #f5f5f7;
}

body.dark-mode .offline-sync-banner,
body.dark-mode .sw-update-popup {
    background: rgba(28, 30, 35, 0.95);
    color: #f5f5f7;
    border-color: rgba(255, 255, 255, 0.12);
}

body.dark-mode .offline-sync-badge {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(62, 133, 255, 0.2);
    color: #d4e7ff;
}

body.dark-mode .offline-sync-badge.is-offline {
    background: rgba(248, 107, 71, 0.24);
    color: #ffd7cd;
}

body.dark-mode .sw-update-popup button {
    border-color: rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08);
    color: #f5f5f7;
}

/* Sidebar */
#classSidebar {
    grid-row: 2;
    padding: 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(0, 0, 0, 0.06);
    backdrop-filter: blur(14px);
    min-width: 0;
}

body.dark-mode #topNav,
body.dark-mode #classSidebar,
body.dark-mode main {
    background: rgba(22, 24, 28, 0.72);
    border-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode .calendar-area {
    background: rgba(22, 24, 28, 0.82);
    border-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode #topNav .nav-menu,
body.dark-mode #topNav .nav-action,
body.dark-mode .calendar-view-toggle {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

body.dark-mode #topNav .nav-menu-icon,
body.dark-mode #topNav .nav-action-icon {
    filter: invert(1);
}

body.dark-mode .calendar-view-label {
    color: rgba(245, 245, 247, 0.82);
}

body.dark-mode .class-code,
body.dark-mode .class-name {
    color: #f5f5f7;
}

body.dark-mode #classSidebar .class-sidebar-add {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: #f5f5f7;
}

body.dark-mode #classSidebar .class-sidebar-add:hover,
body.dark-mode #classSidebar .class-sidebar-add:focus-visible {
    background: rgba(62, 133, 255, 0.32);
    border-color: rgba(62, 133, 255, 0.6);
}

#classSidebar header h2 {
    margin: 0;
    font-size: 1.1rem;
}

#classSidebar header .class-sidebar-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 4px;
}

#classSidebar .class-sidebar-add {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: rgba(255, 255, 255, 0.7);
    color: rgba(0, 0, 0, 0.78);
    font-size: 1.2rem;
    line-height: 1;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

#classSidebar .class-sidebar-add:hover,
#classSidebar .class-sidebar-add:focus-visible {
    background: rgba(62, 133, 255, 0.2);
    border-color: rgba(62, 133, 255, 0.5);
    transform: translateY(-1px) scale(1.04);
    box-shadow: 0 6px 16px rgba(28, 66, 128, 0.18);
}

#classSidebar .class-sidebar-add:focus-visible {
    outline: 2px solid rgba(62, 133, 255, 0.55);
    outline-offset: 2px;
}

#classSidebar header p {
    margin: 0 0 16px;
    color: rgba(0, 0, 0, 0.6);
    font-size: 0.9rem;
}

#classList {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 12px;
}

.class-item {
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(var(--class-color, 62, 133, 255), 0.16);
    border: 1px solid rgba(var(--class-color, 62, 133, 255), 0.45);
    display: grid;
    gap: 2px;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
    transform: translateX(0) scale(1);
    transition: transform 0.22s ease, box-shadow 0.22s ease, background-color 0.22s ease;
}

.class-item:hover,
.class-item:focus-visible {
    transform: translateX(6px) scale(1.02);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.13);
    background: rgba(var(--class-color, 62, 133, 255), 0.24);
}

.class-item:focus-visible {
    outline: 2px solid rgba(var(--class-color, 62, 133, 255), 0.7);
    outline-offset: 2px;
}

.class-code {
    font-weight: 600;
    letter-spacing: 0.2px;
}

.class-name {
    color: rgba(0, 0, 0, 0.65);
    font-size: 0.9rem;
}

/* Main area + calendar */
main {
    grid-row: 2;
    position: relative;
    z-index: 1;
    padding: 16px 16px 20px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(18px);
    display: grid;
    grid-template-rows: 1fr;
    gap: 0;
    min-height: 0;
    min-width: 0;
}

.calendar-view-toggle {
    min-width: 74px;
    height: 38px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.75);
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0 12px;
}

.calendar-view-control {
    position: relative;
    display: grid;
    justify-items: end;
}

.calendar-view-label {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: rgba(0, 0, 0, 0.72);
}

.auth-page {
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 16px;
}

.auth-card {
    width: min(420px, 100%);
    display: grid;
    gap: 12px;
    padding: 20px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.08);
}

.auth-card h1 {
    margin: 0;
    font-size: 1.4rem;
}

.auth-subtitle {
    margin: 0;
    color: rgba(0, 0, 0, 0.58);
}

.auth-form {
    display: grid;
    gap: 8px;
}

.auth-label {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: rgba(0, 0, 0, 0.62);
}

.auth-input {
    width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
    background: rgba(255, 255, 255, 0.92);
    color: inherit;
}

.auth-primary,
.auth-secondary {
    border-radius: 12px;
    padding: 10px 12px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid transparent;
}

.auth-primary {
    background: rgba(62, 133, 255, 0.2);
    border-color: rgba(62, 133, 255, 0.45);
    color: inherit;
}

.auth-secondary {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    color: inherit;
}

.auth-status {
    margin: 2px 0 0;
    min-height: 1.25em;
    font-size: 0.88rem;
    color: rgba(0, 0, 0, 0.65);
}

.auth-status.is-error {
    color: #b42318;
}

.register-popup {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 1200;
}

.register-popup.is-open {
    display: block;
}

.register-popup-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
}

.register-popup-panel {
    position: relative;
    width: min(430px, calc(100vw - 24px));
    margin: max(70px, 8vh) auto 0;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    padding: 18px;
    display: grid;
    gap: 10px;
}

.register-popup-panel h2 {
    margin: 0;
}

.register-popup-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

body.auth-mode {
    grid-template-columns: 1fr;
}

body.auth-mode #classSidebar {
    display: none;
}

body.auth-mode #topNav .nav-menu,
body.auth-mode .nav-actions-right {
    visibility: hidden;
}

body.dark-mode .auth-card,
body.dark-mode .register-popup-panel {
    background: rgba(22, 24, 28, 0.92);
    border-color: rgba(255, 255, 255, 0.12);
    color: #f5f5f7;
}

body.dark-mode .auth-subtitle,
body.dark-mode .auth-label,
body.dark-mode .auth-status {
    color: rgba(245, 245, 247, 0.7);
}

body.dark-mode .auth-input {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.16);
    color: #f5f5f7;
}

body.dark-mode .auth-secondary {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

body.dark-mode .auth-status.is-error {
    color: #fda29b;
}

.calendar-area {
    border-radius: 18px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.82);
    padding: 12px;
    min-height: 420px;
    min-height: clamp(340px, 70vh, 820px);
    display: grid;
    min-width: 0;
}

body.calendar-mode {
    height: 100vh;
    overflow: hidden;
}

body.calendar-mode main {
    overflow: hidden;
}

body.calendar-mode .calendar-area {
    position: relative;
    min-height: 0;
    height: 100%;
    overflow: auto;
}

/* FullCalendar container */
#calendar {
    height: 100%;
}

.sidebar-hidden {
    grid-template-columns: 1fr;
}

.sidebar-hidden #classSidebar {
    display: none;
}

@media (max-width: 900px) {
    body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        padding: 8px;
        gap: 10px;
    }

    #classSidebar {
        position: fixed;
        top: 72px;
        left: 10px;
        right: 10px;
        max-width: 360px;
        max-height: calc(100vh - 96px);
        overflow: auto;
        z-index: 10;
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
        display: none;
    }

    .sidebar-open #classSidebar {
        display: block;
    }

    main {
        padding: 10px;
    }

    .calendar-area {
        min-height: calc(100vh - 136px);
        padding: 8px;
        overflow-x: auto;
        overflow-y: auto;
    }

    #topNav {
        padding: 8px 12px;
        border-radius: 14px;
        width: 100%;
        max-width: 100%;
        grid-template-columns: auto minmax(0, 1fr) auto;
        overflow-x: clip;
    }

    #topNav .nav-title {
        font-size: 1.1rem;
        justify-self: start;
        display: block;
        width: 100%;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #topNav .nav-menu,
    #topNav .nav-action {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .calendar-view-toggle {
        min-width: 66px;
        height: 36px;
        border-radius: 10px;
        padding: 0 8px;
    }

    .calendar-view-label {
        font-size: 0.76rem;
    }

    .nav-actions-right {
        gap: 6px;
        min-width: 0;
    }

}
