/* ============================================
   SISTEC TELECOM - CHATBOT MINIMALISTA
   100% Responsive
   ============================================ */

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

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #ffffff;
    color: #1a1a1a;
    height: 100%;
    height: 100dvh; /* Dynamic viewport height para móviles */
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    max-width: 800px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: env(safe-area-inset-bottom, 16px); /* Soporte para notch en iPhone */
}

/* ============================================
   MENSAJES
   ============================================ */

.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch; /* Smooth scroll en iOS */
}

.messages::-webkit-scrollbar {
    display: none;
}

.message {
    max-width: 90%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    animation: fadeIn 0.2s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    background: #1a73e8;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.bot {
    align-self: flex-start;
    background: #f5f5f5;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
}

/* ============================================
   FORMATO DE CONTENIDO (Markdown)
   ============================================ */

/* Negritas */
.message.bot strong {
    font-weight: 600;
    color: #1a73e8;
}

/* Enlaces */
.message.bot a {
    color: #1a73e8;
    text-decoration: underline;
    word-break: break-all;
    transition: color 0.2s;
}

.message.bot a:hover {
    color: #1557b0;
    text-decoration: none;
}

/* Enlaces de teléfono */
.message.bot a.phone-link {
    background: #e3f2fd;
    padding: 4px 12px;
    border-radius: 20px;
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #1a73e8;
}

.message.bot a.phone-link:hover {
    background: #1a73e8;
    color: white;
}

/* Enlaces de WhatsApp */
.message.bot a.whatsapp-link {
    background: #e8f5e9;
    color: #2e7d32;
    padding: 4px 12px;
    border-radius: 20px;
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #4caf50;
}

.message.bot a.whatsapp-link:hover {
    background: #4caf50;
    color: white;
}

/* Cursiva */
.message.bot em {
    font-style: italic;
    color: #555;
}

/* Párrafos */
.message.bot p {
    margin-bottom: 10px;
}

.message.bot p:last-child {
    margin-bottom: 0;
}

/* Listas */
.message.bot ul {
    margin: 10px 0;
    padding-left: 20px;
}

.message.bot li {
    margin-bottom: 6px;
    line-height: 1.4;
}

/* Espaciado entre secciones (ul + p o p + ul) */
.message.bot ul + p,
.message.bot p + ul {
    margin-top: 10px;
}

.message.bot li::marker {
    color: #1a73e8;
}

/* Código inline */
.message.bot code {
    background: #e8e8e8;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: 13px;
    color: #d32f2f;
}

/* Bloques de código */
.message.bot pre {
    background: #263238;
    color: #aed581;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
    -webkit-overflow-scrolling: touch;
}

.message.bot pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

/* Saltos de línea */
.message.bot br {
    display: block;
    content: "";
    margin-bottom: 6px;
}

/* Mensaje de bienvenida */
.welcome {
    text-align: center;
    color: #666;
    padding: 20px 16px;
    align-self: center;
    max-width: 100%;
}

.welcome h1 {
    font-size: 22px;
    font-weight: 500;
    margin-bottom: 8px;
    color: #1a1a1a;
}

.welcome p {
    font-size: 14px;
    color: #666;
}

/* Indicador de escritura */
.typing {
    display: flex;
    gap: 4px;
    padding: 12px;
}

.typing span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

.typing span:nth-child(1) { animation-delay: -0.32s; }
.typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ============================================
   INPUT CON EFECTO RGB CELESTE/VIOLETA
   ============================================ */

.input-wrapper {
    padding: 8px 0;
    flex-shrink: 0;
    position: relative;
}

/* Contenedor del efecto RGB */
.input-container {
    position: relative;
    border-radius: 26px;
    padding: 3px;
    background: linear-gradient(
        90deg,
        #00d4ff,
        #8b5cf6,
        #00d4ff
    );
    background-size: 200% 100%;
    animation: rgbBorder 3s linear infinite;
    box-shadow: 
        0 0 10px rgba(0, 212, 255, 0.3),
        0 0 20px rgba(139, 92, 246, 0.2);
}

/* Animación del borde RGB */
@keyframes rgbBorder {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Efecto de brillo pulsante */
.input-container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(
        45deg,
        #00d4ff,
        transparent,
        #8b5cf6,
        transparent,
        #00d4ff
    );
    background-size: 400% 400%;
    border-radius: 28px;
    z-index: -1;
    animation: rgbGlow 4s ease-in-out infinite;
    opacity: 0.6;
}

@keyframes rgbGlow {
    0%, 100% {
        background-position: 0% 50%;
        opacity: 0.4;
    }
    50% {
        background-position: 100% 50%;
        opacity: 0.7;
    }
}

.input-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    border-radius: 23px;
    padding: 4px;
    padding-left: 16px;
    border: none;
    min-height: 44px;
    position: relative;
    z-index: 1;
}

.input-box:focus-within {
    background: #fff;
}

.input-box input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px; /* 16px evita zoom en iOS */
    outline: none;
    padding: 8px 0;
    font-family: inherit;
    min-width: 0; /* Evita overflow */
}

.input-box input::placeholder {
    color: #999;
}

.send-btn {
    width: 40px;
    height: 40px;
    min-width: 40px; /* Evita que se encoja */
    border: none;
    border-radius: 50%;
    background: #1a73e8;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: #1557b0;
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.send-btn .material-icons {
    font-size: 20px;
}

.footer-text {
    text-align: center;
    font-size: 11px;
    color: #888;
    margin-top: 8px;
    padding: 0 8px;
    line-height: 1.4;
}

/* ============================================
   RESPONSIVE - TABLET
   ============================================ */

@media (max-width: 768px) {
    .chat-wrapper {
        padding: 12px;
    }
    
    .message {
        max-width: 92%;
        font-size: 15px;
        padding: 11px 14px;
    }
}

/* ============================================
   RESPONSIVE - MÓVIL
   ============================================ */

@media (max-width: 480px) {
    .chat-wrapper {
        padding: 8px;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
    }
    
    .messages {
        gap: 10px;
        padding-bottom: 8px;
    }
    
    .message {
        max-width: 95%;
        font-size: 14px;
        padding: 10px 12px;
        border-radius: 16px;
    }
    
    .message.bot ul {
        padding-left: 18px;
        margin: 8px 0;
    }
    
    .message.bot li {
        margin-bottom: 5px;
    }
    
    .message.bot pre {
        padding: 10px;
        font-size: 12px;
        margin: 8px 0;
    }
    
    .welcome {
        padding: 16px 12px;
    }
    
    .welcome h1 {
        font-size: 20px;
    }
    
    .welcome p {
        font-size: 13px;
    }
    
    .input-wrapper {
        padding: 6px 0;
    }
    
    .input-container {
        border-radius: 24px;
        padding: 2px;
        box-shadow: 
            0 0 8px rgba(0, 212, 255, 0.25),
            0 0 15px rgba(139, 92, 246, 0.15);
    }
    
    .input-container::before {
        top: -1px;
        left: -1px;
        right: -1px;
        bottom: -1px;
        border-radius: 26px;
    }
    
    .input-box {
        padding: 3px;
        padding-left: 12px;
        min-height: 40px;
        border-radius: 21px;
    }
    
    .input-box input {
        font-size: 16px; /* Previene zoom en iOS */
        padding: 6px 0;
    }
    
    .send-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }
    
    .send-btn .material-icons {
        font-size: 18px;
    }
    
    .footer-text {
        font-size: 10px;
        margin-top: 6px;
        padding: 0 4px;
    }
    
    /* Ajustar enlaces de contacto en móvil */
    .message.bot a.phone-link,
    .message.bot a.whatsapp-link {
        padding: 3px 10px;
        font-size: 14px;
    }
}

/* ============================================
   RESPONSIVE - MÓVIL PEQUEÑO
   ============================================ */

@media (max-width: 360px) {
    .chat-wrapper {
        padding: 6px;
    }
    
    .message {
        font-size: 13px;
        padding: 9px 11px;
    }
    
    .input-container {
        border-radius: 22px;
        padding: 2px;
    }
    
    .input-box {
        padding-left: 10px;
        min-height: 38px;
        border-radius: 20px;
    }
    
    .input-box input::placeholder {
        font-size: 14px;
    }
}

/* ============================================
   LANDSCAPE EN MÓVIL
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .chat-wrapper {
        padding: 8px;
    }
    
    .welcome {
        padding: 12px;
    }
    
    .welcome h1 {
        font-size: 18px;
        margin-bottom: 4px;
    }
    
    .messages {
        gap: 8px;
    }
    
    .message {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    .footer-text {
        font-size: 9px;
        margin-top: 4px;
    }
    
    .input-container {
        border-radius: 22px;
        padding: 2px;
    }
    
    .input-box {
        min-height: 38px;
        border-radius: 20px;
    }
}

/* ============================================
   SOPORTE PARA TECLADO VIRTUAL EN MÓVIL
   ============================================ */

@media (max-height: 400px) {
    .welcome {
        display: none; /* Ocultar welcome cuando el teclado está abierto */
    }
}