/* Tamaño de fuente según parámetro fsize (1=normal, 2=grande, 3=extra grande) */
html { font-size: 16px; }
html.fsize-1 { font-size: 16px; }
html.fsize-2 { font-size: 20px; }
html.fsize-3 { font-size: 24px; }

/* --- ESTILOS CRÍTICOS --- */
:root {
    /* Colores Base */
    --primary-color: #008069;
    --accent-color: #7dba00;
    --bg-color: #efeae2;
    --bg-app: #ffffff;
    --text-primary: #111b21;
    --text-secondary: #667781;
    --border-color: #e9edef;
    --danger: #ef5350;
    --bg-pinned: rgba(241, 243, 224, 0.95);
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    /* Colores Halo */
    --aqua: #c3dd90;
    --blue: #7dba00;
    --navy: #FFDC00;
    --teal: #a8c176;
    --green: #7baa00;
    --olive: #3D9970;
    --lime: #7dba00;
    --yellow: #FFDC00;
    --orange: #c3dd90;
    --red: #7dba00;
    --fuchsia: #a8c176;
    --purple: #3D9970;
    --maroon: #7dba00;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- HEADER MODIFICADO CON BUSCADOR --- */
.main-header {
    background-color: var(--accent-color);
    color: white;
    padding: 12px 12px 12px 12px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.header-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 1.1rem;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.icon-btn:active {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Estilos del Buscador */
.search-bar-container {
    width: 100%;
    display: flex;
    align-items: center;
}

.search-input-wrapper {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    flex: 1;
    height: 40px;
}

.search-input-wrapper input {
    background: transparent;
    border: none;
    color: white;
    padding: 0 10px;
    width: 100%;
    outline: none;
    font-size: 1.0625rem;
    font-weight: 500;
}

.search-input-wrapper input::placeholder {
    color: rgba(255, 255, 255, 0.8);
    font-weight: 400;
}

.search-icon {
    opacity: 0.8;
}

#btn-clear-search {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}

#btn-clear-search:hover {
    opacity: 1;
}

#btn-clear-search.hidden {
    display: none;
}

/* --- LISTA Y FONDO --- */
.conversation-list-container {
    flex: 1;
    overflow-y: auto;
    background-color: var(--bg-color);
    background-image: url('/unica/static/vegetables.png');
    background-repeat: repeat;
    background-size: 700px;
}

.conversation-item {
    display: flex;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    background: white;
    align-items: center;
}

.conversation-item:active {
    background-color: #f5f5f5;
}

.conversation-item.hidden {
    display: none !important;
}

.conv-content {
    flex: 1;
    min-width: 0;
}

.conv-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Estilos para el subheader/preview del mensaje */
.conv-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    /* Gris */
    margin-top: 2px;
    margin-bottom: 4px;
    display: block;

    /* Truco para cortar el texto con "..." si es muy largo (una sola línea) */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 95%;
}

/* Ajuste para la fecha, para que se vea más pequeña abajo */
.conv-date {
    font-size: 0.75rem;
    color: #8fa0a8;
    /* Un gris un poco más claro para la fecha */
}

/* Acciones en la lista (Editar / Borrar) */
.conv-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.action-btn-list {
    padding: 8px;
    border-radius: 50%;
    color: var(--text-secondary);
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.action-btn-list:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--primary-color);
}

.btn-delete-conv:hover {
    color: var(--danger);
    background: rgba(239, 83, 80, 0.1);
}

/* ACORDEÓN */
.month-container.hidden {
    display: none !important;
}

.month-header {
    background-color: var(--bg-pinned);
    padding: 12px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(5px);
}

.month-chevron {
    transition: transform 0.3s ease;
}

.month-chevron.closed {
    transform: rotate(-90deg);
}

.historial-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* FAB */
.fab {
    position: absolute;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent-color);
    color: white;
    border: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
}

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.8);
    margin: 20px;
    border-radius: 12px;
}

/* --- MODAL RENOMBRAR --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    animation: scaleIn 0.2s ease-out;
    width: 90%;
    max-width: 360px;
    padding: 24px;
    text-align: center;
}

.modal-content h3 {
    margin-bottom: 16px;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.input-group {
    margin-bottom: 24px;
    text-align: left;
}

.input-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    font-family: inherit;
}

.input-group input:focus {
    border-color: var(--primary-color);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn-modal {
    flex: 1;
    padding: 12px;
    border-radius: 24px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    border: none;
}

.btn-cancel {
    background: #e9edef;
    color: var(--text-primary);
}

.btn-save {
    background: var(--primary-color);
    color: white;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ================= ESTILOS ONBOARDING ================= */
.onboarding-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    background-image: url('/unica/static/vegetables.png');
    background-repeat: repeat;
    background-size: 700px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.onboarding-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.onboarding-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    margin-top: 40px;
    width: 100%;
}

.onboarding-slides {
    width: 100%;
    height: 100%;
    position: relative;
}

.slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.slide.active {
    opacity: 1;
    pointer-events: auto;
}

.slide h1 {
    font-size: 1.8rem;
    margin-bottom: 16px;
    color: var(--primary-color);
}

.slide p {
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.5;
    max-width: 320px;
}

.story-progress-container {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 2001;
}

.progress-bar-bg {
    flex: 1;
    height: 2px;
    background-color: #aaa;
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--primary-color);
    width: 0%;
    transition: width 0.1s linear;
}

.progress-bar-bg.completed .progress-bar-fill {
    width: 100%;
}

.progress-bar-bg.active .progress-bar-fill {
    width: 100%;
}

.content-loader-animation {
    position: relative;
    width: 260px;
    height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 60px;
}

.logo-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    overflow: hidden;
    z-index: 10;
}

.logo-placeholder img {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: contain;
    display: block;
    background: transparent;
}

.stack {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    animation: breathe infinite 3s ease-in-out;
}

.blobs {
    display: grid;
    grid-template-areas: 'stack';
    position: relative;
    animation: spin infinite 5s linear;
    width: 240px;
    height: 240px;
    filter: blur(8px);
    -webkit-filter: blur(8px);
}

.blob {
    --border-radius: 115% 140% 145% 110% / 125% 140% 110% 125%;
    --border-width: 12px;
    aspect-ratio: 1;
    display: block;
    grid-area: stack;
    background-size: calc(100% + var(--border-width) * 2);
    background-repeat: no-repeat;
    background-position: center;
    border: var(--border-width) solid transparent;
    border-radius: var(--border-radius, 50%);
    -webkit-mask-image: linear-gradient(transparent, transparent), linear-gradient(black, white);
    mask-image: linear-gradient(transparent, transparent), linear-gradient(black, white);
    -webkit-mask-clip: padding-box, border-box;
    mask-clip: padding-box, border-box;
    -webkit-mask-composite: source-in, xor;
    mask-composite: intersect;
    mix-blend-mode: screen;
    height: 100%;
    width: 100%;
    filter: none;
}

.blob:nth-child(1) {
    background-color: var(--blue);
    background-image: linear-gradient(var(--blue), var(--teal), var(--blue));
    rotate: 30deg;
    scale: 1.03;
}

.blob:nth-child(2) {
    background-color: var(--red);
    background-image: linear-gradient(var(--red), var(--orange), var(--red));
    rotate: 60deg;
    scale: 0.95;
}

.blob:nth-child(3) {
    background-color: var(--olive);
    background-image: linear-gradient(var(--olive), var(--lime), var(--olive));
    rotate: 90deg;
    scale: 0.97;
}

.blob:nth-child(4) {
    background-color: var(--purple);
    background-image: linear-gradient(var(--purple), var(--maroon), var(--purple));
    rotate: 120deg;
    scale: 1.02;
}

@keyframes spin {
    from {
        rotate: 0deg;
    }

    to {
        rotate: 360deg;
    }
}

@keyframes breathe {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.onboarding-actions {
    padding: 24px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    padding-bottom: 40px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 24px;
    font-size: 1rem;
    font-weight: 600;
    width: 100%;
    max-width: 300px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.6);
    padding: 4px 12px;
    border-radius: 12px;
}

/* --- ESTILOS SELECTOR CAMPAÑA HISTORIAL --- */
.campaign-selector-wrapper {
    position: relative;
    background-color: #7dba00;
    /* Color verde claro según tu diseño */
    color: white;
    border-radius: 8px;
    height: 40px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    margin-left: 8px;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* El select real está oculto encima del botón */
#historial-campanya-select {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

#historial-campanya-label {
    z-index: 1;
    pointer-events: none;
    /* Click pasa al select */
}

/* --- Estilos para el Menú Desplegable (Tres Puntitos) --- */
.dropdown-container {
    position: relative;
}

/* --- Estilos para el botón del menú (Tres Puntitos) --- */
.dropdown-trigger {
    /* Esto crea el "recuadro" */
    border: 1px solid var(--border-color);
    background-color: transparent;
    /* Fondo transparente inicialmente */

    padding: 6px;
    /* Un poco más de espacio interno */
    border-radius: 6px;
    /* Bordes redondeados */
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

/* Al pasar el ratón */
.dropdown-trigger:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: #c0c7ce;
    /* Un gris un poco más oscuro para el borde al hover */
}

/* Estilo cuando el menú está ABIERTO (requiere cambio en JS) */
.dropdown-trigger.active {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--text-secondary);
    /* Borde más oscuro cuando está activo */
}

/* El menú oculto por defecto */
.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;

    /* --- CORRECCIÓN: Usar blanco directo --- */
    background-color: #ffffff;

    border: 1px solid var(--border-color);
    border-radius: 8px;

    /* Sombra pronunciada para que destaque sobre el texto */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);

    padding: 6px 0;
    min-width: 180px;

    /* Z-index alto para estar encima de todo */
    z-index: 1000;

    display: none;
    overflow: hidden;
}

/* Clase para mostrar el menú */
.dropdown-menu.show {
    display: block;
    animation: fadeIn 0.15s ease-out;
}

/* Ítems del menú */
.dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.2s;
}

.dropdown-item:hover {
    background-color: var(--bg-secondary);
}

.dropdown-item svg {
    color: var(--text-secondary);
    stroke-width: 2;
}

/* Estilo específico para la opción de eliminar */
.dropdown-item.delete {
    color: #e53935;
    /* Rojo */
}

.dropdown-item.delete svg {
    color: #e53935;
}

.dropdown-item.delete:hover {
    background-color: #feebe9;
    /* Fondo rojo claro al pasar el ratón */
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- ESTILOS ACTION SHEET (Selector Campaña) --- */
.action-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    /* Fondo oscuro */
    z-index: 5000;
    /* Por encima de todo */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    /* Alineado abajo */
}

.action-sheet-overlay.show {
    opacity: 1;
    visibility: visible;
}

.action-sheet-container {
    background-color: transparent;
    width: 100%;
    max-width: 500px;
    /* Limitado en tablets/pc */
    margin: 0 auto;
    padding: 10px;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.action-sheet-overlay.show .action-sheet-container {
    transform: translateY(0);
}

/* Grupo de opciones (Blanco redondeado) */
.sheet-group {
    background: white;
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 10px;
    text-align: center;
}

.sheet-header {
    padding: 14px;
    font-size: 0.8rem;
    color: #8e8e93;
    font-weight: 600;
    border-bottom: 1px solid #e5e5e5;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sheet-btn {
    display: block;
    width: 100%;
    padding: 16px;
    font-size: 1.1rem;
    color: #007aff;
    /* Azul iOS o usar var(--primary-color) */
    background: white;
    border: none;
    border-bottom: 1px solid #e5e5e5;
    cursor: pointer;
    font-weight: 400;
}

.sheet-btn:last-child {
    border-bottom: none;
}

.sheet-btn:active {
    background-color: #f2f2f2;
}

.sheet-btn.selected {
    font-weight: 600;
    color: var(--primary-color);
}

/* Botón cancelar separado */
.sheet-cancel-btn {
    display: block;
    width: 100%;
    padding: 16px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #007aff;
    background: white;
    border: none;
    border-radius: 14px;
    cursor: pointer;
}

.sheet-cancel-btn:active {
    background-color: #f2f2f2;
}

/* Ajuste del botón trigger en el header (quitamos el select oculto) */
.campaign-selector-wrapper {
    /* ... mantén tus estilos existentes ... */
    cursor: pointer;
    user-select: none;
}

/* Ocultamos el select antiguo completamente */
#historial-campanya-select {
    display: none !important;
}

/* --- ESTILOS ACTION SHEET (Selector Campaña) --- */
.action-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 5000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.action-sheet-overlay.show {
    opacity: 1;
    visibility: visible;
}

.action-sheet-container {
    background-color: transparent;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 10px;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.action-sheet-overlay.show .action-sheet-container {
    transform: translateY(0);
}

.sheet-group {
    background: white;
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 10px;
    text-align: center;
}

.sheet-header {
    padding: 14px;
    font-size: 0.8rem;
    color: #8e8e93;
    font-weight: 600;
    border-bottom: 1px solid #e5e5e5;
    text-transform: uppercase;
}

.sheet-btn {
    display: block;
    width: 100%;
    padding: 16px;
    font-size: 1.1rem;
    color: #007aff;
    background: white;
    border: none;
    border-bottom: 1px solid #e5e5e5;
    cursor: pointer;
    font-weight: 400;
}

.sheet-btn:last-child {
    border-bottom: none;
}

.sheet-btn:active {
    background-color: #f2f2f2;
}

.sheet-btn.selected {
    font-weight: 600;
    color: var(--primary-color);
}

.sheet-cancel-btn {
    display: block;
    width: 100%;
    padding: 16px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #007aff;
    background: white;
    border: none;
    border-radius: 14px;
    cursor: pointer;
}

/* Ocultar el select nativo antiguo para evitar conflictos */
#historial-campanya-select {
    display: none !important;
}

.campaign-selector-wrapper {
    cursor: pointer;
    user-select: none;
}

/* --- TAMAÑOS DE FUENTE AJUSTADOS (Intermedio) --- */

/* Título de la conversación */
.conv-title {
    font-size: 1.15rem !important;
    /* Aprox 18px */
    font-weight: 600;
    margin-bottom: 3px;
}

/* Subtítulo o previsualización del mensaje */
.conv-subtitle {
    font-size: 1rem !important;
    /* Aprox 16px (Tamaño estándar lectura) */
    color: #667781;
    line-height: 1.3;
}

/* Fecha */
.conv-date {
    font-size: 0.85rem !important;
    /* Aprox 13.5px */
    color: #8fa0a8;
    margin-top: 4px;
}