@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap'); /* Fallback for iOS Font on Windows */

:root {
    --ios-blue: #0A7AFF;
    --wa-green-light: #E1F6CB;
    --wa-bg-color: #EFE7DE;
    --wa-header-bg: #F6F6F6;
    --wa-text-color: #000000;
    --wa-gray-text: #8E8D92;
    --wa-tick-blue: #34B7F1;
    --wa-tick-gray: #8E8D92;
    --font-apple: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
    
    /* Configurable Colors */
    --bubble-out-bg: var(--wa-green-light);
    --bubble-in-bg: #FFFFFF;
    --bubble-text: var(--wa-text-color);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-apple);
    background-color: #2c2c2e;
    color: white;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar BG Picker */
.bg-color-picker {
    width: 320px;
    background: #1c1c1e;
    padding: 24px;
    border-right: 1px solid #38383a;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.bg-color-picker h2 {
    font-size: 18px;
    font-weight: 500;
}

.color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.swatch {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid #38383a;
    transition: transform 0.2s, border-color 0.2s;
}

.swatch:hover {
    transform: scale(1.1);
    border-color: #fff;
}

.hint {
    font-size: 12px;
    color: #8E8D92;
    margin-top: 10px;
    text-align: center;
}

/* Preview Area */
.preview-panel {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #121212; /* Checkerboard or dark code */
}

/* Wrapper for overlapping layers */
.simulator-wrapper {
    position: relative;
}

/* Crop Marks for Screenshot Isolation (Corners only) - Toggled via JS */
.simulator-wrapper.show-crop-lines::before {
    content: '';
    position: absolute;
    top: -10px; left: -10px; right: -10px; bottom: -10px;
    pointer-events: none;
    z-index: 9999;
    mix-blend-mode: difference;
    
    --c: white;
    --t: 2px; /* Grosor de la línea */
    --l: 24px; /* Longitud de la línea */
    
    background:
        linear-gradient(var(--c), var(--c)) top left / var(--l) var(--t) no-repeat,
        linear-gradient(var(--c), var(--c)) top left / var(--t) var(--l) no-repeat,
        linear-gradient(var(--c), var(--c)) top right / var(--l) var(--t) no-repeat,
        linear-gradient(var(--c), var(--c)) top right / var(--t) var(--l) no-repeat,
        linear-gradient(var(--c), var(--c)) bottom left / var(--l) var(--t) no-repeat,
        linear-gradient(var(--c), var(--c)) bottom left / var(--t) var(--l) no-repeat,
        linear-gradient(var(--c), var(--c)) bottom right / var(--l) var(--t) no-repeat,
        linear-gradient(var(--c), var(--c)) bottom right / var(--t) var(--l) no-repeat;
}



/* Chat UI Container */
.chat-ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--wa-bg-color);
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-size: 400px;
    background-repeat: repeat;
    background-blend-mode: overlay; /* Soften the doodle over EFE7DE */
    z-index: 1; /* UNDER the phone mock! */
    display: flex;
    overflow: hidden;
    flex-direction: column;
}

/* Header UI iOS Style */
.chat-header {
    background: #F6F6F6;
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    padding: 54px 16px 10px 16px; /* 44px added for status bar, +10px original */
    height: 110px; /* 66px original + 44px space */
    border-bottom: 0.5px solid rgba(0,0,0,0.15);
    z-index: 10;
    margin-top: 0;
    color: #000000;
}
.header-back {
    display: flex;
    align-items: center;
    color: #000000; /* WhatsApp icons are black in this context */
    cursor: pointer;
    margin-right: 15px;
    font-weight: 400; /* Regular weight for unread count */
}

.header-back svg {
    width: 31px;
    height: 31px;
    color: #000000;
}

.header-info {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 8px;
}

.avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
}

.contact-details h1 {
    font-size: 18px;
    font-weight: 700; /* Bold as requested by user */
    margin: 0;
    line-height: 1.2;
}

.contact-status {
    font-size: 14px;
    color: var(--wa-gray-text);
}

.header-actions {
    display: flex;
    gap: 20px;
    color: #000000; /* Black icons */
    margin-left: auto; /* Push to right */
}

.header-actions svg {
    width: 26px;
    height: 26px;
}

/* Chat Messages Area */
.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 12px;
    padding-bottom: 110px; /* Space for the taller input bar */
    display: flex;
    flex-direction: column;
}

/* Hide scrollbar for a clean screenshot */
.chat-messages-container::-webkit-scrollbar {
    width: 0;
}

.date-divider {
    text-align: center;
    margin: 12px 0;
    width: 100%;
    display: flex;
    justify-content: center;
}
.date-divider span {
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 13.5px;
    font-weight: 500;
    color: #555;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

.chat-messages {
    zoom: var(--bubble-zoom, 1);
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: auto; /* Push to bottom naturally without clipping top scroll */
}

.chat-messages.flow-top {
    margin-top: 0;
}

/* Message Bubbles */
.message-row {
    display: flex;
    width: 100%;
}

.message-row.incoming {
    justify-content: flex-start;
}

.message-row.outgoing {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 21px;
    line-height: 1.3;
    position: relative;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    color: var(--bubble-text);
    display: flex;
    flex-direction: column;
    word-break: break-word;
}

.incoming .message-bubble {
    background-color: var(--bubble-in-bg);
    border-top-left-radius: 4px;
}

.outgoing .message-bubble {
    background-color: var(--bubble-out-bg);
    border-top-right-radius: 4px;
}

/* Small tails pseudo-elements mimicking iOS */
.incoming .message-bubble::before {
    content: "";
    position: absolute;
    top: 0;
    left: -8px;
    width: 16px;
    height: 16px;
    background: var(--bubble-in-bg);
    clip-path: polygon(100% 0, 0 0, 100% 100%);
}

.outgoing .message-bubble::before {
    content: "";
    position: absolute;
    top: 0;
    right: -8px;
    width: 16px;
    height: 16px;
    background: var(--bubble-out-bg);
    clip-path: polygon(0 0, 100% 0, 0 100%);
}

/* Message Meta (Time & Ticks) */
.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
    margin-left: 10px;
    float: right;
    align-self: flex-end;
}

/* Clean up meta to sit next to short text or below long text */
.message-text {
    margin-bottom: -5px; /* Pull meta inline if possible */
}

.message-meta .time {
    font-size: 14px;
    color: #8E8D92;
}

.message-meta .status-ticks svg {
    width: 16px;
    height: 16px;
}

.status-read { color: var(--wa-tick-blue); }
.status-sent, .status-delivered { color: var(--wa-tick-gray); }

/* Images in Bubbles */
.message-bubble-image {
    padding: 4px; /* WhatsApp native tighter padding for images */
    width: 310px; /* Force text to wrap and bubble to hug the image perfectly */
}

.message-image {
    width: 100%;
    max-width: none;
    border-radius: 8px;
    margin-bottom: 2px;
    display: block;
}

.message-bubble-image .message-text {
    padding: 2px 4px 0 4px;
}

.message-bubble-image .message-meta {
    padding-right: 4px;
}

/* Document / PDF Messages */
.message-document {
    width: 280px;
    display: flex;
    flex-direction: column;
}
.document-thumbnail {
    width: 100%;
    height: 140px;
    object-fit: cover;
    object-position: top;
    border-radius: 8px 8px 0 0;
    margin-bottom: 0 !important;
}
.document-info {
    display: flex;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.04);
    padding: 10px 12px;
    gap: 12px;
    border-radius: 0 0 8px 8px;
}
.outgoing .document-info {
    background-color: rgba(0, 0, 0, 0.05); /* Slight contrast bump for the green background */
}
.document-icon-wrapper {
    width: 38px;
    height: 48px;
    background-color: #E53935;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding-bottom: 4px;
    position: relative;
    flex-shrink: 0;
}
.document-icon-wrapper::before {
    content: "PDF";
    color: white;
    font-size: 11px;
    font-weight: 800;
}
.document-icon-wrapper::after {
    content: ""; /* Folded corner trick */
    position: absolute;
    top: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: linear-gradient(to bottom left, rgba(255,255,255,0.8) 50%, rgba(0,0,0,0.1) 50%);
    border-bottom-left-radius: 3px;
}
.document-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    gap: 2px;
}
.document-title {
    font-size: 17px;
    color: #000000;
    font-weight: 500;
    line-height: 1.2;
    white-space: wrap;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
.document-meta-text {
    font-size: 14px;
    color: #667781;
}
.outgoing .document-meta-text {
    color: #65846F;
}

/* Link Previews */
.message-link-preview {
    background-color: #F0F2F5;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 4px;
    cursor: pointer;
}
.outgoing .message-link-preview {
    background-color: #D2ECD8;
}
.link-preview-title {
    font-size: 16px;
    color: #111b21;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}
.link-preview-domain {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #667781;
}
.link-preview-domain svg {
    color: #8b959a;
}
a.wa-link {
    color: #128C7E; /* WhatsApp standard green text color for links */
    text-decoration: underline;
    word-break: break-all;
}
.incoming a.wa-link {
    color: #128C7E;
}

/* Audio Player Mock */
.message-audio {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
}
.audio-play {
    width: 32px; height: 32px;
    color: #8E8D92;
}
.audio-waves {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 2px;
}
.audio-waves span {
    width: 3px;
    background: #8E8D92;
    border-radius: 2px;
}
.audio-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
}
.incoming .audio-play { color: var(--ios-blue); }
.outgoing .audio-play { color: #0EA629; }

/* Status Bar */
.status-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 44px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 25px;
    font-size: 16px;
    font-weight: 600;
    color: #000;
    z-index: 20;
    pointer-events: none;
}
.status-left { display: flex; gap: 8px; align-items: center; }
.status-right { display: flex; gap: 6px; align-items: center; }

/* Chat Input Bar (Bottom) */
.chat-input-bar {
    position: absolute;
    bottom: 0px;
    left: 0;
    width: 100%;
    background: #F6F6F6;
    backdrop-filter: blur(10px);
    border-top: 0.5px solid rgba(0,0,0,0.15);
    display: flex;
    align-items: flex-start;
    padding: 8px 12px 46px 12px; /* Gran margen inferior para el Home Indicator */
    gap: 12px;
    z-index: 10;
}
.input-fake {
    flex: 1;
    height: 36px;
    background: #FFFFFF;
    border: 0.5px solid rgba(0,0,0,0.15);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px 0 16px;
}
.input-fake-text {
    flex: 1;
}
.chat-input-bar > svg {
    width: 26px;
    height: 26px;
    margin-top: 5px; /* Para alinear con el centro del input de 36px */
    color: #000000;
}
.input-fake svg {
    color: #000000;
}

/* ==================================
   AUDIO MESSAGE STYLES
   ================================== */
.message-audio {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 2px;
    padding-top: 4px;
}

.audio-avatar-container {
    position: relative;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.audio-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.audio-mic-icon {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-row.outgoing .audio-mic-icon { background: #E7FFDB; }
.message-row.incoming .audio-mic-icon { background: #FFFFFF; }

.audio-mic-icon svg {
    width: 11px;
    height: 11px;
}

.message-row.outgoing .audio-mic-icon svg { fill: #5A9C69; }
.message-row.incoming .audio-mic-icon svg { fill: #34B7F1; }

.audio-play-btn {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.message-row.outgoing .audio-play-btn svg { fill: #607565; }
.message-row.incoming .audio-play-btn svg { fill: #8E8D92; }

.audio-waveform-container {
    display: flex;
    align-items: center;
    flex: 1;
}

.audio-dot {
    width: 11px;
    height: 11px;
    background-color: #1A1A1A;
    border-radius: 50%;
    margin-right: 0px;
}

.message-row.incoming .audio-dot { background-color: #34B7F1; }

.audio-dots-start, .audio-dots-end {
    display: none;
}

.message-row.incoming .audio-dots-start,
.message-row.incoming .audio-dots-end { display: none; }

.audio-bars {
    display: flex;
    align-items: center;
    gap: 2.5px;
}

.wave-bar {
    width: 2.5px;
    background-color: #A3C5AE;
    border-radius: 3px;
}

.message-row.incoming .wave-bar { background-color: #D3D3D3; }

.audio-meta-row {
    width: 100%;
    justify-content: space-between !important;
    align-items: center !important;
    padding-left: 58px; /* Align precisely beneath the audio wave start */
    padding-right: 2px !important;
    margin-top: -3px !important;
    margin-bottom: 2px !important;
    align-self: stretch;
    float: none;
    box-sizing: border-box;
}

.audio-duration {
    font-size: 13px;
    color: #65846F; /* Darkish green for outgoing */
    line-height: 1;
    transform: translateY(1px); /* Slight micro-alignment with time */
}

.message-row.incoming .audio-duration {
    color: #8E8D92; /* Gray for incoming */
}

.meta-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* UI Hidden Mode (Bubbles Only) */
.simulator-wrapper.ui-hidden .status-bar,
.simulator-wrapper.ui-hidden .chat-header,
.simulator-wrapper.ui-hidden .chat-input-bar,
.simulator-wrapper.ui-hidden #phoneCanvas {
    display: none !important;
}

.simulator-wrapper.ui-hidden .chat-ui-layer {
    background-image: none !important;
    background-color: transparent !important;
    padding-top: 20px;
}

.simulator-wrapper.ui-hidden .chat-messages-container {
    height: 100% !important;
    background: transparent !important;
}

.simulator-wrapper.ui-hidden .date-divider span {
    background: #F2F2F2 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* Crop lines spacing */
.simulator-wrapper.show-crop-lines {
    /* extra padding to ensure the outline isn't cut off if it's tight */
    padding: 8px;
}

/* Animations */
/* 1. Standard: Sube con suavidad estandar */
@keyframes slideUpFade {
    0% {
        opacity: 0;
        transform: translateY(40px) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
.animate-standard {
    animation: slideUpFade 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.1) forwards;
    transform-origin: bottom center;
}

/* 2. Blur: Sube aplicanco un efecto de difuminado muy suave */
@keyframes slideUpBlur {
    0% {
        opacity: 0;
        transform: translateY(30px);
        filter: blur(6px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0px);
    }
}
.animate-blur {
    animation: slideUpBlur 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    transform-origin: bottom center;
}

/* 3. Pop (Rebote): Como si la burbuja explotase desde la base */
@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.7) translateY(10px);
    }
    60% {
        opacity: 1;
        transform: scale(1.03) translateY(-2px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}
.animate-pop {
    animation: popIn 0.35s cubic-bezier(0.3, 1.5, 0.6, 1) forwards;
    /* Originate from the side of the tail */
}
.message-row.outgoing .message-bubble.animate-pop {
    transform-origin: bottom right;
}
.message-row.incoming .message-bubble.animate-pop {
    transform-origin: bottom left;
}

.message-bubble.message-bubble-audio {
    max-width: 88%;
}

/* 4. Zoom Soft: Zoom cinematico lento con fade in */
@keyframes zoomSoft {
    0% {
        opacity: 0;
        transform: scale(0.92);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}
.animate-zoom {
    animation: zoomSoft 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    transform-origin: center center;
}

/* ========================================= */
/* DOWNWARD VARIANTS */
/* ========================================= */

@keyframes slideDownFade {
    0% { opacity: 0; transform: translateY(-40px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
.animate-standard-down {
    animation: slideDownFade 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.1) forwards;
    transform-origin: top center;
}

@keyframes slideDownBlur {
    0% { opacity: 0; transform: translateY(-30px); filter: blur(6px); }
    100% { opacity: 1; transform: translateY(0); filter: blur(0px); }
}
.animate-blur-down {
    animation: slideDownBlur 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    transform-origin: top center;
}

@keyframes popInDown {
    0% { opacity: 0; transform: scale(0.7) translateY(-10px); }
    60% { opacity: 1; transform: scale(1.03) translateY(2px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
.animate-pop-down {
    animation: popInDown 0.35s cubic-bezier(0.3, 1.5, 0.6, 1) forwards;
}
.message-row.outgoing .message-bubble.animate-pop-down { transform-origin: top right; }
.message-row.incoming .message-bubble.animate-pop-down { transform-origin: top left; }

.animate-zoom-down {
    animation: zoomSoft 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    transform-origin: top center;
}

/* Custom Searchable Dropdown */
.custom-select-container {
    position: relative;
    width: 100%;
    margin-bottom: 25px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
}
.custom-select-trigger {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #fff;
    color: #333;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
}
.custom-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-top: 4px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
}
.custom-select-dropdown.open {
    display: flex;
}
.search-box {
    padding: 8px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 8px;
}
.search-box input {
    border: none;
    outline: none;
    width: 100%;
    font-size: 14px;
    color: #333;
    background: transparent;
}
.scenario-options {
    list-style: none;
    max-height: 250px;
    overflow-y: auto;
    padding: 0;
    margin: 0;
}
.scenario-options li {
    padding: 10px 12px;
    color: #333;
    cursor: pointer;
    border-bottom: 1px solid #fafafa;
    display: flex;
    align-items: center;
    gap: 8px;
}
.scenario-options li:hover {
    background-color: #f0f0f0;
}
.scenario-options li.hidden {
    display: none;
}

/* Nombre del escenario en el dropdown */
.scenario-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
}

/* Botón de borrado (🗑) por item del dropdown */
.scenario-delete-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: none;
    border: none;
    border-radius: 4px;
    color: #bbb;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
    padding: 0;
    line-height: 1;
}
.scenario-options li:hover .scenario-delete-btn {
    opacity: 1;
}
.scenario-delete-btn:hover {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.12);
}


/* Collapsible Sidebar Sections */
details.sidebar-section {
    margin-top: 15px;
    border-top: 1px solid #38383a;
    padding-top: 12px;
}

details.sidebar-section summary {
    display: flex;
    align-items: center;
    cursor: pointer;
    list-style: none; /* Hide default arrow */
    user-select: none;
    outline: none;
}

details.sidebar-section summary::-webkit-details-marker {
    display: none;
}

details.sidebar-section summary::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-right: 2px solid #aaa;
    border-bottom: 2px solid #aaa;
    transform: rotate(45deg);
    margin-left: auto;
    transition: transform 0.2s ease;
}

details.sidebar-section[open] summary::after {
    transform: rotate(225deg);
}

details.sidebar-section summary h2 {
    margin: 0;
    font-size: 14px;
    border: none;
    padding: 0;
    color: #e5e5e5;
}


/* Collapsible Sidebar Sections */
details.sidebar-section {
    margin-top: 15px;
    border-top: 1px solid #38383a;
    padding-top: 12px;
}

details.sidebar-section summary {
    display: flex;
    align-items: center;
    cursor: pointer;
    list-style: none; /* Hide default arrow */
    user-select: none;
    outline: none;
}

details.sidebar-section summary::-webkit-details-marker {
    display: none;
}

details.sidebar-section summary::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-right: 2px solid #aaa;
    border-bottom: 2px solid #aaa;
    transform: rotate(45deg);
    margin-left: auto;
    transition: transform 0.2s ease;
}

details.sidebar-section[open] summary::after {
    transform: rotate(225deg);
}

details.sidebar-section summary h2 {
    margin: 0;
    font-size: 14px;
    border: none;
    padding: 0;
    color: #e5e5e5;
}

details.sidebar-section .section-content {
    margin-top: 12px;
    animation: fadeInSlideDown 0.2s ease-out;
}

@keyframes fadeInSlideDown {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- BUBBLE AVATAR SUPPORT --- */
.msg-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50% !important;
    object-fit: cover !important;
    display: none;
    align-self: flex-start;
    margin-top: 5px;
    margin: 0 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.show-avatars .msg-avatar {
    display: block !important;
}
.message-row.incoming .msg-avatar {
    order: -1;
    margin-left: 0;
}
.message-row.outgoing .msg-avatar {
    order: 2;
    margin-right: 0;
}


/* --- Nuevo iPhone Frame Pure CSS --- */
.simulator-wrapper.has-phone-frame {
    /* Responsive Box Model */
    min-width: 320px;
    max-width: 380px;
    width: 100%;
    height: 750px; /* Base height that can scale or flex inside preview panel */
    margin: 0 auto;
    
    /* iPhone Casing */
    border: 14px solid #1f1f21;
    border-radius: 40px;
    box-shadow: 
        inset 0 0 0 2px #444, 
        inset 0 0 0 6px #000, 
        0 20px 40px -10px rgba(0,0,0,0.3);
    
    background: #000;
    position: relative;
    
    /* To clip the interior chat perfectly along the rounded edges */
    overflow: hidden; 
}

/* The Screen inner edge */
.simulator-wrapper.has-phone-frame::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 26px; /* Inner radius */
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05); /* very subtle highlight */
    pointer-events: none;
    z-index: 100;
}

/* The Notch */
.simulator-wrapper.has-phone-frame .notch {
    position: absolute;
    top: -1px; /* Align strictly with top interior */
    left: 50%;
    transform: translateX(-50%);
    width: 130px;
    height: 25px;
    background: #1f1f21;
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 18px;
    z-index: 101;
    display: flex;
    justify-content: center;
    align-items: center;
}

.simulator-wrapper.has-phone-frame .notch::after {
    content: '';
    width: 40px;
    height: 4px;
    border-radius: 4px;
    background: #333; /* Speaker hole */
    margin-top: -5px;
}

/* Side buttons (using pseudo elements on the wrapper via child divs to bypass z-index issues) */
.simulator-wrapper.has-phone-frame .buttons-left {
    position: absolute;
    top: 100px;
    left: -17px;
    width: 3px;
    height: 25px;
    background-color: #2b2b2b;
    border-top-left-radius: 2px;
    border-bottom-left-radius: 2px;
}
.simulator-wrapper.has-phone-frame .buttons-left::after {
    content: '';
    position: absolute;
    top: 40px;
    left: 0;
    width: 3px;
    height: 45px;
    background-color: #2b2b2b;
    border-top-left-radius: 2px;
    border-bottom-left-radius: 2px;
}
.simulator-wrapper.has-phone-frame .buttons-left::before {
    content: '';
    position: absolute;
    top: 95px;
    left: 0;
    width: 3px;
    height: 45px;
    background-color: #2b2b2b;
    border-top-left-radius: 2px;
    border-bottom-left-radius: 2px;
}
.simulator-wrapper.has-phone-frame .buttons-right {
    position: absolute;
    top: 130px;
    right: -17px;
    width: 3px;
    height: 65px;
    background-color: #2b2b2b;
    border-top-right-radius: 2px;
    border-bottom-right-radius: 2px;
}

/* Override .chat-ui-layer relative to wrapper */
.simulator-wrapper.has-phone-frame .chat-ui-layer {
    position: relative;
    top: 0; left: 0;
    width: 100%; height: 100%; border-radius: 26px; overflow: hidden;
}
/* Ocultar elementos de UI frame nativo cuando ui-hidden es activo */
.simulator-wrapper.ui-hidden.has-phone-frame {
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: transparent !important;
}
.simulator-wrapper.ui-hidden .notch,
.simulator-wrapper.ui-hidden .buttons-left,
.simulator-wrapper.ui-hidden .buttons-right {
    display: none !important;
}

/* ============================================================
   AI GENERATOR PANEL
   ============================================================ */

.bg-color-picker {
    overflow-y: auto;
    overflow-x: hidden;
}

.bg-color-picker::-webkit-scrollbar {
    width: 4px;
}
.bg-color-picker::-webkit-scrollbar-track {
    background: transparent;
}
.bg-color-picker::-webkit-scrollbar-thumb {
    background: #38383a;
    border-radius: 4px;
}

.ai-generator-panel {
    background: rgba(37, 211, 102, 0.06);
    border: 1px solid rgba(37, 211, 102, 0.25);
    border-left: 3px solid #25D366;
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #25D366;
    letter-spacing: 0.02em;
}

.ai-panel-header svg {
    flex-shrink: 0;
    filter: drop-shadow(0 0 4px rgba(37, 211, 102, 0.5));
}

.ai-badge {
    margin-left: auto;
    background: rgba(37, 211, 102, 0.15);
    color: #25D366;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 20px;
    border: 1px solid rgba(37, 211, 102, 0.3);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

#aiPromptInput {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #e8e8e8;
    font-family: var(--font-apple);
    font-size: 13px;
    line-height: 1.5;
    padding: 10px 12px;
    resize: vertical;
    min-height: 80px;
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease;
}

#aiPromptInput::placeholder {
    color: #555;
    font-style: italic;
}

#aiPromptInput:focus {
    border-color: rgba(37, 211, 102, 0.45);
    background: rgba(255, 255, 255, 0.07);
}

#aiGenerateBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    padding: 10px 16px;
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: opacity 0.2s, transform 0.15s;
    position: relative;
    overflow: hidden;
}

#aiGenerateBtn::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
    transition: left 0.4s ease;
}

#aiGenerateBtn:hover:not(:disabled)::after {
    left: 100%;
}

#aiGenerateBtn:hover:not(:disabled) {
    opacity: 0.92;
    transform: translateY(-1px);
}

#aiGenerateBtn:active:not(:disabled) {
    transform: translateY(0);
    opacity: 0.85;
}

#aiGenerateBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

@keyframes ai-btn-shimmer {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

#aiGenerateBtn.loading {
    background: linear-gradient(
        90deg,
        #1a9e52 0%,
        #25D366 30%,
        #34eb77 50%,
        #25D366 70%,
        #1a9e52 100%
    );
    background-size: 200% auto;
    animation: ai-btn-shimmer 1.5s linear infinite;
}

.ai-status {
    font-size: 12px;
    border-radius: 6px;
    padding: 8px 12px;
    line-height: 1.4;
    transition: opacity 0.3s ease;
}

.ai-status-hidden {
    display: none;
}

.ai-status.loading {
    background: rgba(37, 211, 102, 0.1);
    border: 1px solid rgba(37, 211, 102, 0.2);
    color: #7fdb9e;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-status.success {
    background: rgba(37, 211, 102, 0.12);
    border: 1px solid rgba(37, 211, 102, 0.3);
    color: #25D366;
    display: block;
}

.ai-status.error {
    background: rgba(255, 69, 58, 0.1);
    border: 1px solid rgba(255, 69, 58, 0.25);
    color: #ff6b6b;
    display: block;
}

@keyframes ai-dot-spin {
    0%   { opacity: 1; }
    50%  { opacity: 0.3; }
    100% { opacity: 1; }
}

.ai-loading-dots span {
    display: inline-block;
    width: 5px;
    height: 5px;
    background: #25D366;
    border-radius: 50%;
    margin-right: 3px;
    animation: ai-dot-spin 1.2s infinite ease;
}
.ai-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ─── Choice Bar: editar actual vs. crear nuevo ───────────────────────────── */
.ai-choice-bar {
    background: rgba(255, 196, 0, 0.08);
    border: 1px solid rgba(255, 196, 0, 0.3);
    border-radius: 8px;
    padding: 10px 12px;
    animation: fadeInDown 0.2s ease;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ai-choice-bar p {
    font-size: 12px;
    color: #d4a800;
    margin-bottom: 8px;
    line-height: 1.4;
}

.ai-choice-bar strong {
    color: #ffd60a;
}

.ai-choice-buttons {
    display: flex;
    gap: 8px;
}

.ai-choice-buttons button {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: #e5e5e5;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

#aiChoiceEdit:hover {
    background: rgba(255, 196, 0, 0.18);
    border-color: rgba(255, 196, 0, 0.5);
    color: #ffd60a;
}

#aiChoiceNew:hover {
    background: rgba(37, 211, 102, 0.15);
    border-color: rgba(37, 211, 102, 0.4);
    color: #25D366;
}
