/* ============================================================
   MwalimuPlus — app stylesheet
   Editorial-academic redesign: warm paper, forest ink,
   serif display voice, border-led document surfaces.
   Every class name and JS data-hook is preserved.
   ============================================================ */

:root {
    /* ---- Warm paper neutrals (tinted toward the brand hue) ---- */
    --canvas:          oklch(0.967 0.008 100);
    --surface:         oklch(0.995 0.004 100);
    --surface-2:       oklch(0.952 0.012 100);
    --surface-3:       oklch(0.935 0.016 100);
    --ink:             oklch(0.30 0.03 160);
    --ink-2:           oklch(0.44 0.03 160);
    --muted:           oklch(0.53 0.025 160);
    --line:            oklch(0.875 0.02 100);
    --line-strong:     oklch(0.79 0.03 100);

    /* ---- Forest ink (brand / structure) ---- */
    --green-900:       oklch(0.30 0.06 160);
    --green-700:       oklch(0.40 0.075 160);
    --green-600:       oklch(0.47 0.085 160);
    --green-50:        oklch(0.955 0.02 160);

    /* Terracotta accent — reserved for generate/create moments */
    --accent:          oklch(0.55 0.13 45);
    --accent-deep:     oklch(0.47 0.12 45);
    --accent-ink:      oklch(0.99 0.005 45);
    --accent-soft:     oklch(0.945 0.03 45);

    /* ---- Semantic status ---- */
    --warn-bg:         oklch(0.96 0.04 85);
    --warn-line:       oklch(0.85 0.07 80);
    --warn-ink:        oklch(0.45 0.07 70);
    --danger:          oklch(0.50 0.13 28);
    --danger-bg:       oklch(0.955 0.02 28);
    --danger-line:     oklch(0.88 0.045 28);
    --success-bg:      oklch(0.955 0.02 160);
    --success-line:    oklch(0.87 0.045 160);
    --success-ink:     oklch(0.40 0.06 160);
    --tint-blue:       oklch(0.94 0.02 240);
    --blue-ink:        oklch(0.40 0.05 250);
    --tint-violet:     oklch(0.94 0.025 290);
    --violet-ink:      oklch(0.42 0.05 290);

    /* ---- Elevation (whisper only; border-led system) ---- */
    --shadow-1: 0 1px 2px oklch(0.35 0.04 90 / 0.06), 0 2px 8px oklch(0.35 0.04 90 / 0.04);
    --shadow-2: 0 10px 34px oklch(0.25 0.05 100 / 0.16);
    --shadow-border:
        0 0 0 1px oklch(0.30 0.03 100 / 0.07),
        0 1px 2px -1px oklch(0.30 0.03 100 / 0.06),
        0 2px 6px 0 oklch(0.30 0.03 100 / 0.04);
    --shadow-border-hover:
        0 0 0 1px oklch(0.30 0.03 100 / 0.10),
        0 1px 2px -1px oklch(0.30 0.03 100 / 0.08),
        0 3px 8px 0 oklch(0.30 0.03 100 / 0.07);

    /* ---- Edge language ---- */
    --radius:        6px;
    --radius-sm:     4px;
    --radius-lg:     12px;

    /* ---- Type ---- */
    --font-display: "Georgia", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
    --font-body: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "Cascadia Mono", Consolas, "Courier New", monospace;

    /* ---- Layout ---- */
    --sidebar-w: 236px;
    --content-max: 1180px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
    margin: 0;
    font-family: var(--font-body);
    color: var(--ink);
    background: var(--canvas);
    line-height: 1.6;
    font-size: 1rem;
}

a { color: var(--green-700); text-decoration: none; text-underline-offset: 2px; }
a:hover { text-decoration: underline; text-decoration-color: var(--green-600); }

h1, h2, h3 {
    font-family: var(--font-display);
    line-height: 1.2;
    margin: 0 0 .5rem;
    text-wrap: balance;
    color: var(--ink);
}
h1 { font-size: 1.72rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.16rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: .4rem 0; }
ul, ol { margin: .4rem 0; }
code { font-family: var(--font-mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: var(--radius-sm); }

.muted { color: var(--muted); }
.lead { font-size: 1.05rem; color: var(--muted); max-width: 62ch; line-height: 1.65; }

/* ---- Brand mark ---- */
.brand {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--ink);
    letter-spacing: -.005em;
}
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: var(--radius-sm);
    background: var(--green-900);
    color: oklch(0.955 0.02 100);
    font-family: var(--font-display);
    font-size: .92rem;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
    box-shadow: var(--shadow-border);
}
.brand-name { line-height: 1; }
.brand-name span { color: var(--accent-deep); }
.brand:hover { text-decoration: none; }

/* ---- App shell ---- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}
.app-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ---- Sidebar ---- */
.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 1.4rem;
    padding: 1.35rem 1rem 1.1rem;
    background: var(--surface);
    border-inline-end: 1px solid var(--line);
}
.sidebar .brand { padding: .2rem .5rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: .1rem; }
.sidebar-label {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
    margin: .4rem .55rem .5rem;
    font-family: var(--font-body);
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem .65rem;
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-weight: 600;
    font-size: .93rem;
    position: relative;
}
.sidebar-nav a:hover { background: var(--green-50); text-decoration: none; }
.sidebar-nav a.active {
    background: var(--green-900);
    color: oklch(0.96 0.015 100);
    box-shadow: var(--shadow-border);
}
.nav-icon { font-size: 1rem; line-height: 1; width: 1.25rem; text-align: center; opacity: .85; }
.sidebar-nav a.active .nav-icon { opacity: 1; }
.sidebar-note {
    margin-top: auto;
    font-size: .8rem;
    line-height: 1.55;
    color: var(--muted);
    border-top: 1px solid var(--line);
    padding: 1rem .35rem 0;
    font-style: italic;
}

/* ---- Top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .8rem 2rem;
    background: color-mix(in oklch, var(--surface) 88%, var(--canvas));
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(6px);
}
.topbar .breadcrumbs { margin: 0; font-size: .9rem; min-width: 0; flex: 1; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--green-700); }
.topbar .breadcrumbs > *:last-child {
    color: var(--ink);
    font-weight: 650;
    font-family: var(--font-display);
    font-size: .98rem;
}
.topbar-toggle {
    display: none;
    flex-shrink: 0;
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: var(--radius-sm);
    font-size: 1.1rem;
    line-height: 1;
    padding: .4rem .6rem;
    cursor: pointer;
    color: var(--ink);
}
.topbar-toggle:hover { border-color: var(--green-600); }

/* Sidebar drawer backdrop (mobile only) */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: oklch(0.25 0.05 160 / 0.45);
    backdrop-filter: blur(2px);
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 1.2rem; }
.topbar-clock {
    color: var(--muted);
    font-size: .85rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.topbar-user { display: flex; align-items: center; gap: .6rem; }
.user-avatar {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    background: var(--green-900);
    color: oklch(0.96 0.015 100);
    font-weight: 700;
    font-size: .85rem;
    text-transform: uppercase;
    font-family: var(--font-display);
    box-shadow: var(--shadow-border);
}
.topbar-user-link { display: flex; align-items: center; gap: .6rem; color: var(--ink); }
.topbar-user-link:hover { text-decoration: none; }
.topbar-user-link:hover .user-name { text-decoration: underline; }
.user-name { font-size: .9rem; font-weight: 600; }
.nav-logout {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .32rem .95rem;
    font-size: .84rem;
    color: var(--ink-2);
    font-weight: 600;
}
.nav-logout:hover { border-color: var(--green-600); color: var(--green-700); text-decoration: none; }
.topbar-public .btn { margin: 0; }

/* ---- Content wrapper ---- */
.content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 2rem 2.25rem 3rem;
}
.content [id] { scroll-margin-top: 5rem; }

/* ---- Page header ---- */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.25rem;
    flex-wrap: wrap;
    margin-bottom: 1.75rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--line-strong);
}
.page-head-main { display: flex; align-items: flex-start; gap: 1rem; }
.page-head-icon {
    display: grid;
    place-items: center;
    width: 2.7rem;
    height: 2.7rem;
    border-radius: var(--radius);
    background: var(--green-50);
    font-size: 1.3rem;
    flex-shrink: 0;
    border: 1px solid var(--line);
}
.page-head h1 { margin: 0; }
.page-head-sub { color: var(--ink-2); margin: .3rem 0 0; max-width: 72ch; font-size: .98rem; }
.page-head-actions { display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }
.page-head-actions .btn { margin: 0; }

/* ---- Stat cards (ledger cells) ---- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
}
.stat-label {
    margin: 0;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--muted);
    font-family: var(--font-body);
}
.stat-value {
    margin: .3rem 0 0;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.02em;
}
.stat-icon {
    display: grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: var(--radius);
    font-size: 1.2rem;
    flex-shrink: 0;
}
.stat-icon-green  { background: var(--green-50); }
.stat-icon-amber  { background: var(--warn-bg); }
.stat-icon-blue   { background: var(--tint-blue); }
.stat-icon-violet { background: var(--tint-violet); }

/* ---- Toolbar / filter bar ---- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1.1rem;
}
.toolbar .field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.toolbar .field-search { flex: 1 1 240px; }
.toolbar label {
    margin: 0;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
}
.toolbar input, .toolbar select {
    width: 100%;
    margin: 0;
    padding: .5rem .7rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: .95rem;
    background: var(--surface);
}
.toolbar select { min-width: 170px; }

/* ---- Layout ---- */
.container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 1.5rem;
}
.breadcrumbs { display: flex; gap: .5rem; font-size: .92rem; color: var(--muted); margin-bottom: 1rem; }
.crumb-sep { color: var(--line-strong); }

/* ---- Cards (genuinely card-shaped: subjects) ---- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    margin: 1.25rem 0 .25rem;
}
.card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.2rem 1.3rem;
    color: var(--ink);
    box-shadow: var(--shadow-border);
    transition: box-shadow .12s ease, border-color .12s ease, transform .12s ease;
    position: relative;
}
.card:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
    box-shadow: var(--shadow-border-hover);
    text-decoration: none;
}
.card h3 { margin: .35rem 0 .25rem; font-size: 1.12rem; }
.subject-code {
    display: inline-block;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .1em;
    color: var(--green-700);
    background: var(--green-50);
    padding: .18rem .55rem;
    border-radius: 999px;
    margin-bottom: .55rem;
    text-transform: uppercase;
}

/* ---- Panels (ruled document sheets) ---- */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.4rem 1.6rem;
    margin: 1.25rem 0;
}
.panel > h2:first-child,
.panel > h1:first-child {
    font-size: 1.12rem;
    padding-bottom: .65rem;
    margin-bottom: .9rem;
    border-bottom: 1px solid var(--line);
    position: relative;
}
.panel > h2:first-child::after {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    bottom: -1px;
    width: 2.4rem;
    height: 2px;
    background: var(--accent);
}

/* Profile */
.profile-summary { display: flex; align-items: center; gap: 1.2rem; }
.profile-summary h2 { margin: 0; font-size: 1.3rem; }
.profile-summary p { margin: .15rem 0 0; }
.user-avatar-lg {
    width: 3.6rem;
    height: 3.6rem;
    font-size: 1.5rem;
    flex-shrink: 0;
    border-radius: 12px;
}

/* ---- Profile modal ---- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: oklch(0.25 0.05 160 / 0.5);
    backdrop-filter: blur(2px);
}
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 51;
    width: min(560px, calc(100vw - 2rem));
    max-height: min(680px, calc(100vh - 3rem));
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-2);
    animation: modal-in .18s ease-out;
}
@keyframes modal-in {
    from { opacity: 0; transform: translate(-50%, -48%); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
}
@media (prefers-reduced-motion: reduce) {
    .modal { animation: none; }
}
.modal-header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 1;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-close {
    border: none;
    background: transparent;
    padding: .25rem .55rem;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--ink); background: var(--surface-2); }
.modal-body { padding: 1.5rem; }
.modal-body .panel { margin: 0 0 1.25rem; box-shadow: none; }
.modal-body .panel:last-child { margin-bottom: 0; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: .55rem;
    margin-top: 1.4rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--line);
}
.modal-actions .btn { margin: 0; }
body.modal-open { overflow: hidden; }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td {
    text-align: start;
    padding: .7rem .7rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.table th {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--muted);
    font-weight: 700;
    border-bottom: 1px solid var(--line-strong);
    font-family: var(--font-body);
}
.table td { font-variant-numeric: tabular-nums; }
.table td:first-child { font-variant-numeric: normal; }
.table tbody tr { transition: background-color .1s ease; }
.table tbody tr:hover { background: var(--canvas); }
.table tr:last-child td { border-bottom: 0; }
.table a { font-weight: 600; }

.btn-link-danger {
    border: 0;
    background: none;
    padding: 0;
    font: inherit;
    color: var(--danger);
    font-weight: 600;
    cursor: pointer;
}
.btn-link-danger:hover { text-decoration: underline; }
.btn-link-danger:disabled { opacity: .5; cursor: default; text-decoration: none; }

/* ---- Scheme of work: grouped by week, document-style ---- */
.scheme-week {
    scroll-margin-top: 5rem;
}
.scheme-week.scheme-week > h2:first-child {
    padding: .55rem .9rem;
    margin: 0 0 1rem;
    background: var(--green-900);
    color: oklch(0.96 0.015 100);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    letter-spacing: .01em;
    border-bottom: 0;
    display: flex;
    align-items: center;
    gap: .6rem;
    text-align: start;
}
.scheme-week.scheme-week > h2:first-child::before {
    content: "";
    width: .5rem;
    height: .5rem;
    background: var(--accent);
    border-radius: 2px;
    transform: rotate(45deg);
    flex-shrink: 0;
}
.scheme-week.scheme-week > h2:first-child::after { content: none; }
.scheme-lesson {
    padding: 1.1rem 0;
    border-top: 1px solid var(--line);
}
.scheme-lesson:first-of-type { border-top: 0; padding-top: .25rem; }
.scheme-lesson h3 {
    font-size: 1.02rem;
    color: var(--green-900);
}
.scheme-lesson h3 a { color: var(--green-700); }
.scheme-fields {
    display: grid;
    grid-template-columns: 13rem 1fr;
    gap: .3rem 1.4rem;
    margin: 0;
}
.scheme-fields dt {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    padding: .32rem 0;
    font-family: var(--font-body);
}
.scheme-fields dd { margin: 0; padding: .32rem 0; }
.scheme-fields ul { margin: 0; padding-inline-start: 1.1rem; }
.scheme-fields li { margin: .15rem 0; }
.scheme-reflection {
    display: block;
    min-height: 1.6rem;
    border-bottom: 1px dashed var(--line-strong);
}
.field-hint-inline { font-weight: 400; text-transform: none; letter-spacing: normal; color: var(--muted); font-size: .82rem; }
.scheme-preview-actions { display: flex; gap: .5rem; margin: 1.25rem 0; }
.scheme-preview-actions .btn { margin: 0; }

/* ---- Learning materials (teacher-added) ---- */
.resource-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.resource-item {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    padding: .35rem 0;
}
.resource-list .resource-item + .resource-item { border-top: 1px solid var(--line); }
.scheme-fields .resource-list { margin: 0; font-size: .85rem; }
.resource-icon { flex-shrink: 0; font-size: .85rem; opacity: .8; }
.resource-item a { word-break: break-word; }
.resource-del { display: inline; margin: 0 0 0 auto; }
.resource-del .btn-link-danger { font-size: .8rem; }

.add-resource {
    display: grid;
    gap: .35rem;
    max-width: 34rem;
    margin-top: 1.25rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--line);
}
.add-resource .resource-type {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: .5rem .75rem;
    margin: .3rem 0 0;
    background: var(--canvas);
}
.add-resource .resource-type legend { font-size: .78rem; font-weight: 600; color: var(--muted); padding: 0 .3rem; }
.add-resource .radio {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    margin: 0 1rem 0 0;
    font-weight: 500;
}
.add-resource .radio input { width: auto; margin: 0; }
.add-resource select[multiple] {
    width: 100%;
    margin-top: .3rem;
    padding: .3rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    background: var(--surface);
}
.add-resource textarea {
    width: 100%;
    margin-top: .3rem;
    padding: .5rem .7rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    resize: vertical;
    background: var(--surface);
}
.add-resource .field-hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }
.add-resource-label { display: block; font-weight: 600; font-size: .92rem; margin: .9rem 0 .35rem; }
.add-resource [data-link-fields] { display: grid; gap: .4rem; }
.add-resource [data-link-fields] input { width: 100%; margin: 0; padding: .5rem .7rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font: inherit; background: var(--surface); }
.add-resource .link-row { display: flex; align-items: center; gap: .4rem; }
.add-resource .link-row input { flex: 1; }
.add-resource .link-remove { flex-shrink: 0; font-size: 1.1rem; line-height: 1; padding: .2rem .5rem; }
.btn-small { padding: .32rem .75rem; font-size: .84rem; margin: .5rem 0 0; }

/* Lesson media (grouped by section) */
.media-group { margin-top: 1rem; }
.media-group h3 {
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin: 0 0 .2rem;
}
.resource-thumb {
    max-width: 120px;
    max-height: 90px;
    border-radius: 6px;
    border: 1px solid var(--line);
    display: block;
    object-fit: cover;
}
.resource-item .resource-thumb + a { align-self: center; }

/* Badges */
.badge {
    display: inline-block;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .06em;
    padding: .2rem .6rem;
    border-radius: 999px;
    text-transform: uppercase;
    font-family: var(--font-body);
    border: 1px solid transparent;
}
.badge-supported { background: var(--success-bg); color: var(--success-ink); border-color: var(--success-line); }
.badge-needs_verification { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.badge-unknown { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.badge-scheduled { background: var(--tint-blue); color: var(--blue-ink); margin-inline-start: .5rem; border-color: transparent; }

/* ---- Alerts & disclosure ---- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    padding: .75rem 1rem;
    border-radius: var(--radius-sm);
    margin: .75rem 0;
    font-size: .93rem;
    line-height: 1.5;
    border: 1px solid;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.alert-success { background: var(--success-bg); color: var(--success-ink); border-color: var(--success-line); }
.alert-info { background: var(--tint-blue); color: var(--blue-ink); border-color: color-mix(in oklch, var(--tint-blue) 60%, var(--blue-ink) 25%); }
.disclosure {
    font-size: .88rem;
    color: var(--muted);
    border-inline-start: 2px solid var(--line-strong);
    padding-inline-start: .8rem;
    font-style: italic;
    line-height: 1.55;
}
.citations { font-size: .83rem; color: var(--muted); font-style: italic; }
.panel-sijui { border-color: var(--warn-line); background: color-mix(in oklch, var(--warn-bg) 45%, var(--surface)); }
.panel-sijui h2 { color: var(--warn-ink); }
.panel-sijui h2::after { background: var(--warn-ink); }

/* ---- Forms ---- */
label { display: block; font-weight: 600; font-size: .92rem; margin: 1rem 0 .4rem; }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: .6rem .8rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: .95rem;
    background: var(--surface);
    margin-top: .3rem;
    color: var(--ink);
    transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--green-600);
    outline-offset: 2px;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--green-600);
    box-shadow: 0 0 0 3px color-mix(in oklch, var(--green-50) 80%, transparent);
}
input::placeholder, textarea::placeholder { color: color-mix(in oklch, var(--muted) 75%, transparent); }
textarea { resize: vertical; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    font: inherit;
    font-weight: 600;
    font-size: .92rem;
    padding: .55rem 1.2rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    margin: .75rem .25rem 0 0;
    line-height: 1.3;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease, transform .08s ease;
    text-decoration: none;
}
.btn:hover {
    text-decoration: none;
    border-color: var(--green-600);
    background: var(--canvas);
    color: var(--ink);
}
.btn:active { transform: scale(.985); }
.btn:focus-visible { outline: 2px solid var(--green-600); outline-offset: 2px; }
.btn-primary {
    background: var(--green-700);
    border-color: var(--green-700);
    color: oklch(0.97 0.01 100);
}
.btn-primary:hover { background: var(--green-900); border-color: var(--green-900); color: #fff; }
.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}
.btn-accent:hover { background: var(--accent-deep); border-color: var(--accent-deep); color: #fff; }
.btn-danger-ghost {
    background: transparent;
    border-color: var(--danger-line);
    color: var(--danger);
}
.btn-danger-ghost:hover {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
}
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; margin: 1rem 0 0; }

/* ---- Topic list ---- */
.topic-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.topic-list li {
    padding: .05rem 0;
    border-bottom: 1px solid var(--line);
}
.topic-list li:last-child { border-bottom: 0; }
.topic-list a {
    font-weight: 600;
    display: flex;
    align-items: baseline;
    gap: .7rem;
    padding: .6rem .2rem;
    border-radius: var(--radius-sm);
    color: var(--ink);
    transition: background-color .1s ease, color .1s ease;
}
.topic-list a::before {
    content: "§";
    font-family: var(--font-display);
    color: var(--accent);
    font-size: .8rem;
    font-weight: 700;
    opacity: .7;
    flex-shrink: 0;
}
.topic-list a:hover { background: var(--green-50); text-decoration: none; color: var(--green-900); }
.topic-list a.active { color: var(--green-900); }
.topic-list a.active::before { opacity: 1; }
.topic-list .badge { margin-inline-start: auto; flex-shrink: 0; align-self: center; }

/* ---- Public browse pages ---- */
.browse-layout {
    display: grid;
    grid-template-columns: 1fr 270px;
    gap: 1.5rem;
    align-items: start;
}
.browse-sidebar { margin: 0; position: sticky; top: 1.5rem; }
.browse-sidebar h2 { font-size: .95rem; text-transform: uppercase; letter-spacing: .06em; font-family: var(--font-body); }
.browse-sidebar .topic-list a { font-size: .88rem; font-weight: 500; }
.browse-sidebar .topic-list a::before { content: none; }
.browse-pager {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.browse-pager .btn { margin: 0; }
@media (max-width: 780px) {
    .browse-layout { grid-template-columns: 1fr; }
    .browse-sidebar { position: static; }
}

/* ---- Lesson body ---- */
.prose { white-space: normal; line-height: 1.7; }
.board-plan {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 1.1rem 1.2rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: .9rem;
    line-height: 1.65;
    color: var(--ink);
    box-shadow: inset 0 1px 0 oklch(1 0 0 / .5), inset 0 0 0 1px oklch(0 0 0 / .02);
}
.print-actions { margin: 1.5rem 0; }
.print-actions .btn { margin-top: 0; }

/* ---- Auth ---- */
.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: var(--canvas);
    padding: 1.5rem;
}

.auth-shell {
    display: grid;
    grid-template-columns: minmax(300px, 5fr) minmax(360px, 4fr);
    width: 100%;
    max-width: 1000px;
    min-height: 590px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-2);
    background: var(--surface);
    border: 1px solid var(--line);
}
.auth-shell-single {
    grid-template-columns: 1fr;
    max-width: 480px;
    min-height: 0;
}

/* Brand / "notebook cover" side */
.auth-panel {
    background:
        radial-gradient(520px 320px at 18% -5%, oklch(0.42 0.09 160 / 0.4), transparent 55%),
        linear-gradient(168deg, oklch(0.34 0.06 160) 0%, oklch(0.27 0.05 160) 62%, oklch(0.23 0.045 160) 100%);
    color: oklch(0.92 0.02 130);
    padding: 2.75rem 2.5rem;
    display: flex;
    flex-direction: column;
    position: relative;
}
.auth-panel::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: .5;
    background-image:
        linear-gradient(oklch(1 0 0 / .035) 1px, transparent 1px);
    background-size: 100% 28px;
}
.auth-panel > * { position: relative; }
.auth-panel .auth-brand {
    color: oklch(0.97 0.01 110);
    font-size: 1.1rem;
    text-align: start;
    padding: 0;
    margin: 0 0 3rem;
}
.auth-panel .auth-brand .brand-mark { background: oklch(0.96 0.015 100); color: var(--green-900); }
.auth-panel .auth-brand .brand-name span { color: oklch(0.75 0.12 60); }
.auth-panel-lead {
    font-size: 1.75rem;
    line-height: 1.3;
    font-weight: 700;
    color: #fff;
    max-width: 20ch;
    margin: 0 0 2rem;
    font-family: var(--font-display);
    text-wrap: balance;
}
.auth-points {
    list-style: none;
    margin: 0 0 2.5rem;
    padding: 0;
    display: grid;
    gap: .9rem;
}
.auth-points li {
    position: relative;
    padding-inline-start: 1.7rem;
    color: oklch(0.9 0.025 135);
    font-size: .97rem;
    line-height: 1.5;
}
.auth-points li::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    top: .35rem;
    width: .72rem;
    height: .72rem;
    border-radius: 2px;
    background: var(--accent);
    box-shadow: 0 0 0 3px oklch(0.75 0.12 60 / 0.25);
    transform: rotate(45deg);
}
.auth-panel-note {
    margin-top: auto;
    font-size: .85rem;
    line-height: 1.6;
    color: oklch(0.82 0.03 135);
    border-top: 1px solid oklch(1 0 0 / 0.15);
    padding-top: 1.25rem;
    max-width: 42ch;
    font-style: italic;
}

/* Form side */
.auth-form-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 2.75rem 3rem;
    background: var(--surface);
}
.auth-form-panel .auth-brand {
    text-align: start;
    padding: 0;
    margin: 0 0 2rem;
    display: none; /* only used on the single-column variants */
}
.auth-shell-single .auth-form-panel .auth-brand { display: flex; }
.auth-form-panel h1 {
    font-size: 1.85rem;
    margin: 0 0 .4rem;
    letter-spacing: -.01em;
}
.auth-sub { color: var(--ink-2); margin: 0 0 1.75rem; font-size: .98rem; line-height: 1.6; max-width: 42ch; }
.auth-switch { margin-top: 1.75rem; text-align: center; color: var(--muted); font-size: .92rem; }

/* Form styling scoped to auth screens */
.auth-form {
    display: grid;
    gap: .4rem;
}
.auth-form label {
    font-weight: 600;
    font-size: .92rem;
    margin: 1rem 0 .15rem;
}
.auth-form input {
    margin-top: .35rem;
}
.field-hint {
    font-size: .84rem;
    color: var(--muted);
    margin: .35rem 0 0;
}

/* Password visibility toggle */
.password-input-wrap {
    position: relative;
    margin-top: .35rem;
}
.password-input-wrap input {
    margin-top: 0;
    padding-inline-end: 4.6rem;
}
.password-toggle {
    position: absolute;
    inset-inline-end: .35rem;
    top: 50%;
    transform: translateY(-50%);
    min-height: 40px;
    padding: 0 .85rem;
    border: 0;
    background: transparent;
    color: var(--green-700);
    font: inherit;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.password-toggle:hover { background: var(--green-50); }
.password-toggle:focus-visible {
    outline: 2px solid var(--green-600);
    outline-offset: 1px;
}
.auth-forgot {
    margin: 1rem 0 0;
    font-size: .92rem;
    text-align: end;
}

/* Password strength meter + confirm match (setup) */
.strength-meter {
    height: 5px;
    border-radius: 999px;
    background: var(--surface-3);
    margin-top: .65rem;
    overflow: hidden;
}
.strength-bar {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: var(--surface-3);
    transition: width .2s ease, background-color .2s ease;
}
.strength-bar.strength-1 { width: 25%; background: var(--danger); }
.strength-bar.strength-2 { width: 50%; background: oklch(0.62 0.12 70); }
.strength-bar.strength-3 { width: 75%; background: var(--green-600); }
.strength-bar.strength-4 { width: 100%; background: var(--green-700); }
.strength-label-strength-1 { color: var(--danger); font-weight: 600; }
.strength-label-strength-2 { color: oklch(0.5 0.09 70); font-weight: 600; }
.strength-label-strength-3, .strength-label-strength-4 { color: var(--green-900); font-weight: 600; }
.match-hint { min-height: 1.2em; }
.match-hint.match-ok { color: var(--green-700); font-weight: 600; }
.match-hint.match-error { color: var(--danger); font-weight: 600; }

/* ---- Result area (topic.php / schemes.php generators) ---- */
#generate-result { margin-top: 1.25rem; }
.result-success {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.2rem 1.4rem;
    background: var(--surface);
    box-shadow: var(--shadow-border);
}
.result-success h3 { margin-top: .5rem; }
.result-status { font-weight: 700; text-transform: uppercase; font-size: .8rem; letter-spacing: .05em; }
.result-unknown {
    border: 1px solid var(--warn-line);
    background: var(--warn-bg);
    border-radius: var(--radius);
    padding: 1.1rem 1.3rem;
}

/* Generator worksheet fields */
.generate-form {
    display: grid;
    gap: .15rem;
    max-width: 46rem;
}
.generate-form label { margin-top: .9rem; }

/* Scheme input wells inside the editable preview */
.scheme-input {
    width: 100%;
    margin-top: .3rem;
    padding: .5rem .7rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: .92rem;
    background: var(--surface);
}
.scheme-input:focus { border-color: var(--green-600); }

/* ---- Footer ---- */
.site-footer {
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 1.25rem 2.25rem 2.25rem;
    color: var(--muted);
    font-size: .82rem;
    border-top: 1px solid var(--line);
    text-align: center;
}

/* ---- Public header brand ---- */
.topbar-public { padding: .9rem 2rem; justify-content: space-between; }
.topbar-public .topbar-right { margin-left: auto; }
.site-header {
    display: flex;
    align-items: center;
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

/* ---- Print ---- */
@media print {
    :root {
        --canvas: #fff;
        --surface: #fff;
        --ink: #1a1a1a;
        --line: #d8d8d8;
    }
    .sidebar, .topbar, .site-footer, .print-actions, .page-head-actions, .modal-backdrop, .modal { display: none; }
    .app { display: block; }
    .content { max-width: none; padding: 0; }
    body { background: #fff; }
    .panel {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
        margin: 1rem 0;
    }
    .scheme-lesson { break-inside: avoid; }
    .add-resource, .resource-del, #materials { display: none; }
    #lesson-media .add-resource, #lesson-media .resource-del { display: none; }
    .page-head { border-bottom: 1px solid #999; }
    a { color: inherit; }
    .auth-body { background: #fff; }
    .auth-shell { box-shadow: none; border: none; max-width: none; }
}

/* ---- Responsive shell ---- */
@media (min-width: 1025px) {
    .sidebar-backdrop { display: none !important; }
}

@media (max-width: 1024px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 40;
        width: min(var(--sidebar-w), 86vw);
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-2);
    }
    .sidebar.open { transform: none; }
    .topbar-toggle { display: inline-flex; }
}

@media (max-width: 880px) {
    .auth-shell {
        grid-template-columns: 1fr;
        max-width: 500px;
    }
    .auth-panel { display: none; }
}

@media (max-width: 640px) {
    .content { padding: 1.25rem 1.1rem 2rem; }
    .scheme-fields { grid-template-columns: 1fr; }
    .scheme-fields dt { padding-bottom: 0; }
    .topbar { padding: .7rem 1rem; gap: .6rem; }
    .topbar-right { gap: .7rem; }
    .topbar-clock, .user-name { display: none; }
    .nav-logout { white-space: nowrap; }
    .page-head-icon { display: none; }
    input, select, textarea { font-size: 1rem; } /* avoid iOS zoom */

    /* Collapse the breadcrumb trail to just the current page */
    .topbar .breadcrumbs { flex-wrap: nowrap; overflow: hidden; }
    .topbar .breadcrumbs > * { display: none; }
    .topbar .breadcrumbs > *:last-child {
        display: block;
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--ink);
        font-weight: 600;
    }
}

/* ---- Online / offline indicator (installed web app & pages) ---- */
.conn-pill {
    position: fixed;
    left: 1rem;
    bottom: 1rem;
    z-index: 120;
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    max-width: min(24rem, calc(100vw - 2rem));
    padding: .6rem 1rem;
    border-radius: 999px;
    background: var(--ink);
    color: #fff;
    font-size: .85rem;
    font-weight: 600;
    line-height: 1.3;
    box-shadow: var(--shadow-2);
}
.conn-pill::before {
    content: '';
    flex: none;
    width: .55rem;
    height: .55rem;
    border-radius: 50%;
    background: #f0a93c;
}
.conn-pill-ok::before { background: #56c271; }
.conn-pill-ok { background: var(--green-900); }
