:root {
    color-scheme: light;
    --ink: #241316;
    --muted: #725b61;
    --line: #ead9dd;
    --panel: #ffffff;
    --soft: #f8eef1;
    --brand: #7d2033;
    --brand-dark: #4b101d;
    --brand-deep: #2b0a12;
    --accent: #c8923f;
    --danger: #b42318;
    --success: #2d6a4f;
    --focus: rgba(125, 32, 51, 0.16);
    --shadow: rgba(75, 16, 29, 0.12);
    /* Spacing scale */
    --sp-1: 0.25rem;
    --sp-2: 0.5rem;
    --sp-3: 0.75rem;
    --sp-4: 1rem;
    --sp-5: 1.25rem;
    --sp-6: 1.5rem;
    --sp-8: 2rem;
    --sp-10: 2.5rem;
    --sp-12: 3rem;
}

.theme-wcm-maroon {
    --ink: #18181b;
    --muted: #52525b;
    --line: #d4d4d8;
    --soft: #f4f4f5;
    --brand: #7d2033;
    --brand-dark: #27272a; /* Neutral dark for topbar/accents */
    --brand-deep: #18181b; /* Neutral black for sidebar */
    --accent: #c8923f;
    --focus: rgba(0, 0, 0, 0.05);
    --shadow: rgba(0, 0, 0, 0.1);
}

.theme-woodland-green {
    --ink: #17211b;
    --muted: #617067;
    --line: #dce5df;
    --soft: #eef5f1;
    --brand: #1e6b4f;
    --brand-dark: #144938;
    --brand-deep: #0d2f25;
    --accent: #c28a2c;
    --focus: rgba(30, 107, 79, 0.14);
    --shadow: rgba(20, 73, 56, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", "Trebuchet MS", Arial, sans-serif;
    color: var(--ink);
    background: linear-gradient(135deg, #fbf7f3 0%, #f3e8eb 100%);
}

.auth-shell {
    display: grid;
    grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
    min-height: 100vh;
}

.brand-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
    padding: 56px;
    color: #ffffff;
    background: linear-gradient(150deg, rgba(43, 10, 18, 0.97), rgba(125, 32, 51, 0.92)), url("../img/woodland-pattern.svg");
    background-size: cover;
}

.brand-panel h1,
.form-heading h2 {
    margin: 0;
    line-height: 1.05;
}

.brand-panel h1 {
    max-width: 640px;
    font-size: clamp(2.25rem, 5vw, 4.75rem);
}

.brand-panel p {
    max-width: 520px;
    margin: 0;
    font-size: 1.08rem;
    line-height: 1.65;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.form-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: min(100%, 560px);
    margin: 0 auto;
    padding: 48px 28px;
}

.form-heading {
    margin-bottom: 24px;
}

.form-heading h2 {
    margin-top: 8px;
    font-size: 2rem;
}

form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--ink);
    background: var(--panel);
    font: inherit;
    font-weight: 400;
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    min-height: auto;
    padding: 0;
    margin: 0;
    cursor: pointer;
}

select {
    appearance: auto;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand);
    outline: 3px solid var(--focus);
}

button {
    min-height: 50px;
    margin-top: 6px;
    border: 0;
    border-radius: 8px;
    padding: 0 18px;
    color: #ffffff;
    background: var(--brand);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
}

button:hover {
    background: var(--brand-dark);
}

a, strong {
    color: var(--brand);
    font-weight: 600;
}

.alert {
    margin-bottom: 18px;
    border-radius: 8px;
    padding: 12px 14px;
    line-height: 1.45;
}

.alert-success {
    color: var(--success);
    background: #e9f7ef;
    border: 1px solid #badbcc;
}

.alert-error {
    color: var(--danger);
    background: #fdecea;
    border: 1px solid #f5c2c7;
}

.form-link {
    margin: 0;
    color: var(--muted);
    font-size: 0.94rem;
    line-height: 1.5;
}

.app-body {
    background: #fbf7f3;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;        /* lets context-actions flow onto its own full-width row */
    gap: 8px 24px;
    padding: 14px 32px;
    color: #ffffff;
    background: var(--brand-dark);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.topbar h1 {
    margin: 4px 0 0;
    font-size: 1.55rem;
}

.topbar-module-label {
    font-size: 1.2rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.01em;
    white-space: nowrap;
    padding-right: 4px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1;
    min-width: 0;
    padding-bottom: 1px; /* keeps scroll track hidden */
}
.topbar-actions::-webkit-scrollbar { display: none; }

.topbar-actions a:not(.button-link) {
    color: #ffffff;
}

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    border-radius: 8px;
    padding: 0 11px;
    font-size: 0.88rem;
    white-space: nowrap;
    color: var(--brand-dark);
    background: #ffffff;
    text-decoration: none;
}

.button-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border-radius: 8px;
    padding: 0 14px;
    color: var(--brand);
    border: 1.5px solid var(--brand);
    background: transparent;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
}

.button-ghost:hover {
    background: var(--brand);
    color: #ffffff;
}

/* ── L2 module-tab active/disabled states ────────────────────────────── */
.button-link.active {
    background: var(--brand);
    color: #ffffff;
    font-weight: 600;
}

.button-link-muted {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border-radius: 8px;
    padding: 0 14px;
    color: rgba(255, 255, 255, 0.45);
    background: rgba(255, 255, 255, 0.12);
    text-decoration: none;
    cursor: not-allowed;
    font-size: 0.88rem;
    gap: 5px;
}

/* ── L3 secondary navigation bar ─────────────────────────────────────── */

/* Wrapper provides the clipping context for the overflow-fade indicator */
.module-subnav-wrap {
    position: relative;
    background: var(--soft);
    border-bottom: 1px solid var(--line);
}

/* Right-edge gradient — fades out automatically once scroll reaches end
   (JS toggling .at-end on the wrapper removes this pseudo-element) */
.module-subnav-wrap::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 52px;
    background: linear-gradient(to right, transparent, var(--soft) 80%);
    pointer-events: none;
    transition: opacity 0.2s;
}

.module-subnav-wrap.at-end::after {
    opacity: 0;
}

.module-subnav {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 32px;
    background: transparent; /* wrapper owns the bg now */
    border-bottom: none;     /* wrapper owns the border now */
    overflow-x: auto;
    scrollbar-width: none;
}

.module-subnav::-webkit-scrollbar {
    display: none;
}

.subnav-link {
    display: inline-flex;
    align-items: center;
    padding: 9px 14px;
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
    margin-bottom: -1px; /* overlap container border */
}

.subnav-link:hover {
    color: var(--ink);
    border-bottom-color: var(--line);
}

.subnav-link.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
    font-weight: 600;
}

.dashboard-shell {
    width: min(1120px, calc(100% - 32px));
    margin: 28px auto 48px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 0 0 18px;
}

.metric-card,
.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 16px 40px var(--shadow);
}

.metric-card {
    min-height: 170px;
    padding: 22px;
}

.metric-card h2,
.panel-heading h2 {
    margin: 8px 0;
    line-height: 1.2;
}

.metric-card h2 {
    font-size: 1.7rem;
}

.metric-card p:last-child {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.panel {
    padding: 22px;
}

.panel-heading {
    margin-bottom: 16px;
}

.split-panel {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 26px;
    margin-bottom: 18px;
    align-items: start;
}

.split-panel > div {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.split-panel .panel-heading {
    min-height: 90px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-start;
    margin-bottom: 20px;
}

.compact-form {
    gap: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.timeline {
    display: grid;
    gap: 10px;
    margin: 0;
    padding-left: 20px;
}

.timeline li {
    padding: 8px 0;
}

.timeline span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.timeline .is-current {
    font-weight: 600;
}

.action-form {
    border-bottom: 1px solid var(--line);
    margin-bottom: 16px;
    padding-bottom: 18px;
}

.inline-action {
    display: grid;
    grid-template-columns: 150px minmax(160px, 1fr) auto;
    gap: 10px;
    align-items: center;
}

.wide-action {
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) 160px 150px auto;
}

.inline-action button {
    margin-top: 0;
}

.mini-form {
    display: inline-grid;
    gap: 0;
}

.mini-form button {
    min-height: 34px;
    margin: 0;
    padding: 0 12px;
}

.muted-text {
    color: var(--muted);
    line-height: 1.6;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.kb-compose-card,
.kb-thread-card {
    max-width: 860px;
    margin-bottom: var(--sp-6);
}

.kb-thread-card--accepted {
    border-left: 3px solid #22c55e;
}

.kb-question-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
}

.kb-question-header__content {
    flex: 1;
    min-width: 0;
}

.kb-question-title {
    word-break: break-word;
}

.kb-question-header__form {
    display: block;
    margin: 0;
    flex-shrink: 0;
}

.kb-form-block {
    margin-bottom: var(--sp-4);
}

.kb-form-label {
    display: block;
    margin-bottom: var(--sp-2);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink);
}

.kb-text-input,
.kb-markdown-input {
    background: var(--soft);
}

.kb-inline-error {
    margin-bottom: var(--sp-4);
    color: var(--danger);
}

.kb-inline-note {
    margin-top: var(--sp-2);
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.5;
}

.kb-form-actions {
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
}

.kb-dropzone {
    position: relative;
    margin-bottom: var(--sp-4);
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: var(--sp-4);
    background: var(--soft);
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.kb-dropzone.is-dragover,
.kb-dropzone.is-uploading {
    border-color: var(--brand);
    background: rgba(125, 32, 51, 0.06);
}

.kb-dropzone__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ink);
}

.kb-dropzone__hint,
.kb-dropzone__status {
    margin: var(--sp-2) 0 0;
    font-size: 0.8125rem;
    color: var(--muted);
    line-height: 1.5;
}

.kb-dropzone__input {
    display: none;
}

.kb-pending-attachments {
    display: grid;
    gap: var(--sp-2);
    margin-bottom: var(--sp-4);
}

.kb-pending-attachment {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.kb-pending-attachment__meta {
    min-width: 0;
}

.kb-pending-attachment__name {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.kb-pending-attachment__hint {
    display: block;
    margin-top: 0.1rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.kb-markdown-body {
    font-size: 0.9375rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.kb-markdown-body > :first-child {
    margin-top: 0;
}

.kb-markdown-body > :last-child {
    margin-bottom: 0;
}

.kb-markdown-body pre {
    overflow-x: auto;
    padding: var(--sp-3);
    border-radius: 8px;
    background: var(--soft);
}

.kb-markdown-body code {
    font-family: Consolas, "Courier New", monospace;
}

.hearth-md-image {
    display: block;
    max-width: 100%;
    height: auto;
    margin: var(--sp-3) 0;
    border-radius: 8px;
}

.kb-section-title {
    margin: 0 0 var(--sp-3);
    font-size: 1rem;
    font-weight: 600;
}

.kb-accepted-flag {
    margin: 0 0 var(--sp-2);
    font-size: 0.75rem;
    font-weight: 600;
    color: #22c55e;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.kb-answer-meta {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    flex-wrap: wrap;
    margin-top: var(--sp-4);
    font-size: 0.8125rem;
    color: var(--muted);
}

.kb-answer-submit {
    width: 100%;
    min-height: 3rem;
    padding: 0.75rem var(--sp-5);
    font-size: 0.9375rem;
    font-weight: 700;
}

.editor-toolbar {
    border-color: var(--line);
}

.editor-toolbar a,
.editor-toolbar button {
    color: var(--ink) !important;
    background: transparent !important;
    min-height: unset !important;
    margin-top: 0 !important;
    border-radius: 3px !important;
    padding: 0 6px !important;
    font-size: 1rem !important;
    font-weight: 400 !important;
}

.editor-toolbar a:hover,
.editor-toolbar a.active,
.editor-toolbar button:hover,
.editor-toolbar button.active {
    background: var(--soft) !important;
    border-color: var(--line) !important;
}

.editor-toolbar i.separator {
    border-left-color: var(--line);
    border-right-color: var(--line);
}

.editor-toolbar a.kb-toolbar-fallback,
.editor-toolbar button.kb-toolbar-fallback {
    min-width: 2.2rem;
    font-family: inherit;
    font-size: 0.75rem !important;
    font-weight: 700 !important;
    line-height: 1;
    text-transform: uppercase;
}

.kb-inline-form {
    display: inline-block;
    margin: 0;
}

.kb-accept-btn {
    color: #22c55e;
}

.kb-attachment-list {
    margin-top: var(--sp-4);
    display: grid;
    gap: var(--sp-2);
}

.kb-attachment-list__title {
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.kb-attachment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    text-decoration: none;
}

.kb-attachment-item__name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.kb-attachment-item__meta {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--muted);
}

.kb-page-header {
    align-items: center;
}

.kb-header-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: wrap;
}

.kb-filter-bar {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex-wrap: wrap;
    margin-bottom: var(--sp-5);
}

.kb-filter-input {
    flex: 1 1 240px;
    min-width: min(240px, 100%);
    background: var(--soft);
}

.kb-filter-select {
    width: auto;
    min-width: 170px;
    background: var(--soft);
}

.kb-content-card {
    max-width: 960px;
}

.kb-content-card > .card-body {
    padding: 0;
}

.kb-form-panel {
    margin-bottom: var(--sp-6);
}

.kb-form-panel.is-hidden,
.is-hidden {
    display: none;
}

.kb-form-card {
    max-width: 860px;
}

.kb-form-stack {
    display: grid;
    gap: var(--sp-4);
}

.kb-form-grid {
    display: grid;
    gap: var(--sp-4);
}

.kb-form-grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kb-form-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kb-textarea {
    min-height: 140px;
    background: var(--soft);
}

.kb-checkbox-row {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    color: var(--ink);
    font-size: 0.9rem;
}

.kb-empty-state {
    padding: var(--sp-8) var(--sp-6);
    text-align: center;
    color: var(--muted);
}

.kb-empty-state--compact {
    padding: var(--sp-5) var(--sp-6);
    text-align: left;
}

.kb-rich-text {
    white-space: pre-wrap;
    font-size: 0.9375rem;
    line-height: 1.7;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.kb-meta-note {
    margin-top: var(--sp-4);
    font-size: 0.75rem;
    color: var(--muted);
}

.kb-status-text {
    font-size: 0.8125rem;
}

.kb-table-title {
    font-weight: 600;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.kb-table-subtitle {
    margin-top: var(--sp-1);
    color: var(--muted);
    font-size: 0.8125rem;
    overflow-wrap: anywhere;
}

.kb-table-link {
    color: var(--ink);
    text-decoration: none;
}

.kb-table-link:hover {
    color: var(--brand);
}

.kb-table-actions {
    text-align: right;
    white-space: nowrap;
}

.kb-category-card {
    margin-bottom: var(--sp-6);
}

.kb-category-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.kb-category-card__title {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
}

.kb-category-card__meta {
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 400;
}

.kb-category-card__description {
    margin: var(--sp-1) 0 0;
    color: var(--muted);
    font-size: 0.8125rem;
}

.kb-chip {
    display: inline-flex;
    align-items: center;
    margin-right: var(--sp-2);
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: rgba(125, 32, 51, 0.1);
    color: var(--brand);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.kb-hearth-list {
    padding: 0;
}

.kb-hearth-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.kb-hearth-row:hover {
    background: var(--soft);
}

.kb-hearth-row__main {
    flex: 1;
    min-width: 0;
}

.kb-hearth-row__title {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.kb-hearth-row__excerpt {
    margin-top: var(--sp-1);
    color: var(--muted);
    font-size: 0.84rem;
    overflow-wrap: anywhere;
}

.kb-hearth-row__meta {
    display: grid;
    justify-items: end;
    gap: var(--sp-1);
    flex-shrink: 0;
    color: var(--muted);
    font-size: 0.8rem;
    text-align: right;
}

.kb-quick-index {
    position: relative;
}

.kb-quick-index__menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 200;
    min-width: 220px;
    padding: var(--sp-2) 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.kb-quick-index__item {
    display: block;
    width: 100%;
    min-height: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: var(--sp-3) var(--sp-4);
    background: none;
    color: var(--ink);
    font-size: 0.875rem;
    font-weight: 400;
    text-align: left;
}

.kb-quick-index__item:hover {
    background: var(--soft);
}

.kb-danger-button {
    color: var(--danger);
}

.kb-inline-error--hidden {
    display: none;
}

.table-wrap-mobile-hide {
    display: block;
}

.mobile-record-list {
    display: none;
    padding: var(--sp-4);
    gap: var(--sp-3);
}

.mobile-record-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    padding: var(--sp-4);
    display: grid;
    gap: var(--sp-3);
}

.mobile-record-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-3);
}

.mobile-record-header > * {
    min-width: 0;
}

.mobile-record-title {
    font-weight: 700;
    color: var(--ink);
    line-height: 1.3;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.mobile-record-subtitle {
    margin-top: var(--sp-1);
    color: var(--muted);
    font-size: 0.84rem;
    overflow-wrap: anywhere;
}

.mobile-record-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-3);
}

.mobile-record-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: var(--sp-3);
}

.mobile-record-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.mobile-record-value {
    color: var(--ink);
    line-height: 1.45;
    overflow-wrap: anywhere;
    text-align: right;
}

.mobile-record-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    align-items: center;
}

.mobile-record-actions form {
    display: inline-flex;
    gap: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 14px 12px;
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 0.82rem;
    text-transform: uppercase;
}

/* UI Overhaul Styles */
.app-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
    height: 100vh;
    background: linear-gradient(135deg, #fbf7f3 0%, #f4eaed 100%);
    transition: grid-template-columns 0.3s ease;
    overflow: hidden;
}

.sidebar-collapsed .app-layout {
    grid-template-columns: 70px 1fr;
}

.sidebar {
    background: var(--brand-deep);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    border-right: 1px solid var(--line);
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
    transition: width 0.3s ease;
}

.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.16);
    border-radius: 999px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.24);
}

.sidebar-brand {
    padding: 20px 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.sidebar-brand svg {
    height: 36px;
    width: auto;
    display: block;
    fill: var(--brand);
}

.brand-text {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    line-height: 1.3;
}

.sidebar-collapsed .brand-text {
    display: none;
}

/* Hide the entire brand block when sidebar is collapsed */
.sidebar-collapsed .sidebar-brand {
    display: none;
}

.sidebar-toggle-topbar {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 6px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.sidebar-toggle-topbar:hover {
    background: var(--soft);
    color: var(--ink);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
}

.sidebar-footer {
    margin-top: auto;
    padding: 12px 16px 16px;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.4;
}

.sidebar-nav a {
    color: rgba(255, 255, 255, 0.72);
    text-decoration: none;
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-icon {
    flex-shrink: 0;
}

.sidebar-collapsed .nav-label {
    display: none;
}

.sidebar-collapsed .sidebar-footer {
    display: none;
}

.sidebar-collapsed .sidebar-nav a {
    justify-content: center;
    padding: 12px 0;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 999;
}

.mobile-sidebar-open .sidebar-overlay {
    display: block;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
    border-left: 4px solid var(--brand);
}

.sidebar-nav a:not(.active) {
    border-left: 4px solid transparent;
}

.main-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.topbar-context {
    display: flex;
    align-items: center;
    min-width: 0;
    /* natural width on desktop (breadcrumbs only); flex:1 applied on mobile via media query */
}

/* sidebar-toggle-mobile removed — use sidebar-toggle-topbar instead */

.back-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.back-button:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.18);
}

.back-button:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.18);
    outline-offset: 2px;
}

.back-button:active {
    transform: translateY(1px);
}

.breadcrumbs {
    font-size: 0.85rem;
    color: #a0b4aa;
    display: flex;
    align-items: center;
    gap: 8px;
}

.breadcrumbs a {
    color: #ffffff;
    text-decoration: none;
    font-weight: 600;
}

.breadcrumbs .separator {
    color: rgba(255, 255, 255, 0.4);
}

.context-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 0 0 100%; /* own full-width row, below breadcrumbs + user-menu */
    min-width: 0;
}

.user-menu {
    position: relative;
    display: flex;
    align-items: center;
}

.profile-toggle {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    overflow: hidden;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    aspect-ratio: 1 / 1;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.profile-toggle:hover {
    border-color: #ffffff;
    background: none;
}

.avatar {
    width: 100%;
    height: 100%;
    min-width: 100%;
    min-height: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: var(--muted);
    border-radius: 50%;
    display: block;
}

.avatar-circle {
    border-radius: 50%;
}

.avatar-preview {
    width: 80px;
    height: 80px;
    min-width: 80px;
    min-height: 80px;
    aspect-ratio: 1 / 1;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    min-width: 220px;
    z-index: 100;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-header {
    padding: 16px;
    background: var(--soft);
    border-bottom: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dropdown-header strong {
    color: var(--ink);
    font-size: 0.95rem;
}

.dropdown-header span {
    color: var(--muted);
    font-size: 0.8rem;
}

.dropdown-company {
    display: block;
    margin-top: 6px;
    padding: 4px 8px;
    background: var(--brand);
    color: #fff !important;
    font-size: 0.7rem !important;
    font-weight: 600;
    border-radius: 4px;
    letter-spacing: 0.02em;
    line-height: 1.4;
}

.dropdown-menu a {
    display: block;
    padding: 12px 16px;
    color: var(--ink);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    border-bottom: 1px solid var(--line);
}

.dropdown-menu a:last-child {
    border-bottom: none;
}

.dropdown-menu a:hover {
    background: var(--soft);
}

.dropdown-menu a.text-danger {
    color: var(--danger);
}

/* ── Notifications ───────────────────────────────────────────────────── */
.notification-bell {
    position: relative;
    display: flex;
    align-items: center;
    margin-right: 12px;
}

.bell-toggle {
    background: none;
    border: none;
    padding: 8px;
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.75);
    transition: all 0.2s;
}

.bell-toggle:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.unread-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--danger);
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--brand-dark);
}

.notification-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
    width: 320px;
    max-height: 480px;
    z-index: 1000;
    overflow: hidden;
    flex-direction: column;
}

.notification-dropdown.show {
    display: flex;
}

.notification-dropdown .dropdown-header {
    padding: 16px;
    background: var(--soft);
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notification-list {
    overflow-y: auto;
    flex: 1;
}

.notification-item {
    display: flex;
    flex-direction: column;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
    color: var(--ink);
    transition: background 0.15s;
}

.notification-item:hover {
    background: var(--soft);
}

.notification-item.unread {
    background: rgba(125, 32, 51, 0.03);
    border-left: 3px solid var(--brand);
}

.notification-item .notif-title {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 4px;
    color: var(--brand);
}

.notification-item .notif-body {
    font-size: 0.84rem;
    color: var(--muted);
    line-height: 1.4;
    margin-bottom: 6px;
}

.notification-item .notif-time {
    font-size: 0.72rem;
    color: #a0a0a0;
}

.notification-dropdown .dropdown-footer {
    padding: 12px;
    text-align: center;
    background: var(--soft);
    border-top: 1px solid var(--line);
}

.notification-dropdown .dropdown-footer a {
    font-size: 0.84rem;
    color: var(--brand);
    text-decoration: none;
    font-weight: 600;
}

@media (max-width: 820px) {
    .auth-shell {
        grid-template-columns: 1fr;
    }

    .app-layout {
        display: block;
        min-height: 100vh;
        height: auto;
        overflow: visible;
    }

    .sidebar {
        display: block;
        position: fixed;
        top: 0;
        left: -280px;
        bottom: 0;
        width: 280px;
        z-index: 2000;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
        border-right: 0;
        transition: left 0.3s ease;
        height: 100vh;
    }

    .main-content {
        width: 100%;
        max-height: none;
        overflow: visible;
    }

    .mobile-sidebar-open .sidebar {
        left: 0;
    }

    .sidebar-brand {
        display: flex;
        padding: 20px 24px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .sidebar-nav {
        flex-direction: column;
        padding: 16px 0;
    }

    .sidebar-nav a {
        padding: 16px 24px;
        border-left: 4px solid transparent;
        border-bottom: 0;
        font-size: 1rem;
        flex-direction: row;
        justify-content: flex-start !important;
        gap: 16px;
    }

    .mobile-sidebar-open .nav-label {
        display: block !important;
    }

    .brand-panel {
        min-height: 34vh;
        padding: 36px 24px;
    }

    .brand-panel h1 {
        font-size: 2.35rem;
    }

    .topbar {
        padding: 10px 16px;
        gap: 6px 16px;
    }

    .user-menu {
        margin-left: auto;
    }

    .topbar-context {
        flex: 1;          /* fill available space left of user-menu in row 1 */
        min-width: 0;
    }

    .topbar-module-label {
        font-size: 1rem;
        white-space: nowrap;
    }

    .context-actions {
        gap: 8px;
        padding: 2px 0;
    }

    .topbar-actions {
        gap: 6px;
    }

    .button-link {
        min-height: 36px;
        padding: 0 10px;
        font-size: 0.86rem;
    }

    .module-subnav {
        padding: 0 16px;
    }

    .subnav-link {
        padding: 8px 10px;
        font-size: 0.82rem;
    }

    .dashboard-shell {
        width: min(100% - 20px, 1120px);
        margin: 16px auto 32px;
    }

    .panel,
    .metric-card {
        padding: 16px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .split-panel,
    .form-row,
    .inline-action,
    .wide-action {
        grid-template-columns: 1fr;
    }

    th,
    td {
        padding: 11px 10px;
        font-size: 0.88rem;
    }
}

@media (max-width: 520px) {
    .brand-panel {
        padding: 28px 18px;
    }

    .brand-panel h1 {
        font-size: 1.9rem;
    }

    .form-panel {
        padding: 32px 18px;
    }

    .breadcrumbs {
        flex-wrap: wrap;
    }

    .dropdown-menu {
        top: 100%;
        right: 0;
        left: auto;
        width: 220px;
    }

    .table-wrap-mobile-hide {
        display: none;
    }

    .mobile-record-list-show-sm {
        display: grid;
    }
}

@media (max-width: 640px) {
    .table-wrap-mobile-hide {
        display: none;
    }

    .mobile-record-list-show-sm {
        display: grid;
    }

    .kb-form-grid--2,
    .kb-form-grid--3 {
        grid-template-columns: 1fr;
    }

    .kb-filter-select {
        width: 100%;
        min-width: 0;
    }

    .kb-hearth-row {
        display: grid;
        gap: var(--sp-3);
    }

    .kb-hearth-row__meta {
        justify-items: start;
        text-align: left;
    }
}

/* ============================================================
   UI STANDARDS — Component library  v3
   ============================================================ */

/* --- Page layout --- */
.page-body {
    padding: var(--sp-6) var(--sp-8);
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
}

.page-body--wide {
    max-width: none;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    margin-bottom: var(--sp-6);
    padding-bottom: var(--sp-5);
    border-bottom: 2px solid var(--line);
    flex-wrap: wrap;
}

.page-title {
    margin: 0;
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.page-subtitle {
    margin: var(--sp-2) 0 0;
    font-size: 0.875rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: wrap;
}

.page-actions {
    display: flex;
    gap: var(--sp-2);
    align-items: center;
    flex-wrap: wrap;
    padding-top: var(--sp-1);
}

/* --- Cards --- */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: var(--sp-5);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.06);
}

.card-header {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--line);
    background: var(--soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.card-header h2,
.card-header h3 {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    line-height: 1.3;
}

.card-title {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.card-body {
    padding: var(--sp-5) var(--sp-6);
}

.card-footer {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--line);
    background: var(--soft);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

/* Table-in-card sits flush (no extra top border or radius) */
.card > .table-wrap {
    border-top: 1px solid var(--line);
    border-radius: 0;
    overflow-x: auto;
}

/* --- Stat cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--sp-4);
    margin-bottom: var(--sp-6);
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: var(--sp-5) var(--sp-5) var(--sp-5);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.06);
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.06), 0 12px 32px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}

/* Brand accent bar at top of every stat card */
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--brand) 0%, var(--accent) 100%);
}

.stat-label {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 0 0 var(--sp-3);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0 0 var(--sp-2);
    line-height: 1.05;
    letter-spacing: -0.03em;
    overflow-wrap: anywhere;
}

.stat-note {
    font-size: 0.8rem;
    color: var(--muted);
    margin: 0;
    line-height: 1.4;
}

/* Stat card color modifiers — brand-adjacent warm palette */
.stat-card--success::before { background: linear-gradient(90deg, #c8923f, #d4a84b); } /* warm gold  */
.stat-card--warning::before { background: linear-gradient(90deg, #b8960a, #c8a520); } /* amber/ochre */
.stat-card--danger::before  { background: linear-gradient(90deg, #9A313B, #b33f4a); } /* WCM brown  */
.stat-card--info::before    { background: linear-gradient(90deg, #96989A, #aaadb0); } /* WCM grey   */
.stat-card--neutral::before { background: var(--line); }

/* --- Table standards --- */
thead th {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
    background: var(--soft);
    border-bottom: 2px solid var(--line);
    padding: 0.75rem var(--sp-4);
}

tbody td {
    padding: 0.8125rem var(--sp-4);
    vertical-align: middle;
    border-bottom: 1px solid var(--line);
    font-size: 0.9rem;
}

/* Allow a specific table's headers to wrap onto 2 lines */
.table-wrap-headers thead th {
    white-space: normal;
    line-height: 1.3;
    vertical-align: bottom;
}

/* Remove bottom border from last row */
tbody tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: background 0.1s;
}

tbody tr:hover td {
    background: var(--soft);
}

/* --- Section dividers (inside cards) --- */
.section-label {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 0 0 var(--sp-3);
    padding-bottom: var(--sp-2);
    border-bottom: 1px solid var(--line);
}

/* ═══════════════════════════════════════════════════════════════════════════
   FORM STANDARDS — read before writing form HTML
   ═══════════════════════════════════════════════════════════════════════════

   ANATOMY OF A FORM FIELD:
     <div class="form-group">
       <label class="form-label" for="myId">Label <span class="text-danger">*</span></label>
       <input id="myId" name="myField" class="form-control" …>
       <span class="form-hint">Helper text below the control.</span>
     </div>

   LAYOUT — TWO-LEVEL NESTING (required):

     Every form inside a .card-body must have exactly ONE outer form-grid with
     no column override. This outer grid sits directly inside .card-body and
     provides row-gap between every row of the form. Without it, sibling rows
     have zero spacing between them.

     Inside the outer form-grid, each multi-column row gets its own inner
     form-grid with an explicit grid-template-columns override:

       <div class="card-body">
         <div class="form-grid">                          <!-- outer: 1-col, supplies row-gap -->

           <div class="form-group">…</div>               <!-- full-width single field -->

           <div class="form-grid"                        <!-- inner: 2-col row -->
                style="grid-template-columns:1fr 1fr;">
             <div class="form-group">…</div>
             <div class="form-group">…</div>
           </div>

           <div class="form-grid"                        <!-- inner: 3-col row -->
                style="grid-template-columns:1fr 1fr 1fr;">
             <div class="form-group">…</div>
             <div class="form-group">…</div>
             <div class="form-group">…</div>
           </div>

           <div class="form-group" style="grid-column:1/-1;">…</div>  <!-- spans full width -->

         </div><!-- /outer form-grid -->
       </div><!-- /card-body -->

   COLUMN SHORTCUTS:
     1-col (default)  → <div class="form-grid">
     2-col            → <div class="form-grid" style="grid-template-columns:1fr 1fr;">
     3-col            → <div class="form-grid" style="grid-template-columns:repeat(3,1fr);">
     mixed widths     → <div class="form-grid" style="grid-template-columns:2fr 1fr;">

   CLASSES:
     form-grid    — grid wrapper; column-gap + row-gap set automatically
     form-group   — flex column: label → control → hint
     form-label   — label text (bold, 0.8125rem); add class="required" for * suffix
     form-control — any input / select / textarea
     form-hint    — muted helper text beneath a control
     form-actions — button row (flex, border-top separator)

   REQUIRED FIELD MARKER:
     <label class="form-label required">Field</label>   ← CSS appends " *" in red
     OR inline: <label class="form-label">Field <span class="text-danger">*</span></label>

   CARD HEADER:
     ✓ <div class="card-header"><h2>Title</h2><a class="btn …">Action</a></div>
     ✗ <div class="card-header"><span class="fw-600">Title</span></div>

   DO NOT:
     ✗ Put multiple sibling form-grid divs directly in .card-body — they get no
       vertical gap between them; wrap them all in ONE outer form-grid instead
     ✗ Put class="form-grid" on the <form> element itself — it strips card-body padding
     ✗ Use form-row / form-select (undefined → invisible spacing bugs)
     ✗ Use style="display:grid;gap:16px;" inline instead of form-grid
     ✗ Add empty spacer <div>s to pad out a grid row — use fewer columns instead
   ═══════════════════════════════════════════════════════════════════════════ */

/* --- Form components --- */
.form-section {
    display: grid;
    gap: var(--sp-4);
}

/* Multi-column form grid — column count set by inline style on the element.
   row-gap is larger than column-gap to give labels breathing room above. */
.form-grid {
    display: grid;
    column-gap: var(--sp-4);
    row-gap: var(--sp-5);
    align-items: start;
}

/* Safety net: when form-groups are accidentally stacked directly in .card-body
   (without a form-grid wrapper), still give them breathing room. */
.card-body > .form-group + .form-group {
    margin-top: var(--sp-5);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

/* Canonical label class — mirrors .form-group label */
.form-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 var(--sp-1);
    display: block;
}

.form-group label,
.form-group .form-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0;
    display: block;
}

/* Explicit form-control class — inherits global input/select styles,
   adding only the class name as a hook for overrides. */
.form-control {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--ink);
    background: var(--panel);
    font: inherit;
    font-weight: 400;
}
.form-control:focus {
    border-color: var(--brand);
    outline: 3px solid var(--focus);
}
select.form-control {
    appearance: auto;
}
textarea.form-control {
    resize: vertical;
}

.search-select-native {
    display: none !important;
}

.search-select {
    position: relative;
    width: 100%;
}

.search-select-input {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 42px 12px 14px;
    color: var(--ink);
    background: var(--panel);
    font: inherit;
    font-weight: 400;
}

.search-select-input:focus {
    border-color: var(--brand);
    outline: 3px solid var(--focus);
}

.search-select-toggle {
    position: absolute;
    top: 50%;
    right: 12px;
    width: 18px;
    height: 18px;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
    transition: transform 0.16s ease, color 0.16s ease;
}

.search-select.is-open .search-select-toggle {
    transform: translateY(-50%) rotate(180deg);
    color: var(--brand);
}

.search-select-panel {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2200;
    display: none;
    max-height: 18rem;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel, #fff);
    box-shadow: 0 14px 30px rgba(20, 22, 28, 0.14);
}

.search-select-panel.is-open {
    display: block;
}

.search-select-panel[data-position="up"] {
    transform-origin: bottom center;
}

.search-select-panel[data-position="down"] {
    transform-origin: top center;
}

.search-select-empty {
    padding: 12px 14px;
    color: var(--muted);
    font-size: 0.875rem;
}

.search-select-option {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    padding: 10px 14px;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 2px;
    font: inherit;
    color: var(--ink);
}

.search-select-option:last-child {
    border-bottom: 0;
}

.search-select-option:hover,
.search-select-option.is-active {
    background: var(--soft);
}

.search-select-option.is-selected {
    background: color-mix(in srgb, var(--focus) 55%, white);
}

.search-select-option-main {
    font-size: 0.9375rem;
    font-weight: 600;
}

.search-select-option-meta {
    color: var(--muted);
    font-size: 0.75rem;
}

/* Required-field asterisk via class (treasury pattern) */
.form-label.required::after {
    content: ' *';
    color: var(--danger);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--muted);
    margin: 0;
}

.form-actions {
    display: flex;
    gap: var(--sp-3);
    align-items: center;
    padding-top: var(--sp-4);
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
    margin-top: var(--sp-2);
}

/* ── Filter strip: horizontal row of selects/inputs inside card-header ── */
.filter-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
}
.filter-strip select,
.filter-strip input[type="text"],
.filter-strip input[type="date"],
.filter-strip input[type="search"] {
    flex: 0 1 auto;
    min-width: 130px;
    max-width: 220px;
    height: 34px;
    padding: 0 var(--sp-2);
    font-size: 0.8rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    color: var(--text);
    min-height: unset;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ink);
}

.checkbox-row input {
    flex: 0 0 auto;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 0.5rem var(--sp-4);
    border: 1px solid transparent;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, box-shadow 0.15s, transform 0.1s, border-color 0.15s;
    line-height: 1.4;
    min-height: auto;
    margin: 0;
    letter-spacing: 0.01em;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--brand);
    color: #fff !important;
    border-color: var(--brand);
    box-shadow: 0 1px 3px rgba(125,32,51,0.3);
}

.btn-primary:hover {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    box-shadow: 0 2px 6px rgba(125,32,51,0.35);
}

.btn-secondary {
    background: #fff;
    color: var(--ink) !important;
    border-color: var(--line);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.btn-secondary:hover {
    background: var(--soft);
    border-color: #c8b0b8;
}

.btn-danger {
    background: var(--danger);
    color: #fff !important;
    border-color: var(--danger);
    box-shadow: 0 1px 3px rgba(180,35,24,0.3);
}

.btn-danger:hover {
    opacity: 0.88;
    box-shadow: 0 2px 6px rgba(180,35,24,0.35);
}

.btn-ghost {
    background: transparent;
    color: var(--muted) !important;
    border-color: var(--line);
}

.btn-ghost:hover {
    background: var(--soft);
    color: var(--ink) !important;
    border-color: #c8b0b8;
}

.btn-sm {
    padding: 0.3125rem var(--sp-3);
    font-size: 0.8125rem;
}

.btn-xs {
    padding: 0.1875rem var(--sp-2);
    font-size: 0.75rem;
    border-radius: 4px;
}

.table-icon-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: nowrap;
}

.table-icon-form {
    margin: 0;
}

.table-icon-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--muted);
    text-decoration: none;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
    cursor: pointer;
    padding: 0;
}

.table-icon-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.table-icon-btn:hover {
    background: var(--soft);
    border-color: #c8b0b8;
    color: var(--ink);
}

.table-icon-btn:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--brand) 55%, white);
    outline-offset: 2px;
}

.table-icon-btn--view {
    color: var(--brand);
}

.table-icon-btn--edit {
    color: #8a5a2a;
}

.table-icon-btn--delete {
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 24%, var(--line));
}

.table-icon-btn--delete:hover {
    background: #fff1f1;
    border-color: color-mix(in srgb, var(--danger) 38%, var(--line));
    color: #9f1d1d;
}

/* --- Badges / pills --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 99px;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    line-height: 1.3;
}

.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef9c3; color: #a16207; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-info    { background: #dbeafe; color: #1d4ed8; }
.badge-neutral { background: var(--soft); color: var(--muted); border: 1px solid var(--line); }

/* --- Flash messages --- */
.flash {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: var(--sp-5);
    border-left: 4px solid;
    line-height: 1.5;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.flash-success { background: #f0fdf4; color: #15803d; border-color: #22c55e; }
.flash-error   { background: #fef2f2; color: #b91c1c; border-color: #ef4444; }
.flash-warning { background: #fffbeb; color: #a16207; border-color: #f59e0b; }
.flash-info    { background: #eff6ff; color: #1d4ed8; border-color: #3b82f6; }

/* --- Utility helpers --- */
.text-muted   { color: var(--muted); }
.text-danger  { color: var(--danger) !important; }
.text-success { color: var(--success); }
.text-warning { color: #b8960a; }
.text-sm      { font-size: 0.875rem; }
.text-xs      { font-size: 0.75rem; }
.text-lg      { font-size: 1.125rem; }
.fw-600       { font-weight: 600; }
/* Progress bar — used by scorecard and similar pages */
.progress-bar  { background: var(--border); border-radius: 4px; overflow: hidden; height: 8px; }
.progress-fill { height: 100%; background: var(--primary, #9A313B); border-radius: 4px; transition: width 0.3s ease; }
.fw-700       { font-weight: 700; }
.mt-0         { margin-top: 0; }
.mb-0         { margin-bottom: 0; }
.mb-4         { margin-bottom: var(--sp-4); }
.mb-5         { margin-bottom: var(--sp-5); }
.mb-6         { margin-bottom: var(--sp-6); }
.wrap-anywhere { overflow-wrap: anywhere; word-break: break-word; min-width: 0; }
.inline-details {
  position: relative;
}
.inline-details > summary {
  list-style: none;
}
.inline-details > summary::-webkit-details-marker {
  display: none;
}
.inline-details[open] > summary {
  margin-bottom: 0.5rem;
}
.client-email-text {
    display: block;
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-all;
}

/* Inline action-button group in table cells */
.action-buttons {
    display: flex;
    gap: var(--sp-2);
    align-items: center;
    flex-wrap: wrap;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    column-gap: var(--sp-3);
    row-gap: var(--sp-5);
    margin-bottom: var(--sp-4);
}

.collapsible-card {
    overflow: hidden;
}

.card-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-4) var(--sp-5);
    cursor: pointer;
    list-style: none;
}

.card-summary::-webkit-details-marker {
    display: none;
}

.card-summary-copy {
    display: grid;
    gap: var(--sp-1);
}

.card-summary-copy h2,
.card-summary-copy p {
    margin: 0;
}

.card-summary-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: var(--sp-2) var(--sp-3);
    color: var(--muted);
    background: var(--panel);
    font-size: 0.85rem;
    font-weight: 600;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--sp-4);
}

.detail-grid > * {
    min-width: 0;
}

.detail-grid dt,
.detail-grid dd {
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

.detail-grid-single-mobile {
    grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
}

.detail-item {
    display: grid;
    gap: var(--sp-1);
}

.detail-label {
    margin: 0;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.detail-value {
    margin: 0;
    font-size: 0.95rem;
    color: var(--ink);
    line-height: 1.5;
    overflow-wrap: break-word;
    word-break: break-word;
    min-width: 0;
}

@media (max-width: 520px) {
    .detail-grid-single-mobile {
        grid-template-columns: 1fr;
    }
}

.empty-state {
    padding: var(--sp-8);
    text-align: center;
    color: var(--muted);
}

.stack-list {
    display: grid;
    gap: var(--sp-3);
}

.stack-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: var(--sp-4);
    background: var(--panel);
}

/* ── Org tree: top-down chart with CSS connector lines ─────────────────── */
.org-tree {
    overflow-x: auto;
    padding: 8px 4px 20px;
}

.org-tree ul {
    position: relative;
    display: flex;
    justify-content: center;
    padding: 18px 0 0;
    margin: 0;
    list-style: none;
}

.org-tree > ul {
    padding-top: 0;
    min-width: max-content;
    margin: 0 auto;
}

.org-tree li {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 18px 6px 0;
}

/* horizontal rail across siblings + vertical drop to each card */
.org-tree li::before,
.org-tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    width: 50%;
    height: 18px;
    border-top: 1px solid var(--line);
}

.org-tree li::after {
    right: auto;
    left: 50%;
    border-left: 1px solid var(--line);
}

.org-tree li:first-child::before,
.org-tree li:last-child::after {
    border-top: 0;
}

.org-tree li:last-child::before {
    border-right: 1px solid var(--line);
    border-radius: 0 6px 0 0;
}

.org-tree li:first-child::after {
    border-radius: 6px 0 0 0;
}

.org-tree li:only-child::before {
    display: none;
}

.org-tree li:only-child::after {
    border-top: 0;
    border-radius: 0;
}

/* vertical stem from a parent card down to its children rail */
.org-tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 0;
    height: 18px;
    border-left: 1px solid var(--line);
}

/* roots have no connectors above them */
.org-tree > ul > li {
    padding-top: 0;
}

.org-tree > ul > li::before,
.org-tree > ul > li::after {
    display: none;
}

.org-node {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 10px 14px;
    min-width: 130px;
    max-width: 200px;
    text-align: center;
    display: grid;
    gap: 2px;
}

.org-node--vacant {
    border-style: dashed;
    background: transparent;
    opacity: 0.75;
}

.org-node-title {
    font-weight: 600;
    color: var(--ink);
    font-size: 0.85rem;
    line-height: 1.25;
}

.org-node-dept {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.org-node-people {
    font-size: 0.78rem;
    color: var(--brand-dark, #5a1a2b);
    line-height: 1.35;
}

.org-node-people--vacant {
    color: var(--muted);
    font-style: italic;
}

.org-tree-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.section-note {
    margin: 0 0 var(--sp-4);
    color: var(--muted);
    font-size: 0.875rem;
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--sp-3);
}

.permission-card {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-2);
    padding: var(--sp-3);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--soft);
}

.permission-card input {
    margin-top: 0.15rem;
}

/* Card split layout (two-column) */
.card-split {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
    gap: var(--sp-5);
    margin-bottom: var(--sp-5);
}

.employee-profile-page .card-split {
    grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr));
}

.employee-profile-page .detail-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
}

.activity-inline-form {
    width: 100%;
    max-width: none;
}

.activity-inline-form .form-actions {
    justify-content: flex-start;
}

/* ============================================================
   Responsive overrides for new components
   ============================================================ */
@media (max-width: 1024px) {
    .page-body {
        padding: var(--sp-5) var(--sp-6);
    }
    .card-split {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .page-body {
        padding: var(--sp-4);
    }
    .page-header {
        flex-direction: column;
        gap: var(--sp-3);
    }
    .page-title {
        font-size: 1.5rem;
    }
    .page-actions {
        width: 100%;
    }
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .card-body {
        padding: var(--sp-4);
    }
    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }
    /* Two per row — UI_STANDARDS.md section 10. Applies to .dashboard-grid
       too, which otherwise collapses to one column at 820px and leaves the
       home dashboard disagreeing with every other page. */
    .stats-grid,
    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--sp-3);
    }
    /* min-width:0 lets a grid item shrink below its content width; without it
       a long figure widens the column and breaks the two-up layout. */
    .stat-card,
    .metric-card {
        min-width: 0;
        padding: var(--sp-4);
    }
    .stat-value {
        font-size: 1.5rem;
    }
    .stat-label {
        font-size: 0.625rem;
        margin-bottom: var(--sp-2);
    }
    .stat-note {
        font-size: 0.72rem;
    }
    .btn {
        font-size: 0.875rem;
    }
}

/* Single column only on genuinely tiny viewports. Two-up survives 360-375px,
   which covers the common phone sizes; below ~340px a money figure with a
   currency symbol and separators starts wrapping badly. */
@media (max-width: 340px) {
    .stats-grid,
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   Text alignment utilities

   .text-right is used in 485 places across the app — and was never
   defined, so every "right-aligned" money column has been rendering
   left-aligned. .text-center and .text-left were missing too. The
   siblings these sit beside (.text-sm, .text-xs, .text-muted, .fw-600)
   already existed, which is why the omission went unnoticed.
   ============================================================ */

/* ============================================================
   Dialog

   Native <dialog>. The browser handles focus trapping, Esc and the
   backdrop, so this only supplies the house shell. Used instead of a
   div with a "hidden" class, which needs a CSS framework this app
   does not load.
   ============================================================ */
.app-dialog {
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    color: var(--ink);
    width: min(560px, calc(100vw - 2 * var(--sp-4)));
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.app-dialog::backdrop { background: rgba(15, 16, 20, 0.55); }

.app-dialog .card-header,
.app-dialog .card-footer { background: var(--soft); }

.app-dialog .card-header { border-bottom: 1px solid var(--line); }
.app-dialog .card-footer { border-top: 1px solid var(--line); }

@media (max-width: 640px) {
    .app-dialog .card-footer { flex-direction: column-reverse; }
    .app-dialog .card-footer .btn { width: 100%; justify-content: center; }
}

.text-right  { text-align: right; }
.text-left   { text-align: left; }
.text-center { text-align: center; }

/* Numeric columns line up on the decimal point only when the digits are
   the same width. Applies to the cell and anything nested in it. */
td.text-right,
th.text-right {
    font-variant-numeric: tabular-nums;
}
/* ============================================================
   Font picker card grid (settings page)
   ============================================================ */
.font-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--sp-3);
    padding: var(--sp-2) 0;
}

.font-picker-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-4) var(--sp-3);
    border: 2px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    background: var(--panel);
    text-align: center;
}

.font-picker-card:hover {
    border-color: var(--brand);
    background: var(--soft);
}

.font-picker-card.is-selected {
    border-color: var(--brand);
    background: var(--soft);
    box-shadow: 0 0 0 3px rgba(154, 49, 59, 0.12);
}

.font-picker-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.font-picker-preview {
    font-size: 2rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1;
    display: block;
}

.font-picker-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink);
    display: block;
    line-height: 1.3;
}

.font-picker-cat {
    font-size: 0.6875rem;
    color: var(--muted);
    display: block;
}

/* ============================================================
   Font family switcher — applied via body class
   ============================================================ */

/* Sans-serif — fallback is Arial not system-ui (system-ui = Segoe UI on Windows,
   which is indistinguishable from the base body font if Google Fonts is slow) */
.font-inter          { font-family: 'Inter',             Arial, Helvetica, sans-serif; }
.font-open-sans      { font-family: 'Open Sans',         Arial, Helvetica, sans-serif; }
.font-work-sans      { font-family: 'Work Sans',         Arial, Helvetica, sans-serif; }
.font-poppins        { font-family: 'Poppins',           Arial, Helvetica, sans-serif; }
.font-raleway        { font-family: 'Raleway',           Arial, Helvetica, sans-serif; }
.font-dm-sans        { font-family: 'DM Sans',           Arial, Helvetica, sans-serif; }
.font-plus-jakarta   { font-family: 'Plus Jakarta Sans', Arial, Helvetica, sans-serif; }
.font-nunito         { font-family: 'Nunito',            Arial, Helvetica, sans-serif; }
.font-outfit         { font-family: 'Outfit',            Arial, Helvetica, sans-serif; }

/* Display (headings only — body falls back to Arial) */
.font-bebas-neue .page-title,
.font-bebas-neue .card-header h2,
.font-bebas-neue .card-header h3,
.font-bebas-neue h1,
.font-bebas-neue h2,
.font-bebas-neue h3 {
    font-family: 'Bebas Neue', Arial, sans-serif;
    letter-spacing: 0.03em;
}

/* Serif */
.font-playfair       { font-family: 'Playfair Display', Georgia, serif; }
.font-lora           { font-family: 'Lora',             Georgia, serif; }
.font-merriweather   { font-family: 'Merriweather',     Georgia, serif; }

/* ============================================================
   Group C — Task discussion, history timeline, action-list
   ============================================================ */

/* Comment thread */
.comment-row {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--line);
}
.comment-row:last-child {
    border-bottom: none;
}
.comment-row.comment-system {
    background: var(--soft);
    font-style: italic;
}
.comment-meta {
    display: flex;
    align-items: baseline;
    gap: var(--sp-3);
    margin-bottom: var(--sp-1);
}
.comment-body {
    margin: 0;
    font-size: 0.9rem;
    color: var(--ink);
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Activity timeline */
.timeline {
    padding: 0;
}
.timeline-item {
    padding: var(--sp-3) var(--sp-5);
    border-left: 3px solid var(--line);
    margin-left: var(--sp-5);
    position: relative;
    border-bottom: 1px solid var(--line);
}
.timeline-item:last-child {
    border-bottom: none;
}
.timeline-item::before {
    content: '';
    position: absolute;
    left: -7px;
    top: 50%;
    transform: translateY(-50%);
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--brand);
    border: 2px solid var(--panel);
}
.timeline-meta {
    display: flex;
    align-items: baseline;
    gap: var(--sp-3);
    margin-bottom: var(--sp-1);
}
.timeline-body {
    margin: 0;
    color: var(--muted);
}

/* Quick-access action list (tasks.php sidebar) */
.action-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
}
.action-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border: 1px solid var(--line);
    border-radius: 8px;
    text-decoration: none;
    color: var(--ink);
    transition: background 0.12s, border-color 0.12s;
}
.action-item:hover {
    background: var(--soft);
    border-color: var(--brand);
}
.action-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--brand);
    flex-shrink: 0;
}

/* Table row warning highlight (queue explorer) */
.table-row-warning td {
    background: hsl(35 100% 97%);
}

/* Form section title */
.form-section-title {
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

/* Help list */
.help-list {
    margin: 0;
    padding-left: var(--sp-5);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}
.help-list li {
    font-size: 0.875rem;
    color: var(--muted);
    line-height: 1.5;
}
.help-list li strong {
    color: var(--ink);
}

/* ── Collapsable filter panel ─────────────────────────────────────────────── */
/* Use <details class="card"> with a <summary> header and <div class="card-body">. */
/* See UI_STANDARDS.md § Filter Panel for the canonical pattern.                  */
details.card > summary {
    list-style: none;
    cursor: pointer;
}
details.card > summary::-webkit-details-marker { display: none; }

/* Quick actions and compact Ask Anita surface */
.dropdown-menu {
    width: min(360px, calc(100vw - 20px));
    max-height: min(78vh, 680px);
    overflow-y: auto;
}

.qa-section {
    padding: var(--sp-3) var(--sp-3) var(--sp-2);
}

.qa-section-heading,
.qa-anita-label {
    display: block;
    margin-bottom: var(--sp-2);
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
}

.qa-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--sp-1);
}

.dropdown-menu .qa-item {
    min-width: 0;
    padding: var(--sp-2) var(--sp-1);
    border: 0;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-1);
    color: var(--ink);
    text-align: center;
}

.dropdown-menu .qa-item:hover {
    background: var(--soft);
    color: var(--brand);
}

.qa-icon-svg {
    width: 21px;
    height: 21px;
    flex: 0 0 21px;
}

.qa-inline-icon {
    width: 14px;
    height: 14px;
}

.qa-label {
    width: 100%;
    overflow: hidden;
    color: inherit;
    font-size: 0.68rem;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-menu .qa-manage-link {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--sp-1);
    padding: var(--sp-2) 0 0;
    border: 0;
    color: var(--muted);
    font-size: 0.72rem;
}

.qa-divider {
    border-top: 1px solid var(--line);
}

.qa-anita-section {
    padding: var(--sp-3);
}

.qa-anita-compose {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 36px;
    gap: var(--sp-2);
    align-items: end;
}

.qa-anita-compose textarea {
    width: 100%;
    min-height: 58px;
    max-height: 120px;
    resize: vertical;
    padding: var(--sp-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--soft);
    color: var(--ink);
    font: inherit;
    font-size: 0.8rem;
}

.qa-ask-button {
    width: 36px;
    height: 36px;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
}

.qa-ask-button:hover { background: var(--brand-dark); }
.qa-ask-button:disabled { cursor: wait; opacity: 0.65; }
.qa-ask-button svg { width: 17px; height: 17px; }
.qa-ask-button.is-loading svg { animation: qa-pulse 0.8s ease-in-out infinite alternate; }

@keyframes qa-pulse { to { transform: translateX(2px); opacity: 0.5; } }

.qa-anita-response {
    margin-top: var(--sp-2);
    max-height: 130px;
    overflow-y: auto;
    padding: var(--sp-2);
    border-radius: var(--radius);
    background: var(--soft);
    color: var(--ink);
    font-size: 0.78rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.qa-profile-links { display: block; }

.qa-modal {
    width: min(620px, calc(100vw - 24px));
    max-height: 80vh;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: var(--panel);
    box-shadow: 0 18px 48px var(--shadow);
}

.qa-modal::backdrop { background: rgba(15, 16, 20, 0.55); }
.qa-modal-header { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4); border-bottom: 1px solid var(--line); }
.qa-modal-close { width: 32px; height: 32px; min-height: 0; margin: 0; padding: 0; border: 0; border-radius: var(--radius); background: var(--soft); color: var(--ink); font-size: 1.3rem; cursor: pointer; }
.qa-modal-body { max-height: 64vh; overflow-y: auto; padding: var(--sp-4); line-height: 1.6; overflow-wrap: anywhere; white-space: pre-wrap; }

.qa-settings-list { display: grid; gap: var(--sp-2); }
.qa-settings-row { display: grid; grid-template-columns: 34px minmax(120px, 1fr) auto 112px; gap: var(--sp-3); align-items: center; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius); }
.qa-settings-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius); background: var(--soft); color: var(--brand); }
.qa-settings-name { font-weight: 650; }
.qa-visible-toggle { display: flex; align-items: center; gap: var(--sp-1); font-size: 0.82rem; }
.qa-order-field { display: grid; grid-template-columns: auto 58px; align-items: center; gap: var(--sp-1); color: var(--muted); font-size: 0.75rem; }
.qa-order-field input { min-width: 0; padding: var(--sp-2); }
.qa-custom-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.qa-custom-card { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: var(--sp-3); align-items: center; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius); }
.qa-custom-card strong, .qa-custom-card span { display: block; overflow-wrap: anywhere; }
.qa-custom-card span { margin-top: var(--sp-1); color: var(--muted); font-size: 0.76rem; }
.qa-custom-actions { display: flex; gap: var(--sp-1); align-items: center; }
.qa-custom-actions form { margin: 0; }

@media (max-width: 820px) {
    .dropdown-menu { right: -4px; width: min(340px, calc(100vw - 16px)); }
    .qa-settings-row { grid-template-columns: 34px minmax(0, 1fr) auto; }
    .qa-order-field { grid-column: 2 / -1; justify-content: start; }
    .qa-custom-grid { grid-template-columns: 1fr; }
}

@media (max-width: 390px) {
    .qa-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .qa-custom-card { grid-template-columns: 34px minmax(0, 1fr); }
    .qa-custom-actions { grid-column: 2; }
}
.qa-settings-row { grid-template-columns: 24px 34px minmax(120px, 1fr) auto 68px; }
.qa-settings-row.is-dragging { opacity: 0.55; }
.qa-drag-handle { color: var(--muted); cursor: grab; }
.qa-drag-handle .qa-icon-svg { width: 18px; height: 18px; }
.qa-move-controls { display: flex; gap: var(--sp-1); }
.qa-move-button { width: 30px; height: 30px; min-height: 0; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); display: grid; place-items: center; background: var(--panel); color: var(--ink); cursor: pointer; }
.qa-move-button:hover { border-color: var(--brand); color: var(--brand); }
.qa-move-button svg { width: 15px; height: 15px; }
@media (max-width: 820px) { .qa-settings-row { grid-template-columns: 22px 34px minmax(0, 1fr) auto; } .qa-move-controls { grid-column: 3 / -1; justify-content: flex-end; } }

/* ── KB video grid, tags, player modal ─────────────────────────────────────── */
.kb-video-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2);
    margin-bottom: var(--sp-4);
    padding: var(--sp-3) var(--sp-4);
    background: var(--panel, #fff);
    border: 1px solid var(--line, #e5d6d9);
    border-radius: var(--radius);
}
.kb-video-filter-label { font-size: .8rem; font-weight: 600; color: var(--muted); }
/* Override global button defaults (brand bg, 50px min-height) for chips */
.kb-tag-chip {
    background: var(--soft, #f8eef1);
    color: var(--ink, #2b2b2b);
    border: 1px solid var(--line, #e5d6d9);
    border-radius: 999px;
    padding: 2px 12px;
    font-size: .78rem;
    min-height: 0;
    margin: 0;
    cursor: pointer;
    line-height: 1.6;
}
.kb-tag-chip:hover { border-color: var(--brand); color: var(--brand); }
.kb-tag-chip--active { background: var(--brand); color: #fff; border-color: var(--brand); }
.kb-tag-chip--sm { font-size: .7rem; padding: 1px 9px; }

.kb-video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: var(--sp-4);
}
.kb-video-card {
    border: 1px solid var(--line, #e5d6d9);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--panel, #fff);
    display: flex;
    flex-direction: column;
}
/* Thumb can be a <button> (embeddable) or <a> (external) — neutralise both */
.kb-video-thumb {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #1c1c1e;
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 0;
    min-height: 0;
    cursor: pointer;
    overflow: hidden;
}
.kb-video-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kb-video-thumb__placeholder {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    font-size: 2.4rem;
}
.kb-video-thumb__play {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 1.1rem;
    color: #fff;
    background: rgba(0,0,0,.25);
    opacity: 0;
    transition: opacity .15s ease;
}
.kb-video-thumb:hover .kb-video-thumb__play { opacity: 1; }
.kb-video-thumb__duration {
    position: absolute;
    right: var(--sp-2);
    bottom: var(--sp-2);
    background: rgba(0,0,0,.75);
    color: #fff;
    font-size: .7rem;
    padding: 1px 7px;
    border-radius: 4px;
}
.kb-video-card__body {
    padding: var(--sp-3) var(--sp-4) var(--sp-4);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    flex: 1;
}
.kb-video-card__title-row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.kb-video-card__title { font-weight: 600; font-size: .9rem; color: var(--ink); }
.kb-video-card__desc {
    margin: 0;
    font-size: .8rem;
    color: var(--muted);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.kb-video-card__tags { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.kb-video-card__actions { display: flex; gap: var(--sp-2); margin-top: auto; padding-top: var(--sp-2); }

.kb-video-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(0,0,0,.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
}
.kb-video-modal__panel {
    background: var(--panel, #fff);
    border-radius: var(--radius);
    width: min(960px, 100%);
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.kb-video-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--line, #e5d6d9);
}
.kb-video-modal__header h3 {
    margin: 0;
    font-size: .95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kb-video-modal__frame { aspect-ratio: 16 / 9; background: #000; }
.kb-video-modal__frame iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ── Reminder toasts ───────────────────────────────────────────────────────── */
#reminder-toast-container {
    position: fixed;
    top: var(--sp-5);
    right: var(--sp-5);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    pointer-events: none;
    max-width: 360px;
    width: calc(100vw - 2 * var(--sp-5));
}
.reminder-toast {
    background: var(--panel, #fff);
    border: 1px solid var(--line, #e5d6d9);
    border-left: 4px solid var(--brand);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,.14);
    padding: var(--sp-3) var(--sp-4);
    pointer-events: all;
    animation: toast-in .2s ease;
}
.reminder-toast.toast-out { animation: toast-out .2s ease forwards; }
@keyframes toast-in  { from { opacity:0; transform:translateX(24px); } to { opacity:1; transform:none; } }
@keyframes toast-out { from { opacity:1; transform:none; } to { opacity:0; transform:translateX(24px); } }
.reminder-toast__title { font-weight: 600; font-size: .9rem; margin-bottom: var(--sp-1); color: var(--ink); }
.reminder-toast__body  { font-size: .8rem; color: var(--muted); margin-bottom: var(--sp-3); }
.reminder-toast__task  { font-size: .78rem; color: var(--muted); margin-bottom: var(--sp-3); }
.reminder-toast__actions { display: flex; gap: var(--sp-2); }
.reminder-toast__actions button { min-height: 0; padding: var(--sp-1) var(--sp-3); font-size: .8rem; }
