/*
 * Academy Portal UX26
 * Shared Design System Foundation
 *
 * This file contains presentation primitives only.
 * It must not contain application/business logic.
 */

:root {
    /* Brand */
    --ap-navy-950: #071a3d;
    --ap-navy-900: #0b2348;
    --ap-navy-800: #0f2747;

    --ap-blue-700: #1457d9;
    --ap-blue-600: #2563eb;
    --ap-blue-500: #3b82f6;
    --ap-blue-50: #eff6ff;

    --ap-gold-500: #d8a72e;
    --ap-gold-400: #e7b54b;

    /* Semantic */
    --ap-success-700: #15803d;
    --ap-success-50: #f0fdf4;

    --ap-danger-700: #b42318;
    --ap-danger-50: #fef2f2;

    --ap-warning-700: #a16207;
    --ap-warning-50: #fffbeb;

    /* Neutral */
    --ap-ink: #172033;
    --ap-muted: #667085;
    --ap-subtle: #98a2b3;

    --ap-page: #f6f8fb;
    --ap-surface: #ffffff;
    --ap-surface-soft: #f8fafc;

    --ap-border: #e4e7ec;
    --ap-border-strong: #d0d5dd;

    /* Typography */
    --ap-font:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    /* Radius */
    --ap-radius-xs: 8px;
    --ap-radius-sm: 10px;
    --ap-radius-md: 14px;
    --ap-radius-lg: 18px;
    --ap-radius-xl: 22px;
    --ap-radius-pill: 999px;

    /* Shadow */
    --ap-shadow-xs:
        0 1px 2px rgba(16, 24, 40, .04);

    --ap-shadow-sm:
        0 8px 24px rgba(15, 39, 71, .06);

    --ap-shadow-md:
        0 16px 45px rgba(20, 35, 70, .08);

    --ap-shadow-modal:
        0 28px 80px rgba(15, 23, 42, .24);

    /* Spacing */
    --ap-space-1: .25rem;
    --ap-space-2: .5rem;
    --ap-space-3: .75rem;
    --ap-space-4: 1rem;
    --ap-space-5: 1.25rem;
    --ap-space-6: 1.5rem;
    --ap-space-8: 2rem;
    --ap-space-10: 2.5rem;
    --ap-space-12: 3rem;

    /* Layout */
    --ap-content: 1400px;
    --ap-content-readable: 760px;

    /* Motion */
    --ap-motion-fast: 140ms;
    --ap-motion-normal: 220ms;

    color-scheme: light;
}

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

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

body {
    margin: 0;
    font-family: var(--ap-font);
    background: var(--ap-page);
    color: var(--ap-ink);
    line-height: 1.5;
}

img,
svg {
    max-width: 100%;
}

button,
input,
select,
textarea {
    font: inherit;
}

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

/*
 * Accessibility
 */

:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .30);
    outline-offset: 3px;
}

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

/*
 * Application shell
 */

.ap-shell {
    width: min(
        calc(100% - 32px),
        var(--ap-content)
    );
    margin-inline: auto;
}

.ap-page {
    padding-block:
        clamp(24px, 4vw, 56px);
}

.ap-page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--ap-space-6);
    flex-wrap: wrap;
    margin-bottom: var(--ap-space-8);
}

.ap-page-title {
    margin: 0;
    font-size:
        clamp(1.9rem, 4vw, 3rem);
    line-height: 1.05;
    letter-spacing: -.035em;
    color: var(--ap-navy-950);
}

.ap-page-description {
    max-width: var(--ap-content-readable);
    margin:
        var(--ap-space-3)
        0
        0;
    color: var(--ap-muted);
}

/*
 * Surfaces
 */

.ap-card {
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius-lg);
    box-shadow: var(--ap-shadow-sm);
}

.ap-card-body {
    padding:
        clamp(18px, 3vw, 28px);
}

.ap-panel {
    background: var(--ap-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius-xl);
    box-shadow: var(--ap-shadow-xs);
}

/*
 * KPI / summary cards
 */

.ap-stat-grid {
    display: grid;
    grid-template-columns:
        repeat(
            auto-fit,
            minmax(180px, 1fr)
        );
    gap: var(--ap-space-4);
}

.ap-stat {
    padding: var(--ap-space-5);
}

.ap-stat-label {
    display: block;
    color: var(--ap-muted);
    font-size: .875rem;
    font-weight: 650;
}

.ap-stat-value {
    display: block;
    margin-top: var(--ap-space-2);
    color: var(--ap-navy-950);
    font-size:
        clamp(1.55rem, 3vw, 2.15rem);
    font-weight: 800;
    line-height: 1;
}

/*
 * Buttons
 */

.ap-button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ap-space-2);
    padding:
        .7rem
        1rem;
    border: 1px solid transparent;
    border-radius: var(--ap-radius-sm);
    text-decoration: none;
    font-weight: 750;
    cursor: pointer;
    transition:
        transform var(--ap-motion-fast) ease,
        box-shadow var(--ap-motion-fast) ease,
        background-color var(--ap-motion-fast) ease,
        border-color var(--ap-motion-fast) ease;
}

.ap-button:hover {
    transform: translateY(-1px);
}

.ap-button-primary {
    background: var(--ap-blue-600);
    color: #fff;
    box-shadow:
        0 8px 18px rgba(37, 99, 235, .18);
}

.ap-button-primary:hover {
    background: var(--ap-blue-700);
}

.ap-button-secondary {
    background: var(--ap-surface);
    color: var(--ap-ink);
    border-color: var(--ap-border-strong);
}

.ap-button-danger {
    background: var(--ap-danger-700);
    color: #fff;
}

/*
 * Forms
 */

.ap-field {
    display: grid;
    gap: var(--ap-space-2);
}

.ap-label {
    font-weight: 700;
    color: var(--ap-ink);
}

.ap-input,
.ap-select,
.ap-textarea {
    width: 100%;
    min-height: 44px;
    padding:
        .7rem
        .8rem;
    color: var(--ap-ink);
    background: var(--ap-surface);
    border: 1px solid var(--ap-border-strong);
    border-radius: var(--ap-radius-sm);
}

.ap-textarea {
    min-height: 110px;
    resize: vertical;
}

.ap-input:focus,
.ap-select:focus,
.ap-textarea:focus {
    border-color: var(--ap-blue-600);
    outline: none;
    box-shadow:
        0 0 0 3px rgba(37, 99, 235, .10);
}

/*
 * Status badges
 */

.ap-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    width: fit-content;
    padding:
        .3rem
        .65rem;
    border-radius: var(--ap-radius-pill);
    font-size: .78rem;
    font-weight: 800;
}

.ap-badge-success {
    color: var(--ap-success-700);
    background: var(--ap-success-50);
}

.ap-badge-danger {
    color: var(--ap-danger-700);
    background: var(--ap-danger-50);
}

.ap-badge-warning {
    color: var(--ap-warning-700);
    background: var(--ap-warning-50);
}

.ap-badge-info {
    color: var(--ap-blue-700);
    background: var(--ap-blue-50);
}

/*
 * Tables
 */

.ap-table-region {
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--ap-border);
    border-radius: var(--ap-radius-lg);
    background: var(--ap-surface);
}

.ap-table {
    width: 100%;
    border-collapse: collapse;
}

.ap-table th,
.ap-table td {
    padding:
        .85rem
        1rem;
    text-align: left;
    border-bottom: 1px solid var(--ap-border);
}

.ap-table th {
    color: var(--ap-muted);
    background: var(--ap-surface-soft);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .035em;
}

.ap-table tbody tr:last-child td {
    border-bottom: 0;
}

/*
 * Empty states
 */

.ap-empty {
    display: grid;
    place-items: center;
    min-height: 220px;
    padding: var(--ap-space-8);
    text-align: center;
    color: var(--ap-muted);
}

/*
 * Utility layouts
 */

.ap-stack {
    display: grid;
    gap: var(--ap-space-4);
}

.ap-cluster {
    display: flex;
    align-items: center;
    gap: var(--ap-space-3);
    flex-wrap: wrap;
}

.ap-grid-2 {
    display: grid;
    grid-template-columns:
        repeat(2, minmax(0, 1fr));
    gap: var(--ap-space-4);
}

.ap-grid-3 {
    display: grid;
    grid-template-columns:
        repeat(3, minmax(0, 1fr));
    gap: var(--ap-space-4);
}

/*
 * Mobile-first refinements
 */

@media (max-width: 760px) {
    .ap-shell {
        width: min(
            calc(100% - 24px),
            var(--ap-content)
        );
    }

    .ap-page {
        padding-block: 24px;
    }

    .ap-page-header {
        align-items: stretch;
    }

    .ap-grid-2,
    .ap-grid-3 {
        grid-template-columns: 1fr;
    }

    .ap-button {
        min-height: 46px;
    }
}

/*
 * Reduced motion
 */

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