/* ================================================================
   Settings Modal — ChatGPT-parity v2 (960×640, top-left close,
   grey left rail, dropdown controls)
   ================================================================ */

.settings-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 2100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

.settings-modal-backdrop[aria-hidden="false"] {
    display: flex;
    animation: settings-fade-in 180ms ease-out;
}

@keyframes settings-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.settings-modal-dialog {
    background: #ffffff;
    color: #0d0d0d;
    border-radius: 16px;
    width: 100%;
    max-width: 960px;
    max-height: 640px;
    height: 100%;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.04),
        0 16px 48px rgba(0, 0, 0, 0.18),
        0 4px 12px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    position: relative;
    animation: settings-slide-up 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes settings-slide-up {
    from { opacity: 0; transform: translateY(8px) scale(0.99); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- top-left close button ---------- */
.settings-modal-close {
    position: absolute;
    top: 14px;
    left: 14px;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: rgba(0, 0, 0, 0.55);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    z-index: 2;
    transition: background 120ms ease, color 120ms ease;
}

.settings-modal-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: rgba(0, 0, 0, 0.9);
}

/* ---------- two-pane body ---------- */
.settings-modal-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* ---------- left rail (grey) ---------- */
.settings-modal-rail {
    width: 240px;
    background: #f7f7f7;
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    padding: 56px 12px 16px;
    overflow-y: auto;
    flex-shrink: 0;
}

.settings-rail-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 12px;
    margin-bottom: 1px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: rgba(0, 0, 0, 0.78);
    font-size: 0.875rem;
    font-weight: 400;
    text-align: left;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
    line-height: 1.3;
}

.settings-rail-item:hover {
    background: rgba(0, 0, 0, 0.05);
    color: rgba(0, 0, 0, 0.95);
}

.settings-rail-item.is-active {
    background: rgba(0, 0, 0, 0.08);
    color: rgba(0, 0, 0, 1);
    font-weight: 500;
}

.settings-rail-item i {
    width: 16px;
    text-align: center;
    font-size: 0.95rem;
    color: rgba(0, 0, 0, 0.6);
}

.settings-rail-item.is-active i {
    color: rgba(0, 0, 0, 0.92);
}

.settings-rail-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.08);
    margin: 8px 8px;
}

.settings-rail-item--admin {
    color: rgba(0, 0, 0, 0.78);
    font-style: normal;
}

/* ---------- right content pane ---------- */
.settings-modal-content {
    flex: 1;
    padding: 28px 32px 32px;
    overflow-y: auto;
    min-width: 0;
    background: #ffffff;
}

.settings-pane {
    display: none;
}

.settings-pane.is-active {
    display: block;
}

.settings-pane-title {
    margin: 0 0 20px;
    font-size: 1.25rem;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.95);
    letter-spacing: -0.01em;
}

.settings-pane-subhead {
    margin: 24px 0 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.95);
}

.settings-pane-empty {
    color: rgba(0, 0, 0, 0.5);
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 4px 0 0;
}

.settings-pane-hint {
    color: rgba(0, 0, 0, 0.55);
    font-size: 0.8125rem;
    margin: 0 0 12px;
}

/* ---------- MFA promo card ---------- */
.settings-mfa-card {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
    background: #f5f5f5;
    border: 1px solid rgba(0, 0, 0, 0.04);
    border-radius: 12px;
    margin-bottom: 24px;
}

.settings-mfa-card[aria-hidden="true"] {
    display: none;
}

.settings-mfa-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(0, 0, 0, 0.78);
    font-size: 0.95rem;
    margin-top: 2px;
}

.settings-mfa-text {
    flex: 1;
    min-width: 0;
}

.settings-mfa-text strong {
    display: block;
    font-size: 0.9375rem;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.95);
    margin-bottom: 4px;
}

.settings-mfa-text p {
    margin: 0 0 12px;
    font-size: 0.8125rem;
    color: rgba(0, 0, 0, 0.6);
    line-height: 1.5;
}

.btn-pill {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.18);
    color: rgba(0, 0, 0, 0.92);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}

.btn-pill:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.3);
}

.settings-mfa-dismiss {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: rgba(0, 0, 0, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: background 120ms ease, color 120ms ease;
}

.settings-mfa-dismiss:hover {
    background: rgba(0, 0, 0, 0.06);
    color: rgba(0, 0, 0, 0.9);
}

/* ---------- rows ---------- */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 14px 0;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    min-height: 36px;
}

.settings-row:first-of-type,
.settings-mfa-card + .settings-row {
    border-top: none;
}

.settings-row--with-helper {
    align-items: flex-start;
}

.settings-row-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.settings-row-text strong {
    font-size: 0.9rem;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.92);
    line-height: 1.4;
}

.settings-row-text span {
    font-size: 0.8125rem;
    color: rgba(0, 0, 0, 0.55);
    line-height: 1.4;
}

.settings-row-helper {
    margin: 6px 0 0;
    font-size: 0.78rem;
    color: rgba(0, 0, 0, 0.5);
    line-height: 1.45;
    max-width: 460px;
}

.settings-row-control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ---------- pane sections (Personalization & friends) ---------- */
/* A pane-section groups a subhead + helper + rows. The first row inside a
   section drops its top border so the subhead acts as the visual divider. */
.settings-pane-section {
    margin-top: 0;
}

.settings-pane-section .settings-row:first-of-type {
    border-top: none;
}

.settings-pane-section-helper {
    margin: 0 0 12px;
    font-size: 0.8125rem;
    color: rgba(0, 0, 0, 0.55);
    line-height: 1.45;
    max-width: 540px;
}

.settings-pane-subhead {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.settings-pane-subhead-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 24px 0 8px;
}

.settings-pane-subhead-row .settings-pane-subhead {
    margin: 0;
}

.settings-help-icon {
    font-size: 0.8rem;
    color: rgba(0, 0, 0, 0.4);
    cursor: help;
}

.btn-pill {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.16);
    color: rgba(0, 0, 0, 0.85);
    border-radius: 999px;
    padding: 6px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease;
    flex-shrink: 0;
}

.btn-pill:hover {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.24);
}

.btn-pill:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.5);
    outline-offset: 2px;
}

/* ---------- text inputs (Personalization About-you / Custom instructions) ---------- */
.settings-input {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 12px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.025);
    color: rgba(0, 0, 0, 0.92);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.45;
    transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.settings-input::placeholder {
    color: rgba(0, 0, 0, 0.4);
}

.settings-input:hover {
    border-color: rgba(0, 0, 0, 0.18);
}

.settings-input:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.55);
    background: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.settings-input-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.settings-input-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: text;
}

.settings-input-label > span {
    font-size: 0.8125rem;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.78);
}

/* ---------- collapsible (Advanced section) ---------- */
.settings-collapsible-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: inherit;
    font-family: inherit;
    text-align: left;
    margin: 24px 0 0;
}

.settings-collapsible-toggle:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.5);
    outline-offset: 2px;
    border-radius: 4px;
}

.settings-collapsible-toggle .settings-pane-subhead {
    margin: 0;
}

.settings-collapsible-chevron {
    font-size: 0.78rem;
    color: rgba(0, 0, 0, 0.5);
    transition: transform 200ms ease;
}

.settings-collapsible-toggle[aria-expanded="true"] .settings-collapsible-chevron {
    transform: rotate(180deg);
}

.settings-collapsible-panel {
    overflow: hidden;
    max-height: 0;
    transition: max-height 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

.settings-collapsible-toggle[aria-expanded="true"] + .settings-collapsible-panel {
    max-height: 1600px;
}

.settings-collapsible-panel > .settings-row:first-of-type {
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    margin-top: 8px;
}

/* ---------- toggle (button[role=switch] — ARIA pattern, no input/label) ---------- */
/* Using <button role="switch"> instead of <label><input> sidesteps the
   responsive-foundation.css `label:has(input[type="checkbox"])` rule that
   was forcing min-height: 44px. .settings-toggle (class, specificity 0,1,0)
   cleanly beats `button` (element, 0,0,1) — no !important needed. */
.settings-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    height: 24px;
    min-height: 24px;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    box-sizing: border-box;
}

.settings-toggle-slider {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 999px;
    transition: background-color 200ms cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.settings-toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #ffffff;
    border-radius: 50%;
    transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.settings-toggle:hover .settings-toggle-slider {
    background: #c5cad1;
}

.settings-toggle[aria-checked="true"] .settings-toggle-slider {
    background: #3b82f6;
}

.settings-toggle[aria-checked="true"] .settings-toggle-slider::before {
    transform: translateX(20px);
}

.settings-toggle[aria-checked="true"]:hover .settings-toggle-slider {
    background: #2f6fe5;
}

.settings-toggle:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.5);
    outline-offset: 2px;
    border-radius: 999px;
}

.settings-toggle:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---------- custom dropdown (popover) ---------- */
.settings-dropdown {
    position: relative;
    flex-shrink: 0;
}

.settings-dropdown-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    padding: 6px 10px 6px 12px;
    color: rgba(0, 0, 0, 0.92);
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
    min-width: 140px;
    justify-content: space-between;
}

.settings-dropdown-trigger:hover {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.2);
}

.settings-dropdown-trigger i {
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
}

.settings-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 100%;
    list-style: none;
    margin: 0;
    padding: 4px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    z-index: 10;
    display: none;
    max-height: 280px;
    overflow-y: auto;
    white-space: nowrap;
}

.settings-dropdown.is-open .settings-dropdown-menu {
    display: block;
}

.settings-dropdown-menu li {
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 0.875rem;
    color: rgba(0, 0, 0, 0.92);
    cursor: pointer;
    transition: background 100ms ease;
}

.settings-dropdown-menu li:hover,
.settings-dropdown-menu li.is-selected {
    background: rgba(0, 0, 0, 0.05);
}

.settings-dropdown-menu li.is-selected {
    font-weight: 500;
}

.settings-dropdown-menu li.dropdown-section-header {
    padding: 8px 12px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: rgba(0, 0, 0, 0.45);
    cursor: default;
    background: transparent;
}

.settings-dropdown-menu li.dropdown-section-header:hover {
    background: transparent;
}

.settings-dropdown-menu li.dropdown-section-header:not(:first-child) {
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    margin-top: 4px;
    padding-top: 10px;
}

.dropdown-opt-hint {
    color: rgba(0, 0, 0, 0.4);
    font-size: 0.74rem;
    margin-left: 4px;
    font-weight: 400;
}

/* ---------- play button ---------- */
.settings-play-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: rgba(0, 0, 0, 0.78);
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}

.settings-play-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: rgba(0, 0, 0, 0.95);
}

.settings-play-btn i {
    font-size: 0.7rem;
}

/* ---------- buttons ---------- */
.settings-pane .btn {
    font-size: 0.8125rem;
    padding: 6px 14px;
    border-radius: 8px;
    line-height: 1.3;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
    flex-shrink: 0;
}

.settings-pane .btn-secondary {
    background: #ffffff;
    color: rgba(0, 0, 0, 0.92);
    border-color: rgba(0, 0, 0, 0.18);
}

.settings-pane .btn-secondary:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.25);
}

.settings-pane .btn-danger {
    background: transparent;
    color: #dc2626;
    border-color: rgba(220, 38, 38, 0.4);
}

.settings-pane .btn-danger:hover:not(:disabled) {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.6);
}

.settings-pane .btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ================================================================
   Memory child modal — themed to match settings modal
   (legacy markup from settings_api_keys.html, included globally;
   styles here apply on the chat page where api-keys.css doesn't load
   AND override api-keys.css on /account/manage via #id specificity)
   ================================================================ */

#memory-modal,
#clear-memory-confirm-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

#memory-modal[aria-hidden="false"],
#clear-memory-confirm-modal[aria-hidden="false"],
#memory-modal.open,
#clear-memory-confirm-modal.open {
    display: flex;
    animation: settings-fade-in 180ms ease-out;
}

#memory-modal { z-index: 2200; }
#clear-memory-confirm-modal { z-index: 2300; }

#memory-modal .modal-card,
#clear-memory-confirm-modal .modal-card {
    position: relative;
    background: #ffffff;
    color: #0d0d0d;
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.04),
        0 16px 48px rgba(0, 0, 0, 0.18);
    border: none;
    animation: settings-slide-up 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

#memory-modal .modal-card-lg {
    max-width: 640px;
}

#memory-modal .modal-close-btn,
#clear-memory-confirm-modal .modal-close-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: rgba(0, 0, 0, 0.55);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    transition: background 120ms ease, color 120ms ease;
}

#memory-modal .modal-close-btn:hover,
#clear-memory-confirm-modal .modal-close-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: rgba(0, 0, 0, 0.92);
}

/* ---------- Memory modal header ---------- */
#memory-modal .memory-modal-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding-right: 32px; /* leave room for close btn */
    margin: 0;
    border: none;
}

#memory-modal .memory-modal-header .modal-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(0, 0, 0, 0.78);
    font-size: 1rem;
    margin: 0;
}

#memory-modal .memory-modal-header h3 {
    margin: 0 0 2px;
    font-size: 1.05rem;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.95);
    letter-spacing: -0.01em;
}

#memory-modal .memory-modal-header p {
    margin: 0;
    font-size: 0.825rem;
    color: rgba(0, 0, 0, 0.55);
    line-height: 1.4;
}

/* ---------- Memory modal toggle rows (re-skin .dream-toggle-row + .dream-switch) ---------- */
#memory-modal .memory-toggle-rows,
#memory-modal .dream-toggle-row {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    border-radius: 0;
}

#memory-modal .memory-toggle-rows .dream-toggle-row,
#memory-modal > .modal-card > .dream-toggle-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: transparent;
    border-radius: 0;
}

#memory-modal .memory-toggle-rows .dream-toggle-row:first-child {
    border-top: none;
}

#memory-modal .dream-toggle-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

#memory-modal .dream-toggle-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.92);
    line-height: 1.3;
}

#memory-modal .dream-toggle-desc {
    font-size: 0.78rem;
    color: rgba(0, 0, 0, 0.55);
    line-height: 1.4;
}

/* Re-skin .dream-switch to match settings-toggle (44×24 pill).
   Markup is <button role="switch" aria-checked="..."> — no <input>, so
   responsive-foundation.css's `label:has(input[type="checkbox"])` rule
   can't reach it and force min-height: 44px. */
#memory-modal .dream-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    height: 24px;
    min-height: 24px;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    box-sizing: border-box;
}

#memory-modal .dream-switch-slider {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 999px;
    transition: background-color 200ms cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

#memory-modal .dream-switch-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #ffffff;
    border-radius: 50%;
    transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

#memory-modal .dream-switch:hover .dream-switch-slider {
    background: #c5cad1;
}

#memory-modal .dream-switch[aria-checked="true"] .dream-switch-slider {
    background: #3b82f6;
}

#memory-modal .dream-switch[aria-checked="true"] .dream-switch-slider::before {
    transform: translateX(20px);
}

#memory-modal .dream-switch[aria-checked="true"]:hover .dream-switch-slider {
    background: #2f6fe5;
}

#memory-modal .dream-switch:focus-visible {
    outline: 2px solid rgba(59, 130, 246, 0.5);
    outline-offset: 2px;
    border-radius: 999px;
}

#memory-modal .dream-switch:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---------- Memory modal tab strip ---------- */
#memory-modal .memory-tab-toggle {
    display: flex;
    gap: 2px;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 8px;
    padding: 3px;
    margin: 0;
}

#memory-modal .memory-tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: rgba(0, 0, 0, 0.6);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}

#memory-modal .memory-tab-btn:hover:not(.active) {
    color: rgba(0, 0, 0, 0.85);
}

#memory-modal .memory-tab-btn.active {
    background: #ffffff;
    color: rgba(0, 0, 0, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ---------- Memory tab panels ---------- */
#memory-modal .memory-tab-panel {
    display: none;
}

#memory-modal .memory-tab-panel.active {
    display: block;
}

#memory-modal .memory-list-container,
#memory-modal .conversation-memory-container,
#memory-modal .dream-activity-container {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    max-height: 320px;
    overflow-y: auto;
    padding: 8px;
}

#memory-modal .memory-loading,
#memory-modal .memory-empty,
#memory-modal .conversation-loading,
#memory-modal .conversation-empty,
#memory-modal .dream-activity-loading,
#memory-modal .dream-activity-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 28px 16px;
    color: rgba(0, 0, 0, 0.45);
    font-size: 0.82rem;
    text-align: center;
}

#memory-modal .memory-empty i,
#memory-modal .conversation-empty i,
#memory-modal .dream-activity-empty i {
    font-size: 1.4rem;
    opacity: 0.6;
    margin-bottom: 4px;
}

/* Conversation memory rows */
#memory-modal .conversation-memory-filter {
    display: flex;
    gap: 6px;
    padding: 6px 8px 10px;
}

#memory-modal .conv-filter-chip {
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.6);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.74rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 120ms ease;
}

#memory-modal .conv-filter-chip:hover:not(.active) {
    background: rgba(0, 0, 0, 0.04);
    color: rgba(0, 0, 0, 0.85);
}

#memory-modal .conv-filter-chip.active {
    background: rgba(0, 0, 0, 0.08);
    color: rgba(0, 0, 0, 0.95);
    border-color: rgba(0, 0, 0, 0.15);
}

#memory-modal .conv-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
}

#memory-modal .conv-row:hover {
    background: rgba(0, 0, 0, 0.03);
}

#memory-modal .conv-role-badge {
    flex-shrink: 0;
    font-size: 0.66rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1.3;
    margin-top: 1px;
}

#memory-modal .conv-role-user {
    background: rgba(34, 197, 94, 0.12);
    color: #15803d;
}

#memory-modal .conv-role-assistant {
    background: rgba(59, 130, 246, 0.12);
    color: #1e40af;
}

#memory-modal .conv-text {
    flex: 1;
    font-size: 0.82rem;
    color: rgba(0, 0, 0, 0.78);
    line-height: 1.45;
    word-break: break-word;
}

#memory-modal .conv-delete-btn {
    background: transparent;
    border: none;
    color: rgba(0, 0, 0, 0.4);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 120ms ease, background 120ms ease;
}

#memory-modal .conv-delete-btn:hover:not(:disabled) {
    background: rgba(220, 38, 38, 0.1);
    color: #dc2626;
}

/* ---------- Memory modal footer ---------- */
#memory-modal .memory-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    margin: 0;
    background: transparent;
}

#memory-modal .memory-count {
    font-size: 0.78rem;
    color: rgba(0, 0, 0, 0.55);
}

#memory-modal .memory-actions {
    display: flex;
    gap: 8px;
}

#memory-modal .btn,
#clear-memory-confirm-modal .btn {
    font-size: 0.8125rem;
    padding: 6px 14px;
    border-radius: 8px;
    line-height: 1.3;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 120ms ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#memory-modal .btn-ghost {
    background: transparent;
    color: rgba(0, 0, 0, 0.7);
    border-color: rgba(0, 0, 0, 0.12);
}

#memory-modal .btn-ghost:hover {
    background: rgba(0, 0, 0, 0.04);
    color: rgba(0, 0, 0, 0.92);
}

#memory-modal .btn-danger,
#clear-memory-confirm-modal .btn-danger {
    background: transparent;
    color: #dc2626;
    border-color: rgba(220, 38, 38, 0.4);
}

#memory-modal .btn-danger:hover,
#clear-memory-confirm-modal .btn-danger:hover {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.6);
}

#clear-memory-confirm-modal .btn-secondary {
    background: #ffffff;
    color: rgba(0, 0, 0, 0.92);
    border-color: rgba(0, 0, 0, 0.18);
}

#clear-memory-confirm-modal .btn-secondary:hover {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.25);
}

/* ---------- Clear memory confirmation modal ---------- */
#clear-memory-confirm-modal .modal-card {
    max-width: 420px;
    text-align: left;
}

#clear-memory-confirm-modal .modal-icon.caution {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(220, 38, 38, 0.1);
    color: #dc2626;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    margin: 0;
}

#clear-memory-confirm-modal h3 {
    margin: 0 0 6px;
    font-size: 1.05rem;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.95);
}

#clear-memory-confirm-modal p,
#clear-memory-confirm-modal ul {
    color: rgba(0, 0, 0, 0.65);
    font-size: 0.82rem;
    line-height: 1.5;
    margin: 0;
}

#clear-memory-confirm-modal ul {
    padding-left: 1.2rem;
    margin: 6px 0;
}

#clear-memory-confirm-modal strong {
    color: rgba(0, 0, 0, 0.85);
    font-weight: 600;
}

#clear-memory-confirm-modal .modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 4px;
}

/* ---------- Dark theme overrides for memory modal ---------- */
[data-theme="dark"] #memory-modal .modal-card,
[data-theme="dark"] #clear-memory-confirm-modal .modal-card {
    background: #2f2f2f;
    color: rgba(255, 255, 255, 0.92);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.04),
        0 16px 48px rgba(0, 0, 0, 0.55);
}

[data-theme="dark"] #memory-modal .modal-close-btn,
[data-theme="dark"] #clear-memory-confirm-modal .modal-close-btn {
    color: rgba(255, 255, 255, 0.55);
}

[data-theme="dark"] #memory-modal .modal-close-btn:hover,
[data-theme="dark"] #clear-memory-confirm-modal .modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] #memory-modal .memory-modal-header .modal-icon {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] #memory-modal .memory-modal-header h3 {
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] #memory-modal .memory-modal-header p {
    color: rgba(255, 255, 255, 0.55);
}

[data-theme="dark"] #memory-modal .memory-toggle-rows .dream-toggle-row,
[data-theme="dark"] #memory-modal > .modal-card > .dream-toggle-row {
    border-top-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] #memory-modal .dream-toggle-label {
    color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] #memory-modal .dream-toggle-desc {
    color: rgba(255, 255, 255, 0.55);
}

[data-theme="dark"] #memory-modal .dream-switch-slider {
    background: #4a4a4f;
}

[data-theme="dark"] #memory-modal .dream-switch:hover .dream-switch-slider {
    background: #5a5a5f;
}

[data-theme="dark"] #memory-modal .dream-switch[aria-checked="true"] .dream-switch-slider {
    background: #3b82f6;
}

[data-theme="dark"] #memory-modal .dream-switch[aria-checked="true"]:hover .dream-switch-slider {
    background: #2f6fe5;
}

[data-theme="dark"] #memory-modal .memory-tab-toggle {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] #memory-modal .memory-tab-btn {
    color: rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] #memory-modal .memory-tab-btn:hover:not(.active) {
    color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] #memory-modal .memory-tab-btn.active {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.98);
    box-shadow: none;
}

[data-theme="dark"] #memory-modal .memory-list-container,
[data-theme="dark"] #memory-modal .conversation-memory-container,
[data-theme="dark"] #memory-modal .dream-activity-container {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] #memory-modal .memory-loading,
[data-theme="dark"] #memory-modal .memory-empty,
[data-theme="dark"] #memory-modal .conversation-loading,
[data-theme="dark"] #memory-modal .conversation-empty {
    color: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] #memory-modal .conv-filter-chip {
    border-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] #memory-modal .conv-filter-chip:hover:not(.active) {
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] #memory-modal .conv-filter-chip.active {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.95);
    border-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] #memory-modal .conv-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] #memory-modal .conv-text {
    color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] #memory-modal .conv-role-user {
    background: rgba(74, 222, 128, 0.15);
    color: #4ade80;
}

[data-theme="dark"] #memory-modal .conv-role-assistant {
    background: rgba(96, 165, 250, 0.15);
    color: #93c5fd;
}

[data-theme="dark"] #memory-modal .memory-modal-footer {
    border-top-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] #memory-modal .memory-count {
    color: rgba(255, 255, 255, 0.55);
}

[data-theme="dark"] #memory-modal .btn-ghost {
    color: rgba(255, 255, 255, 0.78);
    border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] #memory-modal .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] #memory-modal .btn-danger,
[data-theme="dark"] #clear-memory-confirm-modal .btn-danger {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.4);
}

[data-theme="dark"] #memory-modal .btn-danger:hover,
[data-theme="dark"] #clear-memory-confirm-modal .btn-danger:hover {
    background: rgba(248, 113, 113, 0.1);
    border-color: rgba(248, 113, 113, 0.6);
}

[data-theme="dark"] #clear-memory-confirm-modal .btn-secondary {
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.92);
    border-color: rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] #clear-memory-confirm-modal .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.25);
}

[data-theme="dark"] #clear-memory-confirm-modal h3 {
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] #clear-memory-confirm-modal p,
[data-theme="dark"] #clear-memory-confirm-modal ul {
    color: rgba(255, 255, 255, 0.65);
}

[data-theme="dark"] #clear-memory-confirm-modal strong {
    color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] #clear-memory-confirm-modal .modal-icon.caution {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

/* ---------- mobile (≤640px) ---------- */
@media (max-width: 640px) {
    .settings-modal-backdrop {
        padding: 0;
    }

    .settings-modal-dialog {
        max-width: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
    }

    .settings-modal-close {
        top: calc(12px + env(safe-area-inset-top, 0px));
    }

    .settings-modal-body {
        flex-direction: column;
    }

    .settings-modal-rail {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
        display: flex;
        flex-direction: row;
        gap: 4px;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 56px 12px 8px;
        scroll-snap-type: x proximity;
    }

    .settings-rail-item {
        flex-direction: column;
        gap: 4px;
        flex-shrink: 0;
        width: auto;
        min-width: 76px;
        padding: 8px 12px;
        scroll-snap-align: start;
        font-size: 0.74rem;
        margin-bottom: 0;
    }

    .settings-rail-divider {
        display: none;
    }

    .settings-modal-content {
        padding: 20px 18px 28px;
    }

    .settings-row {
        flex-wrap: wrap;
        gap: 10px;
    }

    .settings-row-control-group {
        margin-left: auto;
    }
}

/* ---------- dark theme overrides ---------- */
[data-theme="dark"] .settings-modal-dialog {
    background: #2f2f2f;
    color: rgba(255, 255, 255, 0.92);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.04),
        0 16px 48px rgba(0, 0, 0, 0.55);
}

[data-theme="dark"] .settings-modal-close {
    color: rgba(255, 255, 255, 0.55);
}

[data-theme="dark"] .settings-modal-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .settings-modal-rail {
    background: rgba(255, 255, 255, 0.03);
    border-right-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .settings-rail-item {
    color: rgba(255, 255, 255, 0.78);
}

[data-theme="dark"] .settings-rail-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .settings-rail-item.is-active {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

[data-theme="dark"] .settings-rail-item i {
    color: rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] .settings-rail-item.is-active i {
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .settings-rail-divider {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .settings-modal-content {
    background: #2f2f2f;
}

[data-theme="dark"] .settings-pane-title,
[data-theme="dark"] .settings-pane-subhead {
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .settings-pane-empty {
    color: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .settings-pane-hint {
    color: rgba(255, 255, 255, 0.55);
}

[data-theme="dark"] .settings-mfa-card {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .settings-mfa-icon {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] .settings-mfa-text strong {
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .settings-mfa-text p {
    color: rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] .btn-pill {
    border-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .btn-pill:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .settings-mfa-dismiss {
    color: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .settings-mfa-dismiss:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .settings-row {
    border-top-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .settings-row-text strong {
    color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .settings-row-text span {
    color: rgba(255, 255, 255, 0.55);
}

[data-theme="dark"] .settings-row-helper {
    color: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .settings-pane-section-helper {
    color: rgba(255, 255, 255, 0.55);
}

[data-theme="dark"] .settings-help-icon {
    color: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .btn-pill {
    border-color: rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .btn-pill:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.28);
}

[data-theme="dark"] .settings-input {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .settings-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .settings-input:hover {
    border-color: rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] .settings-input:focus {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(96, 165, 250, 0.7);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

[data-theme="dark"] .settings-input-label > span {
    color: rgba(255, 255, 255, 0.78);
}

[data-theme="dark"] .settings-collapsible-chevron {
    color: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .settings-collapsible-panel > .settings-row:first-of-type {
    border-top-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .settings-toggle-slider {
    background: #4a4a4f;
}

[data-theme="dark"] .settings-toggle:hover .settings-toggle-slider {
    background: #5a5a5f;
}

[data-theme="dark"] .settings-toggle[aria-checked="true"] .settings-toggle-slider {
    background: #3b82f6;
}

[data-theme="dark"] .settings-toggle[aria-checked="true"]:hover .settings-toggle-slider {
    background: #2f6fe5;
}

[data-theme="dark"] .settings-dropdown-trigger {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .settings-dropdown-trigger:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .settings-dropdown-trigger i {
    color: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .settings-dropdown-menu {
    background: #383838;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .settings-dropdown-menu li {
    color: rgba(255, 255, 255, 0.92);
}

[data-theme="dark"] .settings-dropdown-menu li:hover,
[data-theme="dark"] .settings-dropdown-menu li.is-selected {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .settings-dropdown-menu li.dropdown-section-header {
    color: rgba(255, 255, 255, 0.4);
    background: transparent;
}

[data-theme="dark"] .settings-dropdown-menu li.dropdown-section-header:hover {
    background: transparent;
}

[data-theme="dark"] .settings-dropdown-menu li.dropdown-section-header:not(:first-child) {
    border-top-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .dropdown-opt-hint {
    color: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .settings-play-btn {
    color: rgba(255, 255, 255, 0.78);
}

[data-theme="dark"] .settings-play-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .settings-pane .btn-secondary {
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.92);
    border-color: rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] .settings-pane .btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.25);
}

[data-theme="dark"] .settings-pane .btn-danger {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.4);
}

[data-theme="dark"] .settings-pane .btn-danger:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.1);
    border-color: rgba(248, 113, 113, 0.6);
}
