/* ==========================================================================
   CodeClass - application shell
   ========================================================================== */

.app {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: grid;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-areas:
        'brand header'
        'nav   main';
}

.app-student {
    grid-template-columns: 1fr;
    grid-template-areas:
        'header'
        'main';
}

/* ---- header ------------------------------------------------------------ */
.brand {
    grid-area: brand;
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: 0 var(--s4);
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    text-decoration: none;
    color: inherit;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--brand);
    color: var(--on-brand);
    flex: 0 0 auto;
}

.brand-name {
    font-family: var(--font-brand);
    font-size: 1.25rem;
    letter-spacing: -0.01em;
    line-height: 1;
}

.brand-sub {
    font-size: var(--text-2xs);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-4);
    line-height: 1;
    margin-top: 2px;
}

.topbar {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: 0 var(--s4);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
}

.topbar-title {
    font-size: var(--text-md);
    font-weight: 650;
    letter-spacing: -0.01em;
}

.topbar-crumb {
    display: flex;
    align-items: center;
    gap: var(--s2);
    font-size: var(--text-sm);
    color: var(--ink-3);
    min-width: 0;
}

/* ---- sync indicator ---------------------------------------------------- */
.sync-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--s2);
    height: 26px;
    padding: 0 var(--s2);
    border-radius: var(--r-pill);
    font-size: var(--text-xs);
    color: var(--ink-3);
    background: transparent;
    border: 1px solid transparent;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.sync-pill[data-state='saving'] { color: var(--ink-2); }
.sync-pill[data-state='offline'] { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.sync-pill[data-state='error'] { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }

/* ---- sidebar ----------------------------------------------------------- */
.sidenav {
    grid-area: nav;
    display: flex;
    flex-direction: column;
    gap: var(--s1);
    padding: var(--s3) var(--s2);
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: var(--s2) var(--s3);
    border-radius: var(--r);
    color: var(--ink-2);
    font-size: var(--text-sm);
    font-weight: 550;
    text-decoration: none;
    cursor: pointer;
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.nav-item:hover {
    background: var(--surface-3);
    color: var(--ink);
}

.nav-item[aria-current='page'] {
    background: var(--brand-soft);
    color: var(--brand-soft-ink);
    font-weight: 650;
}

.nav-item svg {
    flex: 0 0 auto;
    opacity: 0.85;
}

.nav-count {
    margin-left: auto;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    display: grid;
    place-items: center;
    border-radius: var(--r-pill);
    background: var(--attn);
    color: var(--surface);
    font-size: var(--text-2xs);
    font-weight: 700;
}

.nav-section {
    padding: var(--s4) var(--s3) var(--s1);
    font-size: var(--text-2xs);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-4);
}

.nav-foot {
    margin-top: auto;
    padding-top: var(--s3);
    border-top: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: var(--s1);
}

/* ---- collapsed to a rail ------------------------------------------------
   The same shape the layout takes at 1024, asked for deliberately. Screens
   that fill the window - grading, the live monitor - are the reason: 184px
   back is most of a column. */
.app.is-rail { grid-template-columns: var(--rail-w) 1fr; }
.app.is-rail .brand { justify-content: center; padding: 0; }
.app.is-rail .brand-text { display: none; }
.app.is-rail .nav-section { display: none; }
.app.is-rail .nav-item {
    justify-content: center;
    padding: var(--s2);
    position: relative;
}
.app.is-rail .nav-item span { display: none; }
.app.is-rail .nav-count {
    position: absolute;
    transform: translate(12px, -12px);
}
.app.is-rail .nav-toggle svg { transform: rotate(180deg); }

.nav-toggle {
    color: var(--ink-3);
    font-weight: 500;
}

/* Below 768 the nav is a bar along the bottom and there is nothing to
   collapse. */
@media (max-width: 768px) {
    .nav-toggle { display: none; }
}

/* ---- main -------------------------------------------------------------- */
.main {
    grid-area: main;
    overflow: auto;
    scroll-behavior: smooth;
}

.page {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--s6) var(--s6) var(--s16);
    display: flex;
    flex-direction: column;
    gap: var(--s5);
}

.page-wide {
    max-width: none;
}

.page-head {
    display: flex;
    align-items: flex-end;
    gap: var(--s4);
    flex-wrap: wrap;
}

.page-title {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    line-height: 1;
    letter-spacing: -0.02em;
}

.page-desc {
    color: var(--ink-3);
    font-size: var(--text-sm);
    max-width: 62ch;
    margin-top: var(--s2);
}

/* ---- split panes ------------------------------------------------------- */
.split {
    display: grid;
    height: 100%;
    min-height: 0;
}

.split-h {
    grid-auto-flow: column;
}

.resizer {
    position: relative;
    flex: 0 0 auto;
    background: var(--line);
    transition: background-color var(--dur) var(--ease);
}

.resizer-v {
    width: 1px;
    cursor: col-resize;
}

.resizer-h {
    height: 1px;
    cursor: row-resize;
}

.resizer::after {
    content: '';
    position: absolute;
    inset: -3px;
}

.resizer:hover,
.resizer[data-dragging='true'] {
    background: var(--brand);
}

/* ---- auth screens ------------------------------------------------------ */
.auth {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--s6);
    background:
        radial-gradient(1100px 620px at 12% -10%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 60%),
        radial-gradient(900px 520px at 108% 108%, color-mix(in srgb, var(--attn) 10%, transparent), transparent 62%);
}

.auth-card {
    width: min(400px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-3);
    padding: var(--s8);
    display: flex;
    flex-direction: column;
    gap: var(--s5);
    animation: rise var(--dur-slow) var(--ease);
}

@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
}

.auth-head {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    align-items: center;
    text-align: center;
}

.auth-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: 700;
    line-height: 1.05;
}

.auth-sub {
    color: var(--ink-3);
    font-size: var(--text-sm);
}

.pin-boxes {
    display: flex;
    gap: var(--s2);
    justify-content: center;
}

.pin-boxes input {
    width: 46px;
    height: 54px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    border: 1px solid var(--line-2);
    border-radius: var(--r);
    background: var(--surface-2);
    color: var(--ink);
    caret-color: var(--brand);
}

.pin-boxes input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
    background: var(--surface);
}

.pin-boxes input[data-filled='true'] {
    border-color: var(--line-strong);
}

.auth-alt {
    text-align: center;
    font-size: var(--text-xs);
    color: var(--ink-4);
}

.pin-field {
    font-family: var(--font-mono);
    letter-spacing: 0.28em;
}

.input-group > .btn {
    border-left-color: var(--line-2);
}

/* ---- misc shell -------------------------------------------------------- */
.swatch {
    width: 22px;
    height: 22px;
    border-radius: var(--r-sm);
    border: 1px solid rgba(0, 0, 0, 0.18);
    cursor: pointer;
    padding: 0;
    transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.swatch:hover { transform: scale(1.08); }

.swatch[aria-pressed='true'] {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink-3);
}

.field-inline {
    flex-direction: row;
    align-items: center;
    gap: var(--s3);
}

.boot {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: grid;
    place-items: center;
    background: var(--bg);
    gap: var(--s3);
}

.boot-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s3);
    color: var(--ink-3);
    font-size: var(--text-sm);
}

.demo-flag {
    position: fixed;
    right: var(--s3);
    bottom: var(--s3);
    z-index: var(--z-toast);
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: var(--s1) var(--s2);
    border-radius: var(--r-pill);
    background: var(--attn-soft);
    border: 1px solid color-mix(in srgb, var(--attn) 40%, transparent);
    color: var(--attn);
    font-size: var(--text-2xs);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    box-shadow: var(--shadow-2);
}

.demo-flag button {
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--r-sm);
    opacity: 0.8;
}

.demo-flag button:hover {
    background: color-mix(in srgb, var(--attn) 18%, transparent);
    opacity: 1;
}

.fatal {
    max-width: 560px;
    margin: var(--s16) auto;
    padding: var(--s6);
    background: var(--surface);
    border: 1px solid var(--bad);
    border-radius: var(--r-lg);
}

/* ---- responsive -------------------------------------------------------- */
@media (max-width: 1024px) {
    .app {
        grid-template-columns: var(--rail-w) 1fr;
    }

    .brand {
        justify-content: center;
        padding: 0;
    }

    .brand-text { display: none; }

    .nav-item {
        justify-content: center;
        padding: var(--s2);
    }

    .nav-item span,
    .nav-section {
        display: none;
    }

    .nav-count {
        position: absolute;
        transform: translate(12px, -12px);
    }

    .nav-item { position: relative; }

    .page { padding: var(--s5) var(--s4) var(--s12); }
}

@media (max-width: 768px) {
    /* The nav becomes a bar along the bottom. A page that wants to fill the
       screen exactly has to subtract it as well as the header, so its height
       is stated rather than left to the contents. */
    .app {
        --navbar-h: 50px;
        grid-template-columns: 1fr;
        grid-template-rows: var(--header-h) 1fr var(--navbar-h);
        grid-template-areas:
            'header'
            'main'
            'nav';
    }

    .brand { display: none; }

    .sidenav {
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        border-right: 0;
        border-top: 1px solid var(--line);
        padding: 0 var(--s2);
        position: sticky;
        bottom: 0;
        z-index: var(--z-sticky);
    }

    .nav-foot {
        display: none;
    }

    .page-title { font-size: var(--text-xl); }
}
