/* ==========================================================================
   Notes Management System - design system
   Brand tokens, typography, light and dark palettes, base components.
   Loaded after Bootstrap and the Tailwind utility build so it wins.
   ========================================================================== */

:root {
    /* Brand - overridden at runtime from Settings > Appearance */
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --brand-light: #dbeafe;
    --secondary: #0f172a;

    /* Surfaces */
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --surface-3: #e2e8f0;

    /* Text */
    --text: #0f172a;
    --text-muted: #64748b;
    --text-soft: #94a3b8;
    --text-invert: #ffffff;

    /* Lines */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Status */
    --success: #16a34a;
    --success-bg: #dcfce7;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --info: #0891b2;
    --info-bg: #cffafe;

    /* Code */
    --code-bg: #0f172a;
    --code-text: #e2e8f0;
    --code-inline-bg: #f1f5f9;
    --code-inline-text: #be185d;

    /* Shape */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 10px 24px rgba(15, 23, 42, .10);

    /* Spacing scale */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;
    --sp-7: 48px;
    --sp-8: 64px;

    /* Type */
    --font: "Times New Roman", Times, "Liberation Serif", Georgia, serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

    --header-h: 56px;
    --sidebar-w: 264px;
}

[data-theme="dark"] {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1f2937;
    --surface-3: #374151;

    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --text-soft: #6b7280;

    --border: #1f2937;
    --border-strong: #374151;

    --brand-light: #1e3a8a;

    --success-bg: #052e16;
    --warning-bg: #422006;
    --danger-bg: #450a0a;
    --info-bg: #083344;

    --code-bg: #020617;
    --code-inline-bg: #1f2937;
    --code-inline-text: #f472b6;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 3px rgba(0, 0, 0, .5);
    --shadow-lg: 0 10px 24px rgba(0, 0, 0, .55);
}


/* --------------------------------------------------------------------------
   Sepia - a warm tan/beige reading palette alongside light and dark.
   Only the tokens are redefined; every component picks the new values up
   through var(), so no component rule needs a sepia variant. Ink stays a warm
   near-black rather than pure #000, which is what makes paper themes readable.
   -------------------------------------------------------------------------- */
[data-theme="sepia"] {
    --bg: #f0e5d2;
    --surface: #fbf5ea;
    --surface-2: #ece0cb;
    --surface-3: #ddcdb0;

    --text: #3a2f23;
    --text-muted: #6f6153;
    --text-soft: #948673;

    --border: #ddcfb6;
    --border-strong: #c7b493;

    --brand-light: #e2dcc9;

    --success-bg: #dfe8cf;
    --warning-bg: #f6e6c4;
    --danger-bg: #f4dcd2;
    --info-bg: #d8e6e4;

    --code-bg: #2f2820;
    --code-text: #eee3d2;
    --code-inline-bg: #ebdec6;
    --code-inline-text: #9d174d;

    --shadow-sm: 0 1px 2px rgba(74, 56, 33, .10);
    --shadow: 0 1px 3px rgba(74, 56, 33, .13), 0 1px 2px rgba(74, 56, 33, .08);
    --shadow-lg: 0 10px 24px rgba(74, 56, 33, .16);
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text);
    font-weight: 700;
    line-height: 1.3;
    margin: 0 0 var(--sp-3);
}
h1 { font-size: clamp(1.7rem, 1.3rem + 1.6vw, 2.35rem); letter-spacing: -.02em; }
h2 { font-size: clamp(1.35rem, 1.15rem + .8vw, 1.7rem); letter-spacing: -.01em; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1.05rem; }

p { margin: 0 0 var(--sp-4); }

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); text-decoration: underline; }
/* brand-dark is a darker shade, which disappears against the dark bg. */
[data-theme="dark"] a:hover { color: color-mix(in srgb, var(--brand) 60%, #fff); }

img { max-width: 100%; height: auto; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-5) 0; }

/* Focus visibility - never removed, only restyled */
:focus-visible {
    outline: 3px solid var(--brand);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 999;
    background: var(--brand);
    color: #fff;
    padding: 10px 18px;
    border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; color: #fff; }

.container-app {
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 var(--sp-4);
}

/*
 * Vertical rhythm for a full page shell.
 *
 * This exists because the pages that need top and bottom spacing used to set
 * `style="padding:24px 0 48px"` inline. That shorthand also reset the
 * horizontal padding above to zero, so on a phone the content sat flush
 * against both screen edges. Using logical block padding keeps the two axes
 * independent: never reintroduce a `padding` shorthand on .container-app.
 */
.container-page {
    padding-block: var(--sp-5) var(--sp-7);
}

/* A little more breathing room where the screen is narrowest. */
@media (max-width: 575.98px) {
    .container-app { padding-inline: 18px; }
}

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

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: 44px;
    padding: 10px 18px;
    font-size: .95rem;
    font-weight: 600;
    font-family: inherit;
    line-height: 1.2;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .05s ease;
    text-decoration: none;
    background: none;
}
.btn:active { transform: translateY(1px); }
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }

.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .84rem; border-radius: var(--radius-sm); }
.btn-lg { min-height: 52px; padding: 14px 28px; font-size: 1.03rem; }
.btn-block { width: 100%; }
.btn-icon { min-height: 38px; width: 38px; padding: 0; }

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card-app {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-app-body { padding: var(--sp-5); }
.card-app-header {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    flex-wrap: wrap;
}
.card-app-header h2, .card-app-header h3 { margin: 0; font-size: 1.05rem; }
.card-app-footer {
    padding: var(--sp-3) var(--sp-5);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

/* --------------------------------------------------------------------------
   Badges and chips
   -------------------------------------------------------------------------- */
.badge {
    display: inline-block;
    align-self: flex-start; /* never stretch inside a column flex parent */
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 3px 11px;
    font-size: .74rem;
    font-weight: 600;
    line-height: 1.6;
    letter-spacing: .01em;
    border: 1px solid transparent;
    border-radius: 999px;
    white-space: nowrap;
}
a.badge { text-decoration: none; transition: background-color .15s ease, border-color .15s ease; }
a.badge:hover { text-decoration: none; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-info    { background: var(--info-bg);    color: var(--info); }
.badge-muted   { background: var(--surface-3);  color: var(--text-muted); }

/* Brand badge - the category label on note cards.
   The tint is mixed against `transparent` instead of a fixed pale colour, so
   the one rule stays readable on a white card and on a dark one, whatever
   primary colour the admin picks. The flat declaration before each color-mix()
   is the fallback for browsers that do not support it. */
.badge-brand {
    background: var(--brand-light);
    background: color-mix(in srgb, var(--brand) 13%, transparent);
    color: var(--brand-dark);
    border-color: #cbd9f8;
    border-color: color-mix(in srgb, var(--brand) 30%, transparent);
}
a.badge-brand:hover {
    background: color-mix(in srgb, var(--brand) 22%, transparent);
    border-color: color-mix(in srgb, var(--brand) 48%, transparent);
}

[data-theme="dark"] .badge-success { color: #4ade80; }
[data-theme="dark"] .badge-warning { color: #fbbf24; }
[data-theme="dark"] .badge-danger  { color: #f87171; }
[data-theme="dark"] .badge-info    { color: #22d3ee; }
[data-theme="dark"] .badge-muted   { background: var(--surface-2); color: var(--text-muted); border-color: var(--border-strong); }
[data-theme="dark"] .badge-brand {
    background: rgba(37, 99, 235, .24);
    background: color-mix(in srgb, var(--brand) 26%, transparent);
    color: #dbe6fd;
    color: color-mix(in srgb, var(--brand) 20%, #ffffff);
    border-color: color-mix(in srgb, var(--brand) 48%, transparent);
}
[data-theme="dark"] a.badge-brand:hover {
    background: color-mix(in srgb, var(--brand) 40%, transparent);
    border-color: color-mix(in srgb, var(--brand) 65%, transparent);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: .84rem;
    font-weight: 500;
    text-decoration: none;
}
.chip:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.chip.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }

/*
 * Collapsible chip set.
 * A subject with thirty topics fills a phone screen before the reader reaches
 * a single note, so app.js hides the overflow behind a toggle on narrow
 * screens. Without JavaScript nothing is hidden and the full list shows.
 */
.chip-set .chip.is-chip-hidden { display: none; }

.chip-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px dashed var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--brand);
    font: inherit;
    font-size: .84rem;
    font-weight: 600;
    cursor: pointer;
}
.chip-toggle:hover { border-color: var(--brand); border-style: solid; }
.chip-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Chips are the densest thing on a small screen, so tighten them there. */
@media (max-width: 575.98px) {
    .chip,
    .chip-toggle { padding: 4px 10px; font-size: .8rem; }
    .chip-set { gap: 6px; }
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.form-group { margin-bottom: var(--sp-4); }

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: .88rem;
    font-weight: 600;
    color: var(--text);
}
.form-label .req { color: var(--danger); }

.form-control,
.form-select,
textarea.form-control {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    font-size: .95rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    transition: border-color .15s ease, box-shadow .15s ease;
    -webkit-appearance: none;
    appearance: none;
}
.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%2364748b' d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px;
    padding-right: 36px;
}
textarea.form-control { min-height: 120px; resize: vertical; line-height: 1.6; }

.form-control:focus, .form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);
    outline: none;
}
.form-control::placeholder { color: var(--text-soft); }
.form-control:disabled, .form-select:disabled { background: var(--surface-2); cursor: not-allowed; }

.form-control.is-invalid, .form-select.is-invalid { border-color: var(--danger); }
.field-error { display: block; margin-top: 5px; font-size: .82rem; color: var(--danger); }
.form-hint { display: block; margin-top: 5px; font-size: .82rem; color: var(--text-muted); }

.form-check { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.form-check input[type="checkbox"], .form-check input[type="radio"] {
    width: 18px; height: 18px; margin-top: 3px; accent-color: var(--brand); flex-shrink: 0; cursor: pointer;
}
.form-check label { font-size: .92rem; cursor: pointer; margin: 0; }

.form-row { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.char-counter { font-size: .78rem; color: var(--text-muted); text-align: right; margin-top: 4px; }
.char-counter.is-over { color: var(--danger); font-weight: 600; }

/* --------------------------------------------------------------------------
   Alerts and flashes
   -------------------------------------------------------------------------- */
.alert {
    display: flex;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border: 1px solid transparent;
    border-radius: var(--radius);
    margin-bottom: var(--sp-4);
    font-size: .93rem;
}
.alert-success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.alert-danger  { background: var(--danger-bg);  border-color: var(--danger);  color: var(--danger); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.alert-info    { background: var(--info-bg);    border-color: var(--info);    color: var(--info); }

[data-theme="dark"] .alert-success { color: #4ade80; }
[data-theme="dark"] .alert-danger  { color: #f87171; }
[data-theme="dark"] .alert-warning { color: #fbbf24; }
[data-theme="dark"] .alert-info    { color: #22d3ee; }

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */
#toast-container {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, calc(100vw - 32px));
}
.toast-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--brand);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: .9rem;
    animation: toast-in .22s ease;
}
.toast-item.toast-success { border-left-color: var(--success); }
.toast-item.toast-danger  { border-left-color: var(--danger); }
.toast-item.toast-warning { border-left-color: var(--warning); }
.toast-item.is-leaving { opacity: 0; transform: translateX(12px); transition: all .2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal-backdrop-app {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    z-index: 1070;
}
.modal-backdrop-app[hidden] { display: none; }
.modal-app {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow: auto;
}
.modal-app-header { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.modal-app-header h3 { margin: 0; font-size: 1.1rem; }
.modal-app-body { padding: var(--sp-5); }
.modal-app-footer {
    padding: var(--sp-3) var(--sp-5) var(--sp-5);
    display: flex;
    gap: var(--sp-3);
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table-app { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table-app th, .table-app td { padding: 12px 14px; text-align: left; vertical-align: middle; }
.table-app thead th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
.table-app tbody tr { border-bottom: 1px solid var(--border); }
.table-app tbody tr:hover { background: var(--surface-2); }
.table-app tbody tr:last-child { border-bottom: 0; }
.table-app th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.table-app th a:hover { color: var(--brand); text-decoration: none; }
.sort-arrow { font-size: .7rem; opacity: .8; }

.table-empty { padding: var(--sp-7) var(--sp-4); text-align: center; color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */
.pagination-app {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4) 0;
    list-style: none;
    margin: 0;
}
.pagination-app a, .pagination-app span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    font-size: .9rem;
    text-decoration: none;
}
.pagination-app a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.pagination-app .is-current { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pagination-app .is-disabled { opacity: .45; pointer-events: none; }

/* --------------------------------------------------------------------------
   Code blocks
   -------------------------------------------------------------------------- */
code {
    font-family: var(--font-mono);
    font-size: .88em;
    background: var(--code-inline-bg);
    color: var(--code-inline-text);
    padding: 2px 6px;
    border-radius: 4px;
}

pre {
    position: relative;
    margin: var(--sp-4) 0;
    padding: 0;
    background: var(--code-bg);
    border-radius: var(--radius);
    overflow: hidden;
}
pre code {
    display: block;
    padding: var(--sp-4) var(--sp-4) var(--sp-4);
    background: transparent;
    color: var(--code-text);
    font-size: .87rem;
    line-height: 1.65;
    overflow-x: auto;
    white-space: pre;
    tab-size: 4;
}
pre::before {
    content: attr(data-language);
    position: absolute;
    top: 0; left: 0;
    padding: 4px 12px;
    font-family: var(--font-mono);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #94a3b8;
    background: rgba(255, 255, 255, .06);
    border-bottom-right-radius: var(--radius-sm);
}
pre[data-language] code { padding-top: 36px; }

.code-copy {
    position: absolute;
    top: 6px; right: 6px;
    padding: 5px 11px;
    font-size: .74rem;
    font-weight: 600;
    color: #cbd5e1;
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: var(--radius-sm);
    cursor: pointer;
    z-index: 2;
}
.code-copy:hover { background: rgba(255, 255, 255, .2); color: #fff; }
.code-copy.is-copied { background: var(--success); border-color: var(--success); color: #fff; }

/* --------------------------------------------------------------------------
   Rich note content
   -------------------------------------------------------------------------- */
.note-content { font-size: 1.02rem; line-height: 1.78; }
.note-content > h2 {
    margin-top: var(--sp-6);
    padding-top: var(--sp-2);
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}
.note-content > h3 { margin-top: var(--sp-5); }
.note-content ul, .note-content ol { margin: 0 0 var(--sp-4); padding-left: 26px; }
.note-content li { margin-bottom: 8px; }
.note-content blockquote {
    margin: var(--sp-4) 0;
    padding: var(--sp-3) var(--sp-4);
    border-left: 4px solid var(--brand);
    background: var(--brand-light);
    color: var(--text);
    border-radius: 0 var(--radius) var(--radius) 0;
}
[data-theme="dark"] .note-content blockquote { background: var(--surface-2); }
.note-content table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--sp-4) 0;
    font-size: .93rem;
}
.note-content table th, .note-content table td {
    padding: 10px 14px;
    border: 1px solid var(--border);
    text-align: left;
}
.note-content table th { background: var(--surface-2); font-weight: 700; }
.note-content table tbody tr:nth-child(even) { background: var(--surface-2); }
.note-content img { border-radius: var(--radius); margin: var(--sp-3) 0; }
.note-content figure { margin: var(--sp-4) 0; }
.note-content figcaption { font-size: .85rem; color: var(--text-muted); text-align: center; margin-top: 6px; }
.note-content a { text-decoration: underline; text-underline-offset: 2px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* --------------------------------------------------------------------------
   Breadcrumbs
   -------------------------------------------------------------------------- */
.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    list-style: none;
    margin: 0 0 var(--sp-4);
    padding: 0;
    font-size: .86rem;
    color: var(--text-muted);
}
.breadcrumbs li { display: flex; align-items: center; gap: 6px; }
.breadcrumbs li + li::before { content: "/"; color: var(--text-soft); }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--brand); }
.breadcrumbs [aria-current="page"] { color: var(--text); font-weight: 600; }

/* --------------------------------------------------------------------------
   Empty states, spinners, utilities
   -------------------------------------------------------------------------- */
.empty-state { padding: var(--sp-7) var(--sp-4); text-align: center; color: var(--text-muted); }
.empty-state-icon { font-size: 2.4rem; opacity: .35; margin-bottom: var(--sp-3); }
.empty-state h3 { color: var(--text); font-size: 1.05rem; }

.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.text-muted-app { color: var(--text-muted); }
.text-small { font-size: .86rem; }
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.text-truncate-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.stack-2 > * + * { margin-top: var(--sp-2); }
.stack-3 > * + * { margin-top: var(--sp-3); }
.stack-4 > * + * { margin-top: var(--sp-4); }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.flex-row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

mark { background: #fef08a; color: inherit; padding: 0 2px; border-radius: 2px; }
[data-theme="dark"] mark { background: #713f12; color: #fef3c7; }

/* --------------------------------------------------------------------------
   Static document pages (About, Privacy, Terms)
   Centred reading column so the text is not pinned to the left edge, with
   extra breathing room on the right of the copy.
   -------------------------------------------------------------------------- */
.static-doc {
    max-width: 960px;
    margin: 0 auto;
}
.static-doc .static-doc-body {
    padding-right: var(--sp-6);
}
@media (max-width: 767.98px) {
    .static-doc .static-doc-body { padding-right: 0; }
}

/* --------------------------------------------------------------------------
   Justified body copy
   Applied site-wide on the <body> so the alignment inherits into every block
   of text, on every page except the public home page (body.page-home), which
   keeps its default alignment. Elements that already declare their own
   text-align (buttons, badges, empty states, .note-nav) win over inheritance
   and are untouched; the reset below covers the rest of the UI chrome, which
   would otherwise get stretched by the justification.
   -------------------------------------------------------------------------- */
body:not(.page-home) {
    text-align: justify;
    text-justify: inter-word;
}

body:not(.page-home) h1,
body:not(.page-home) h2,
body:not(.page-home) h3,
body:not(.page-home) h4,
body:not(.page-home) h5,
body:not(.page-home) h6,
body:not(.page-home) .navbar,
body:not(.page-home) .nav,
body:not(.page-home) .dropdown-menu,
body:not(.page-home) .breadcrumb,
body:not(.page-home) .pagination,
body:not(.page-home) th,
body:not(.page-home) td,
body:not(.page-home) label,
body:not(.page-home) .form-label,
body:not(.page-home) .form-text,
body:not(.page-home) input,
body:not(.page-home) select,
body:not(.page-home) textarea,
body:not(.page-home) pre,
body:not(.page-home) code,
body:not(.page-home) kbd,
body:not(.page-home) .admin-sidebar,
body:not(.page-home) .admin-topbar {
    text-align: left;
    text-justify: auto;
}

/* --------------------------------------------------------------------------
   Category mark
   The subject logo chip, shared by the categories grid, a subject page header,
   the homepage tiles and the admin category list. Each instance sets
   --cat-accent and --cat-ink inline (see includes/category_logos.php); the
   container stays near white so official multi colour logos keep their own
   palette, with the subject colour carried by the ring and glow.
   -------------------------------------------------------------------------- */
.cat-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 13px;
    background:
        linear-gradient(160deg, color-mix(in srgb, var(--cat-accent, var(--brand)) 9%, transparent), transparent 70%),
        var(--surface);
    box-shadow:
        inset 0 0 0 1px color-mix(in srgb, var(--cat-accent, var(--brand)) 22%, transparent),
        0 4px 10px -6px color-mix(in srgb, var(--cat-accent, var(--brand)) 70%, transparent);
    color: var(--cat-ink, var(--brand));
    font-weight: 800;
    transition: transform .22s ease, box-shadow .22s ease;
}
.cat-mark > svg { display: block; width: 60%; height: 60%; }

.cat-mark-sm { width: 32px; height: 32px; border-radius: 10px; }
.cat-mark-lg { width: 56px; height: 56px; border-radius: 16px; }
.cat-mark-xl { width: 72px; height: 72px; border-radius: 20px; }

[data-theme="dark"] .cat-mark {
    background:
        linear-gradient(160deg, color-mix(in srgb, var(--cat-accent, var(--brand)) 20%, transparent), transparent 70%),
        var(--surface-2);
    box-shadow:
        inset 0 0 0 1px color-mix(in srgb, var(--cat-accent, var(--brand)) 30%, transparent),
        0 4px 12px -6px rgba(0, 0, 0, .6);
    color: color-mix(in srgb, var(--cat-accent, var(--brand)) 55%, #ffffff);
}
