/**
 * ═══════════════════════════════════════════════════════════════
 * VYOMA AI — Personality Engine Styles (personality.css)
 * ─────────────────────────────────────────────────────────────
 * Styles for the Personality & Brain settings modal, toggles,
 * preview window, action buttons, import preview, and per-chat
 * privacy badge.
 *
 * Theme: Dark glassmorphism — consistent with legal.css
 * ADDITIVE-ONLY — Does NOT override any existing selector.
 * ═══════════════════════════════════════════════════════════════
 */

/* ══════════════════════════════════════════════════════════
   1. MODAL OVERLAY
   ══════════════════════════════════════════════════════════ */

.pe-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        backdrop-filter 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0s 0.35s;
}

.pe-modal-overlay.pe-modal-visible {
    opacity: 1;
    visibility: visible;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        backdrop-filter 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0s 0s;
}

/* ══════════════════════════════════════════════════════════
   2. MODAL CONTAINER
   ══════════════════════════════════════════════════════════ */

.pe-modal {
    position: relative;
    width: 94%;
    max-width: 560px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(165deg,
            rgba(22, 24, 30, 0.97) 0%,
            rgba(18, 20, 26, 0.98) 50%,
            rgba(14, 16, 22, 0.99) 100%);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 20px;
    box-shadow:
        0 32px 64px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset,
        0 1px 0 rgba(255, 255, 255, 0.06) inset;
    transform: translateY(24px) scale(0.96);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.pe-modal-overlay.pe-modal-visible .pe-modal {
    transform: translateY(0) scale(1);
}

.pe-modal-sm {
    max-width: 480px;
    max-height: 75vh;
}

/* ══════════════════════════════════════════════════════════
   3. MODAL HEADER
   ══════════════════════════════════════════════════════════ */

.pe-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.pe-modal-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pe-modal-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(59, 130, 246, 0.2));
    padding: 5px;
    flex-shrink: 0;
}

.pe-modal-icon svg {
    width: 18px;
    height: 18px;
    stroke: #a78bfa;
}

.pe-modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #f1f3f5;
    letter-spacing: -0.01em;
    margin: 0;
}

.pe-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
}

.pe-modal-close svg {
    width: 16px;
    height: 16px;
    stroke: #9ca3af;
}

.pe-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

.pe-modal-close:hover svg {
    stroke: #f87171;
}

/* ══════════════════════════════════════════════════════════
   4. MODAL BODY
   ══════════════════════════════════════════════════════════ */

.pe-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 24px 24px;
}

.pe-modal-body::-webkit-scrollbar {
    width: 5px;
}

.pe-modal-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.pe-modal-body::-webkit-scrollbar-track {
    background: transparent;
}

/* ══════════════════════════════════════════════════════════
   5. SECTIONS
   ══════════════════════════════════════════════════════════ */

.pe-section {
    margin-top: 20px;
}

.pe-section:first-child {
    margin-top: 8px;
}

.pe-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.pe-section-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.pe-section-icon svg {
    width: 16px;
    height: 16px;
    stroke: #8b8fa3;
}

.pe-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #8b8fa3;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ══════════════════════════════════════════════════════════
   6. TOGGLE ROWS
   ══════════════════════════════════════════════════════════ */

.pe-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    margin-bottom: 8px;
    transition: background 0.2s, border-color 0.2s;
}

.pe-toggle-row:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.07);
}

.pe-toggle-label {
    flex: 1;
    min-width: 0;
}

.pe-toggle-name {
    display: block;
    font-size: 0.88rem;
    font-weight: 500;
    color: #e5e7eb;
    line-height: 1.3;
}

.pe-toggle-desc {
    display: block;
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 2px;
    line-height: 1.4;
}

/* ── Toggle Switch (iOS-style) ───────────────────────── */

.pe-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.pe-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.pe-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: background 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        border-color 0.3s;
}

.pe-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background: #9ca3af;
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.pe-switch input:checked+.pe-slider {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border-color: rgba(139, 92, 246, 0.3);
}

.pe-switch input:checked+.pe-slider::before {
    transform: translateX(20px);
    background: #ffffff;
}

.pe-switch input:focus-visible+.pe-slider {
    outline: 2px solid rgba(139, 92, 246, 0.5);
    outline-offset: 2px;
}

/* ══════════════════════════════════════════════════════════
   7. SAFETY NOTE
   ══════════════════════════════════════════════════════════ */

.pe-safety-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    margin-top: 8px;
    background: rgba(251, 191, 36, 0.06);
    border: 1px solid rgba(251, 191, 36, 0.12);
    border-radius: 10px;
    font-size: 0.75rem;
    color: #d4a44a;
    line-height: 1.5;
}

.pe-safety-note svg {
    width: 16px;
    height: 16px;
    stroke: #f59e0b;
    flex-shrink: 0;
    margin-top: 1px;
}

.pe-safety-note strong {
    color: #fbbf24;
}

/* ══════════════════════════════════════════════════════════
   8. PREVIEW WINDOW
   ══════════════════════════════════════════════════════════ */

.pe-preview-window {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 16px;
    max-height: 220px;
    overflow-y: auto;
    font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', 'Menlo', monospace;
}

.pe-preview-window::-webkit-scrollbar {
    width: 4px;
}

.pe-preview-window::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
}

.pe-preview-window pre {
    margin: 0;
    padding: 0;
    font-size: 0.72rem;
    line-height: 1.6;
    color: #a1a8b8;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.pe-preview-import {
    max-height: 300px;
}

/* ══════════════════════════════════════════════════════════
   9. ACTION BUTTONS
   ══════════════════════════════════════════════════════════ */

.pe-action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pe-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 18px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    color: #d1d5db;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.15s, color 0.2s;
    font-family: inherit;
}

.pe-action-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.pe-action-btn:hover {
    transform: translateY(-1px);
}

.pe-action-btn:active {
    transform: translateY(0);
}

/* Export button */
.pe-btn-export {
    border-color: rgba(59, 130, 246, 0.15);
}

.pe-btn-export:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.25);
    color: #93c5fd;
}

.pe-btn-export svg {
    stroke: #60a5fa;
}

/* Import button */
.pe-btn-import {
    border-color: rgba(16, 185, 129, 0.15);
}

.pe-btn-import:hover {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.25);
    color: #6ee7b7;
}

.pe-btn-import svg {
    stroke: #34d399;
}

/* Delete button */
.pe-btn-delete {
    border-color: rgba(239, 68, 68, 0.12);
}

.pe-btn-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
}

.pe-btn-delete svg {
    stroke: #f87171;
}

/* Cancel button */
.pe-btn-cancel {
    border-color: rgba(255, 255, 255, 0.08);
    color: #9ca3af;
}

.pe-btn-cancel:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #d1d5db;
}

/* Confirm button */
.pe-btn-confirm {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(99, 102, 241, 0.2));
    border-color: rgba(139, 92, 246, 0.2);
    color: #c4b5fd;
}

.pe-btn-confirm:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.35), rgba(99, 102, 241, 0.3));
    border-color: rgba(139, 92, 246, 0.35);
    color: #e0d5fc;
}

.pe-btn-confirm svg {
    stroke: #a78bfa;
}

/* ══════════════════════════════════════════════════════════
   10. MODAL FOOTER
   ══════════════════════════════════════════════════════════ */

.pe-modal-footer {
    padding: 14px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.pe-footer-text {
    font-size: 0.7rem;
    color: #6b7280;
    display: block;
    text-align: center;
    line-height: 1.5;
}

.pe-import-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.pe-import-warning {
    font-size: 0.82rem;
    color: #f59e0b;
    margin: 0 0 14px 0;
    line-height: 1.5;
}

/* ══════════════════════════════════════════════════════════
   11. SETTINGS BUTTON (injected into existing modal)
   ══════════════════════════════════════════════════════════ */

.pe-open-settings-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    border: 1px solid rgba(139, 92, 246, 0.12);
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.08), rgba(59, 130, 246, 0.06));
    color: #c4b5fd;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.25s, border-color 0.25s, transform 0.15s;
    font-family: inherit;
}

.pe-open-settings-btn svg {
    width: 20px;
    height: 20px;
    stroke: #a78bfa;
    flex-shrink: 0;
}

.pe-open-settings-btn:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(59, 130, 246, 0.12));
    border-color: rgba(139, 92, 246, 0.22);
    transform: translateY(-1px);
}

.pe-open-settings-btn:active {
    transform: translateY(0);
}

/* ══════════════════════════════════════════════════════════
   12. PER-CHAT PRIVACY BADGE
   ══════════════════════════════════════════════════════════ */

.pe-privacy-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.2);
    margin-left: 8px;
    vertical-align: middle;
    cursor: help;
    transition: background 0.2s;
    flex-shrink: 0;
}

.pe-privacy-badge svg {
    width: 12px;
    height: 12px;
    stroke: #fbbf24;
}

.pe-privacy-badge:hover {
    background: rgba(251, 191, 36, 0.2);
}

/* ══════════════════════════════════════════════════════════
   13. LIGHT MODE OVERRIDES
   ══════════════════════════════════════════════════════════ */

body:not(.dark-mode) .pe-modal {
    background: linear-gradient(165deg,
            rgba(255, 255, 255, 0.97) 0%,
            rgba(248, 250, 252, 0.98) 50%,
            rgba(241, 245, 249, 0.99) 100%);
    border-color: rgba(0, 0, 0, 0.08);
    box-shadow:
        0 32px 64px rgba(0, 0, 0, 0.12),
        0 0 0 1px rgba(0, 0, 0, 0.04) inset;
}

body:not(.dark-mode) .pe-modal-overlay.pe-modal-visible {
    background: rgba(0, 0, 0, 0.3);
}

body:not(.dark-mode) .pe-modal-title {
    color: #1e293b;
}

body:not(.dark-mode) .pe-modal-header {
    border-bottom-color: rgba(0, 0, 0, 0.06);
}

body:not(.dark-mode) .pe-modal-close {
    background: rgba(0, 0, 0, 0.04);
}

body:not(.dark-mode) .pe-modal-close svg {
    stroke: #64748b;
}

body:not(.dark-mode) .pe-modal-close:hover {
    background: rgba(0, 0, 0, 0.08);
}

body:not(.dark-mode) .pe-section-title {
    color: #64748b;
}

body:not(.dark-mode) .pe-section-icon svg {
    stroke: #94a3b8;
}

body:not(.dark-mode) .pe-toggle-row {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.06);
}

body:not(.dark-mode) .pe-toggle-row:hover {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.08);
}

body:not(.dark-mode) .pe-toggle-name {
    color: #1e293b;
}

body:not(.dark-mode) .pe-toggle-desc {
    color: #94a3b8;
}

body:not(.dark-mode) .pe-slider {
    background: rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.1);
}

body:not(.dark-mode) .pe-slider::before {
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

body:not(.dark-mode) .pe-preview-window {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.06);
}

body:not(.dark-mode) .pe-preview-window pre {
    color: #475569;
}

body:not(.dark-mode) .pe-action-btn {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.06);
    color: #475569;
}

body:not(.dark-mode) .pe-btn-export:hover {
    background: rgba(59, 130, 246, 0.06);
    color: #2563eb;
}

body:not(.dark-mode) .pe-btn-import:hover {
    background: rgba(16, 185, 129, 0.06);
    color: #059669;
}

body:not(.dark-mode) .pe-btn-delete:hover {
    background: rgba(239, 68, 68, 0.06);
    color: #dc2626;
}

body:not(.dark-mode) .pe-modal-footer {
    border-top-color: rgba(0, 0, 0, 0.06);
}

body:not(.dark-mode) .pe-footer-text {
    color: #94a3b8;
}

body:not(.dark-mode) .pe-safety-note {
    background: rgba(251, 191, 36, 0.06);
    border-color: rgba(251, 191, 36, 0.15);
    color: #92400e;
}

body:not(.dark-mode) .pe-safety-note strong {
    color: #b45309;
}

body:not(.dark-mode) .pe-open-settings-btn {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.06), rgba(59, 130, 246, 0.04));
    border-color: rgba(139, 92, 246, 0.15);
    color: #7c3aed;
}

body:not(.dark-mode) .pe-open-settings-btn svg {
    stroke: #7c3aed;
}

body:not(.dark-mode) .pe-open-settings-btn:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.12), rgba(59, 130, 246, 0.08));
}

body:not(.dark-mode) .pe-privacy-badge {
    background: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.2);
}

body:not(.dark-mode) .pe-privacy-badge svg {
    stroke: #d97706;
}

/* ══════════════════════════════════════════════════════════
   14. RESPONSIVE — TABLET
   ══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .pe-modal {
        width: 96%;
        max-height: 90vh;
        border-radius: 16px;
    }

    .pe-modal-header {
        padding: 16px 18px 14px;
    }

    .pe-modal-body {
        padding: 10px 18px 20px;
    }

    .pe-modal-title {
        font-size: 1rem;
    }

    .pe-toggle-row {
        padding: 12px 14px;
    }

    .pe-action-btn {
        padding: 11px 14px;
        font-size: 0.82rem;
    }

    .pe-preview-window {
        max-height: 180px;
    }
}

/* ══════════════════════════════════════════════════════════
   15. RESPONSIVE — MOBILE
   ══════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .pe-modal {
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
        border: none;
    }

    .pe-modal-sm {
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        margin-top: auto;
    }

    .pe-modal-overlay.pe-modal-visible {
        align-items: flex-end;
    }

    .pe-modal-header {
        padding: 14px 16px 12px;
    }

    .pe-modal-body {
        padding: 8px 16px 18px;
    }

    .pe-modal-title {
        font-size: 0.95rem;
    }

    .pe-toggle-row {
        padding: 10px 12px;
        gap: 12px;
    }

    .pe-toggle-name {
        font-size: 0.84rem;
    }

    .pe-toggle-desc {
        font-size: 0.7rem;
    }

    .pe-action-btn {
        padding: 10px 12px;
        font-size: 0.8rem;
    }

    .pe-preview-window {
        max-height: 150px;
        padding: 12px;
    }

    .pe-preview-window pre {
        font-size: 0.68rem;
    }

    .pe-import-footer {
        flex-direction: column;
    }

    .pe-import-footer .pe-action-btn {
        width: 100%;
    }
}

/* ══════════════════════════════════════════════════════════
   16. ANIMATIONS — Reduced motion
   ══════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {

    .pe-modal-overlay,
    .pe-modal-overlay.pe-modal-visible,
    .pe-modal,
    .pe-slider,
    .pe-slider::before,
    .pe-action-btn,
    .pe-modal-close,
    .pe-toggle-row {
        transition: none !important;
    }

    .pe-modal {
        transform: none !important;
    }
}