:root {
    --paper: #F4F1EA;
    --surface: #FFFFFF;
    --surface-2: #EDEAE1;
    --ink: #1F1D1A;
    --ink-muted: #6B6862;
    --rule: #D9D4C7;
    --accent: #2D5A3A;
    --accent-2: #4A7C59;
    --warning: #A67217;
    --danger: #A03C34;
    --success: #3B7A4B;
    --sidebar-width: 240px;
    --font-ui: "Segoe UI", Inter, system-ui, sans-serif;
    --font-reading: Charter, "Iowan Old Style", Georgia, serif;
    --font-mono: "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
    margin: 0;
    background: var(--paper);
    background-image: linear-gradient(135deg, rgba(255,255,255,.28), rgba(217,212,199,.16));
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
}
h1, h2, h3, h4, h5, h6 { color: var(--ink); font-family: var(--font-reading); font-weight: 700; letter-spacing: -.01em; line-height: 1.3; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); text-decoration: underline; }
button, input, select, textarea { font-family: var(--font-ui); }

.bevel-raised { border: 1px solid rgba(0,0,0,.08); box-shadow: 0 1px 0 rgba(0,0,0,.04); }
.bevel-sunken { border: 1px solid var(--rule); background: var(--surface); }
.bevel-window { border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); box-shadow: 0 1px 0 rgba(0,0,0,.04); }

.app-frame { min-height: calc(100vh - 24px); margin: 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); overflow: hidden; }
.app-shell { min-height: calc(100vh - 48px); display: flex; }

.btn {
    min-height: 32px;
    padding: 6px 12px;
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 4px;
    background: var(--surface);
    color: var(--ink);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
    text-decoration: none;
    transition: background-color .12s ease, color .12s ease, transform .12s ease;
}
.btn:hover, .btn:focus { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary, .btn-success { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.btn-primary:hover, .btn-primary:focus, .btn-success:hover, .btn-success:focus { background: var(--accent-2); border-color: var(--accent-2); color: #FFFFFF; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #FFFFFF; }
.btn-outline-primary { color: var(--accent); border-color: var(--accent); background: transparent; }
.btn-outline-primary:hover { background: rgba(45,90,58,.08); color: var(--accent); border-color: var(--accent); }
.btn-outline-secondary, .btn-outline-danger, .btn-light { color: var(--ink); background: var(--surface); border-color: var(--rule); }
.btn-sm { min-height: 30px; padding: 5px 9px; font-size: 13px; }

.card, .stat-card, .auth-card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 6px;
    box-shadow: 0 1px 0 rgba(0,0,0,.03);
}
.card-header { padding: 9px 12px; background: var(--surface); border-bottom: 1px solid var(--rule); color: var(--ink); font-size: 14px; font-weight: 500; }
.card-body { padding: 16px; }
.card-titlebar, .window-titlebar { padding: 8px 12px; border-bottom: 1px solid var(--rule); font-size: 14px; font-weight: 500; }
.window-controls { display: inline-flex; gap: 4px; }
.window-controls button { width: 22px; height: 20px; padding: 0; min-height: 20px; font-size: 13px; line-height: 1; }

.form-label { margin-bottom: 5px; color: var(--ink); font-size: 13px; font-weight: 600; }
.form-control, .form-select, textarea.form-control {
    min-height: 40px;
    padding: 9px 10px;
    border: 1px solid var(--rule);
    border-radius: 4px;
    background: var(--surface);
    color: var(--ink);
    font-size: 14px;
}
.form-control:focus, .form-select:focus, textarea.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45,90,58,.12); outline: none; }
.form-control::placeholder { color: var(--ink-muted); }
.form-check-input { border-color: var(--rule); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus { box-shadow: 0 0 0 3px rgba(45,90,58,.12); }

.app-sidebar { width: var(--sidebar-width); flex: 0 0 var(--sidebar-width); min-height: calc(100vh - 48px); position: relative; display: flex; flex-direction: column; background: var(--paper); border-right: 1px solid var(--rule); }
.app-sidebar .brand { min-height: 56px; padding: 12px 16px; display: flex; align-items: center; gap: 9px; border-bottom: 1px solid var(--rule); color: var(--ink); font-family: var(--font-reading); font-size: 15px; font-weight: 700; }
.app-sidebar .brand .brand-mark { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--rule); border-radius: 4px; background: var(--surface); color: var(--accent); }
.app-sidebar .nav { padding: 12px 10px !important; }
.app-sidebar .nav-link { min-height: 36px; padding: 8px 10px; display: flex; align-items: center; gap: 9px; border-left: 2px solid transparent; border-radius: 4px; color: var(--ink-muted); font-size: 13px; text-decoration: none; }
.app-sidebar .nav-link i { width: 16px; color: var(--ink-muted); font-size: 14px; text-align: center; }
.app-sidebar .nav-link:hover { color: var(--accent); background: transparent; }
.app-sidebar .nav-link:hover i { color: var(--accent); }
.app-sidebar .nav-link.active { border-left-color: var(--accent); background: rgba(45,90,58,.08); color: var(--accent); font-weight: 600; }
.app-sidebar .nav-link.active i { color: var(--accent); }
.app-sidebar .nav-link.disabled { color: var(--ink-muted); pointer-events: none; }
.app-sidebar .nav-section { margin-top: 12px; padding: 4px 10px; color: var(--ink-muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.app-sidebar .sidebar-footer { margin-top: auto; padding: 10px 16px; border-top: 1px solid var(--rule); color: var(--ink-muted); }
.app-sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 1040; background: rgba(31,29,26,.35); backdrop-filter: blur(2px); }
.app-sidebar-backdrop.show { display: block; }

.app-main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.app-topbar { min-height: 48px; padding: 8px 16px; display: flex; align-items: center; gap: 14px; background: var(--surface); border-bottom: 1px solid var(--rule); }
.topbar-institution { color: var(--ink-muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
.topbar-context { color: var(--ink-muted); font-size: 13px; }
.topbar-hint { color: var(--ink-muted); font-family: var(--font-mono); font-size: 11px; letter-spacing: .02em; }
.avatar-circle, .avatar-circle-img { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--rule); border-radius: 4px; background: var(--surface-2); color: var(--accent); font-family: var(--font-mono); font-size: 11px; font-weight: 700; object-fit: cover; }
.app-content { flex: 1; padding: 28px; }
.app-footer { min-height: 32px; padding: 7px 12px; border-top: 1px solid var(--rule); background: var(--surface-2); color: var(--ink-muted); font-family: var(--font-mono); font-size: 11px; }

.page-header { min-height: 57px; padding-bottom: 16px; margin-bottom: 20px !important; border: 0; border-bottom: 1px solid var(--rule); background: transparent; }
.page-header > div:first-child { padding: 0; }
.page-title { margin: 0; color: var(--ink); font: 700 24px/1.3 var(--font-reading); }
.page-header .text-muted-sm { color: var(--ink-muted); }
.page-header > .btn { align-self: center; }
.text-muted-sm { color: var(--ink-muted); font-size: 12px; }
.section-title { margin-bottom: 12px; font-size: 18px; }
.empty-state { padding: 42px 16px; text-align: center; color: var(--ink-muted); }
.empty-state i { display: block; margin-bottom: 8px; color: var(--accent); font-size: 28px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { min-height: 112px; padding: 20px; display: flex; align-items: center; gap: 14px; transition: border-color .12s ease; }
.stat-card:hover { border-color: rgba(45,90,58,.35); }
.stat-icon { width: 48px; height: 48px; flex: 0 0 48px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid rgba(45,90,58,.18); border-radius: 4px; background: rgba(45,90,58,.10); color: var(--accent); font-size: 20px; }
.stat-content { min-width: 0; }
.stat-value { color: var(--ink); font-family: var(--font-reading); font-size: 28px; font-weight: 600; letter-spacing: -.01em; line-height: 1.05; }
.stat-label { margin-top: 5px; color: var(--ink-muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; line-height: 1.3; text-transform: uppercase; }
.stat-caption { margin-top: 4px; color: var(--ink-muted); font-family: var(--font-mono); font-size: 11px; letter-spacing: .02em; line-height: 1.3; }
.stat-card-users .stat-icon { background: rgba(45,90,58,.10); border-color: rgba(45,90,58,.18); color: var(--accent); }
.stat-card-courses .stat-icon { background: rgba(138,90,43,.10); border-color: rgba(138,90,43,.18); color: #8A5A2B; }
.stat-card-cohorts .stat-icon { background: rgba(63,92,122,.10); border-color: rgba(63,92,122,.18); color: #3F5C7A; }
.stat-card-assignments .stat-icon { background: rgba(140,58,58,.10); border-color: rgba(140,58,58,.18); color: #8C3A3A; }
.stat-card-resources .stat-icon { background: rgba(107,91,46,.10); border-color: rgba(107,91,46,.18); color: #6B5B2E; }
.stat-card-certificates .stat-icon { background: rgba(138,106,31,.10); border-color: rgba(138,106,31,.18); color: #8A6A1F; }
.stat-card-warning .stat-icon { background: rgba(166,114,23,.10); border-color: rgba(166,114,23,.18); color: var(--warning); }
.stat-card-danger .stat-icon { background: rgba(160,60,52,.10); border-color: rgba(160,60,52,.18); color: var(--danger); }
.stat-card-neutral .stat-icon { background: rgba(107,104,98,.10); border-color: rgba(107,104,98,.18); color: var(--ink-muted); }

.table { --bs-table-color: var(--ink); --bs-table-bg: var(--surface); margin-bottom: 0; border-color: var(--rule); font-size: 13px; }
.table > :not(caption) > * > * { padding: 10px 8px; border: 0; border-bottom: 1px solid var(--rule); }
.table thead th, .table tfoot th { padding-left: 12px; padding-right: 12px; background: var(--surface-2); color: var(--ink-muted); border-bottom: 1px solid var(--rule); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.table tbody tr:nth-child(even) > * { background: transparent; }
.table tbody tr:hover > * { background: rgba(237,234,225,.6); }
.badge { padding: 3px 6px; border: 1px solid currentColor; border-radius: 3px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.badge-status-open, .badge-status-active { background: rgba(59,122,75,.08); color: var(--success); }
.badge-status-closed { background: rgba(107,104,98,.08); color: var(--ink-muted); }
.badge-status-blocked { background: rgba(160,60,52,.08); color: var(--danger); }
.alert { padding: 10px 12px; border: 1px solid var(--rule); border-left: 3px solid var(--accent); border-radius: 4px; color: var(--ink); background: var(--surface); }
.alert-success { border-left-color: var(--success); }
.alert-warning, .alert-info { border-left-color: var(--warning); }
.alert-danger { border-left-color: var(--danger); }
.btn-close { width: 20px; height: 20px; padding: 0; opacity: .7; }

.dropdown-menu, .modal-content, .swal2-popup { border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); box-shadow: 0 4px 14px rgba(31,29,26,.12) !important; }
.dropdown-menu { padding: 8px; }
.dropdown-item { min-height: 32px; padding: 6px 8px; border-radius: 4px; color: var(--ink); font-size: 13px; }
.dropdown-item:hover, .dropdown-item:focus { background: rgba(45,90,58,.08); color: var(--accent); }
.dropdown-divider { border-top-color: var(--rule); }
.modal-header { border-bottom: 1px solid var(--rule); }
.modal-body, .modal-footer { padding: 16px; }
.swal2-popup { color: var(--ink); font-family: var(--font-ui); }
.swal2-title { color: var(--ink); font: 700 22px var(--font-reading); }
.swal2-html-container { font-size: 14px; }
.swal2-actions .swal2-styled { min-height: 32px; border: 1px solid rgba(0,0,0,.08) !important; border-radius: 4px !important; box-shadow: none !important; font: 500 14px var(--font-ui); }
.swal2-actions .swal2-confirm { background: var(--accent) !important; }
.swal2-actions .swal2-cancel { background: var(--surface) !important; color: var(--ink) !important; }

.auth-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--paper); background-image: linear-gradient(135deg, rgba(255,255,255,.28), rgba(217,212,199,.16)); }
.auth-card { width: 100%; max-width: 420px; overflow: hidden; }
.auth-titlebar { display: flex; align-items: center; justify-content: space-between; min-height: 42px; padding: 8px 14px; border-bottom: 1px solid var(--rule); color: var(--ink); font-size: 13px; font-weight: 600; }
.auth-card-inner { padding: 24px; }
.auth-brand { margin-bottom: 20px; text-align: left; }
.auth-brand .brand-mark { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--rule); border-radius: 4px; background: var(--surface-2); color: var(--accent); font-size: 18px; }
.auth-brand h1 { margin: 8px 0 0; font-size: 22px; }
.auth-brand p { margin: 4px 0 0; color: var(--ink-muted); }

.course-thumb, .course-thumb-lg, .course-banner { border: 1px solid var(--rule); border-radius: 4px !important; }
.course-thumb { width: 56px; height: 40px; object-fit: cover; }
.course-thumb-empty { display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--ink-muted); }
.course-thumb-lg { width: 160px; height: 100px; object-fit: cover; }
.course-banner { width: 100%; max-height: 280px; object-fit: cover; display: block; }
.avatar-preview { width: 120px; height: 120px; overflow: hidden; border: 1px solid var(--rule); border-radius: 4px; background: var(--surface-2); }
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-preview-initials { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: rgba(45,90,58,.08); color: var(--accent); font-family: var(--font-mono); font-size: 32px; font-weight: 700; }

.list-toolbar .form-label { margin-bottom: 4px; }
table[data-datatable] { width: 100%; }
.dataTables_wrapper .row:first-child, .dataTables_wrapper .row:last-child { align-items: center; padding: 12px; }
.dataTables_wrapper .dataTables_length label, .dataTables_wrapper .dataTables_filter label, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dt-info { padding: 4px 12px; color: var(--ink-muted); font-size: 12px; }
#DataTables_Table_0_info, .dataTables_wrapper [id^="DataTables_Table_"][id$="_info"] { display: block; padding: 8px 16px !important; }
.dataTables_wrapper .row.mt-2.justify-content-between { box-sizing: border-box; width: 100%; margin-left: 0 !important; margin-right: 0 !important; padding-left: 20px !important; padding-right: 20px !important; }
.dataTables_wrapper .row.mt-2.justify-content-between .dt-length, .dataTables_wrapper .row.mt-2.justify-content-between .dt-search { padding-left: 4px; padding-right: 4px; }
.dataTables_wrapper .dt-layout-row:first-child, .dataTables_wrapper > .row:first-child { box-sizing: border-box; width: 100%; margin-left: 0 !important; margin-right: 0 !important; padding-left: 20px !important; padding-right: 20px !important; }
.dataTables_wrapper .dt-layout-row:first-child .dt-length, .dataTables_wrapper .dt-layout-row:first-child .dt-search { padding-left: 4px; padding-right: 4px; }
.dataTables_wrapper .dataTables_filter input, .dataTables_wrapper .dataTables_length select { min-height: 34px; margin-left: 4px; padding: 6px 8px; border: 1px solid var(--rule); border-radius: 4px; background: var(--surface); }
.dataTables_wrapper .dataTables_filter input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45,90,58,.12); outline: none; }
.dataTables_wrapper .pagination { margin: 0; padding: 8px; }
.dataTables_wrapper .pagination .page-link { min-width: 32px; min-height: 32px; padding: 5px 8px; margin: 0 2px; border: 1px solid var(--rule); border-radius: 4px !important; color: var(--ink); background: var(--surface); text-align: center; }
.dataTables_wrapper .pagination .page-item.active .page-link { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.dataTables_wrapper .pagination .page-item.disabled .page-link { color: var(--ink-muted); background: var(--surface-2); }
.dataTables_wrapper .dataTables_empty { padding: 36px 16px; color: var(--ink-muted); }
.dt-hide-server-pager .pagination { display: none !important; }

code, .font-monospace, .topbar-hint, .app-footer, .dataTables_wrapper .dataTables_info { font-family: var(--font-mono); letter-spacing: .02em; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--surface-2); }
::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 4px; }
* { scrollbar-color: var(--rule) var(--surface-2); scrollbar-width: thin; }

@media (min-width: 1200px) { .app-frame { margin: 12px; } }
@media (min-width: 992px) and (max-width: 1199.98px) { .app-frame { margin: 8px; } .app-content { padding: 24px; } }
@media (max-width: 991.98px) {
    .app-frame { margin: 0; border-radius: 0; border-left: 0; border-right: 0; }
    .app-sidebar { position: fixed; top: 0; left: 0; height: 100vh; min-height: 100vh; transform: translateX(-100%); transition: transform .2s ease-in-out; z-index: 1050; }
    .app-sidebar.open { transform: translateX(0); }
    .app-content { padding: 20px; }
}
@media (max-width: 767.98px) {
    .app-content { padding: 16px; }
    .page-title { font-size: 20px; }
    .page-header { min-height: 48px; margin-bottom: 16px !important; padding-bottom: 12px; }
    .table-responsive { border-radius: 4px; box-shadow: inset 0 0 8px rgba(31,29,26,.08); }
    .btn, .btn-sm, .nav-link, .dropdown-item { min-height: 40px; }
    .form-control, .form-select { min-height: 40px; }
    .auth-card-inner { padding: 16px; }
    .app-topbar { padding: 8px 12px; }
    .topbar-context { display: none; }
}
@media (max-width: 479.98px) {
    .stats-grid { gap: 12px; }
    .stat-card { min-height: 96px; padding: 14px; gap: 10px; }
    .stat-icon { width: 40px; height: 40px; flex-basis: 40px; font-size: 18px; }
    .stat-value { font-size: 24px; }
}
/* ---------- Stat cards (vintage-analog) ---------- */
.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface, #FFFFFF);
    border: 1px solid var(--rule, #D9D4C7);
    border-radius: 6px;
    padding: 18px 20px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
    transition: border-color .15s ease;
    height: 100%;
    text-decoration: none;
    color: inherit;
}
.stat-card-link { display: block; height: 100%; text-decoration: none; color: inherit; }
.stat-card-link:hover .stat-card { border-color: color-mix(in srgb, var(--accent) 35%, transparent); }

.stat-card-icon {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--stat-accent, var(--accent)) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--stat-accent, var(--accent)) 18%, transparent);
    color: var(--stat-accent, var(--accent));
    font-size: 20px;
}
.stat-card-icon i { display: inline-block; width: 1em; height: 1em; font-family: "bootstrap-icons" !important; font-style: normal; font-weight: normal; line-height: 1; }
.stat-card-icon i::before { display: inline-block; }

.stat-card-body { min-width: 0; }

.stat-card-value {
    display: block;
    min-width: 1ch;
    font-family: "Charter", "Iowan Old Style", Georgia, serif;
    font-size: 28px;
    font-weight: 600;
    line-height: 1.1;
    color: var(--ink, #1F1D1A) !important;
    letter-spacing: -0.01em;
}

.stat-card-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted, #6B6862) !important;
    margin-top: 4px;
}

.stat-card-caption {
    font-family: "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
    font-size: 11px;
    color: var(--ink-muted, #6B6862);
    margin-top: 2px;
}

@media (max-width: 480px) {
    .stat-card { padding: 14px 16px; gap: 12px; }
    .stat-card-icon { width: 40px; height: 40px; font-size: 18px; }
    .stat-card-value { font-size: 24px; }
}

/* Grid helper — use on the wrapping .row or a plain div */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}
@media (max-width: 480px) {
    .stat-grid { gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* Force the DataTables page/search header inside the card edges. */
.dataTables_wrapper > .row:first-child,
.dataTables_wrapper > .dt-layout-row:first-child,
.dt-container > .row:first-child,
.dt-container > .dt-layout-row:first-child,
.dataTables_wrapper .row.mt-2.justify-content-between,
.dt-container .row.mt-2.justify-content-between {
    box-sizing: border-box !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 24px !important;
    padding-right: 24px !important;
}

.dataTables_wrapper .dt-layout-row:first-child > .dt-layout-cell,
.dt-container .dt-layout-row:first-child > .dt-layout-cell,
.dataTables_wrapper .row.mt-2.justify-content-between > [class*="col-"],
.dt-container .row.mt-2.justify-content-between > [class*="col-"] {
    padding-left: 6px !important;
    padding-right: 6px !important;
}

/* CKEditor content surfaces */
.ck-editor__editable_inline {
    min-height: 220px;
    background: var(--surface, #FFFFFF);
    border: 1px solid var(--rule, #D9D4C7) !important;
    border-radius: 0 0 4px 4px;
    font-family: "Charter", "Iowan Old Style", Georgia, serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--ink, #1F1D1A);
}
.ck-editor__top .ck-sticky-panel .ck-toolbar {
    background: var(--surface-2, #EDEAE1);
    border: 1px solid var(--rule, #D9D4C7) !important;
    border-radius: 4px 4px 0 0;
}
.ck.ck-button:hover { background: rgba(45, 90, 58, 0.08) !important; }
.ck.ck-button.ck-on { background: rgba(45, 90, 58, 0.15) !important; color: var(--accent, #2D5A3A) !important; }
.ck-content iframe { max-width: 100%; }
.ck-content h2 { font-family: "Charter", Georgia, serif; font-size: 22px; margin-top: 18px; }
.ck-content h3 { font-family: "Charter", Georgia, serif; font-size: 18px; margin-top: 14px; }
.ck-content blockquote { border-left: 3px solid var(--accent, #2D5A3A); padding-left: 14px; color: var(--ink-muted, #6B6862); font-style: italic; }

/* ---------- Library grid ---------- */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.library-card {
    background: var(--surface, #fff);
    border: 1px solid var(--rule, #D9D4C7);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 0 rgba(0,0,0,.03);
    transition: border-color .15s ease, transform .15s ease;
}
.library-card:hover { border-color: rgba(45,90,58,.35); }

.library-cover-link { display: block; }

.library-cover {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    display: block;
    background: var(--surface-2, #EDEAE1);
}
.library-cover-placeholder {
    display: flex; align-items: center; justify-content: center;
    color: #B7C5BB; font-size: 2.5rem;
    background: var(--surface-2, #EDEAE1);
}

.library-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; }

.library-title {
    font-family: "Charter", "Iowan Old Style", Georgia, serif;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink, #1F1D1A);
    text-decoration: none;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.library-title:hover { color: var(--accent, #2D5A3A); text-decoration: underline; }

.library-author {
    font-size: 12px;
    color: var(--ink-muted, #6B6862);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.library-category { align-self: flex-start; font-size: 10px; }

.library-desc {
    font-size: 12px;
    color: var(--ink-muted, #6B6862);
    margin: 4px 0 0;
    line-height: 1.4;
    min-height: 34px;
}

.library-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--rule, #D9D4C7);
    font-size: 12px;
    color: var(--ink-muted, #6B6862);
}
.library-meta i { margin-right: 2px; }

.library-like-form { margin-left: auto; }

.library-detail-cover {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    display: block;
    background: var(--surface-2, #EDEAE1);
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}

@media (max-width: 767px) {
    .library-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
    .library-title { font-size: 14px; }
    .library-desc { display: none; }
    .library-meta { font-size: 11px; gap: 8px; }
}

/* Sidebar active state — reads as a pressed button */
.app-sidebar .nav-link {
    border-radius: 4px;
    margin: 2px 8px;
    padding: 8px 12px;
    border: 1px solid transparent;
    transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}

.app-sidebar .nav-link:hover:not(.active) {
    background: rgba(45, 90, 58, 0.08);
}

.app-sidebar .nav-link.active {
    background: var(--accent, #2D5A3A);
    color: #FFFFFF;
    font-weight: 600;
    border-color: rgba(0, 0, 0, 0.15);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        inset 0 -1px 0 rgba(0, 0, 0, 0.20);
}

.app-sidebar .nav-link.active i {
    color: #FFFFFF;
}

.app-sidebar .nav-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: #FFFFFF;
    border-radius: 2px;
}

.app-sidebar .nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
}

/* =========================================================
   Comment threads — chat/social-media style
   ========================================================= */

.chat-thread {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: var(--surface-2);
    border-radius: 6px;
}

.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 82%;
}

.chat-row-theirs { align-self: flex-start; }
.chat-row-mine   { align-self: flex-end; flex-direction: row-reverse; }

.chat-avatar {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--rule);
    border-radius: 4px;
    background: var(--surface);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
}

.chat-bubble {
    position: relative;
    padding: 10px 12px 8px;
    border: 1px solid var(--rule);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 1px 0 rgba(0,0,0,.03);
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

/* Small arrow notch on the side the bubble comes from */
.chat-bubble-theirs::before,
.chat-bubble-mine::before {
    content: "";
    position: absolute;
    bottom: 10px;
    width: 8px;
    height: 8px;
    background: inherit;
    border: inherit;
    transform: rotate(45deg);
}

.chat-bubble-theirs { border-top-left-radius: 4px; }
.chat-bubble-theirs::before {
    left: -5px;
    border-top: 0;
    border-right: 0;
}

.chat-bubble-mine {
    background: var(--accent);
    color: #FFFFFF;
    border-color: var(--accent);
    border-top-right-radius: 4px;
}
.chat-bubble-mine::before {
    right: -5px;
    border-bottom: 0;
    border-left: 0;
    background: var(--accent);
    border-color: var(--accent);
}

.chat-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.chat-author {
    font-size: 13px;
    font-weight: 600;
    color: inherit;
}

.chat-time {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: .02em;
    color: var(--ink-muted);
    white-space: nowrap;
}

.chat-bubble-mine .chat-author,
.chat-bubble-mine .chat-time {
    color: rgba(255, 255, 255, 0.85);
}

.chat-body {
    font-size: 14px;
    line-height: 1.5;
    color: inherit;
}

.chat-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.chat-delete {
    min-height: 22px;
    padding: 0 4px;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: inherit;
    opacity: .55;
    font-size: 12px;
    cursor: pointer;
}

.chat-delete:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.06);
}

.chat-bubble-mine .chat-delete:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* Mobile */
@media (max-width: 767px) {
    .chat-row { max-width: 92%; }
    .chat-avatar { flex-basis: 28px; width: 28px; height: 28px; font-size: 10px; }
    .chat-thread { padding: 12px; gap: 10px; }
    .chat-body { font-size: 13.5px; }
}
