/* Terp Notes app styles: signed-in pages. Light, calm, one red accent (UMD).
   Mobile first; breakpoints at 640px (large phone), 900px (iPad) and 1200px (laptop). */

:root {
    --tn-ink: #14161a;
    --tn-ink-2: #3f454d;
    --tn-muted: #6b717a;
    --tn-line: #e8e6e1;
    --tn-line-strong: #d6d3cc;
    --tn-bg: #ffffff;
    --tn-soft: #f7f6f3;
    --tn-red: #e21833;
    --tn-red-ink: #b3112a;
    --tn-red-soft: #fdecee;
    --tn-warn-bg: #fff6e0;
    --tn-warn-ink: #8a5a00;
    --tn-ok: #157347;
    --tn-radius: 10px;
    --tn-shadow: 0 1px 2px rgba(20, 22, 26, 0.06), 0 8px 24px rgba(20, 22, 26, 0.06);
    --tn-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

.tn-app [hidden] { display: none !important; }

body.tn-app {
    background: var(--tn-bg);
    color: var(--tn-ink);
    font-family: var(--tn-font);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- app shell (views/partials/topnav.ejs) ----------
   Laptop: a fixed sidebar, like a workspace. Phone and small tablet: the same sidebar slides in
   as a drawer, with a slim top bar and a bottom tab bar for the things you reach for most. */
:root {
    --tn-side-w: 256px;
    --tn-tabbar-h: 58px;
    --tn-safe-b: env(safe-area-inset-bottom, 0px);
}
.tn-skip {
    position: fixed; top: 8px; left: 8px; z-index: 100;
    padding: 0.5rem 0.75rem; border-radius: 8px;
    background: var(--tn-ink); color: #fff; font-weight: 600; text-decoration: none;
    transform: translateY(-200%);
}
.tn-skip:focus { transform: none; }

body.tn-app { padding-left: var(--tn-side-w); }
/* Signed-out pages use the same body class but have no sidebar. */
body.tn-app:not(:has(.tn-side)) { padding-left: 0; }

.tn-side {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    width: var(--tn-side-w);
    display: flex; flex-direction: column;
    padding: 0.75rem 0.6rem calc(0.6rem + var(--tn-safe-b));
    background: var(--tn-soft);
    border-right: 1px solid var(--tn-line);
    overflow-y: auto;
    overscroll-behavior: contain;
}
.tn-side-top { display: flex; align-items: center; justify-content: space-between; padding: 0.15rem 0.35rem 0.6rem; }
.tn-side-brand { display: flex; align-items: center; gap: 0.55rem; color: var(--tn-ink); font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em; text-decoration: none; }
.tn-side .tn-side-close { display: none; }

.tn-side-search {
    display: flex; align-items: center; gap: 0.5rem;
    margin: 0 0.1rem 0.6rem; padding: 0 0.65rem; height: 36px;
    background: #fff; border: 1px solid var(--tn-line-strong); border-radius: 9px; color: var(--tn-muted);
}
.tn-side-search:focus-within { border-color: var(--tn-ink); box-shadow: 0 0 0 3px rgba(20, 22, 26, 0.08); }
.tn-side-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: 0; font: 400 0.92rem var(--tn-font); color: var(--tn-ink); -webkit-appearance: none; appearance: none; }

.tn-side-nav { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.tn-side-link {
    display: flex; align-items: center; gap: 0.6rem;
    min-height: 34px; padding: 0.35rem 0.55rem;
    border-radius: 7px; border: 0; background: none;
    color: var(--tn-ink-2); font: 500 0.92rem var(--tn-font); text-decoration: none; text-align: left; cursor: pointer;
    min-width: 0;
}
.tn-side-link svg { flex: none; color: var(--tn-muted); }
.tn-side-link span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tn-side-link:hover { background: rgba(20, 22, 26, 0.055); color: var(--tn-ink); }
.tn-side-link.is-active { background: rgba(20, 22, 26, 0.08); color: var(--tn-ink); font-weight: 600; }
.tn-side-link.is-active svg { color: var(--tn-ink); }

.tn-side-group { margin-top: 1.1rem; display: flex; flex-direction: column; gap: 1px; }
.tn-side-title { margin: 0 0 0.25rem; padding: 0 0.55rem; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--tn-muted); }
.tn-side-courses { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.tn-side-courses li { position: relative; display: flex; }
.tn-side-courses .tn-side-link { flex: 1; padding-right: 2rem; }
.tn-course-dot { flex: none; width: 8px; height: 8px; margin: 0 5px; border-radius: 3px; background: var(--tn-red); opacity: 0.85; }
.tn-side-remove {
    position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
    width: 28px; height: 28px; border: 0; border-radius: 6px; background: none;
    color: var(--tn-muted); font-size: 1.1rem; line-height: 1; cursor: pointer; opacity: 0;
}
.tn-side-courses li:hover .tn-side-remove, .tn-side-remove:focus-visible { opacity: 1; }
.tn-side-remove:hover { background: rgba(20, 22, 26, 0.08); color: var(--tn-ink); }
@media (hover: none) { .tn-side-remove { opacity: 0.7; } }
.tn-side-empty { margin: 0.1rem 0.55rem 0.35rem; font-size: 0.82rem; line-height: 1.4; color: var(--tn-muted); }
.tn-side-add { display: flex; align-items: center; gap: 0.6rem; min-height: 34px; padding: 0 0.55rem; border-radius: 7px; color: var(--tn-muted); }
.tn-side-add:hover, .tn-side-add:focus-within { background: rgba(20, 22, 26, 0.055); }
.tn-side-add input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: 0; font: 400 0.9rem var(--tn-font); color: var(--tn-ink); text-transform: uppercase; }
.tn-side-add input::placeholder { text-transform: none; color: var(--tn-muted); }
.tn-side-error { margin: 0.2rem 0.55rem 0; font-size: 0.8rem; color: var(--tn-red-ink); }

.tn-side-foot { margin-top: 1rem; padding-top: 0.6rem; border-top: 1px solid var(--tn-line); display: flex; flex-direction: column; gap: 0.35rem; }
.tn-side-user { display: flex; align-items: center; gap: 0.6rem; padding: 0.3rem 0.2rem 0.1rem 0.45rem; min-width: 0; }
.tn-side-user-name { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.tn-side-user-name strong { font-size: 0.88rem; font-weight: 600; color: var(--tn-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tn-side-user-name small { font-size: 0.76rem; color: var(--tn-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tn-avatar {
    flex: none; display: inline-grid; place-items: center;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--tn-ink); color: #fff; font: 600 0.72rem var(--tn-font); letter-spacing: 0.02em; text-decoration: none;
}

.tn-mobilebar, .tn-tabbar, .tn-scrim { display: none; }

@media (max-width: 899px) {
    body.tn-app { padding-left: 0; padding-bottom: calc(var(--tn-tabbar-h) + var(--tn-safe-b)); }
    body.tn-app:not(:has(.tn-side)) { padding-bottom: 0; }

    .tn-mobilebar {
        position: sticky; top: 0; z-index: 40;
        display: flex; align-items: center; gap: 0.25rem;
        height: calc(52px + env(safe-area-inset-top, 0px));
        padding: env(safe-area-inset-top, 0px) 0.6rem 0 0.35rem;
        background: rgba(255, 255, 255, 0.94);
        -webkit-backdrop-filter: saturate(180%) blur(12px); backdrop-filter: saturate(180%) blur(12px);
        border-bottom: 1px solid var(--tn-line);
    }
    .tn-mobilebar .tn-icon-btn { width: 44px; height: 44px; color: var(--tn-ink); }
    .tn-mobilebar-brand { flex: 1; display: flex; align-items: center; gap: 0.5rem; color: var(--tn-ink); font-weight: 700; font-size: 1rem; text-decoration: none; }

    .tn-side {
        z-index: 70; width: min(86vw, 320px);
        padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
        transform: translateX(-102%); visibility: hidden;
        transition: transform 0.22s ease, visibility 0s linear 0.22s;
        box-shadow: var(--tn-shadow);
    }
    .side-open .tn-side { transform: none; visibility: visible; transition: transform 0.22s ease; }
    .tn-side .tn-side-close { display: inline-grid; width: 44px; height: 44px; }
    .tn-side-link, .tn-side-add { min-height: 44px; font-size: 1rem; }
    .tn-side-search { height: 44px; }
    .tn-side-search input, .tn-side-add input { font-size: 1rem; }
    .tn-side-remove { width: 40px; height: 40px; }
    .tn-scrim { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(20, 22, 26, 0.35); }
    .side-open { overflow: hidden; }

    .tn-tabbar {
        position: fixed; inset: auto 0 0 0; z-index: 45;
        display: flex; align-items: stretch; justify-content: space-around;
        height: calc(var(--tn-tabbar-h) + var(--tn-safe-b));
        padding: 0 0.25rem var(--tn-safe-b);
        background: rgba(255, 255, 255, 0.96);
        -webkit-backdrop-filter: saturate(180%) blur(12px); backdrop-filter: saturate(180%) blur(12px);
        border-top: 1px solid var(--tn-line);
    }
    .tn-tab {
        flex: 1; min-width: 0;
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
        border: 0; background: none; padding: 0;
        color: var(--tn-muted); font: 500 0.68rem var(--tn-font); text-decoration: none; cursor: pointer;
    }
    .tn-tab.is-active { color: var(--tn-ink); font-weight: 600; }
    .tn-tab-plus { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: var(--tn-ink); color: #fff; }
    .is-selecting .tn-tabbar { display: none; }
}
@media (prefers-reduced-motion: reduce) { .tn-side { transition: none !important; } }

/* Legacy page wrappers sit inside the shell without their own full-bleed backgrounds. */
.tn-app:has(.tn-side) .tn-footer { margin-top: 2rem; }

/* ---------- page ---------- */
.tn-page {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 3vw, 2rem) 6rem;
}
.tn-page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.tn-page-head h1 {
    font-size: clamp(1.75rem, 3.5vw, 2.4rem);
    font-weight: 650;
    letter-spacing: -0.025em;
    line-height: 1.1;
    margin: 0 0 0.35rem;
    color: var(--tn-ink);
    background: none;
    -webkit-text-fill-color: currentColor;
}
.tn-sub { color: var(--tn-muted); margin: 0; font-size: 0.98rem; }

/* ---------- buttons ---------- */
.tn-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 40px;
    padding: 0.55rem 1rem;
    border-radius: var(--tn-radius);
    border: 1px solid transparent;
    font: 600 0.93rem/1.1 var(--tn-font);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.tn-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.tn-btn-primary { background: var(--tn-ink); color: #fff; }
.tn-btn-primary:hover:not(:disabled) { background: #2b2f36; color: #fff; }
.tn-btn-outline { background: #fff; color: var(--tn-ink); border-color: var(--tn-line-strong); }
.tn-btn-outline:hover:not(:disabled) { border-color: var(--tn-ink-2); color: var(--tn-ink); }
.tn-btn-danger { background: var(--tn-red); color: #fff; }
.tn-btn-danger:hover { background: var(--tn-red-ink); }
.tn-btn-sm { min-height: 34px; padding: 0.4rem 0.75rem; font-size: 0.86rem; }
.tn-danger-text { color: var(--tn-red-ink) !important; }
.tn-link { background: none; border: 0; padding: 0.25rem 0; color: var(--tn-ink-2); font: 500 0.92rem var(--tn-font); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--tn-line-strong); }
.tn-link:hover { color: var(--tn-ink); text-decoration-color: currentColor; }
.tn-icon-btn {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 0;
    background: none;
    color: var(--tn-muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    list-style: none;
}
.tn-icon-btn::-webkit-details-marker { display: none; }
.tn-icon-btn:hover { background: var(--tn-soft); color: var(--tn-ink); }
:where(.tn-app) :focus-visible { outline: 2px solid var(--tn-ink); outline-offset: 2px; }

/* ---------- notices ---------- */
.tn-notice {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 0.75rem 0.75rem 1rem;
    border-radius: var(--tn-radius);
    background: var(--tn-soft);
    border: 1px solid var(--tn-line);
    margin-bottom: 1rem;
    color: var(--tn-ink-2);
}
.tn-notice p { margin: 0.35rem 0 0; flex: 1; font-size: 0.95rem; }
.tn-notice strong { color: var(--tn-ink); }
.tn-notice-warning { background: var(--tn-warn-bg); border-color: #f3dfaa; }
.tn-notice-error { background: var(--tn-red-soft); border-color: #f6c6cd; }
.tn-notice .tn-icon-btn { width: 30px; height: 30px; font-size: 1.2rem; }

/* ---------- toolbar ---------- */
.tn-toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}
.tn-search { position: relative; }
.tn-search svg { position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); color: var(--tn-muted); pointer-events: none; }
.tn-search input {
    width: 100%;
    height: 46px;
    padding: 0 1rem 0 2.6rem;
    border: 1px solid var(--tn-line-strong);
    border-radius: 12px;
    font: 400 1rem var(--tn-font);
    color: var(--tn-ink);
    background: #fff;
    -webkit-appearance: none;
    appearance: none;
}
.tn-search input:focus { outline: none; border-color: var(--tn-ink); box-shadow: 0 0 0 3px rgba(20, 22, 26, 0.08); }
.tn-filters-toggle { height: 46px; border-radius: 12px; }
.tn-count {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--tn-ink);
    color: #fff;
    font-size: 0.75rem;
}
.tn-filters {
    grid-column: 1 / -1;
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
    padding: 0.85rem;
    border: 1px solid var(--tn-line);
    border-radius: 12px;
    background: var(--tn-soft);
}
.tn-filters.is-open { display: grid; }
.tn-field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.tn-field > span, .tn-field > label { font-size: 0.8rem; font-weight: 600; color: var(--tn-ink-2); }
.tn-app select, .tn-dialog input[type="text"], .tn-dialog textarea {
    width: 100%;
    min-height: 40px;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--tn-line-strong);
    border-radius: 9px;
    background-color: #fff;
    font: 400 0.95rem var(--tn-font);
    color: var(--tn-ink);
}
.tn-app select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b717a' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
}
.tn-app select:focus, .tn-dialog input:focus, .tn-dialog textarea:focus { outline: none; border-color: var(--tn-ink); box-shadow: 0 0 0 3px rgba(20, 22, 26, 0.08); }
.tn-switch { display: flex; align-items: center; gap: 0.5rem; font-size: 0.92rem; font-weight: 500; color: var(--tn-ink); cursor: pointer; align-self: end; min-height: 40px; }
.tn-switch input { width: 18px; height: 18px; accent-color: var(--tn-ink); }

@media (min-width: 900px) {
    .tn-toolbar { grid-template-columns: 1fr; }
    .tn-filters-toggle { display: none; }
    .tn-filters {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
        padding: 0;
        border: 0;
        background: none;
        align-items: end;
    }
}

.tn-results-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0 0.25rem;
    color: var(--tn-muted);
    font-size: 0.9rem;
}
.tn-results-head p { margin: 0; }
.tn-results-actions { display: flex; gap: 1rem; }

/* ---------- file list ---------- */
.tn-files { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--tn-line); }
.tn-file {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.9rem;
    align-items: start;
    padding: 1rem 0.25rem;
    border-bottom: 1px solid var(--tn-line);
}
.is-selecting .tn-file { grid-template-columns: auto auto minmax(0, 1fr) auto; cursor: pointer; }
.tn-file.is-selected { background: var(--tn-soft); }
.tn-file-check { display: grid; place-items: center; height: 42px; }
.tn-file-check input { width: 20px; height: 20px; accent-color: var(--tn-ink); }
.tn-file-type {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 9px;
    background: var(--tn-soft);
    border: 1px solid var(--tn-line);
    color: var(--tn-ink-2);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}
.tn-type-pdf { background: #fdecee; border-color: #f7d3d8; color: #a3122a; }
.tn-type-docx, .tn-type-doc { background: #eaf1fd; border-color: #d3e1f9; color: #1f4fa3; }
.tn-type-pptx, .tn-type-ppt { background: #fdf0e7; border-color: #f6dcc8; color: #a4470f; }
.tn-type-xlsx, .tn-type-xls, .tn-type-csv { background: #e9f6ee; border-color: #cfe9d9; color: #17683b; }
.tn-file-main { min-width: 0; }
.tn-file-name {
    display: block;
    color: var(--tn-ink);
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.35;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tn-file-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.tn-file-meta, .tn-file-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.85rem; margin-top: 0.35rem; font-size: 0.86rem; color: var(--tn-ink-2); }
.tn-file-sub { color: var(--tn-muted); font-size: 0.82rem; }
.tn-file-desc { margin: 0.35rem 0 0; font-size: 0.9rem; color: var(--tn-ink-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tn-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.5rem;
    border-radius: 6px;
    background: var(--tn-ink);
    color: #fff;
    font: 600 0.78rem/1.5 var(--tn-font);
    letter-spacing: 0.02em;
    border: 0;
    cursor: pointer;
}
.tn-chip:hover { background: var(--tn-red); }
.tn-cat { font-weight: 500; }
.tn-staff { margin-left: 0.35rem; padding: 0 0.4rem; border-radius: 5px; background: #eaf1fd; color: #1f4fa3; font-size: 0.72rem; font-weight: 600; }
.tn-badges { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.tn-badge { font-size: 0.74rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--tn-soft); color: var(--tn-ink-2); border: 1px solid var(--tn-line); }
.tn-badge-warn { background: var(--tn-warn-bg); color: var(--tn-warn-ink); border-color: #f3dfaa; }
.tn-badge-error { background: var(--tn-red-soft); color: var(--tn-red-ink); border-color: #f6c6cd; }
.tn-file-actions { display: flex; align-items: center; gap: 0.25rem; }
.tn-file-actions .tn-btn span { display: none; }
@media (min-width: 640px) {
    .tn-file-actions .tn-btn span { display: inline; }
}

/* row menu */
.tn-menu { position: relative; }
.tn-menu summary { list-style: none; }
.tn-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 30;
    min-width: 190px;
    padding: 0.35rem;
    background: #fff;
    border: 1px solid var(--tn-line);
    border-radius: 12px;
    box-shadow: var(--tn-shadow);
    display: flex;
    flex-direction: column;
}
.tn-menu-list a, .tn-menu-list button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    border: 0;
    background: none;
    font: 500 0.92rem var(--tn-font);
    color: var(--tn-ink);
    text-decoration: none;
    cursor: pointer;
}
.tn-menu-list a:hover, .tn-menu-list button:hover { background: var(--tn-soft); }

.tn-more { display: flex; justify-content: center; margin-top: 1.5rem; }
.tn-empty { text-align: center; padding: 3.5rem 1rem; border-bottom: 1px solid var(--tn-line); }
.tn-empty h2 { font-size: 1.25rem; margin: 0 0 0.4rem; color: var(--tn-ink); }
.tn-empty p { color: var(--tn-muted); margin: 0 0 1.25rem; }
.tn-empty-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

/* select bar */
.tn-selectbar {
    position: fixed;
    left: 50%;
    bottom: max(1rem, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 45;
    width: min(680px, calc(100% - 1.5rem));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.6rem 0.6rem 0.6rem 1.1rem;
    background: #fff;
    border: 1px solid var(--tn-line);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(20, 22, 26, 0.16);
    font-weight: 600;
    font-size: 0.93rem;
}
.tn-selectbar[hidden] { display: none; }
.tn-selectbar > div { display: flex; gap: 0.4rem; }
@media (max-width: 520px) {
    .tn-selectbar { flex-direction: column; align-items: stretch; padding: 0.75rem; }
    .tn-selectbar > div { justify-content: stretch; }
    .tn-selectbar > div .tn-btn { flex: 1; }
}

/* On laptops the select bar centers on the page, not the window (the sidebar takes the left). */
@media (min-width: 900px) { .tn-app:has(.tn-side) .tn-selectbar { left: calc(50% + var(--tn-side-w) / 2); width: min(680px, calc(100% - var(--tn-side-w) - 1.5rem)); } }
.tn-selectbar > div { flex-wrap: wrap; justify-content: flex-end; }
/* Phones upload from the tab bar's + button. */
@media (max-width: 639px) { .tn-page-head .tn-btn-primary { display: none; } }

/* ---------- dialogs ---------- */
.tn-dialog {
    width: min(640px, calc(100% - 2rem));
    max-height: min(90vh, 900px);
    padding: 0;
    border: 0;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(20, 22, 26, 0.25);
    color: var(--tn-ink);
    font-family: var(--tn-font);
    margin: auto;
}
.tn-dialog-sm { width: min(440px, calc(100% - 2rem)); }
.tn-dialog::backdrop { background: rgba(20, 22, 26, 0.45); }
.tn-dialog form { display: flex; flex-direction: column; max-height: inherit; }
.tn-dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1rem 0.5rem 1.4rem; }
.tn-dialog-head h2, .tn-dialog-body h2 { margin: 0; font-size: 1.2rem; font-weight: 650; letter-spacing: -0.01em; }
.tn-dialog-body { padding: 0.5rem 1.4rem 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.9rem; }
.tn-dialog-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.9rem 1.4rem; border-top: 1px solid var(--tn-line); background: #fff; }
.tn-dialog .tn-field label { font-size: 0.85rem; font-weight: 600; color: var(--tn-ink-2); }
.tn-req { color: var(--tn-red); }
.tn-help { font-size: 0.82rem; color: var(--tn-muted); margin: 0; }
.tn-help.ok { color: var(--tn-ok); font-weight: 500; }
.tn-error { color: var(--tn-red-ink); font-size: 0.8rem; }
.tn-error:empty { display: none; }
[aria-invalid="true"] { border-color: var(--tn-red) !important; }
.tn-grid-2, .tn-grid-3 { display: grid; gap: 0.9rem; }
@media (min-width: 560px) {
    .tn-grid-2 { grid-template-columns: 1fr 1fr; }
    .tn-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
}
.tn-check { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.9rem; line-height: 1.45; color: var(--tn-ink-2); cursor: pointer; }
.tn-check input { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; accent-color: var(--tn-ink); }
.tn-radios { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.55rem; }
.tn-editing { font-weight: 600; margin: 0; word-break: break-word; }
.tn-visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tn-drop { border: 1.5px dashed var(--tn-line-strong); border-radius: 12px; padding: 1rem; text-align: center; transition: background 0.15s, border-color 0.15s; }
.tn-drop.is-over { background: var(--tn-soft); border-color: var(--tn-ink); }
.tn-drop-label { display: block; cursor: pointer; color: var(--tn-ink-2); padding: 0.75rem 0; }
.tn-drop-label strong { color: var(--tn-ink); text-decoration: underline; text-underline-offset: 3px; }
.tn-drop-label span { display: block; margin-top: 0.3rem; font-size: 0.8rem; color: var(--tn-muted); }
.tn-picked { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; text-align: left; }
.tn-picked li { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.4rem 0.4rem 0.5rem; border: 1px solid var(--tn-line); border-radius: 10px; }
.tn-picked li.is-bad { border-color: #f6c6cd; background: var(--tn-red-soft); }
.tn-picked .tn-file-type { width: 34px; height: 34px; font-size: 0.6rem; }
.tn-picked-name { flex: 1; min-width: 0; font-size: 0.9rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tn-picked-name small { display: block; color: var(--tn-muted); font-weight: 400; }
.tn-progress { height: 6px; border-radius: 999px; background: var(--tn-soft); overflow: hidden; }
.tn-progress > div { height: 100%; width: 0; background: var(--tn-ink); transition: width 0.2s ease; }
@media (max-width: 559px) {
    .tn-dialog { width: 100%; max-width: 100%; max-height: 100%; height: 100%; margin: 0; border-radius: 0; }
    .tn-dialog-sm { inset: auto 0 0 0; height: auto; margin: 0; border-radius: 16px 16px 0 0; }
    .tn-dialog-foot { padding-bottom: max(0.9rem, env(safe-area-inset-bottom)); }
    .tn-dialog-foot .tn-btn { flex: 1; }
}

/* course combobox (public/javascripts/course-picker.js) */
.combo { position: relative; }
.combo-list {
    position: absolute;
    z-index: 20;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    margin: 0;
    padding: 0.25rem;
    list-style: none;
    background: #fff;
    border: 1px solid var(--tn-line);
    border-radius: 10px;
    box-shadow: var(--tn-shadow);
    max-height: 260px;
    overflow-y: auto;
}
.combo-list li { padding: 0.5rem 0.65rem; border-radius: 7px; cursor: pointer; display: flex; flex-direction: column; }
.combo-list li:hover, .combo-list li[aria-selected="true"] { background: var(--tn-soft); }
.combo-main { font-weight: 600; font-size: 0.9rem; color: var(--tn-ink); }
.combo-detail { color: var(--tn-muted); font-size: 0.8rem; }

/* "My courses" add field: suggestions drop down under the field in the sidebar. Course names can
   be typed too, so the field only looks uppercase when there's no catalog to search. */
.tn-side-add.combo .combo-list { left: -0.1rem; right: -0.1rem; color: var(--tn-ink); }
.tn-side-add[data-catalog] input { text-transform: none; }
.combo-list li .combo-detail { white-space: normal; }

/* toasts */
.tn-toasts { position: fixed; top: calc(70px + env(safe-area-inset-top)); right: 1rem; left: 1rem; z-index: 60; display: flex; flex-direction: column; align-items: flex-end; gap: 0.5rem; pointer-events: none; }
.tn-toast {
    pointer-events: auto;
    max-width: 420px;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    background: var(--tn-ink);
    color: #fff;
    font-size: 0.92rem;
    line-height: 1.4;
    box-shadow: 0 10px 30px rgba(20, 22, 26, 0.2);
    animation: tn-in 0.2s ease;
}
.tn-toast-error { background: var(--tn-red-ink); }
.tn-toast.leaving { opacity: 0; transform: translateY(-4px); transition: all 0.2s ease; }
@keyframes tn-in { from { opacity: 0; transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .tn-toast { animation: none; } }

/* simple content pages (study, staff, AI access, profile) */
.tn-app main.study, .tn-app main.staff-wrap, .tn-app main.wrap { max-width: 860px; margin: 0 auto; padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 3vw, 2rem) 4rem; }
.tn-app main h1 { font-size: clamp(1.75rem, 3.5vw, 2.4rem); font-weight: 650; letter-spacing: -0.025em; color: var(--tn-ink); background: none; -webkit-text-fill-color: currentColor; }
.tn-app .button.primary { background: var(--tn-ink); border-color: var(--tn-ink); color: #fff; border-radius: var(--tn-radius); box-shadow: none; }
.tn-app .button.primary:hover { background: #2b2f36; }

/* sign-in and sign-up forms: labels and help line up with their fields */
.tn-app .auth-form .form-group, .tn-app .auth-form .form-group label, .tn-app .auth-form .form-group small { text-align: left; }
.tn-app .auth-form .form-group label { display: block; }

/* integrations: same button language as the rest of the app */
.integrations-page .btn-primary { background: var(--tn-ink); border-color: var(--tn-ink); color: #fff; }
.integrations-page .btn-primary:hover { background: #2b2f36; }
.integrations-page .btn-secondary { background: #fff; color: var(--tn-ink); border: 1px solid var(--tn-line-strong); }

/* admin: calm sections, same cards as everywhere else */
.tn-app .admin-stats { border: 1px solid var(--tn-line); box-shadow: none; border-radius: 14px; background: #fff; }
.tn-app section.reports-section, .tn-app section.announcements-section, .tn-app section.users-section {
    background: #fff;
    border: 1px solid var(--tn-line);
    border-radius: 14px;
    box-shadow: none;
}
.tn-app section.reports-section h2, .tn-app section.announcements-section h2, .tn-app section.users-section h2 {
    color: var(--tn-ink);
    -webkit-text-fill-color: currentColor;
    background: none;
    font-weight: 650;
    letter-spacing: -0.015em;
}
@media (max-width: 640px) {
    body.tn-app .admin-stats { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 0.75rem !important; padding: 1rem !important; }
    body.tn-app .admin-stats .admin-stat-card { padding: 0.5rem !important; }
}

/* ======================================================================
   Public pages: home, sign-in, sign-up, password reset, status pages,
   legal and contact. Same tokens as the app; no gradients.
   ====================================================================== */
.tn-pubnav {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem clamp(1rem, 3vw, 2rem);
    padding-top: max(0.75rem, env(safe-area-inset-top));
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--tn-line);
}
.tn-brand { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--tn-ink); text-decoration: none; font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.tn-brand img { width: 28px; height: 28px; }
.tn-pubnav-links { display: flex; align-items: center; gap: 0.5rem; }
.tn-pubnav-link { color: var(--tn-ink-2); text-decoration: none; font-weight: 500; font-size: 0.93rem; padding: 0.45rem 0.75rem; border-radius: 8px; }
.tn-pubnav-link:hover { background: var(--tn-soft); color: var(--tn-ink); }
.tn-btn:focus-visible, .tn-pubnav-link:focus-visible, .tn-brand:focus-visible, .tn-input:focus-visible { outline: 2px solid var(--tn-ink); outline-offset: 2px; }
.tn-btn-lg { min-height: 48px; padding: 0.75rem 1.4rem; font-size: 1rem; }
.tn-btn-block { width: 100%; }
a.tn-btn-primary, a.tn-btn-primary:visited { color: #fff; }
a.tn-btn-outline, a.tn-btn-outline:visited { color: var(--tn-ink); }

/* centered single-card pages */
.tn-center {
    min-height: calc(100vh - 140px);
    min-height: calc(100dvh - 140px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: clamp(1.5rem, 6vh, 4.5rem) 1rem 4rem;
}
.tn-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border: 1px solid var(--tn-line);
    border-radius: 16px;
    padding: clamp(1.5rem, 4vw, 2.25rem);
}
.tn-card-wide { max-width: 520px; }
.tn-app .tn-card h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; margin: 0 0 0.4rem; color: var(--tn-ink); background: none; -webkit-text-fill-color: currentColor; text-align: left; }
.tn-card .tn-sub { margin-bottom: 1.5rem; }
.tn-form { display: flex; flex-direction: column; gap: 1rem; }
.tn-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 420px) { .tn-form-row { grid-template-columns: 1fr; } }
.tn-label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.88rem; font-weight: 600; color: var(--tn-ink); }
.tn-label-row { display: flex; justify-content: space-between; align-items: baseline; }
.tn-label-row a { font-weight: 500; font-size: 0.85rem; }
.tn-input {
    width: 100%;
    min-height: 44px;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--tn-line-strong);
    border-radius: var(--tn-radius);
    background: #fff;
    color: var(--tn-ink);
    font: 400 1rem var(--tn-font); /* 16px stops iOS from zooming in */
    box-shadow: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea.tn-input { min-height: 140px; resize: vertical; line-height: 1.5; }
.tn-input:hover { border-color: var(--tn-ink-2); }
.tn-input:focus { outline: none; border-color: var(--tn-ink); box-shadow: 0 0 0 3px rgba(20, 22, 26, 0.08); }
.tn-input[readonly], .tn-input:disabled { background: var(--tn-soft); color: var(--tn-muted); cursor: not-allowed; }
.tn-input.is-invalid { border-color: var(--tn-red); }
.tn-help { font-size: 0.82rem; font-weight: 400; color: var(--tn-muted); line-height: 1.45; }
.tn-check { display: flex; align-items: flex-start; gap: 0.6rem; font-size: 0.92rem; font-weight: 400; color: var(--tn-ink-2); line-height: 1.45; cursor: pointer; }
.tn-check input { width: 18px; height: 18px; margin: 0.1rem 0 0; flex: none; accent-color: var(--tn-ink); }
.tn-check a { color: var(--tn-ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.tn-rules { list-style: none; margin: 0.15rem 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0.2rem 0.75rem; font-size: 0.8rem; font-weight: 400; color: var(--tn-muted); }
.tn-rules li::before { content: "○"; display: inline-block; width: 1.1em; }
.tn-rules li.is-met { color: var(--tn-ok); }
.tn-rules li.is-met::before { content: "✓"; }
.tn-alt { margin: 1.5rem 0 0; text-align: center; font-size: 0.92rem; color: var(--tn-muted); }
.tn-alt a, .tn-card a:not(.tn-btn) { color: var(--tn-ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--tn-line-strong); }
.tn-alt a:hover, .tn-card a:not(.tn-btn):hover { text-decoration-color: currentColor; }
.tn-alert { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.75rem 0.9rem; border-radius: var(--tn-radius); font-size: 0.9rem; line-height: 1.45; border: 1px solid var(--tn-line); background: var(--tn-soft); color: var(--tn-ink); margin: 0 0 1rem; }
.tn-alert-error { background: var(--tn-red-soft); border-color: #f6c6cd; color: var(--tn-red-ink); }
.tn-alert-warn { background: var(--tn-warn-bg); border-color: #f3dfaa; color: var(--tn-warn-ink); }
.tn-alert-ok { background: #ecf7f0; border-color: #cfe9d9; color: #17683b; }
.tn-alert ul { margin: 0.25rem 0 0; padding-left: 1.1rem; }

/* status pages: success, error, 404, verify email, log out, download warning */
.tn-status { text-align: center; }
.tn-app .tn-status h1 { text-align: center; }
.tn-status .tn-sub { margin-bottom: 1.5rem; }
.tn-status-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 1.1rem; background: var(--tn-soft); color: var(--tn-ink); }
.tn-status-icon.is-ok { background: #ecf7f0; color: var(--tn-ok); }
.tn-status-icon.is-error { background: var(--tn-red-soft); color: var(--tn-red); }
.tn-status-icon.is-warn { background: var(--tn-warn-bg); color: var(--tn-warn-ink); }
.tn-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; }
.tn-actions-stack { flex-direction: column; }
.tn-status .tn-alert { text-align: left; }

/* home */
.tn-home { overflow-x: clip; }
.tn-hero { max-width: 880px; margin: 0 auto; padding: clamp(3rem, 10vh, 6.5rem) 1.25rem clamp(2rem, 6vh, 3.5rem); text-align: center; }
.tn-eyebrow { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.02em; color: var(--tn-ink-2); background: var(--tn-soft); border: 1px solid var(--tn-line); padding: 0.3rem 0.75rem; border-radius: 999px; margin-bottom: 1.4rem; }
.tn-eyebrow i { width: 7px; height: 7px; border-radius: 50%; background: var(--tn-red); display: inline-block; }
.tn-app .tn-hero h1 { font-size: clamp(2.5rem, 7vw, 4.4rem); font-weight: 650; letter-spacing: -0.035em; line-height: 1.02; margin: 0 0 1.1rem; color: var(--tn-ink); background: none; -webkit-text-fill-color: currentColor; }
.tn-app .tn-hero h1 span { color: var(--tn-muted); }
.tn-app .tn-hero p { font-size: clamp(1.05rem, 2.2vw, 1.25rem); color: var(--tn-ink-2); max-width: 600px; margin: 0 auto 2rem; line-height: 1.5; }
.tn-hero .tn-actions { margin-bottom: 1rem; }
.tn-app .tn-hero .tn-fine, .tn-app .tn-fine, .tn-fine { font-size: 0.85rem; color: var(--tn-muted); margin: 0; }
.tn-preview { max-width: 980px; margin: 0 auto; padding: 0 1.25rem; }
.tn-preview-frame { border: 1px solid var(--tn-line); border-radius: 18px; background: #fff; box-shadow: var(--tn-shadow); overflow: hidden; }
.tn-preview-bar { display: flex; align-items: center; gap: 0.6rem; padding: 0.85rem 1.1rem; border-bottom: 1px solid var(--tn-line); background: var(--tn-soft); }
.tn-preview-bar .tn-fake-search { flex: 1; display: flex; align-items: center; gap: 0.5rem; background: #fff; border: 1px solid var(--tn-line); border-radius: 10px; padding: 0.5rem 0.75rem; color: var(--tn-muted); font-size: 0.9rem; min-width: 0; white-space: nowrap; overflow: hidden; }
.tn-preview-bar .tn-fake-search b { color: var(--tn-ink); font-weight: 500; }
.tn-preview .tn-files { border-top: 0; padding: 0 1.1rem; }
.tn-preview .tn-file { grid-template-columns: auto minmax(0, 1fr) auto; }
.tn-preview .tn-file:last-child { border-bottom: 0; }
.tn-section { max-width: 1080px; margin: 0 auto; padding: clamp(3.5rem, 10vh, 6rem) 1.25rem; }
.tn-section-head { max-width: 640px; margin-bottom: 2.25rem; }
.tn-section-head .tn-kicker { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--tn-red); margin: 0 0 0.6rem; }
.tn-app .tn-section-head h2 { font-size: clamp(1.75rem, 4vw, 2.6rem); font-weight: 650; letter-spacing: -0.03em; line-height: 1.1; margin: 0 0 0.75rem; color: var(--tn-ink); background: none; -webkit-text-fill-color: currentColor; }
.tn-section-head p { color: var(--tn-ink-2); font-size: 1.05rem; line-height: 1.55; margin: 0; }
.tn-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 900px) { .tn-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .tn-grid { grid-template-columns: 1fr; } }
.tn-feature { border: 1px solid var(--tn-line); border-radius: 14px; padding: 1.4rem; background: #fff; }
.tn-feature svg { color: var(--tn-ink); margin-bottom: 1rem; }
.tn-feature h3 { font-size: 1.05rem; font-weight: 650; margin: 0 0 0.4rem; color: var(--tn-ink); letter-spacing: -0.01em; }
.tn-feature p { margin: 0; color: var(--tn-ink-2); font-size: 0.95rem; line-height: 1.55; }
.tn-steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 760px) { .tn-steps { grid-template-columns: 1fr; } }
.tn-steps li { counter-increment: step; border-top: 2px solid var(--tn-ink); padding-top: 1rem; }
.tn-steps li::before { content: "0" counter(step); display: block; font-size: 0.85rem; font-weight: 700; color: var(--tn-muted); margin-bottom: 0.5rem; font-variant-numeric: tabular-nums; }
.tn-steps h3 { margin: 0 0 0.35rem; font-size: 1.1rem; font-weight: 650; color: var(--tn-ink); }
.tn-steps p { margin: 0; color: var(--tn-ink-2); line-height: 1.55; }
.tn-band { background: var(--tn-soft); border-top: 1px solid var(--tn-line); border-bottom: 1px solid var(--tn-line); }
.tn-faq { max-width: 760px; }
.tn-faq details { border-bottom: 1px solid var(--tn-line); padding: 1rem 0; }
.tn-faq details:first-of-type { border-top: 1px solid var(--tn-line); }
.tn-faq summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 1rem; font-weight: 600; font-size: 1.02rem; color: var(--tn-ink); }
.tn-faq summary::-webkit-details-marker { display: none; }
.tn-faq summary::after { content: "+"; font-weight: 400; font-size: 1.35rem; line-height: 1; color: var(--tn-muted); transition: transform 0.15s ease; }
.tn-faq details[open] summary::after { transform: rotate(45deg); }
.tn-faq details p { margin: 0.6rem 0 0; color: var(--tn-ink-2); line-height: 1.6; }
.tn-faq a { color: var(--tn-ink); text-decoration: underline; text-underline-offset: 3px; }
.tn-cta { text-align: center; }
.tn-app .tn-cta h2 { font-size: clamp(1.75rem, 4vw, 2.6rem); font-weight: 650; letter-spacing: -0.03em; margin: 0 0 0.75rem; color: var(--tn-ink); background: none; -webkit-text-fill-color: currentColor; }
.tn-cta p { color: var(--tn-ink-2); margin: 0 auto 1.75rem; max-width: 520px; font-size: 1.05rem; }

/* legal and contact: readable prose */
.tn-prose { max-width: 720px; margin: 0 auto; padding: clamp(2rem, 6vh, 3.5rem) 1.25rem 5rem; color: var(--tn-ink-2); line-height: 1.7; font-size: 1rem; }
.tn-app .tn-prose h1 { font-size: clamp(2rem, 5vw, 2.6rem); font-weight: 650; letter-spacing: -0.03em; line-height: 1.1; color: var(--tn-ink); margin: 0 0 0.5rem; background: none; -webkit-text-fill-color: currentColor; }
.tn-app .tn-prose h2 { font-size: 1.25rem; font-weight: 650; color: var(--tn-ink); letter-spacing: -0.01em; margin: 2.25rem 0 0.6rem; border: 0; padding: 0; background: none; -webkit-text-fill-color: currentColor; }
.tn-prose h3 { font-size: 1.05rem; font-weight: 650; color: var(--tn-ink); margin: 1.5rem 0 0.4rem; }
.tn-prose a { color: var(--tn-ink); text-decoration: underline; text-underline-offset: 3px; }
.tn-prose ul { padding-left: 1.25rem; }
.tn-prose .tn-meta { color: var(--tn-muted); font-size: 0.9rem; margin: 0 0 2rem; }
.tn-app .legal-content, .tn-app .legal-content * { background: none !important; box-shadow: none !important; }
.tn-app .legal-content [style*="border"] { border-color: var(--tn-line) !important; }
.tn-app .legal-content h1, .tn-app .legal-content h2, .tn-app .legal-content h3, .tn-app .legal-content h4 { color: var(--tn-ink) !important; -webkit-text-fill-color: currentColor; border-bottom: 0 !important; }
.tn-app .legal-content strong { color: var(--tn-ink); }

/* profile: flat sections with the app's buttons */
.tn-app .profile-page { max-width: 720px; margin: 0 auto; }
.tn-app .profile-section { background: #fff !important; border: 1px solid var(--tn-line) !important; border-radius: 14px !important; box-shadow: none !important; padding: clamp(1.25rem, 3vw, 1.75rem) !important; }
.tn-app .profile-section::before, .tn-app .profile-section::after { display: none !important; }
.tn-app .profile-section h2 { color: var(--tn-ink) !important; -webkit-text-fill-color: currentColor !important; background: none !important; font-size: 1.15rem !important; font-weight: 650 !important; letter-spacing: -0.01em; }
.tn-app .profile-section input:not([type="checkbox"]) { min-height: 44px; border: 1px solid var(--tn-line-strong) !important; border-radius: var(--tn-radius) !important; box-shadow: none !important; font-size: 1rem; }
.tn-app .profile-section input:focus { outline: none; border-color: var(--tn-ink) !important; box-shadow: 0 0 0 3px rgba(20, 22, 26, 0.08) !important; }
.tn-app .profile-section .form-help img, .tn-app .profile-section .protected-badge img { width: 16px !important; height: 16px !important; margin-right: 6px !important; }
.tn-app .danger-zone { background: #fff !important; border: 1px solid #f6c6cd !important; }
.tn-app .danger-zone .danger-section, .tn-app .danger-zone .danger-warning { background: none !important; border: 0 !important; padding: 0 !important; box-shadow: none !important; }
.tn-app .danger-zone h2, .tn-app .danger-zone h3 { text-align: left !important; color: var(--tn-red-ink) !important; }
.tn-app .button.danger { background: var(--tn-red) !important; border-color: var(--tn-red) !important; color: #fff !important; background-image: none !important; box-shadow: none !important; }
.tn-app .button.danger:hover { background: var(--tn-red-ink) !important; }
.tn-app .button { border-radius: var(--tn-radius) !important; box-shadow: none !important; background-image: none; font-weight: 600; min-height: 44px; }
.tn-app .button.secondary { background: #fff !important; color: var(--tn-ink) !important; border: 1px solid var(--tn-line-strong) !important; }
.tn-app .button.secondary:hover { border-color: var(--tn-ink-2) !important; }
.tn-app .button:disabled { opacity: 0.45; cursor: not-allowed; }

@media (max-width: 560px) {
    .tn-preview .tn-file > .tn-btn { display: none; }
    .tn-preview .tn-file { grid-template-columns: auto minmax(0, 1fr); }
    .tn-hero .tn-actions .tn-btn { width: 100%; }
}
.tn-app .profile-section .form-group { margin-bottom: 1rem !important; }
.tn-app .profile-section .form-group label { font-size: 0.88rem; font-weight: 600; color: var(--tn-ink); }
.tn-app .profile-section .role-display .user-role { background: var(--tn-soft) !important; color: var(--tn-ink-2) !important; border: 1px solid var(--tn-line) !important; border-radius: 999px; text-transform: capitalize; }
.tn-app .profile-section .form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.tn-app .profile-section .button.primary { background: var(--tn-ink) !important; border-color: var(--tn-ink) !important; color: #fff !important; }
@media (max-width: 480px) { .tn-center .tn-card { border: 0; padding: 0.25rem 0.25rem 1rem; } .tn-center { padding-top: 1.25rem; } }

/* ---------- Study Buddy panel (views/partials/buddy.ejs) ---------- */
.tn-buddy-launch {
    position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 55;
    display: inline-flex; align-items: center; gap: 0.5rem;
    height: 46px; padding: 0 1.1rem 0 0.9rem;
    border: 0; border-radius: 999px;
    background: var(--tn-ink); color: #fff; font: 600 0.93rem var(--tn-font); cursor: pointer;
    box-shadow: 0 6px 20px rgba(20, 22, 26, 0.22);
}
.tn-buddy-launch:hover { background: #2b2f36; }
.buddy-open .tn-buddy-launch, .is-selecting .tn-buddy-launch { display: none; }

.tn-buddy {
    position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 56;
    width: min(420px, calc(100vw - 2.5rem));
    height: min(640px, calc(100vh - 2.5rem)); height: min(640px, calc(100dvh - 2.5rem));
    display: flex; flex-direction: column;
    background: #fff; border: 1px solid var(--tn-line-strong); border-radius: 16px;
    box-shadow: 0 12px 40px rgba(20, 22, 26, 0.18);
    overflow: hidden;
}
.tn-buddy-head { display: flex; align-items: center; gap: 0.25rem; padding: 0.75rem 0.6rem 0.65rem 1rem; border-bottom: 1px solid var(--tn-line); }
.tn-buddy-head > div { flex: 1; min-width: 0; }
.tn-buddy-head h2 { margin: 0; font-size: 1rem; font-weight: 650; letter-spacing: -0.01em; color: var(--tn-ink); }
.tn-buddy-head p { margin: 0.1rem 0 0; font-size: 0.8rem; color: var(--tn-muted); }

.tn-buddy-context { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--tn-line); background: var(--tn-soft); }
.tn-buddy-context select { flex: 1 1 150px; width: auto; min-height: 36px; padding-top: 0.35rem; padding-bottom: 0.35rem; font-size: 0.9rem; }
.tn-buddy-files-btn {
    min-height: 36px; padding: 0 0.75rem; border-radius: 9px;
    border: 1px solid var(--tn-line-strong); background: #fff; color: var(--tn-ink);
    font: 500 0.86rem var(--tn-font); cursor: pointer; white-space: nowrap;
}
.tn-buddy-files-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tn-buddy-files-btn[aria-expanded="true"] { border-color: var(--tn-ink); }
.tn-buddy-chips { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tn-buddy-chips:empty { display: none; }
.tn-buddy-chip { display: inline-flex; align-items: center; gap: 0.15rem; max-width: 100%; padding: 0.1rem 0.15rem 0.1rem 0.55rem; border-radius: 999px; background: #fff; border: 1px solid var(--tn-line-strong); font-size: 0.78rem; color: var(--tn-ink-2); }
.tn-buddy-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.tn-buddy-chip button { width: 24px; height: 24px; border: 0; border-radius: 50%; background: none; color: var(--tn-muted); font-size: 1rem; line-height: 1; cursor: pointer; }
.tn-buddy-chip button:hover { background: var(--tn-soft); color: var(--tn-ink); }
.tn-buddy-files { flex: 1 1 100%; max-height: 200px; overflow-y: auto; background: #fff; border: 1px solid var(--tn-line-strong); border-radius: 10px; padding: 0.5rem; }
.tn-buddy-files-help { margin: 0 0.25rem 0.4rem; font-size: 0.78rem; color: var(--tn-muted); }
.tn-buddy-files ul { list-style: none; margin: 0; padding: 0; }
.tn-buddy-files label { display: flex; align-items: center; gap: 0.55rem; min-height: 38px; padding: 0.25rem 0.3rem; border-radius: 7px; font-size: 0.88rem; color: var(--tn-ink); cursor: pointer; }
.tn-buddy-files label:hover { background: var(--tn-soft); }
.tn-buddy-files label span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tn-buddy-files label small { flex: none; color: var(--tn-muted); font-size: 0.74rem; }
.tn-buddy-files input { flex: none; width: 17px; height: 17px; accent-color: var(--tn-ink); }
.tn-buddy-files-none { padding: 0.4rem 0.3rem; font-size: 0.85rem; color: var(--tn-muted); }

.tn-buddy-thread { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0.9rem 0.85rem; display: flex; flex-direction: column; gap: 0.7rem; }
.tn-buddy-thread:focus-visible { outline-offset: -2px; }
.tn-buddy-empty { margin: auto 0; padding: 1rem 0.75rem; text-align: center; }
.tn-buddy-empty h3 { margin: 0 0 0.35rem; font-size: 1rem; font-weight: 650; color: var(--tn-ink); overflow-wrap: anywhere; }
.tn-buddy-empty p { margin: 0; font-size: 0.88rem; line-height: 1.5; color: var(--tn-muted); }
.tn-buddy .msg { padding: 0.6rem 0.8rem; border-radius: 14px; font-size: 0.92rem; line-height: 1.5; overflow-wrap: anywhere; }
.tn-buddy .msg.you { align-self: flex-end; max-width: 88%; background: var(--tn-ink); color: #fff; border-bottom-right-radius: 5px; white-space: pre-wrap; }
.tn-buddy .msg.buddy { align-self: stretch; background: var(--tn-soft); color: var(--tn-ink); border-bottom-left-radius: 5px; }
.tn-buddy .msg.is-pending { color: var(--tn-muted); align-self: flex-start; }
.tn-buddy .msg.is-error { background: var(--tn-red-soft); color: var(--tn-red-ink); align-self: flex-start; }
.tn-buddy .badge { display: inline-block; margin-bottom: 0.3rem; padding: 1px 8px; border-radius: 999px; font-size: 0.7rem; font-weight: 600; background: #fff; border: 1px solid var(--tn-line-strong); color: var(--tn-ink-2); }
.tn-buddy-answer > :first-child { margin-top: 0; }
.tn-buddy-answer > :last-child { margin-bottom: 0; }
.tn-buddy-answer p { margin: 0.45rem 0; }
.tn-buddy-answer h4 { margin: 0.8rem 0 0.25rem; font-size: 0.95rem; font-weight: 650; }
.tn-buddy-answer ul, .tn-buddy-answer ol { margin: 0.35rem 0; padding-left: 1.2rem; }
.tn-buddy-answer li { margin: 0.15rem 0; }
.tn-buddy-answer code { padding: 1px 5px; border-radius: 5px; background: #fff; border: 1px solid var(--tn-line); font-size: 0.85em; }
.tn-cite { color: var(--tn-red-ink); font-weight: 600; padding: 0 1px; }
.tn-buddy .sources { margin-top: 0.6rem; font-size: 0.84rem; }
.tn-buddy .sources summary { cursor: pointer; color: var(--tn-ink-2); font-weight: 600; padding: 0.2rem 0; }
.tn-buddy .source { margin-top: 0.4rem; padding: 0.5rem 0.65rem; border-radius: 9px; background: #fff; border: 1px solid var(--tn-line); }
.tn-buddy .source a { font-weight: 600; color: var(--tn-ink); overflow-wrap: anywhere; }
.tn-buddy .source p { margin: 0.2rem 0 0; color: var(--tn-ink-2); }
.tn-buddy-privacy { margin: 0.35rem 1rem; font-size: 0.78rem; color: var(--tn-ink-2); }
.tn-buddy-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.tn-buddy-actions button { min-height: 44px; padding: 0 0.7rem; border-radius: 8px; border: 1px solid var(--tn-line-strong); background: #fff; color: var(--tn-ink); font: 500 0.8rem var(--tn-font); cursor: pointer; }
.tn-buddy-actions button:hover { border-color: var(--tn-ink-2); }

.tn-buddy-make { display: flex; gap: 0.4rem; padding: 0.5rem 0.75rem 0; overflow-x: auto; scrollbar-width: none; }
.tn-buddy-make::-webkit-scrollbar { display: none; }
.tn-buddy-make button { flex: none; min-height: 34px; padding: 0 0.8rem; border-radius: 999px; border: 1px solid var(--tn-line-strong); background: #fff; color: var(--tn-ink); font: 500 0.84rem var(--tn-font); cursor: pointer; white-space: nowrap; }
.tn-buddy-make button:hover:not(:disabled) { border-color: var(--tn-ink); }
.tn-buddy-make button:disabled { opacity: 0.5; cursor: wait; }
.tn-buddy-form { display: flex; align-items: flex-end; gap: 0.5rem; padding: 0.6rem 0.75rem calc(0.75rem + var(--tn-safe-b)); }
.tn-buddy-form textarea {
    flex: 1; min-width: 0; min-height: 42px; max-height: 140px; resize: none;
    padding: 0.6rem 0.8rem; border: 1px solid var(--tn-line-strong); border-radius: 12px;
    font: 400 1rem/1.35 var(--tn-font); color: var(--tn-ink); background: #fff;
}
.tn-buddy-form textarea:focus { outline: none; border-color: var(--tn-ink); box-shadow: 0 0 0 3px rgba(20, 22, 26, 0.08); }
.tn-buddy-form .tn-btn { flex: none; width: 42px; min-height: 42px; padding: 0; border-radius: 12px; }

@media (max-width: 899px) {
    /* The tab bar's Buddy tab opens the panel, so the floating button isn't needed. */
    .tn-buddy-launch { display: none; }
    .tn-buddy { inset: 0; width: auto; height: auto; border: 0; border-radius: 0; z-index: 80; padding-top: env(safe-area-inset-top, 0px); }
    .buddy-open { overflow: hidden; }
    .tn-buddy-head .tn-icon-btn { width: 44px; height: 44px; }
    .tn-buddy-context select, .tn-buddy-files-btn { min-height: 44px; font-size: 1rem; }
    .tn-buddy-files label { min-height: 44px; }
    .tn-buddy-make button { min-height: 40px; }
    .tn-buddy .msg { font-size: 0.98rem; }
}

/* ---------- settings (profile, integrations, AI apps) ---------- */
.tn-settings-head { margin-bottom: 1.5rem; }
.tn-settings-head h1 {
    margin: 0 0 0.9rem; font-size: clamp(1.75rem, 3.5vw, 2.4rem); font-weight: 650; letter-spacing: -0.025em; line-height: 1.1;
    color: var(--tn-ink); background: none; -webkit-text-fill-color: currentColor; text-align: left;
}
.tn-tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--tn-line); overflow-x: auto; scrollbar-width: none; }
.tn-tabs::-webkit-scrollbar { display: none; }
.tn-tab-link {
    flex: none; padding: 0.6rem 0.75rem; margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color: var(--tn-muted); font: 500 0.95rem var(--tn-font); text-decoration: none; white-space: nowrap;
}
.tn-tab-link:hover { color: var(--tn-ink); }
.tn-tab-link.is-active { color: var(--tn-ink); font-weight: 600; border-bottom-color: var(--tn-red); }
.tn-app main.tn-settings { padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 3vw, 2rem) 6rem; margin-top: 0; }
.tn-settings.integrations-page .page-header { text-align: left; padding-top: 0; }
.tn-settings.integrations-page .page-header h2 { margin: 0 0 0.4rem; font-size: 1.25rem; color: var(--tn-ink); }
.tn-settings.integrations-page .page-header p { margin: 0; max-width: 640px; text-align: left; font-size: 0.98rem; color: var(--tn-muted); }

/* ---------- older pages inside the shell (admin, course staff) ---------- */
.tn-app .admin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tn-app .admin-stat-card { min-width: 0; width: auto; }
@media (min-width: 900px) { .tn-app .admin-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tn-app main.container, .tn-app main.staff-wrap, .tn-app main.wrap { min-width: 0; overflow-wrap: anywhere; }
.tn-app main.container, .tn-app main.staff-wrap { padding-bottom: 6rem; }
.tn-app .role-select { min-width: 8rem; flex: 1 1 8rem; }

/* ---------- phones: what a bottom button opens comes up from the bottom ----------
   The tab bar's Courses and Buddy buttons open sheets that rise from the bottom edge, where the
   thumb already is. Only the menu button (top left) opens the drawer from the left. */
.tn-sheet { display: none; }
@media (max-width: 899px) {
    @keyframes tn-rise { from { transform: translateY(100%); } to { transform: none; } }

    .tn-sheet {
        position: fixed; inset: auto 0 0 0; z-index: 75;
        display: flex; flex-direction: column;
        max-height: min(78vh, 78dvh);
        background: #fff; border-radius: 18px 18px 0 0;
        box-shadow: 0 -8px 30px rgba(20, 22, 26, 0.18);
        padding-bottom: var(--tn-safe-b);
        animation: tn-rise 0.22s ease;
    }
    .tn-sheet-grab { width: 36px; height: 4px; margin: 8px auto 0; border-radius: 4px; background: var(--tn-line-strong); }
    .tn-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0.35rem 0.5rem 0.25rem 1.1rem; }
    .tn-sheet-head h2 { margin: 0; font-size: 1.1rem; font-weight: 650; letter-spacing: -0.01em; color: var(--tn-ink); }
    .tn-sheet-head .tn-icon-btn { width: 44px; height: 44px; }
    .tn-sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 0 0.6rem 0.9rem; }
    .tn-sheet .tn-side-link { min-height: 50px; font-size: 1.05rem; }
    .tn-sheet .tn-side-remove { width: 44px; height: 44px; opacity: 0.7; }
    .tn-sheet-add { margin-top: 0.35rem; min-height: 50px; padding-right: 0.3rem; border: 1px solid var(--tn-line-strong); border-radius: 12px; background: #fff; }
    .tn-sheet-add input { font-size: 1rem; }
    /* In the sheet the keyboard is up: list matches in the flow, right under the field. */
    .tn-sheet-add { flex-wrap: wrap; row-gap: 0; }
    .tn-sheet-add .combo-list { position: static; flex-basis: 100%; order: 3; margin: 0.15rem -0.3rem 0.35rem -0.55rem; border: 0; border-top: 1px solid var(--tn-line); border-radius: 0 0 12px 12px; box-shadow: none; max-height: 40vh; }
    .tn-sheet-add .combo-list li { min-height: 48px; justify-content: center; }
    .tn-sheet .tn-side-empty { margin: 0.4rem 0.55rem 0.7rem; font-size: 0.92rem; }
    .tn-sheet .tn-side-error { font-size: 0.88rem; }
    .tn-sheet-all { display: block; margin: 0.9rem 0.55rem 0; color: var(--tn-ink-2); font-size: 0.95rem; }
    .sheet-open { overflow: hidden; }

    /* Study Buddy: a tall sheet from the bottom, not a separate screen. */
    .tn-buddy {
        inset: auto 0 0 0; height: min(92vh, 92dvh);
        border-radius: 18px 18px 0 0; padding-top: 0;
        box-shadow: 0 0 0 100vmax rgba(20, 22, 26, 0.35);
        animation: tn-rise 0.24s ease;
    }
    .tn-buddy-head { position: relative; padding-top: 1.1rem; }
    .tn-buddy-head::before { content: ""; position: absolute; top: 7px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--tn-line-strong); }

    /* The tab that opened a sheet reads as the current one while it is open. */
    .sheet-open .tn-tab.is-active, .buddy-open .tn-tab.is-active { color: var(--tn-muted); font-weight: 500; }
    .sheet-open #tabCourses, .buddy-open .tn-tab[data-buddy-open] { color: var(--tn-ink); font-weight: 600; }

    /* Upload, edit and report forms rise from the bottom too. */
    .tn-dialog[open] { animation: tn-rise 0.22s ease; }
}
@media (prefers-reduced-motion: reduce) { .tn-sheet, .tn-buddy, .tn-dialog[open] { animation: none !important; } }
.tn-sheet:focus { outline: none; }
