/* ------------------------------------------------------------------ */
/* Theme tokens                                                       */
/* ------------------------------------------------------------------ */

:root {
    color-scheme: light;

    --background: #f5f7fa;
    --surface: #ffffff;
    --surface-alt: #eef1f5;
    --text: #17202a;
    --text-muted: #5f6b76;
    --border: #d7dde4;
    --primary: #2457a7;
    --focus: #1b6fd1;
    --danger: #b42318;
    --danger-surface: #fdecea;
    --success: #1c7a4d;
    --success-surface: #eaf6ef;
}

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

    --background: #11151a;
    --surface: #1a2027;
    --surface-alt: #222a33;
    --text: #eef2f6;
    --text-muted: #aab4bf;
    --border: #36404b;
    --primary: #78a9ff;
    --focus: #8bb8ff;
    --danger: #ff8a80;
    --danger-surface: #3a1f1c;
    --success: #4fd68a;
    --success-surface: #143026;
}

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--background);
    color: var(--text);
}

a {
    color: var(--primary);
}

:focus-visible {
    outline: 2px solid var(--focus);
    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;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    background: var(--surface);
    color: var(--text);
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0 0 4px 0;
}

.skip-link:focus {
    left: 0;
}

/* ------------------------------------------------------------------ */
/* Flash messages                                                      */
/* ------------------------------------------------------------------ */

.flash,
.error {
    background: var(--danger-surface);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.6rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.flash--success {
    background: var(--success-surface);
    border-color: var(--success);
    color: var(--success);
}

.flash__list {
    margin: 0;
    padding-left: 1.1rem;
}

/* ------------------------------------------------------------------ */
/* Public/login page (unchanged layout, themed colours)                */
/* ------------------------------------------------------------------ */

.page {
    display: flex;
    min-height: calc(100vh - 3.5rem);
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    width: 100%;
    max-width: 360px;
}

.card h1 {
    margin-top: 0;
    font-size: 1.25rem;
}

.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.field input {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
}

.btn {
    width: 100%;
    padding: 0.6rem;
    border: none;
    border-radius: 4px;
    background: var(--primary);
    color: var(--surface);
    font-size: 1rem;
    cursor: pointer;
}

.btn:hover {
    filter: brightness(0.92);
}

.dashboard {
    max-width: 640px;
    margin: 3rem auto;
    padding: 0 1.5rem;
}

.dashboard .logout {
    display: inline-block;
    margin-top: 1.5rem;
}

/* ------------------------------------------------------------------ */
/* Application shell                                                   */
/* ------------------------------------------------------------------ */

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-shell--with-sidebar .app-main {
    padding: 1.5rem;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.app-header__start,
.app-header__end {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.app-header__brand {
    font-weight: 700;
    font-size: 1.1rem;
    text-decoration: none;
    color: var(--text);
}

.app-header__title {
    color: var(--text-muted);
    font-size: 0.95rem;
    padding-left: 0.75rem;
    border-left: 1px solid var(--border);
}

.app-header__menu-button {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--text);
}

.app-header__menu-button:hover {
    background: var(--surface-alt);
}

.app-main {
    flex: 1;
}

/* ------------------------------------------------------------------ */
/* Sidebar (optional; hidden entirely if the page passes no items)     */
/* ------------------------------------------------------------------ */

.app-shell--with-sidebar {
    display: grid;
    grid-template-columns: 220px 1fr;
    grid-template-rows: auto 1fr;
}

.app-shell--with-sidebar .app-header {
    grid-column: 1 / -1;
}

.app-shell--with-sidebar .app-sidebar {
    grid-column: 1;
}

.app-shell--with-sidebar .app-main {
    grid-column: 2;
}

.app-sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1rem 0.75rem;
}

.app-sidebar__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.app-sidebar__link {
    display: block;
    padding: 0.55rem 0.75rem;
    border-radius: 4px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.95rem;
}

.app-sidebar__link:hover {
    background: var(--surface-alt);
}

.app-sidebar__link--active {
    background: var(--surface-alt);
    font-weight: 600;
    color: var(--primary);
}

.app-sidebar__heading {
    padding: 1rem 0.75rem 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.app-sidebar-toggle-input {
    position: absolute;
}

@media (max-width: 720px) {
    .app-shell--with-sidebar {
        grid-template-columns: 1fr;
    }

    .app-shell--with-sidebar .app-sidebar,
    .app-shell--with-sidebar .app-main {
        grid-column: 1;
    }

    .app-header__menu-button {
        display: inline-flex;
    }

    .app-sidebar {
        display: none;
    }

    .app-sidebar-toggle-input:checked ~ .app-shell .app-sidebar {
        display: block;
    }
}

/* ------------------------------------------------------------------ */
/* Theme switcher                                                      */
/* ------------------------------------------------------------------ */

.theme-switcher {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.theme-switcher__option {
    border: none;
    background: var(--surface);
    color: var(--text-muted);
    padding: 0.4rem 0.65rem;
    font-size: 0.8rem;
    cursor: pointer;
    border-right: 1px solid var(--border);
}

.theme-switcher__option:last-child {
    border-right: none;
}

.theme-switcher__option:hover {
    background: var(--surface-alt);
}

.theme-switcher__option[aria-pressed="true"] {
    background: var(--primary);
    color: var(--surface);
    font-weight: 600;
}

/* ------------------------------------------------------------------ */
/* Profile menu                                                        */
/* ------------------------------------------------------------------ */

.profile-menu {
    position: relative;
}

.profile-menu__trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    list-style: none;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    color: var(--text);
}

.profile-menu__trigger::-webkit-details-marker {
    display: none;
}

.profile-menu__trigger:hover {
    background: var(--surface-alt);
}

.profile-menu__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    background: var(--primary);
    color: var(--surface);
    font-size: 0.85rem;
    font-weight: 700;
}

.profile-menu__panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.4rem);
    min-width: 260px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding: 0.75rem;
    z-index: 20;
}

.profile-menu__identity {
    padding: 0.25rem 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

.profile-menu__full-name {
    margin: 0;
    font-weight: 600;
}

.profile-menu__email,
.profile-menu__workspace {
    margin: 0.15rem 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.profile-menu__roles {
    list-style: none;
    margin: 0;
    padding: 0;
}

.profile-menu__role {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.profile-menu__role-check {
    width: 1rem;
    display: inline-block;
    color: var(--primary);
    font-weight: 700;
}

.profile-menu__role--current {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    background: var(--surface-alt);
    color: var(--text);
    font-weight: 600;
}

.profile-menu__role-form {
    margin: 0;
}

.profile-menu__role-switch {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    border: none;
    background: none;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    font: inherit;
    color: var(--text-muted);
    cursor: pointer;
    text-align: left;
}

.profile-menu__role-switch:hover {
    background: var(--surface-alt);
    color: var(--text);
}

.profile-menu__role-current-tag {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.profile-menu__divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 0;
}

.profile-menu__actions {
    list-style: none;
    margin: 0;
    padding: 0;
}

.profile-menu__item {
    display: block;
    padding: 0.45rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--text);
}

a.profile-menu__item:hover {
    background: var(--surface-alt);
}

.profile-menu__item--disabled {
    color: var(--text-muted);
    pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* Workspace dashboards (placeholder cards only, Stage 3)              */
/* ------------------------------------------------------------------ */

.workspace-intro {
    margin-bottom: 1.5rem;
}

.workspace-intro h1 {
    margin: 0 0 0.25rem;
}

.workspace-intro .text-muted {
    margin: 0;
}

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

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.dashboard-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
}

.dashboard-card h2 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
}

/* ------------------------------------------------------------------ */
/* Primary Role settings                                               */
/* ------------------------------------------------------------------ */

.primary-role-list {
    list-style: none;
    margin: 1.5rem 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 480px;
}

.primary-role-list__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.primary-role-list__item--current {
    border-color: var(--primary);
}

.primary-role-list__item form {
    margin: 0;
}

.btn--small {
    width: auto;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
}

.dashboard-card p {
    margin: 0;
    font-size: 0.9rem;
}

/* ------------------------------------------------------------------ */
/* Admin User management                                               */
/* ------------------------------------------------------------------ */

.btn--secondary {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn--secondary:hover {
    filter: none;
    background: var(--border);
}

.actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.actions-row .btn,
.actions-row .btn--secondary {
    width: auto;
}

.filters-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.filters-form .field {
    margin-bottom: 0;
    min-width: 180px;
}

.filters-form .field input,
.filters-form .field select {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
}

.table-responsive {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.data-table th,
.data-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 0.9rem;
    vertical-align: top;
}

.data-table thead th {
    color: var(--text-muted);
    font-weight: 600;
    background: var(--surface-alt);
    white-space: nowrap;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.role-badge-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.role-badge {
    display: inline-block;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1rem 0.45rem;
    font-size: 0.75rem;
    color: var(--text);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--text);
}

.status-badge::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-badge--active::before {
    background: var(--success);
}

.status-badge--invited::before {
    background: var(--primary);
}

.status-badge--suspended::before,
.status-badge--deactivated::before {
    background: var(--danger);
}

.status-badge--ready::before {
    background: var(--success);
}

.status-badge--draft::before {
    background: var(--primary);
}

.status-badge--archived::before {
    background: var(--text-muted);
}

.empty-state {
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: 8px;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 1.25rem;
}

.pagination a,
.pagination span {
    display: inline-block;
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.85rem;
}

.pagination__current {
    background: var(--primary);
    color: var(--surface);
    border-color: var(--primary);
    font-weight: 600;
}

.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin: 0.25rem 0 1rem;
}

.checkbox-list label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.checkbox-list input[type="checkbox"],
.field input[type="radio"] {
    width: auto;
}

.detail-list {
    margin: 1rem 0;
    padding: 0;
    display: grid;
    grid-template-columns: minmax(160px, 220px) 1fr;
    gap: 0.5rem 1rem;
}

.detail-list dt {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.detail-list dd {
    margin: 0;
    font-size: 0.95rem;
}

.form-wide {
    max-width: 640px;
}

.audit-history {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
}

.audit-history li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.audit-history li:last-child {
    border-bottom: none;
}

.audit-history .text-muted {
    display: block;
    font-size: 0.8rem;
}

/* ------------------------------------------------------------------ */
/* Invited-User activation                                             */
/* ------------------------------------------------------------------ */

.invitation-link-box {
    background: var(--success-surface);
    border: 1px solid var(--success);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.invitation-link-box p {
    margin: 0 0 0.5rem;
    color: var(--success);
}

.invitation-link-box input {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    font-family: monospace;
    font-size: 0.85rem;
}

/* ------------------------------------------------------------------ */
/* Learner onboarding                                                  */
/* ------------------------------------------------------------------ */

.radio-list {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin: 0.25rem 0 1rem;
}

.radio-list label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.onboarding-document {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.onboarding-document h2 {
    margin-top: 0;
    font-size: 1.05rem;
}

.onboarding-document__content {
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 1rem;
    white-space: pre-line;
}

.onboarding-document__confirm {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}
