/* Code Vortex Academy LMS: design tokens, base styles, layout helpers and the app shell. */

:root {
    color-scheme: light;
    --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-heading: "Space Grotesk", "Inter", system-ui, sans-serif;

    --bg: #f5f4fa;
    --surface: #ffffff;
    --surface-2: #faf9fd;
    --surface-3: #f2f0f8;
    --overlay: rgba(17, 12, 34, 0.46);
    --border: #e7e4ef;
    --border-strong: #d6d1e3;

    --text: #16131f;
    --text-2: #4e4a60;
    --muted: #767189;

    --primary: #6d28d9;
    --primary-hover: #5b21b6;
    --primary-soft: #f1ebfe;
    --primary-soft-2: #e4d8fd;
    --on-primary: #ffffff;
    --focus-ring: rgba(109, 40, 217, 0.28);
    --accent: #facc15;

    --good: #15803d;
    --good-soft: #e6f6ec;
    --warn: #a16207;
    --warn-soft: #fdf3d3;
    --bad: #c0262d;
    --bad-soft: #fdecec;
    --info: #1d4ed8;
    --info-soft: #e8efff;
    --neutral-soft: #efedf5;

    /* Chart roles (validated against the chart surface in each theme). */
    --chart-series: #6d28d9;
    --chart-grid: #ece9f3;
    --chart-axis: #cfcadb;
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;
    --status-neutral: #a7a2b6;

    --radius-lg: 16px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(22, 19, 31, 0.06);
    --shadow: 0 8px 24px rgba(22, 19, 31, 0.07);
    --shadow-lg: 0 24px 60px rgba(22, 19, 31, 0.18);

    --sidebar-width: 268px;
    --sidebar-collapsed: 76px;
    --topbar-height: 64px;
    --page-gutter: clamp(16px, 2.4vw, 40px);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d0b13;
    --surface: #17141f;
    --surface-2: #1b1826;
    --surface-3: #231f30;
    --overlay: rgba(0, 0, 0, 0.62);
    --border: #2a2638;
    --border-strong: #3b3549;

    --text: #f2f0f8;
    --text-2: #c3bed3;
    --muted: #938ea7;

    --primary: #8b5cf6;
    --primary-hover: #a78bfa;
    --primary-soft: #251c3d;
    --primary-soft-2: #33275a;
    --focus-ring: rgba(139, 92, 246, 0.36);

    --good: #4ade80;
    --good-soft: #12281c;
    --warn: #fbbf24;
    --warn-soft: #2c2310;
    --bad: #f87171;
    --bad-soft: #321618;
    --info: #93b4ff;
    --info-soft: #172240;
    --neutral-soft: #25212f;

    --chart-series: #8b5cf6;
    --chart-grid: #26222f;
    --chart-axis: #3b3549;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.42);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
}

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

html,
body {
    margin: 0;
}

body {
    min-height: 100vh;
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
    margin: 0;
    font-family: var(--font-heading);
    line-height: 1.2;
    letter-spacing: -0.01em;
}

p {
    margin: 0;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    display: block;
    max-width: 100%;
}

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

[hidden] {
    display: none !important;
}

.theme-switching *,
.theme-switching *::before,
.theme-switching *::after {
    transition: none !important;
}

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

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

.muted {
    color: var(--muted);
}

.text-2 {
    color: var(--text-2);
}

.nowrap {
    white-space: nowrap;
}

.num {
    font-variant-numeric: tabular-nums;
}

/* ---------- Layout helpers ---------- */

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stack.tight {
    gap: 8px;
}

.cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.cluster.spread {
    justify-content: space-between;
}

.grid {
    display: grid;
    gap: 16px;
}

.grid.kpis {
    grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
}

.grid.two {
    grid-template-columns: repeat(auto-fit, minmax(min(460px, 100%), 1fr));
}

.grid.three {
    grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
}

.grid.cards {
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
}

.grid.main-aside {
    grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
    align-items: start;
}

@media (max-width: 1180px) {
    .grid.main-aside {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Pages whose main column holds a wide table only sit side by side on very wide screens. */
@media (max-width: 1599px) {
    .grid.main-aside.roomy {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ---------- App shell ---------- */

.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.app.is-collapsed {
    grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--topbar-height);
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
}

.sidebar-brand:hover {
    text-decoration: none;
}

.sidebar-brand img {
    flex: none;
    width: 36px;
    height: 36px;
    padding: 3px;
    border-radius: 10px;
    background: var(--primary-soft);
}

.sidebar-brand strong {
    display: block;
    font-family: var(--font-heading);
    font-size: 1rem;
    white-space: nowrap;
}

.sidebar-brand small {
    display: block;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
}

.nav-group + .nav-group {
    margin-top: 18px;
}

.nav-group-label {
    padding: 0 10px 6px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
    border-radius: 10px;
    color: var(--text-2);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}

.nav-link i {
    width: 18px;
    color: var(--muted);
    text-align: center;
}

.nav-link:hover {
    background: var(--surface-3);
    color: var(--text);
    text-decoration: none;
}

.nav-link.is-active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

.nav-link.is-active i {
    color: var(--primary);
}

.nav-count {
    margin-left: auto;
    min-width: 22px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--primary);
    color: var(--on-primary);
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
}

.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border);
}

.sidebar-footer .nav-link {
    flex: 1;
}

.app.is-collapsed .sidebar-brand div,
.app.is-collapsed .nav-group-label,
.app.is-collapsed .nav-link span,
.app.is-collapsed .nav-count,
.app.is-collapsed .sidebar-footer .nav-link {
    display: none;
}

.app.is-collapsed .sidebar-brand {
    justify-content: center;
    padding: 0;
}

.app.is-collapsed .nav-link {
    justify-content: center;
}

.app.is-collapsed .sidebar-footer {
    justify-content: center;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: var(--overlay);
}

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--topbar-height);
    padding: 0 var(--page-gutter);
    background: color-mix(in srgb, var(--bg) 84%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
}

.topbar-menu {
    display: none;
}

.topbar-search {
    display: flex;
    flex: 0 1 440px;
    align-items: center;
    gap: 10px;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    text-align: left;
}

.topbar-search:hover {
    border-color: var(--border-strong);
}

.topbar-search span {
    flex: 1;
}

kbd {
    padding: 1px 6px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--muted);
    font-family: var(--font-body);
    font-size: 0.72rem;
}

.topbar-spacer {
    flex: 1;
}

.topbar-item {
    position: relative;
}

.icon-button {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}

.icon-button:hover {
    background: var(--surface-3);
    color: var(--text);
}

.icon-button.bordered {
    border-color: var(--border);
    background: var(--surface);
}

.badge-count {
    position: absolute;
    top: 3px;
    right: 3px;
    display: grid;
    place-items: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border: 2px solid var(--bg);
    border-radius: 999px;
    background: var(--bad);
    color: #ffffff;
    font-size: 0.62rem;
    font-weight: 700;
}

.user-button {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 4px 4px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    cursor: pointer;
    text-align: left;
}

.user-button:hover {
    border-color: var(--border-strong);
}

.user-meta strong {
    display: block;
    max-width: 180px;
    overflow: hidden;
    font-size: 0.85rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-meta small {
    display: block;
    color: var(--muted);
    font-size: 0.72rem;
    text-transform: capitalize;
}

.content {
    width: 100%;
    padding: 28px var(--page-gutter) 56px;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.8rem;
}

.breadcrumbs a {
    color: var(--muted);
}

.page-title {
    font-size: clamp(1.5rem, 2.1vw, 2rem);
}

.page-subtitle {
    max-width: 75ch;
    margin-top: 4px;
    color: var(--text-2);
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ---------- Popovers and menus ---------- */

.popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 60;
    min-width: 240px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.menu-item i {
    width: 16px;
    color: var(--muted);
    text-align: center;
}

.menu-item:hover {
    background: var(--surface-3);
    text-decoration: none;
}

.menu-item.danger,
.menu-item.danger i {
    color: var(--bad);
}

.menu-divider {
    height: 1px;
    margin: 6px 0;
    background: var(--border);
}

.menu-label {
    padding: 8px 10px 4px;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.notifications-panel {
    width: min(400px, calc(100vw - 24px));
    padding: 0;
}

.notifications-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.notifications-list {
    max-height: min(460px, 70vh);
    overflow-y: auto;
}

.notification-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
}

.notification-item:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.notification-item.is-unread {
    background: color-mix(in srgb, var(--primary-soft) 55%, transparent);
}

.notification-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--primary-soft);
    color: var(--primary);
}

.notification-item strong {
    display: block;
    font-size: 0.86rem;
    font-weight: 600;
}

.notification-item p {
    margin-top: 2px;
    color: var(--text-2);
    font-size: 0.8rem;
}

.notification-item time {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.72rem;
}

.notifications-foot {
    padding: 10px 16px;
    text-align: center;
}

/* ---------- Command palette ---------- */

.palette-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 12vh 16px 16px;
    background: var(--overlay);
}

.palette {
    width: min(640px, 100%);
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.palette-input {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
}

.palette-input input {
    flex: 1;
    height: 56px;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 1rem;
}

.palette-results {
    max-height: min(420px, 60vh);
    overflow-y: auto;
    padding: 6px;
}

.palette-results .menu-item.is-selected {
    background: var(--primary-soft);
}

.palette-results .menu-item small {
    margin-left: auto;
    color: var(--muted);
}

/* ---------- Responsive shell ---------- */

@media (max-width: 1024px) {
    .app,
    .app.is-collapsed {
        grid-template-columns: minmax(0, 1fr);
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(300px, 86vw);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: var(--shadow-lg);
    }

    .app.is-nav-open .sidebar {
        transform: none;
    }

    .app.is-nav-open .sidebar-backdrop {
        display: block;
    }

    .app.is-collapsed .sidebar-brand div,
    .app.is-collapsed .nav-group-label,
    .app.is-collapsed .nav-link span,
    .app.is-collapsed .sidebar-footer .nav-link {
        display: revert;
    }

    .app.is-collapsed .nav-link {
        justify-content: flex-start;
    }

    .sidebar-collapse {
        display: none;
    }

    .topbar-menu {
        display: inline-grid;
    }
}

@media (max-width: 640px) {
    .topbar-search {
        flex: 0 0 40px;
        justify-content: center;
        padding: 0;
    }

    .topbar-search span,
    .topbar-search kbd,
    .user-meta {
        display: none;
    }

    .user-button {
        padding: 4px;
    }

    .content {
        padding-top: 20px;
    }
}
