/* Workspace settings and persisted appearance preferences */

.settings-page {
    width: min(1240px, 100%);
    margin: 0 auto;
    display: grid;
    gap: 20px;
}

.settings-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 4px;
}

.settings-heading .eyebrow { margin: 0 0 7px; }
.settings-heading h1 {
    margin: 0;
    color: var(--text);
    font-size: clamp(26px, 3vw, 34px);
    letter-spacing: -.035em;
}
.settings-heading p:not(.eyebrow) {
    max-width: 680px;
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.55;
}

.settings-owner-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    margin-top: 5px;
    padding: 7px 10px;
    color: var(--success);
    font-size: 10px;
    font-weight: 750;
    letter-spacing: .035em;
    text-transform: uppercase;
    background: var(--success-soft);
    border: 1px solid color-mix(in srgb, var(--success) 24%, var(--border));
    border-radius: 999px;
}

.settings-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 286px;
    align-items: start;
    gap: 18px;
}

.settings-preference-form,
.settings-summary { min-width: 0; display: grid; gap: 16px; }

.settings-card,
.settings-staff-card,
.settings-summary-card,
.settings-security-card { overflow: hidden; }

.settings-card-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

.settings-card > .settings-card-head,
.settings-staff-head {
    padding: 19px 20px 17px;
    border-bottom: 1px solid var(--border);
}

.settings-card-icon {
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: var(--brand);
    background: var(--brand-soft);
    border-radius: 10px;
}

.settings-card-head h2,
.settings-security-card h2 {
    margin: 1px 0 0;
    color: var(--text);
    font-size: 14px;
    letter-spacing: -.01em;
}

.settings-card-head p,
.settings-security-card p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.5;
}

.settings-card-body { padding: 18px 20px 20px; }
.settings-preferences-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.settings-field { display: grid; gap: 7px; color: var(--text-subtle); font-size: 11px; font-weight: 700; }
.settings-field select,
.settings-field input,
.settings-field textarea { width: 100%; }
.settings-field textarea { min-height: 92px; resize: vertical; }
.settings-field-wide { grid-column: 1 / -1; }
.settings-field small { color: var(--muted); font-size: 10px; font-weight: 450; line-height: 1.45; }

.settings-info-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 14px;
    padding: 10px 12px;
    color: var(--info);
    background: var(--info-soft);
    border: 1px solid color-mix(in srgb, var(--info) 16%, var(--border));
    border-radius: 9px;
}
.settings-info-row p { margin: 0; color: var(--text-subtle); font-size: 10px; line-height: 1.5; }

.settings-choice-group { min-width: 0; margin: 0; padding: 0; border: 0; }
.settings-choice-group + .settings-choice-group {
    margin-top: 19px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}
.settings-choice-group legend {
    margin-bottom: 10px;
    padding: 0;
    color: var(--muted-strong);
    font-size: 10px;
    font-weight: 750;
    letter-spacing: .045em;
    text-transform: uppercase;
}

.theme-choice-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.theme-choice {
    position: relative;
    min-width: 0;
    display: grid;
    gap: 8px;
    padding: 8px;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 11px;
    transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.theme-choice:hover { border-color: color-mix(in srgb, var(--brand) 36%, var(--border)); }
.theme-choice:has(input:checked) {
    background: var(--brand-soft);
    border-color: var(--brand);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 13%, transparent);
}
.theme-choice > input,
.accent-choice > input,
.density-choice > input,
.staff-role-choice > input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}
.theme-choice:has(input:focus-visible),
.accent-choice:has(input:focus-visible),
.density-choice:has(input:focus-visible),
.staff-role-choice:has(input:focus-visible) {
    outline: 3px solid color-mix(in srgb, var(--brand) 28%, transparent);
    outline-offset: 2px;
}

.theme-choice-preview {
    position: relative;
    height: 58px;
    display: grid;
    grid-template-columns: 25% 1fr;
    grid-template-rows: 15px 1fr;
    overflow: hidden;
    background: #f6f8fc;
    border: 1px solid #d0d5dd;
    border-radius: 7px;
}
.theme-choice-preview i { grid-row: 1 / -1; background: #172033; }
.theme-choice-preview b { background: #fff; border-bottom: 1px solid #e4e7ec; }
.theme-choice-preview em {
    margin: 8px;
    background: #fff;
    border: 1px solid #e4e7ec;
    border-radius: 3px;
}
.theme-preview-dark { background: #111827; border-color: #475569; }
.theme-preview-dark i { background: #080d18; }
.theme-preview-dark b { background: #182235; border-color: #334155; }
.theme-preview-dark em { background: #1d2939; border-color: #344054; }
.theme-preview-midnight { background: #07111f; border-color: #28435d; }
.theme-preview-midnight i { background: #020813; }
.theme-preview-midnight b { background: #0a192b; border-color: #1c3852; }
.theme-preview-midnight em { background: #0e2238; border-color: #264861; }
.theme-preview-system::after {
    position: absolute;
    inset: 0 0 0 50%;
    content: "";
    background: linear-gradient(90deg, transparent, rgba(15,23,42,.13));
}

.theme-choice-copy { min-width: 0; display: grid; gap: 2px; padding-right: 20px; }
.theme-choice-copy strong { overflow: hidden; color: var(--text); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.theme-choice-copy small { overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.choice-check {
    position: absolute;
    right: 8px;
    bottom: 12px;
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    color: transparent;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 50%;
}
.choice-check .icon { width: 11px; height: 11px; stroke-width: 2.5; }
label:has(input:checked) > .choice-check { color: #fff; background: var(--brand); border-color: var(--brand); }

.accent-choice-row { display: flex; flex-wrap: wrap; gap: 10px; }
.accent-choice {
    position: relative;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    cursor: pointer;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
}
.accent-choice > span:not(.sr-only) { width: 19px; height: 19px; background: var(--accent-swatch); border-radius: 6px; }
.accent-choice:has(input:checked) { border-color: var(--accent-swatch); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-swatch) 18%, transparent); }
.accent-indigo { --accent-swatch: #4f46e5; }
.accent-blue { --accent-swatch: #2563eb; }
.accent-emerald { --accent-swatch: #059669; }
.accent-violet { --accent-swatch: #7c3aed; }
.accent-slate { --accent-swatch: #475569; }

.density-choice-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.density-choice {
    position: relative;
    display: flex;
    cursor: pointer;
    padding: 11px 34px 11px 12px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 9px;
}
.density-choice:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); }
.density-choice > span { display: grid; gap: 2px; }
.density-choice strong { color: var(--text-subtle); font-size: 11px; }
.density-choice small { color: var(--muted); font-size: 9px; }
.density-choice::after {
    position: absolute;
    top: 50%;
    right: 12px;
    width: 14px;
    height: 14px;
    content: "";
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    transform: translateY(-50%);
}
.density-choice:has(input:checked)::after { background: var(--brand); border: 4px solid var(--surface); box-shadow: 0 0 0 1px var(--brand); }

.settings-save-bar {
    position: sticky;
    bottom: 14px;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 62px;
    padding: 11px 13px 11px 17px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
}
.settings-save-state { color: var(--muted); font-size: 10px; line-height: 1.4; }
.settings-save-bar .primary { flex: 0 0 auto; }

.settings-summary { position: sticky; top: 86px; }
.settings-summary-card { display: flex; align-items: center; gap: 14px; padding: 18px; }
.settings-summary-icon {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: var(--brand);
    background: var(--brand-soft);
    border-radius: 12px;
}
.settings-summary-card div { min-width: 0; display: grid; }
.settings-summary-card p { margin: 0; color: var(--muted); font-size: 10px; }
.settings-summary-card strong { margin-top: 2px; color: var(--text); font-size: 25px; letter-spacing: -.03em; }
.settings-summary-card small { margin-top: 1px; color: var(--muted); font-size: 9px; }

.settings-security-card { padding: 18px; }
.settings-security-card header { display: flex; align-items: flex-start; gap: 10px; }
.settings-security-card header > span {
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: var(--success);
    background: var(--success-soft);
    border-radius: 9px;
}
.settings-security-card header .icon { width: 16px; height: 16px; }
.settings-security-card ul { display: grid; gap: 8px; margin: 15px 0 0; padding: 14px 0 0; border-top: 1px solid var(--border); list-style: none; }
.settings-security-card li { position: relative; padding-left: 14px; color: var(--muted-strong); font-size: 9px; line-height: 1.45; }
.settings-security-card li::before { position: absolute; top: .48em; left: 0; width: 5px; height: 5px; content: ""; background: var(--success); border-radius: 50%; }

.settings-staff-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.settings-staff-head > .primary { flex: 0 0 auto; }
.settings-staff-card {
    /* Three 40px actions plus their gaps must fit without entering Status. */
    --settings-staff-columns: minmax(250px, 1.5fr) minmax(190px, .8fr) minmax(180px, .65fr) 132px;
}
.settings-staff-toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 165px 165px auto;
    align-items: end;
    gap: 9px;
    padding: 13px 15px 14px;
    background: var(--surface-soft);
    border-bottom: 1px solid var(--border);
}
.settings-staff-search,
.settings-staff-filter { min-width: 0; display: grid; gap: 6px; }
.settings-filter-label {
    color: var(--muted-strong);
    font-size: var(--type-meta, 12px);
    font-weight: 750;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.settings-search-control { position: relative; min-width: 0; display: block; }
.settings-search-control .icon { position: absolute; top: 50%; left: 11px; width: 16px; height: 16px; color: var(--muted); transform: translateY(-50%); pointer-events: none; }
.settings-search-control input { width: 100%; padding-left: 35px; }
.settings-staff-toolbar select { width: 100%; }
.settings-staff-toolbar output {
    min-height: 38px;
    min-width: 108px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 10px;
    color: var(--muted-strong);
    font-size: 10px;
    font-weight: 700;
    text-align: center;
    background: var(--surface-raised, var(--surface));
    border: 1px solid var(--border);
    border-radius: 9px;
}

.settings-list-columns {
    --settings-list-inline-padding: 15px;
    display: grid;
    align-items: center;
    gap: 16px;
    padding: 9px var(--settings-list-inline-padding);
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: .05em;
    text-transform: uppercase;
    background: var(--surface-raised, var(--surface));
    border-bottom: 1px solid var(--border);
}
.settings-staff-columns { grid-template-columns: var(--settings-staff-columns); }
.settings-list-columns span:last-child { text-align: right; }

.settings-list-scroll { min-width: 0; }
.settings-list-scroll:has(> .is-scrollable) > .settings-list-columns {
    padding-inline-end: calc(
        var(--settings-list-inline-padding) + var(--scrollbar-size)
    );
}
.settings-staff-list.is-scrollable,
.settings-security-list.is-scrollable {
    max-height: min(560px, 60dvh);
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: stable;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}
.settings-staff-list.is-scrollable:focus-visible,
.settings-security-list.is-scrollable:focus-visible {
    outline: 2px solid var(--focus-ring, var(--brand));
    outline-offset: -3px;
}

.settings-staff-list { display: grid; }
.settings-staff-row {
    display: grid;
    grid-template-columns: var(--settings-staff-columns);
    align-items: start;
    gap: 16px;
    min-height: 80px;
    padding: 13px 15px;
    border-bottom: 1px solid var(--border);
    transition: background 120ms ease;
}
.settings-staff-row:last-child { border-bottom: 0; }
.settings-staff-row:hover,
.settings-staff-row:focus-within { background: var(--surface-soft); }
.staff-person { min-width: 0; display: flex; align-items: center; gap: 10px; }
.staff-person .avatar { flex: 0 0 auto; }
.staff-person div { min-width: 0; display: grid; gap: 3px; }
.staff-person strong { min-width: 0; overflow: hidden; color: var(--text); font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.staff-person small { min-width: 0; overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.staff-you { display: inline-flex; margin-left: 4px; padding: 2px 5px; color: var(--brand); font-size: 8px; letter-spacing: .04em; text-transform: uppercase; background: var(--brand-soft); border-radius: 4px; }
.staff-role,
.staff-status { min-width: 0; display: grid; align-self: start; justify-items: start; gap: 4px; }
.staff-role-details,
.staff-status-details {
    min-width: 0;
    display: grid;
    justify-items: start;
    gap: 4px;
}
.staff-status-details {
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: 5px;
}
.role-badge { display: inline-flex; padding: 5px 8px; color: var(--muted-strong); font-size: 8px; font-weight: 750; letter-spacing: .035em; text-transform: uppercase; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 999px; }
.role-badge.admin { color: var(--brand); background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 21%, var(--border)); }
.app .settings-page .staff-status .status-dot {
    width: max-content;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted-strong);
    font-size: var(--type-meta, 12px);
    font-weight: 700;
    line-height: 1.25;
    white-space: normal;
}
.staff-status-label { min-width: 0; overflow-wrap: anywhere; }
.status-dot::before { width: 6px; height: 6px; flex: 0 0 6px; content: ""; background: var(--muted); border-radius: 50%; }
.status-dot.active::before { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.status-dot.pending::before { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.status-dot.inactive::before { background: var(--muted); }
.app .settings-page .status-dot.active { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 24%, var(--border)); }
.app .settings-page .status-dot.pending { color: var(--warning); background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 24%, var(--border)); }
.staff-status .staff-status-note {
    max-width: 100%;
    display: block;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}
.staff-actions { min-width: 0; display: inline-flex; align-self: start; justify-content: flex-end; gap: 6px; }
.staff-actions .icon-button.success { color: var(--success); }
.staff-mobile-label { display: none; }

.settings-staff-empty,
.settings-no-results {
    min-height: 220px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 6px;
    padding: 34px;
    color: var(--muted);
    text-align: center;
}
.settings-staff-empty > .icon,
.settings-no-results > .icon { width: 28px; height: 28px; margin-bottom: 4px; color: var(--brand); }
.settings-staff-empty strong,
.settings-no-results strong { color: var(--text); font-size: 12px; }
.settings-staff-empty span,
.settings-no-results span { font-size: 10px; }

.settings-staff-form .form-grid { padding-top: 4px; }
.settings-staff-form label:not(.staff-role-choice):not(.staff-show-password) { display: grid; gap: 7px; color: var(--text-subtle); font-size: 11px; font-weight: 650; }
.settings-staff-form input { width: 100%; }
.settings-staff-field { display: grid; gap: 7px; }
.staff-password-group { display: grid; gap: 7px; }
.staff-password-group > label:first-child { color: var(--text-subtle); font-size: 11px; font-weight: 650; }
.staff-password-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.staff-invite-note {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 12px 13px;
    color: var(--text-subtle);
    background: var(--success-soft);
    border: 1px solid color-mix(in srgb, var(--success) 18%, var(--border));
    border-radius: 9px;
}
.staff-invite-note > span {
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: var(--success);
    background: var(--surface);
    border-radius: 8px;
}
.staff-invite-note strong { display: block; color: var(--text); font-size: 11px; }
.staff-invite-note p { margin: 4px 0 0; font-size: 10px; line-height: 1.45; }
.staff-show-password { display: inline-flex; align-items: center; gap: 7px; margin-top: 2px; color: var(--muted-strong); font-size: 10px; font-weight: 500; }
.staff-show-password input { width: 15px; min-height: 15px; height: 15px; margin: 0; }
.staff-role-choices { min-width: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 16px 0 0; padding: 0; border: 0; }
.staff-role-choices legend { grid-column: 1 / -1; margin-bottom: 0; padding: 0; color: var(--text-subtle); font-size: 11px; font-weight: 650; }
.staff-role-choice { position: relative; min-width: 0; display: flex; padding: 12px 34px 12px 12px; cursor: pointer; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 10px; }
.staff-role-choice:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); }
.staff-role-choice > span:not(.choice-check) { min-width: 0; display: grid; gap: 4px; }
.staff-role-choice strong { color: var(--text); font-size: 11px; }
.staff-role-choice small { color: var(--muted); font-size: 9px; line-height: 1.4; }
.staff-role-choice .choice-check { top: 11px; right: 10px; bottom: auto; }
.settings-deactivate-copy { display: grid; gap: 15px; padding-top: 17px; }
.settings-deactivate-copy > p { margin: 0; color: var(--text-subtle); font-size: 11px; line-height: 1.55; }
.settings-deactivate-copy .staff-person { padding: 12px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 10px; }
.danger-button { color: #fff; background: var(--danger); border-color: var(--danger); }
.danger-button:hover { background: #912018; border-color: #912018; }

.settings-forbidden { min-height: 420px; display: grid; place-items: center; align-content: center; gap: 10px; padding: 40px; text-align: center; }
.settings-forbidden > span { width: 44px; height: 44px; display: grid; place-items: center; color: var(--danger); background: var(--danger-soft); border-radius: 12px; }
.settings-forbidden h1 { margin: 5px 0 0; font-size: 19px; }
.settings-forbidden p { margin: 0 0 8px; color: var(--muted); }

/* Persisted accent palettes */
html[data-rees-accent='blue'] { --brand: #2563eb; --brand-hover: #1d4ed8; --brand-soft: #eff6ff; --surface-brand: #eff6ff; }
html[data-rees-accent='emerald'] { --brand: #059669; --brand-hover: #047857; --brand-soft: #ecfdf5; --surface-brand: #ecfdf5; }
html[data-rees-accent='violet'] { --brand: #7c3aed; --brand-hover: #6d28d9; --brand-soft: #f5f3ff; --surface-brand: #f5f3ff; }
html[data-rees-accent='slate'] { --brand: #475569; --brand-hover: #334155; --brand-soft: #f1f5f9; --surface-brand: #f1f5f9; }

/* Dark appearance applies to the existing V2 shell as well as settings. */
html[data-rees-theme='dark'] {
    color: #f8fafc;
    background: #0b1120;
    --bg: #0b1120;
    --surface: #111827;
    --surface-soft: #172033;
    --surface-brand: #20244a;
    --text: #f8fafc;
    --text-subtle: #d5dbea;
    --muted: #9aa6bb;
    --muted-strong: #bec7d7;
    --border: #293449;
    --border-strong: #3b4962;
    --brand-soft: #252858;
    --success: #47d18c;
    --success-soft: #0d3427;
    --warning: #fdb65d;
    --warning-soft: #3b2810;
    --danger: #ff8a82;
    --danger-soft: #3d1b1d;
    --info: #7eb6ff;
    --info-soft: #132b4b;
    --sidebar: #070c16;
    --sidebar-soft: #152035;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.25);
    --shadow-sm: 0 4px 12px rgba(0,0,0,.2);
    --shadow-md: 0 18px 40px rgba(0,0,0,.32);
}
html[data-rees-theme='dark'][data-rees-accent='indigo'] { --brand: #818cf8; --brand-hover: #a5b4fc; --brand-soft: #252858; --surface-brand: #252858; }
html[data-rees-theme='dark'][data-rees-accent='blue'] { --brand: #60a5fa; --brand-hover: #93c5fd; --brand-soft: #152c4e; --surface-brand: #152c4e; }
html[data-rees-theme='dark'][data-rees-accent='emerald'] { --brand: #34d399; --brand-hover: #6ee7b7; --brand-soft: #12372d; --surface-brand: #12372d; }
html[data-rees-theme='dark'][data-rees-accent='violet'] { --brand: #a78bfa; --brand-hover: #c4b5fd; --brand-soft: #302655; --surface-brand: #302655; }
html[data-rees-theme='dark'][data-rees-accent='slate'] { --brand: #a8b4c7; --brand-hover: #d0d7e4; --brand-soft: #273348; --surface-brand: #273348; }
html[data-rees-theme='dark'] body,
html[data-rees-theme='dark'] .body,
html[data-rees-theme='dark'] .content { background: var(--bg); color: var(--text); }
html[data-rees-theme='dark'] .top,
html[data-rees-theme='dark'] .card,
html[data-rees-theme='dark'] .data-surface,
html[data-rees-theme='dark'] .table th,
html[data-rees-theme='dark'] .table .action-heading,
html[data-rees-theme='dark'] .table .action-cell,
html[data-rees-theme='dark'] .modal,
html[data-rees-theme='dark'] .toolbar { background: var(--surface); }
html[data-rees-theme='dark'] input,
html[data-rees-theme='dark'] select,
html[data-rees-theme='dark'] textarea,
html[data-rees-theme='dark'] .icon-button { color: var(--text-subtle); background-color: var(--surface); border-color: var(--border); }
html[data-rees-theme='dark'] .table tbody tr:hover,
html[data-rees-theme='dark'] .table tbody tr:focus-within,
html[data-rees-theme='dark'] .table tbody tr:hover .action-cell,
html[data-rees-theme='dark'] .table tbody tr:focus-within .action-cell { background: var(--surface-soft); }
html[data-rees-theme='dark'] .skeleton { background: #263249; }
html[data-rees-theme='dark'] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent); }
html[data-rees-theme='dark'] ::selection { color: var(--text); background: #384378; }

html[data-rees-theme='midnight'] {
    color: #eff8ff;
    background: #020817;
    --bg: #020817;
    --surface: #071426;
    --surface-soft: #0c2035;
    --surface-brand: #132b48;
    --text: #eff8ff;
    --text-subtle: #cfdeec;
    --muted: #8ca2b8;
    --muted-strong: #b1c4d6;
    --border: #19334c;
    --border-strong: #2a4a66;
    --brand-soft: #142d50;
    --success: #45d6a0;
    --success-soft: #082f29;
    --warning: #f9ba67;
    --warning-soft: #35250e;
    --danger: #ff8e91;
    --danger-soft: #39191f;
    --info: #73baff;
    --info-soft: #0b2945;
    --sidebar: #010611;
    --sidebar-soft: #0a1a2d;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.32);
    --shadow-sm: 0 5px 16px rgba(0,0,0,.3);
    --shadow-md: 0 20px 46px rgba(0,0,0,.42);
}
html[data-rees-theme='midnight'][data-rees-accent='indigo'] { --brand: #8b9cff; --brand-hover: #aeb8ff; --brand-soft: #172853; --surface-brand: #172853; }
html[data-rees-theme='midnight'][data-rees-accent='blue'] { --brand: #62b0ff; --brand-hover: #91c9ff; --brand-soft: #0d3154; --surface-brand: #0d3154; }
html[data-rees-theme='midnight'][data-rees-accent='emerald'] { --brand: #3bd5a3; --brand-hover: #72e7c1; --brand-soft: #09372e; --surface-brand: #09372e; }
html[data-rees-theme='midnight'][data-rees-accent='violet'] { --brand: #b399ff; --brand-hover: #cbbcff; --brand-soft: #2b2355; --surface-brand: #2b2355; }
html[data-rees-theme='midnight'][data-rees-accent='slate'] { --brand: #b3c4d7; --brand-hover: #d2deea; --brand-soft: #1c3348; --surface-brand: #1c3348; }
html[data-rees-theme='midnight'] body,
html[data-rees-theme='midnight'] .body,
html[data-rees-theme='midnight'] .content { background: var(--bg); color: var(--text); }
html[data-rees-theme='midnight'] .top,
html[data-rees-theme='midnight'] .card,
html[data-rees-theme='midnight'] .data-surface,
html[data-rees-theme='midnight'] .table th,
html[data-rees-theme='midnight'] .table .action-heading,
html[data-rees-theme='midnight'] .table .action-cell,
html[data-rees-theme='midnight'] .modal,
html[data-rees-theme='midnight'] .toolbar { background: var(--surface); }
html[data-rees-theme='midnight'] input,
html[data-rees-theme='midnight'] select,
html[data-rees-theme='midnight'] textarea,
html[data-rees-theme='midnight'] .icon-button { color: var(--text-subtle); background-color: var(--surface); border-color: var(--border); }
html[data-rees-theme='midnight'] .table tbody tr:hover,
html[data-rees-theme='midnight'] .table tbody tr:focus-within,
html[data-rees-theme='midnight'] .table tbody tr:hover .action-cell,
html[data-rees-theme='midnight'] .table tbody tr:focus-within .action-cell { background: var(--surface-soft); }
html[data-rees-theme='midnight'] .skeleton { background: #173049; }
html[data-rees-theme='midnight'] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent); }
html[data-rees-theme='midnight'] ::selection { color: var(--text); background: #244f75; }

/* Compact density is deliberately scoped to high-volume UI surfaces. */
html[data-rees-density='compact'] .content { padding-top: 24px; padding-bottom: 32px; }
html[data-rees-density='compact'] .table td { height: 50px; padding-block: 8px; }
html[data-rees-density='compact'] .table th { padding-block: 8px; }
html[data-rees-density='compact'] .kpi { min-height: 124px; padding: 16px; }
html[data-rees-density='compact'] .settings-staff-row { min-height: 58px; padding-block: 7px; }
html[data-rees-density='compact'] .settings-card > .settings-card-head,
html[data-rees-density='compact'] .settings-staff-head { padding-block: 14px; }
html[data-rees-density='compact'] .settings-card-body { padding-block: 14px; }
html[data-rees-density='spacious'] .content { padding-top: 42px; padding-bottom: 56px; }
html[data-rees-density='spacious'] .table td { height: 72px; padding-block: 15px; }
html[data-rees-density='spacious'] .table th { padding-block: 13px; }
html[data-rees-density='spacious'] .kpi { min-height: 164px; padding: 24px; }
html[data-rees-density='spacious'] .settings-staff-row { min-height: 84px; padding-block: 16px; }
html[data-rees-density='spacious'] .settings-card > .settings-card-head,
html[data-rees-density='spacious'] .settings-staff-head { padding-block: 23px; }
html[data-rees-density='spacious'] .settings-card-body { padding-block: 24px; }

@media (max-width: 980px) {
    .settings-layout { grid-template-columns: 1fr; }
    .settings-summary { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .settings-staff-card { --settings-staff-columns: minmax(210px, 1.25fr) minmax(165px, .8fr) minmax(170px, .65fr) 132px; }
    .settings-staff-toolbar { grid-template-columns: minmax(220px, 1fr) 150px 150px auto; }
    .settings-staff-row,
    .settings-list-columns { gap: 10px; }
}

@media (max-width: 820px) {
    .settings-heading { flex-direction: column; gap: 10px; }
    .settings-owner-badge { margin-top: 0; }
    .theme-choice-grid { grid-template-columns: 1fr; }
    .theme-choice { grid-template-columns: 100px minmax(0, 1fr); align-items: center; }
    .theme-choice-preview { height: 52px; }
    .theme-choice .choice-check { top: 50%; bottom: auto; transform: translateY(-50%); }
    .settings-save-bar { bottom: 8px; }
    .settings-summary { grid-template-columns: 1fr; }
    .settings-staff-head { align-items: flex-start; flex-direction: column; }
    .settings-staff-head > .primary { width: 100%; justify-content: center; }
    .settings-staff-toolbar { grid-template-columns: 1fr 1fr; }
    .settings-staff-search { grid-column: 1 / -1; }
    .settings-staff-toolbar output { justify-self: stretch; }
    .settings-list-columns { display: none; }
    .settings-staff-row {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 12px;
        padding: 14px 15px;
    }
    .staff-person { grid-column: 1 / -1; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
    .staff-role,
    .staff-status {
        display: grid;
        grid-template-columns: 72px minmax(0, 1fr);
        align-items: start;
        justify-items: stretch;
        gap: 10px;
    }
    .staff-role-details,
    .staff-status-details { justify-items: start; }
    .staff-status { grid-column: 1; }
    .staff-actions { grid-column: 2; grid-row: 2 / 4; align-self: end; }
    .staff-mobile-label { display: inline; color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
    .staff-status .staff-status-note { display: block; }
}

@media (max-width: 560px) {
    .settings-page { gap: 14px; }
    .settings-card > .settings-card-head,
    .settings-staff-head { padding-inline: 16px; }
    .settings-card-body { padding-inline: 16px; }
    .density-choice-row { grid-template-columns: 1fr; }
    .settings-preferences-grid { grid-template-columns: 1fr; }
    .settings-save-bar { align-items: stretch; flex-direction: column; gap: 9px; padding: 12px; }
    .settings-save-bar .primary { width: 100%; justify-content: center; }
    .settings-staff-toolbar { grid-template-columns: 1fr; padding: 12px; }
    .settings-staff-search,
    .settings-staff-toolbar output { grid-column: auto; }
    .settings-staff-toolbar output { width: 100%; text-align: center; }
    .settings-staff-row { grid-template-columns: minmax(0, 1fr); }
    .staff-person,
    .staff-role,
    .staff-status,
    .staff-actions { grid-column: 1; }
    .staff-actions { grid-row: auto; justify-self: end; }
    .staff-password-field { grid-template-columns: 1fr; }
    .staff-role-choices { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .theme-choice,
    .settings-staff-row { transition: none; }
}

.settings-security-access-card { overflow: hidden; }
.settings-security-summary {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    align-items: center;
    gap: 6px 9px;
    padding: 13px 18px;
    color: var(--muted-strong);
    background: var(--surface-soft);
    border-bottom: 1px solid var(--border);
}
.settings-security-summary strong {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    color: var(--brand);
    font-size: 17px;
    background: var(--brand-soft);
    border-radius: 9px;
}
.settings-security-summary span { font-size: 10px; font-weight: 700; }
.settings-security-summary small { justify-self: end; color: var(--muted); font-size: 9px; line-height: 1.45; }
.settings-security-columns {
    --settings-list-inline-padding: 18px;
    grid-template-columns: minmax(220px, .72fr) minmax(300px, 1.5fr) minmax(110px, auto);
}
.settings-security-list { display: grid; }
.settings-security-row {
    display: grid;
    grid-template-columns: minmax(220px, .72fr) minmax(300px, 1.5fr) minmax(110px, auto);
    align-items: start;
    gap: 16px;
    min-width: 0;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
}
.settings-security-row:last-child { border-bottom: 0; }
.security-property-scope { min-width: 0; display: grid; gap: 6px; }
.security-property-meta {
    min-width: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
}
.security-property-count,
.security-property-active-count {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    line-height: 1.4;
}
.security-property-active-count::before { margin-right: 8px; content: '\00b7'; }
.security-property-list {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
    align-content: flex-start;
    gap: 6px;
}
.security-property-list.is-scrollable {
    max-height: 174px;
    overflow-y: auto;
    padding: 2px 6px 2px 2px;
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
}
.security-property-list.is-scrollable:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 8px;
}
.security-property {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    min-height: 38px;
    padding: 4px 4px 4px 10px;
    color: var(--brand-strong);
    font-size: 8px;
    font-weight: 700;
    background: var(--brand-soft);
    border: 1px solid color-mix(in srgb, var(--brand) 16%, var(--border));
    border-radius: 9px;
}
.security-property-name {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.security-property.inactive { color: var(--muted); background: var(--surface-soft); border-color: var(--border); }
.app .settings-page .security-property-action {
    width: 32px;
    min-width: 32px;
    height: 32px;
    min-height: 32px;
    display: grid;
    place-items: center;
    padding: 0;
    color: currentColor;
    background: var(--surface);
    border: 0;
    border-radius: 50%;
    flex: 0 0 auto;
}
.app .settings-page .security-property-action:hover { background: color-mix(in srgb, var(--surface) 72%, var(--brand-soft)); }
.settings-security-row > .staff-actions { align-self: start; justify-self: end; }
.security-unassigned { color: var(--warning, #b54708); font-size: 9px; font-weight: 650; }
.role-badge.security { color: var(--brand-strong); background: var(--brand-soft); }
.role-badge.manager {
    color: var(--info);
    background: var(--info-soft);
    border-color: color-mix(in srgb, var(--info) 22%, var(--border));
}
.staff-additional-roles {
    max-width: 100%;
    overflow: hidden;
    color: var(--muted-strong);
    font-size: 8px;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.staff-grant-actions {
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
}
.staff-scope-action {
    min-height: 24px;
    padding: 0;
    color: var(--brand);
    font-size: 8px;
    font-weight: 700;
    text-align: left;
    background: transparent;
    border: 0;
}
.staff-scope-action:hover { text-decoration: underline; }
.staff-scope-action:focus-visible {
    outline: 2px solid var(--focus-ring, var(--brand));
    outline-offset: 2px;
    border-radius: 3px;
}
.staff-scope-action.danger-text { color: var(--danger); }
.staff-scope-summary { color: var(--muted); font-size: 8px; line-height: 1.35; }
.settings-staff-modal { width: min(760px, 100%); }
.manager-access-scope {
    grid-column: 1 / -1;
    display: grid;
    gap: 12px;
    margin-top: 16px;
    padding: 15px;
    background: color-mix(in srgb, var(--brand-soft) 32%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--brand) 18%, var(--border));
    border-radius: 12px;
}
.manager-access-scope[hidden] { display: none; }
.manager-access-scope > header h3 {
    margin: 0;
    color: var(--text);
    font-size: 13px;
}
.manager-access-scope > header p,
.manager-scope-note {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 9px;
    line-height: 1.5;
}
.manager-scope-choices {
    position: relative;
    min-width: 0;
    margin: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
}
.manager-scope-choices legend {
    padding: 0 6px;
    color: var(--text-subtle);
    font-size: 10px;
    font-weight: 750;
}
.manager-scope-choices > button {
    position: absolute;
    top: -14px;
    right: 10px;
    min-height: 28px;
    padding: 5px 8px;
    background: var(--surface);
    font-size: 9px;
}
.manager-scope-choices > div {
    max-height: 210px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    overflow-y: auto;
    padding: 2px;
    scrollbar-gutter: stable;
}
.manager-property-choices > div { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.manager-scope-choices label {
    min-width: 0;
    min-height: 38px;
    display: flex !important;
    grid-template-columns: none !important;
    align-items: center;
    gap: 8px !important;
    padding: 8px 9px;
    cursor: pointer;
    color: var(--text-subtle);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 9px !important;
    font-weight: 600 !important;
}
.manager-scope-choices label:has(input:checked) {
    color: var(--text);
    background: var(--brand-soft);
    border-color: color-mix(in srgb, var(--brand) 45%, var(--border));
}
.manager-scope-choices label:has(input:focus-visible) {
    outline: 3px solid color-mix(in srgb, var(--brand) 28%, transparent);
    outline-offset: 1px;
}
.manager-scope-choices input {
    width: 17px !important;
    height: 17px;
    min-height: 17px;
    flex: 0 0 auto;
    margin: 0;
}
.manager-scope-choices label span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.manager-scope-empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 14px;
    color: var(--muted);
    text-align: center;
}
.security-building-choices {
    min-width: 0;
    margin: 16px 0 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
}
.security-building-choices legend { padding: 0 6px; font-size: 9px; font-weight: 740; }
.security-building-choices legend span { margin-left: 5px; color: var(--muted); font-weight: 650; }
.security-building-choice-list {
    max-height: min(360px, 45dvh);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow-y: auto;
    padding: 2px 5px 2px 2px;
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
}
.security-building-choices label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 9px 10px;
    font-size: 9px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.security-building-choices input { width: 16px; height: 16px; flex: 0 0 auto; }
.security-building-choices span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 820px) {
    .settings-list-columns { display: none; }
    .settings-staff-toolbar output { grid-column: 1 / -1; }
    .settings-security-summary { grid-template-columns: auto 1fr; }
    .settings-security-summary small { grid-column: 1 / -1; justify-self: start; }
    .settings-security-row { grid-template-columns: minmax(0, 1fr); }
    .settings-security-row .staff-person,
    .security-property-scope { grid-column: 1 / -1; }
    .settings-security-row .staff-actions {
        grid-column: 1 / -1;
        grid-row: auto;
        align-self: start;
        justify-self: start;
        justify-content: flex-start;
    }
}

@media (max-width: 560px) {
    .settings-security-summary,
    .settings-security-row { padding-inline: 14px; }
    .security-building-choice-list { grid-template-columns: 1fr; }
    .security-property-list { grid-template-columns: 1fr; }
    .security-property { min-height: 48px; }
    .app .settings-page .security-property-action {
        width: 44px;
        min-width: 44px;
        height: 44px;
        min-height: 44px;
    }
    .manager-scope-choices > div,
    .manager-property-choices > div { grid-template-columns: 1fr; }
    .manager-access-scope { padding: 12px; }
}

@media (pointer: coarse) {
    .app .settings-page .security-property-action {
        width: 44px;
        min-width: 44px;
        height: 44px;
        min-height: 44px;
    }
}
