/* LMSCursio — application design system.
   A modern, professional LMS UI (Canvas/Linear/Stripe inspired): an app bar,
   page chrome, cards, stats, tables, tabs and badges. Light/dark + RTL aware.
   All historical class names are preserved and restyled. */

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #4f46e5;
    --primary-strong: #4338ca;
    --primary-soft: #eef2ff;
    --accent: #7c3aed;
    --border: #e6e8ec;
    --border-strong: #d3d8e0;
    --success: #16a34a;
    --success-soft: #ecfdf3;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;

    --radius: 12px;
    --radius-lg: 16px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
    --shadow: 0 1px 3px rgba(15, 23, 42, .07), 0 10px 28px -12px rgba(15, 23, 42, .18);
    --shadow-pop: 0 8px 30px -6px rgba(15, 23, 42, .22);
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --appbar-h: 60px;
}

[data-theme="dark"] {
    --bg: #0a0e1a;
    --surface: #111726;
    --surface-2: #0e1422;
    --text: #e6eaf2;
    --muted: #94a3b8;
    --primary: #818cf8;
    --primary-strong: #a5b4fc;
    --primary-soft: #1e213a;
    --border: #222a3d;
    --border-strong: #2c3650;
    --success-soft: #07210f;
    --warning-soft: #2a1d05;
    --danger-soft: #2a0f0f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 3px rgba(0, 0, 0, .45), 0 12px 30px -12px rgba(0, 0, 0, .6);
    --shadow-pop: 0 10px 34px -6px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: var(--primary); }
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -.01em; }

/* ============================ App bar ============================ */
.appbar {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
}
.appbar__inner {
    max-width: 1180px; margin: 0 auto; padding: 0 1.25rem;
    height: var(--appbar-h); display: flex; align-items: center; gap: 1.25rem;
}
.appbar__brand {
    display: inline-flex; align-items: center; gap: .55rem;
    font-weight: 800; letter-spacing: -.02em; color: var(--text); text-decoration: none; font-size: 1.05rem;
}
.appbar__logo {
    width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff; font-weight: 800; font-size: .95rem;
}
.appbar__nav { display: flex; align-items: center; gap: .25rem; margin-inline-start: .5rem; }
.appbar__link {
    padding: .45rem .7rem; border-radius: 8px; font-size: .92rem; font-weight: 500;
    color: var(--muted); text-decoration: none; transition: background .15s, color .15s;
}
.appbar__link:hover { background: var(--surface-2); color: var(--text); }
.appbar__link.is-active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.appbar__actions { margin-inline-start: auto; display: flex; align-items: center; gap: .6rem; }

.icon-btn {
    width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--surface); color: var(--muted); cursor: pointer; font-size: 1.1rem;
    display: grid; place-items: center; transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

.avatar {
    width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff; font-weight: 700; font-size: .8rem; flex: none;
}

/* User menu (native <details>) */
.usermenu { position: relative; }
.usermenu__trigger {
    list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: .5rem;
    padding: .25rem .5rem .25rem .25rem; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); transition: border-color .15s;
}
.usermenu__trigger::-webkit-details-marker { display: none; }
.usermenu__trigger:hover { border-color: var(--border-strong); }
.usermenu__name { font-size: .9rem; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usermenu__panel {
    position: absolute; inset-inline-end: 0; top: calc(100% + 8px); min-width: 190px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-pop); padding: .35rem; display: grid; gap: 2px;
}
.usermenu__item {
    display: block; width: 100%; text-align: start; padding: .55rem .7rem; border-radius: 8px;
    font: inherit; font-size: .9rem; color: var(--text); text-decoration: none; background: none; border: 0; cursor: pointer;
}
.usermenu__item:hover { background: var(--surface-2); }
.usermenu__item--danger { color: var(--danger); }

/* ============================ Page ============================ */
.page { min-height: calc(100vh - var(--appbar-h)); }
.page__container { max-width: 1180px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }

.page-header {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
    flex-wrap: wrap; margin-bottom: 1.5rem;
}
.page-header__title { margin: 0; font-size: 1.6rem; }
.page-header__meta { margin: .35rem 0 0; color: var(--muted); font-size: .95rem; }
.page-header__actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumb { color: var(--muted); text-decoration: none; font-size: .9rem; font-weight: 500; }
.crumb:hover { color: var(--primary); }

/* ============================ Buttons ============================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .6rem 1rem; border-radius: 10px; border: 1px solid transparent;
    font-size: .92rem; font-weight: 600; cursor: pointer; text-decoration: none;
    font-family: inherit; line-height: 1; transition: filter .15s, background .15s, border-color .15s, transform .05s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn--primary:hover { background: var(--primary-strong); }
.btn--ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn--subtle { background: var(--primary-soft); color: var(--primary); }
.btn--subtle:hover { filter: brightness(.98); }
.btn--danger { background: var(--surface); border-color: var(--border); color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn--sm { padding: .45rem .75rem; font-size: .86rem; border-radius: 8px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ============================ Cards ============================ */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); text-align: start;
}
.card h3 { margin: 0 0 .4rem; font-size: 1.02rem; }
.card p { margin: 0; color: var(--muted); font-size: .92rem; }
a.card { display: block; color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .12s; }
a.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
a.card h3 { color: var(--text); }
.card--wide { grid-column: 1 / -1; }
.card--pad-lg { padding: 1.5rem; }

/* ============================ Stats ============================ */
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 1.5rem; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm);
}
.stat__label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat__value { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; margin-top: .25rem; }

/* ============================ Grid / sections ============================ */
.dashboard { width: 100%; }
.dashboard__header { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.dashboard__title { margin: 0 0 .25rem; font-size: 1.6rem; }
.dashboard__meta { color: var(--muted); margin: .15rem 0 0; }
.dashboard__meta a { color: var(--muted); text-decoration: none; font-weight: 500; }
.dashboard__meta a:hover { color: var(--primary); }
.dashboard__grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.section-title { margin: 2rem 0 1rem; font-size: 1.15rem; }
.muted { color: var(--muted); }
.stack > * + * { margin-top: 1rem; }

/* ============================ Badges / chips ============================ */
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 0; padding: 0; }
.chip, .badge {
    display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .6rem; border-radius: 999px;
    font-size: .78rem; font-weight: 600; line-height: 1.4;
    background: var(--success-soft); color: var(--success);
}
.chip--muted, .badge--muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge--draft, .chip--draft { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }

/* ============================ Tables ============================ */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: .8rem 1rem; text-align: start; border-bottom: 1px solid var(--border); font-size: .92rem; }
.table th { background: var(--surface-2); color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }

/* ============================ Tabs ============================ */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 0 0 1.5rem; flex-wrap: wrap; }
.tab {
    padding: .65rem .9rem; border-radius: 8px 8px 0 0; text-decoration: none; font-weight: 600; font-size: .92rem;
    color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* ============================ Lists ============================ */
.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.list > li { padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.list > li:last-child { border-bottom: 0; }

/* ============================ Empty state ============================ */
.empty {
    text-align: center; padding: 3rem 1.5rem; border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg); background: var(--surface); color: var(--muted);
}
.empty__icon { font-size: 2rem; opacity: .6; }
.empty h3 { margin: .5rem 0 .25rem; color: var(--text); }

/* ============================ Forms ============================ */
.form { display: flex; flex-direction: column; gap: .35rem; }
.form__label { font-size: .85rem; font-weight: 600; margin-top: .85rem; }
.form__input, textarea.form__input, select.form__input {
    padding: .65rem .8rem; border: 1px solid var(--border-strong); border-radius: 10px;
    background: var(--surface); color: var(--text); font-size: .95rem; font-family: inherit; width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
.form__input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
.form__hint { font-size: .82rem; color: var(--muted); }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.5rem; }

/* ============================ Alerts ============================ */
.alert { padding: .8rem 1rem; border-radius: 10px; font-size: .92rem; margin-bottom: 1rem; border: 1px solid transparent; }
.alert--error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert--success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 28%, transparent); }
.alert__list { margin: 0; padding-inline-start: 1.1rem; }

/* ============================ Prose ============================ */
.prose { color: var(--text); }
.prose code, .hero__health code, .error code {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 6px; padding: .15rem .45rem; font-size: .88rem;
}

/* ============================ Hero (landing) ============================ */
.hero { max-width: 820px; margin: 2rem auto; text-align: center; }
.hero__badge {
    display: inline-block; padding: .35rem .8rem; border-radius: 999px;
    background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: .82rem; letter-spacing: .02em;
}
.hero__title { font-size: clamp(2rem, 5vw, 3.1rem); margin: 1rem 0 .5rem; }
.hero__subtitle { color: var(--muted); font-size: 1.1rem; max-width: 620px; margin: 0 auto 1rem; }
.hero__phase { font-weight: 600; color: var(--accent); }
.hero__cta { margin: 1.75rem 0 .5rem; }
.hero__grid { display: grid; gap: 1rem; margin: 2.5rem 0; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); text-align: start; }
.hero__health { color: var(--muted); }

/* ============================ Errors ============================ */
.error { text-align: center; max-width: 640px; margin: 4rem auto; }
.error__code { font-size: 5rem; font-weight: 800; color: var(--primary); line-height: 1; }
.error__message { margin: .5rem 0 1rem; }
.error__home { color: var(--primary); text-decoration: none; font-weight: 600; }
.error__trace { margin-top: 1.5rem; text-align: start; overflow: auto; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: .8rem; }

/* ============================ Auth screens ============================ */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem; background:
    radial-gradient(900px 500px at 50% -10%, color-mix(in srgb, var(--primary) 12%, transparent), transparent); }
.auth-card { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 2rem; }
.auth-brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--text); letter-spacing: -.02em; margin-bottom: 1.25rem; }
.auth-title { font-size: 1.5rem; margin: 0 0 .25rem; }
.auth-subtitle { color: var(--muted); margin: 0 0 1.5rem; font-size: .95rem; }
.auth-sso { display: grid; gap: .5rem; margin-top: 1.25rem; }
.auth-sso .btn { width: 100%; }
.auth-links { margin-top: 1.25rem; font-size: .9rem; text-align: center; }
.auth-links a { color: var(--primary); text-decoration: none; }
.auth-card .btn--primary { width: 100%; margin-top: 1.25rem; }

/* ============================ MFA ============================ */
.mfa-qr { width: 180px; height: 180px; margin: 0 auto 1rem; border: 1px dashed var(--border-strong); border-radius: 10px; display: grid; place-items: center; }
.mfa-secret { text-align: center; font-size: .9rem; color: var(--muted); }

/* ============================ Misc legacy ============================ */
.app-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem; }

[dir="rtl"] .card, [dir="rtl"] .table th, [dir="rtl"] .table td { text-align: start; }

/* ============================ Responsive ============================ */
@media (max-width: 720px) {
    .appbar__nav { display: none; }
    .usermenu__name { display: none; }
    .page__container { padding: 1.5rem 1rem 3rem; }
    .page-header { align-items: flex-start; }
}
