/* ─── Persona Creator – CSS Reset & Scoped Styles ────────────────────────── */

/* Full CSS reset to prevent WordPress theme bleed */
#pc-app {
    all: initial;
    display: flex !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    color: #1a1a2e;
    background: #f8f9fb;
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

#pc-app *, #pc-app *::before, #pc-app *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */

#pc-app .pc-sidebar {
    width: 280px;
    min-width: 280px;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 20;
    height: 100%;
}

#pc-app .pc-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid #e5e7eb;
}

#pc-app .pc-sidebar-title {
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#pc-app .pc-persona-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

#pc-app .pc-persona-list::-webkit-scrollbar {
    width: 4px;
}
#pc-app .pc-persona-list::-webkit-scrollbar-track {
    background: transparent;
}
#pc-app .pc-persona-list::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
}

#pc-app .pc-persona-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
    border: 1px solid transparent;
}

#pc-app .pc-persona-item:hover {
    background: #f3f4f6;
}

#pc-app .pc-persona-item.active {
    background: #eef2ff;
    border-color: #c7d2fe;
}

#pc-app .pc-persona-item-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#pc-app .pc-persona-item-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

#pc-app .pc-persona-item-avatar .pc-initials {
    font-size: 14px;
    font-weight: 600;
    color: #9ca3af;
}

#pc-app .pc-persona-item-info {
    flex: 1;
    min-width: 0;
}

#pc-app .pc-persona-item-name {
    font-size: 14px;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#pc-app .pc-persona-item-title {
    font-size: 12px;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Mobile-only close bar at top of sidebar */
#pc-app .pc-sidebar-mobile-bar {
    display: none;
}

#pc-app .pc-sidebar-mobile-bar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

#pc-app .pc-list-loading {
    display: flex;
    justify-content: center;
    padding: 24px;
}

#pc-app .pc-list-empty {
    text-align: center;
    padding: 24px 16px;
    color: #9ca3af;
    font-size: 14px;
}

/* ─── Editor Panel ─────────────────────────────────────────────────────────── */

#pc-app .pc-editor {
    flex: 1;
    overflow-y: auto;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    height: 100%;
    background: #f8f9fb;
}

#pc-app .pc-editor::-webkit-scrollbar {
    width: 6px;
}
#pc-app .pc-editor::-webkit-scrollbar-track {
    background: transparent;
}
#pc-app .pc-editor::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

#pc-app .pc-sidebar-toggle-btn {
    display: none;
}

/* ─── Center Messages (empty / select states) ─────────────────────────────── */

#pc-app .pc-center-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    padding: 40px 24px;
    gap: 12px;
}

#pc-app .pc-center-icon {
    font-size: 56px;
    color: #d1d5db;
    margin-bottom: 8px;
}

#pc-app .pc-center-heading {
    font-size: 22px;
    font-weight: 600;
    color: #111827;
}

#pc-app .pc-center-text {
    font-size: 15px;
    color: #6b7280;
    max-width: 360px;
    line-height: 1.5;
}

/* ─── Form Container ──────────────────────────────────────────────────────── */

#pc-app .pc-form-container {
    width: 100%;
    max-width: 640px;
    padding: 32px 24px 120px;
}

/* ─── Profile Header ──────────────────────────────────────────────────────── */

#pc-app .pc-profile-header {
    display: flex;
    align-items: center;
    gap: 24px;
    margin-bottom: 28px;
}

#pc-app .pc-avatar-wrapper {
    position: relative;
    width: 96px;
    height: 96px;
    min-width: 96px;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    background: #f3f4f6;
    border: 2px solid #e5e7eb;
    transition: border-color 0.2s;
}

#pc-app .pc-avatar-wrapper:hover {
    border-color: #6366f1;
}

#pc-app #pc-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

#pc-app #pc-avatar-img.visible {
    display: block;
}

#pc-app .pc-avatar-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 20px;
    opacity: 0;
    transition: opacity 0.2s;
}

#pc-app .pc-avatar-wrapper:hover .pc-avatar-overlay {
    opacity: 1;
}

#pc-app .pc-profile-fields {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

/* ─── Form Fields ──────────────────────────────────────────────────────────── */

#pc-app .pc-field-row {
    width: 100%;
}

#pc-app .pc-input-wrap {
    width: 100%;
}

#pc-app .pc-input-with-spark {
    position: relative;
}

#pc-app .pc-input-with-spark input,
#pc-app .pc-input-with-spark textarea {
    padding-right: 44px !important;
}

#pc-app input[type="text"],
#pc-app textarea,
#pc-app select {
    all: unset;
    display: block;
    width: 100%;
    background: #fff;
    border: 1px solid #d1d5db;
    color: #111827;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

#pc-app textarea {
    resize: vertical;
    min-height: 60px;
}

#pc-app input[type="text"]:focus,
#pc-app textarea:focus,
#pc-app select:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

#pc-app input[type="text"]::placeholder,
#pc-app textarea::placeholder {
    color: #9ca3af;
}

#pc-app select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}

#pc-app .pc-field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
    margin-top: 20px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#pc-app .pc-hint {
    font-size: 13px;
    color: #9ca3af;
    margin-bottom: 8px;
    line-height: 1.4;
}

/* ─── Spark Button ─────────────────────────────────────────────────────────── */

#pc-app .pc-spark-btn {
    all: unset;
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    color: #6366f1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.15s;
    box-sizing: border-box;
}

#pc-app .pc-input-with-spark textarea ~ .pc-spark-btn {
    top: 10px;
    transform: none;
}

#pc-app .pc-spark-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    color: #4f46e5;
}

#pc-app .pc-spark-btn.loading {
    animation: pc-pulse 1s ease-in-out infinite;
    pointer-events: none;
}

@keyframes pc-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ─── Tabs ─────────────────────────────────────────────────────────────────── */

#pc-app .pc-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 4px;
}

#pc-app .pc-tab-btn {
    all: unset;
    padding: 10px 18px;
    color: #9ca3af;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    font-family: inherit;
    box-sizing: border-box;
}

#pc-app .pc-tab-btn:hover {
    color: #6b7280;
}

#pc-app .pc-tab-btn.active {
    color: #111827;
    border-bottom-color: #6366f1;
}

#pc-app .pc-tab-panel {
    display: none;
}

#pc-app .pc-tab-panel.active {
    display: flex;
    flex-direction: column;
}

/* ─── Voice Row ────────────────────────────────────────────────────────────── */

#pc-app .pc-voice-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

#pc-app .pc-voice-row select {
    flex: 1;
}

/* ─── Image Section ────────────────────────────────────────────────────────── */

#pc-app .pc-image-section {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin-top: 16px;
    margin-bottom: 20px;
}

#pc-app .pc-image-preview-area {
    width: 160px;
    height: 160px;
    min-width: 160px;
    border-radius: 16px;
    overflow: hidden;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    position: relative;
}

#pc-app #pc-image-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

#pc-app #pc-image-preview.visible {
    display: block;
}

#pc-app .pc-image-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #d1d5db;
    gap: 8px;
    font-size: 13px;
}

#pc-app .pc-image-placeholder i {
    font-size: 32px;
}

#pc-app .pc-image-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 8px;
}

#pc-app .pc-btn-generate-img {
    margin-top: 20px;
    align-self: center;
    display: inline-flex;
}

#pc-app .pc-image-gen-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
    color: #6b7280;
    font-size: 14px;
}

/* ─── Model Selector ──────────────────────────────────────────────────────── */

#pc-app .pc-model-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

#pc-app .pc-model-label {
    font-size: 13px;
    color: #9ca3af;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

#pc-app .pc-model-selector select {
    max-width: 260px;
}

/* ─── Buttons (hardened, fully scoped) ─────────────────────────────────────── */

#pc-app .pc-btn {
    all: unset;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    box-sizing: border-box;
    line-height: 1.4;
    text-decoration: none;
    white-space: nowrap;
}

#pc-app .pc-btn-primary {
    background: #6366f1;
    color: #fff;
}

#pc-app .pc-btn-primary:hover {
    background: #4f46e5;
}

#pc-app .pc-btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#pc-app .pc-btn-primary.saving {
    pointer-events: none;
    opacity: 0.7;
}

#pc-app .pc-btn-secondary {
    background: #fff;
    color: #374151;
    border: 1px solid #d1d5db;
}

#pc-app .pc-btn-secondary:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

#pc-app .pc-btn-danger {
    background: #fff;
    color: #dc2626;
    border: 1px solid #fecaca;
}

#pc-app .pc-btn-danger:hover {
    background: #fef2f2;
    border-color: #f87171;
}

#pc-app .pc-icon-btn {
    all: unset;
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.15s;
    box-sizing: border-box;
}

#pc-app .pc-icon-btn:hover {
    background: #f3f4f6;
    color: #111827;
    border-color: #d1d5db;
}

#pc-app .pc-icon-btn.playing {
    color: #6366f1;
    border-color: #6366f1;
}

/* ─── Action Bar ───────────────────────────────────────────────────────────── */

#pc-app .pc-action-bar {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 0;
    background: linear-gradient(transparent, #f8f9fb 30%);
    display: flex;
    justify-content: center;
    gap: 12px;
    z-index: 15;
    margin-top: 20px;
}

/* ─── Modal ────────────────────────────────────────────────────────────────── */

#pc-app .pc-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

#pc-app .pc-modal {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 28px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

#pc-app .pc-modal-heading {
    font-size: 18px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 12px;
}

#pc-app .pc-modal-text {
    color: #6b7280;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 20px;
}

#pc-app .pc-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ─── Toast ────────────────────────────────────────────────────────────────── */

#pc-app .pc-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    color: #111827;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    z-index: 200;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    border: 1px solid #e5e7eb;
    transition: opacity 0.3s;
}

#pc-app .pc-toast.success {
    border-left: 3px solid #22c55e;
}

#pc-app .pc-toast.error {
    border-left: 3px solid #ef4444;
}

/* ─── Spinner ──────────────────────────────────────────────────────────────── */

#pc-app .pc-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #e5e7eb;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: pc-spin 0.6s linear infinite;
    display: inline-block;
}

@keyframes pc-spin {
    to { transform: rotate(360deg); }
}

/* Loading shimmer for fields being AI-generated */
#pc-app .pc-field-loading {
    background: linear-gradient(90deg, #fff 25%, #f3f4f6 50%, #fff 75%) !important;
    background-size: 200% 100% !important;
    animation: pc-shimmer 1.5s ease-in-out infinite;
}

@keyframes pc-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── Editor Loading Overlay ───────────────────────────────────────────────── */

#pc-app .pc-editor-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 12px;
    color: #9ca3af;
    font-size: 14px;
}

/* ─── Sidebar overlay (mobile) ─────────────────────────────────────────────── */

#pc-app #pc-sidebar-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 19;
}

#pc-app #pc-sidebar-overlay.active {
    display: block;
}

/* ─── Mobile Responsive ────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    #pc-app .pc-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 300px;
        min-width: 300px;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 50;
        box-shadow: none;
    }

    #pc-app .pc-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    }

    #pc-app .pc-sidebar-mobile-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 12px 12px 16px;
        border-bottom: 1px solid #e5e7eb;
        background: #fff;
    }

    #pc-app .pc-sidebar-mobile-bar span {
        font-size: 15px;
        font-weight: 600;
        color: #111827;
    }

    #pc-app .pc-sidebar-header {
        display: none;
    }

    #pc-app .pc-sidebar-toggle-btn {
        all: unset;
        display: flex;
        align-items: center;
        gap: 8px;
        margin: 12px 16px;
        padding: 8px 14px;
        background: #fff;
        border: 1px solid #e5e7eb;
        border-radius: 10px;
        color: #374151;
        font-size: 14px;
        cursor: pointer;
        align-self: flex-start;
        font-family: inherit;
        box-sizing: border-box;
    }

    #pc-app .pc-form-container {
        padding: 16px 16px 120px;
    }

    #pc-app .pc-profile-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 16px;
    }

    #pc-app .pc-action-bar {
        position: sticky;
        bottom: 0;
        background: linear-gradient(transparent, #f8f9fb 30%);
        padding: 16px 24px;
    }

    #pc-app .pc-image-section {
        flex-direction: column;
        align-items: center;
    }
}

@media (max-width: 480px) {
    #pc-app .pc-avatar-wrapper {
        width: 80px;
        height: 80px;
        min-width: 80px;
    }

    #pc-app .pc-image-preview-area {
        width: 140px;
        height: 140px;
        min-width: 140px;
    }

    #pc-app .pc-tabs {
        overflow-x: auto;
    }

    #pc-app .pc-tab-btn {
        padding: 10px 14px;
        font-size: 13px;
        white-space: nowrap;
    }

    #pc-app .pc-model-selector {
        flex-direction: column;
        align-items: flex-start;
    }

    #pc-app .pc-model-selector select {
        max-width: 100%;
    }
}
