/* ==========================================================================
   Student Report
   App Base — Production
   ==========================================================================

   PURPOSE
   --------------------------------------------------------------------------
   True global foundation only:
   - box sizing / element normalization
   - document and typography defaults
   - links, media and form inheritance
   - accessibility / focus
   - scrollbar and table base normalization
   - progressive enhancement
   - global loading / toast / noscript structure

   COMPONENTS such as cards, buttons, badges, tables, sidebar and page
   layout belong to their dedicated stylesheets.

   Load order:
   1. tokens.css
   2. app.css
   3. layout.css
   4. components.css
   5. tables/forms/page-specific CSS
   ========================================================================== */


/* ==========================================================================
   1. BOX MODEL & ELEMENT RESET
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd,
ol,
ul,
fieldset,
legend,
hr {
    margin: 0;
    padding: 0;
}

ul,
ol {
    padding-left: var(--space-5);
}

ul[role="list"],
ol[role="list"] {
    list-style: none;
    padding-left: 0;
}

fieldset {
    border: 0;
    min-width: 0;
}

hr {
    width: 100%;
    height: 1px;
    margin: 0;
    border: 0;
    background-color: var(--color-border);
}


/* ==========================================================================
   2. ROOT & DOCUMENT
   ========================================================================== */

html {
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;
}

body {
    min-height: 100vh;

    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-normal);
    line-height: var(--line-height-normal);
    letter-spacing: var(--letter-spacing-normal);

    color: var(--color-text-primary);
    background-color: var(--color-bg-page);

    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;

    /*
     * Keep horizontal overflow from creating an additional scroll container.
     * `clip` is preferred because it does not interfere with nested scrolling.
     */
    overflow-x: clip;
    overflow-y: visible;
}

body.modal-open,
body.sidebar-lock-scroll {
    overflow: hidden;
}


/* ==========================================================================
   3. TYPOGRAPHY
   ========================================================================== */

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: inherit;
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    letter-spacing: var(--letter-spacing-tight);
    color: var(--color-text-primary);
}

h1 {
    font-size: var(--font-size-3xl);
    font-weight: var(--font-weight-bold);
}

h2 {
    font-size: var(--font-size-2xl);
}

h3 {
    font-size: var(--font-size-xl);
}

h4 {
    font-size: var(--font-size-lg);
}

h5 {
    font-size: var(--font-size-base);
}

h6 {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    letter-spacing: var(--letter-spacing-wide);
    text-transform: uppercase;
}

p {
    color: var(--color-text-secondary);
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
}

small {
    font-size: var(--font-size-sm);
}

strong,
b {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

em,
i {
    font-style: italic;
}

code,
kbd,
samp,
pre {
    font-family: var(--font-mono);
}

code,
kbd {
    font-size: 0.875em;
    border-radius: var(--radius-sm);
}

code {
    padding: 0.125em 0.375em;
    color: var(--color-text-primary);
    background-color: var(--color-bg-hover);
}

kbd {
    display: inline-block;
    padding: 0.125em 0.375em;
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    background-color: var(--color-bg-surface-alt);
    border: 1px solid var(--color-border);
    border-bottom-width: 2px;
}

pre {
    margin: 0;
    padding: var(--space-4);
    overflow: auto;
    color: var(--color-text-primary);
    background-color: var(--color-bg-surface-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

pre code {
    padding: 0;
    background-color: transparent;
    border: 0;
}

blockquote {
    padding-left: var(--space-4);
    color: var(--color-text-secondary);
    font-style: italic;
    border-left: 3px solid var(--color-brand);
}


/* ==========================================================================
   4. LINKS
   ========================================================================== */

a {
    color: var(--color-text-link);
    text-decoration: none;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;

    transition:
        color var(--transition-fast),
        text-decoration-color var(--transition-fast);
}

a:hover {
    color: var(--color-text-link-hover);
    text-decoration: underline;
}

a:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

a.unstyled-link,
a.button-link {
    color: inherit;
    text-decoration: none;
}

a.unstyled-link:hover,
a.button-link:hover {
    color: inherit;
    text-decoration: none;
}


/* ==========================================================================
   5. MEDIA
   ========================================================================== */

img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
}

img,
video {
    height: auto;
}

img {
    font-style: italic;
}

svg {
    flex-shrink: 0;
}


/* ==========================================================================
   6. FORM ELEMENT INHERITANCE
   ==========================================================================

   Detailed control styling belongs in forms.css.
   This section only removes browser typography inconsistencies.
   ========================================================================== */

button,
input,
optgroup,
select,
textarea {
    margin: 0;
    font: inherit;
    color: inherit;
}

button,
select {
    text-transform: none;
}

button,
[type="button"],
[type="reset"],
[type="submit"] {
    -webkit-appearance: button;
    appearance: button;
    cursor: pointer;
}

button:disabled,
button[disabled],
[type="button"]:disabled,
[type="reset"]:disabled,
[type="submit"]:disabled {
    cursor: not-allowed;
}

button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
    padding: 0;
    border: 0;
}

textarea {
    resize: vertical;
}

input,
textarea,
select {
    max-width: 100%;
}


/* ==========================================================================
   7. FOCUS & SELECTION
   ========================================================================== */

:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
}

::selection {
    color: var(--color-text-inverse);
    background-color: var(--color-brand);
}


/* ==========================================================================
   8. SCROLLBAR
   ========================================================================== */

* {
    scrollbar-width: thin;
    scrollbar-color:
        var(--color-border-strong)
        transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: var(--color-border-strong);
    border: 2px solid transparent;
    border-radius: var(--radius-full);
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--color-text-muted);
}


/* ==========================================================================
   9. TABLE BASE
   ==========================================================================

   Structural / visual table styling belongs in tables.css.
   ========================================================================== */

table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
}

th,
td {
    padding: 0;
    text-align: left;
    vertical-align: middle;
}


/* ==========================================================================
   10. ACCESSIBILITY
   ========================================================================== */

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

.sr-only-focusable:focus,
.sr-only-focusable:active {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    clip-path: none;
    white-space: normal;
}

.skip-link {
    position: fixed;
    top: calc(var(--space-4) * -1 - 48px);
    left: var(--space-4);
    z-index: var(--z-tooltip);

    padding: var(--space-2) var(--space-4);

    color: var(--color-brand-contrast);
    background-color: var(--color-brand);
    border-radius: var(--radius-md);

    font-weight: var(--font-weight-semibold);
    text-decoration: none;

    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: var(--space-4);
    color: var(--color-brand-contrast);
    text-decoration: none;
}


/* ==========================================================================
   11. PROGRESSIVE ENHANCEMENT
   ========================================================================== */

.no-js .js-only {
    display: none;
}

.js .no-js-only {
    display: none;
}


/* ==========================================================================
   12. GLOBAL LOADING BAR
   ========================================================================== */

.loading-bar {
    position: fixed;
    top: 0;
    left: 0;

    width: 0;
    height: 2px;

    z-index: var(--z-loading-bar);

    background-color: var(--color-brand);

    opacity: 0;
    pointer-events: none;

    transition:
        width 200ms ease,
        opacity 200ms ease;
}

.loading-bar.is-active {
    opacity: 1;
}


/* ==========================================================================
   13. TOAST CONTAINER
   ========================================================================== */

.toast-container {
    position: fixed;
    right: var(--space-4);
    bottom: var(--space-4);

    z-index: var(--z-toast);

    display: flex;
    flex-direction: column;
    gap: var(--space-2);

    width: min(360px, calc(100vw - var(--space-8)));
    max-width: 100%;

    pointer-events: none;
}

.toast-container > * {
    pointer-events: auto;
}


/* ==========================================================================
   14. NOSCRIPT
   ========================================================================== */

.noscript-warning {
    margin: var(--space-4);
    padding: var(--space-4);

    color: var(--color-badge-danger-text);
    background-color: var(--color-badge-danger-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);

    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
    text-align: center;
}

.noscript-warning strong {
    display: block;
    margin-bottom: var(--space-1);
    color: inherit;
}


/* ==========================================================================
   15. RESPONSIVE BASE ADJUSTMENTS
   ========================================================================== */

@media (max-width: 640px) {
    html {
        scrollbar-gutter: auto;
    }

    body {
        font-size: var(--font-size-sm);
    }

    h1 {
        font-size: var(--font-size-2xl);
    }

    h2 {
        font-size: var(--font-size-xl);
    }

    h3 {
        font-size: var(--font-size-lg);
    }

    .toast-container {
        right: var(--space-3);
        bottom: var(--space-3);
        width: calc(100vw - var(--space-6));
    }
}


/* ==========================================================================
   16. PRINT
   ========================================================================== */

@media print {
    *,
    *::before,
    *::after {
        color: #000 !important;
        background: transparent !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    a,
    a:visited {
        text-decoration: underline;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.85em;
    }

    a[href^="#"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        break-after: avoid;
        page-break-after: avoid;
    }

    img {
        max-width: 100% !important;
    }

    table {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}


/* ==========================================================================
   17. REDUCED MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
