/* Variables */
:root {
    --primary: #1e4b8e;
    --primary-dark: #163a6e;
    --primary-light: #2d6bc4;
    --accent: #5bc0de;
    --accent-light: #8ed4e8;
    --red: #e31e24;
    --black: #1a1a2e;
    --gray-100: #f8fafc;
    --gray-200: #e5e7eb;
    --gray-400: #9ca3af;
    --gray-600: #6b7280;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 20px 40px -10px rgba(0, 0, 0, 0.2);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    height: 100dvh; /* Dynamic viewport para moviles */
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--black);
    line-height: 1.6;
    background: #0d3347;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    /* Safe areas para iOS */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Canvas oceano - fondo fijo */
#ocean-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(30, 75, 142, 0.3);
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    background: var(--white);
    padding: 8px 16px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.logo:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.logo img {
    height: 50px;
    width: auto;
}

.nav {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-link:hover {
    color: var(--white);
}

.btn-call {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--red);
    color: var(--white);
    padding: 10px 20px;
    border-radius: 50px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(227, 30, 36, 0.4);
}

.btn-call:hover {
    background: #c91a1f;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(227, 30, 36, 0.5);
}

/* Boton selector de cliente */
.btn-client {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.15);
    color: var(--white);
    padding: 8px 16px;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    max-width: 200px;
}

.btn-client:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.btn-client span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-client span.selected {
    color: var(--accent-light);
    font-weight: 600;
}

/* Animacion de highlight para llamar atencion */
.btn-client.highlight {
    animation: highlightPulse 0.6s ease-in-out 3;
    border-color: var(--accent-light);
    box-shadow: 0 0 20px rgba(91, 192, 222, 0.5);
}

@keyframes highlightPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(91, 192, 222, 0.3);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 25px rgba(91, 192, 222, 0.7);
    }
}

/* Modal de clientes */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--white);
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--black);
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--gray-100);
    color: var(--gray-600);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--gray-200);
    color: var(--black);
}

.modal-search {
    padding: 16px 24px;
    border-bottom: 1px solid var(--gray-200);
}

.modal-search input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 12px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.modal-search input:focus {
    border-color: var(--primary);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.client-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.client-item:hover {
    background: var(--gray-100);
}

.client-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.client-item .client-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--black);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.client-item .client-city {
    font-size: 12px;
    color: var(--gray-600);
}

.client-item .client-id {
    font-size: 11px;
    color: var(--gray-400);
    font-family: monospace;
}

.modal-body .loading,
.modal-body .error,
.modal-body .no-results {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-600);
    font-size: 14px;
}

.modal-body .error {
    color: var(--red);
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-top: 80px;
    overflow: hidden;
    position: relative;
    z-index: 1;
    height: calc(100vh - 80px);
    max-height: calc(100vh - 80px);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 32px 24px;
}

/* Welcome State */
.welcome-state {
    max-width: 650px;
    margin: 0 auto;
    text-align: center;
    padding: 30px 20px;
}

.welcome-icon {
    width: 130px;
    height: 130px;
    background: var(--white);
    border-radius: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    padding: 15px;
    box-shadow:
        0 15px 40px rgba(0, 0, 0, 0.25),
        0 0 0 6px rgba(255, 255, 255, 0.15),
        inset 0 -3px 15px rgba(0,0,0,0.05);
    animation: float 4s ease-in-out infinite;
    position: relative;
}

.welcome-icon::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 60%);
    animation: shimmer 4s ease-in-out infinite;
    pointer-events: none;
}

@keyframes shimmer {
    0%, 100% { transform: translate(-30%, -30%); }
    50% { transform: translate(30%, 30%); }
}

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(-15px) rotate(1deg); }
}

.welcome-icon .welcome-logo {
    width: 100%;
    height: auto;
    max-height: 100%;
    object-fit: contain;
    position: relative;
    z-index: 1;
}

.welcome-state h1 {
    font-size: 32px;
    font-weight: 700;
    color: var(--white);
    margin-bottom: 12px;
    line-height: 1.2;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.welcome-state p {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 24px;
    line-height: 1.6;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.suggestion-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 22px;
    background: var(--white);
    border: 2px solid var(--gray-200);
    border-radius: 50px;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.suggestion-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: linear-gradient(135deg, rgba(30, 75, 142, 0.05) 0%, rgba(91, 192, 222, 0.05) 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(30, 75, 142, 0.15);
}

.suggestion-btn svg {
    color: var(--accent);
}

/* Messages */
.messages {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.message {
    display: flex;
    gap: 16px;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow);
}

.message.bot .message-avatar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    color: var(--white);
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--black) 0%, #2d2d4a 100%);
    color: var(--white);
}

.message-content {
    max-width: 75%;
}

.message-bubble {
    padding: 16px 20px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.bot .message-bubble {
    background: var(--white);
    color: var(--black);
    border: 1px solid var(--gray-200);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.message.user .message-bubble {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--white);
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 15px rgba(30, 75, 142, 0.3);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 16px 20px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 20px;
    border-bottom-left-radius: 6px;
    width: fit-content;
    box-shadow: var(--shadow-sm);
}

.typing-indicator span {
    width: 10px;
    height: 10px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.input-area {
    flex-shrink: 0;
    padding: 20px 24px 28px;
    background: linear-gradient(to top, rgba(13, 51, 71, 0.9) 0%, rgba(13, 51, 71, 0.7) 60%, transparent);
    backdrop-filter: blur(8px);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--white);
    border: 2px solid var(--gray-200);
    border-radius: 20px;
    padding: 8px;
    box-shadow: var(--shadow-xl);
    transition: all 0.2s;
}

.input-container:focus-within {
    border-color: var(--primary);
    box-shadow: var(--shadow-xl), 0 0 0 4px rgba(30, 75, 142, 0.1);
}

.input-container textarea {
    flex: 1;
    padding: 14px 18px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    color: var(--black);
    min-height: 52px;
    max-height: 150px;
}

.input-container textarea::placeholder {
    color: var(--gray-400);
}

.send-btn {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(30, 75, 142, 0.3);
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(30, 75, 142, 0.4);
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.send-btn.loading svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Input Footer */
.input-footer {
    max-width: 800px;
    margin: 14px auto 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
}

.input-hint {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    color: var(--white);
    background: rgba(255, 255, 255, 0.1);
}

/* Footer Credits */
.footer-credits {
    text-align: center;
    padding: 12px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    background: rgba(13, 51, 71, 0.8);
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
}

.footer-credits a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-weight: 600;
}

.footer-credits a:hover {
    opacity: 1;
}

.footer-credits .nexttia-logo {
    height: 18px;
    width: auto;
    vertical-align: middle;
    margin-left: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.footer-credits a:hover .nexttia-logo {
    opacity: 1;
}

/* Responsive - Prevenir scroll horizontal */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

@media (max-width: 640px) {
    /* Header mobile */
    .header-container {
        padding: 0 10px;
        height: 50px;
    }

    .logo {
        padding: 3px 6px;
    }

    .logo img {
        height: 28px;
    }

    .nav-link {
        display: none;
    }

    /* Boton cliente en mobile */
    .btn-client {
        padding: 6px 10px;
        font-size: 11px;
        gap: 4px;
        max-width: 140px;
    }

    .btn-client svg {
        width: 14px;
        height: 14px;
        flex-shrink: 0;
    }

    /* Modal en mobile */
    .modal-overlay {
        padding: 10px;
        align-items: flex-end;
    }

    .modal-content {
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
    }

    .modal-header {
        padding: 16px 20px;
    }

    .modal-header h2 {
        font-size: 16px;
    }

    .modal-search {
        padding: 12px 16px;
    }

    .modal-search input {
        padding: 10px 14px;
        font-size: 16px;
    }

    .client-item {
        padding: 10px 12px;
    }

    .client-item .client-name {
        font-size: 13px;
    }

    /* Chat area mobile */
    .chat-main {
        padding-top: 50px;
        height: calc(100vh - 50px);
        height: calc(100dvh - 50px);
        max-height: calc(100vh - 50px);
        max-height: calc(100dvh - 50px);
        min-height: 0;
    }

    .messages-container {
        padding: 8px;
        overflow-x: hidden;
        overflow-y: auto;
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    /* Welcome state mobile - con espacio respirable */
    .welcome-state {
        padding: 8px;
        max-width: 100%;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;
        min-height: 0;
        padding-bottom: 35px;
    }

    .welcome-icon {
        width: 60px;
        height: 60px;
        border-radius: 14px;
        padding: 8px;
        margin-bottom: 10px;
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    }

    .welcome-state h1 {
        font-size: 22px;
        margin-bottom: 10px;
    }

    .welcome-state p {
        font-size: 14px;
        margin-bottom: 0;
        line-height: 1.5;
    }

    /* Ocultar sugerencias en mobile */
    .suggestions {
        display: none;
    }

    /* Messages mobile */
    .messages {
        max-width: 100%;
        gap: 12px;
        flex: 1;
    }

    .message {
        gap: 6px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        min-width: 28px;
        border-radius: 8px;
    }

    .message-avatar svg {
        width: 14px;
        height: 14px;
    }

    .message-content {
        max-width: calc(100% - 38px);
        min-width: 0;
    }

    .message-bubble {
        padding: 8px 12px;
        font-size: 13px;
        border-radius: 14px;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .message.bot .message-bubble {
        border-bottom-left-radius: 4px;
    }

    .message.user .message-bubble {
        border-bottom-right-radius: 4px;
    }

    /* Typing indicator mobile */
    .typing-indicator {
        padding: 8px 12px;
    }

    .typing-indicator span {
        width: 6px;
        height: 6px;
    }

    /* Input area mobile - integrado en oceano con distancia al footer */
    .input-area {
        padding: 12px 12px 20px;
        background: transparent;
        flex-shrink: 0;
    }

    .input-container {
        padding: 2px;
        border-radius: 10px;
        gap: 4px;
        max-width: 100%;
    }

    .input-container textarea {
        padding: 6px 10px;
        font-size: 16px; /* Evita zoom en iOS */
        min-height: 34px;
        max-height: 70px;
        width: 100%;
        min-width: 0;
    }

    .send-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
        border-radius: 8px;
    }

    .send-btn svg {
        width: 16px;
        height: 16px;
    }

    /* Input footer mobile - ocultar todo */
    .input-footer {
        display: none;
    }

    /* Footer mobile - integrado en oceano */
    .footer-credits {
        padding: 8px 8px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        font-size: 11px;
        background: transparent;
    }

    .footer-credits .nexttia-logo {
        height: 16px;
    }
}

/* Extra small devices */
@media (max-width: 380px) {
    .header-container {
        padding: 0 6px;
    }

    .logo img {
        height: 24px;
    }

    .btn-call span {
        display: none;
    }

    .welcome-icon {
        width: 50px;
        height: 50px;
        padding: 6px;
    }

    .welcome-state h1 {
        font-size: 16px;
    }

    .welcome-state p {
        font-size: 11px;
    }

    .message-bubble {
        font-size: 12px;
        padding: 6px 10px;
    }
}
