/* ============================================
   Chat Ciudadano - WhatsApp-like styles
   ============================================ */

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #e5ddd5;
}

/* ---- App container ---- */
#chat-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
    background: #e5ddd5;
    position: relative;
}

/* ---- Header ---- */
#chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #075e54 0%, #128c7e 100%);
    color: #fff;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    flex-shrink: 0;
}

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: #ccc;
    flex-shrink: 0;
}

.header-avatar svg {
    display: block;
}

.header-info {
    flex: 1;
    min-width: 0;
}

#header-nombre {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-status {
    font-size: 12px;
    color: rgba(255,255,255,0.85);
}

/* ---- Messages area ---- */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 16px;
    padding-bottom: 70px;
    background-color: #e5ddd5;
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cg fill='%23ccc5b9' fill-opacity='0.15'%3E%3Ccircle cx='25' cy='25' r='2'/%3E%3Ccircle cx='75' cy='25' r='1.5'/%3E%3Ccircle cx='125' cy='25' r='2'/%3E%3Ccircle cx='175' cy='25' r='1'/%3E%3Ccircle cx='225' cy='25' r='1.5'/%3E%3Ccircle cx='275' cy='25' r='2'/%3E%3Ccircle cx='50' cy='50' r='1'/%3E%3Ccircle cx='100' cy='50' r='2'/%3E%3Ccircle cx='150' cy='50' r='1.5'/%3E%3Ccircle cx='200' cy='50' r='2'/%3E%3Ccircle cx='250' cy='50' r='1'/%3E%3Ccircle cx='25' cy='75' r='1.5'/%3E%3Ccircle cx='75' cy='75' r='2'/%3E%3Ccircle cx='125' cy='75' r='1'/%3E%3Ccircle cx='175' cy='75' r='2'/%3E%3Ccircle cx='225' cy='75' r='1.5'/%3E%3Ccircle cx='275' cy='75' r='1'/%3E%3Ccircle cx='50' cy='100' r='2'/%3E%3Ccircle cx='100' cy='100' r='1'/%3E%3Ccircle cx='150' cy='100' r='2'/%3E%3Ccircle cx='200' cy='100' r='1.5'/%3E%3Ccircle cx='250' cy='100' r='2'/%3E%3Ccircle cx='25' cy='125' r='1'/%3E%3Ccircle cx='75' cy='125' r='1.5'/%3E%3Ccircle cx='125' cy='125' r='2'/%3E%3Ccircle cx='175' cy='125' r='1'/%3E%3Ccircle cx='225' cy='125' r='2'/%3E%3Ccircle cx='275' cy='125' r='1.5'/%3E%3Ccircle cx='50' cy='150' r='1.5'/%3E%3Ccircle cx='100' cy='150' r='2'/%3E%3Ccircle cx='150' cy='150' r='1'/%3E%3Ccircle cx='200' cy='150' r='2'/%3E%3Ccircle cx='250' cy='150' r='1'/%3E%3Ccircle cx='25' cy='175' r='2'/%3E%3Ccircle cx='75' cy='175' r='1'/%3E%3Ccircle cx='125' cy='175' r='1.5'/%3E%3Ccircle cx='175' cy='175' r='2'/%3E%3Ccircle cx='225' cy='175' r='1'/%3E%3Ccircle cx='275' cy='175' r='1.5'/%3E%3Ccircle cx='50' cy='200' r='1'/%3E%3Ccircle cx='100' cy='200' r='2'/%3E%3Ccircle cx='150' cy='200' r='1.5'/%3E%3Ccircle cx='200' cy='200' r='1'/%3E%3Ccircle cx='250' cy='200' r='2'/%3E%3Ccircle cx='25' cy='225' r='1.5'/%3E%3Ccircle cx='75' cy='225' r='2'/%3E%3Ccircle cx='125' cy='225' r='1'/%3E%3Ccircle cx='175' cy='225' r='1.5'/%3E%3Ccircle cx='225' cy='225' r='2'/%3E%3Ccircle cx='275' cy='225' r='1'/%3E%3Ccircle cx='50' cy='250' r='2'/%3E%3Ccircle cx='100' cy='250' r='1'/%3E%3Ccircle cx='150' cy='250' r='2'/%3E%3Ccircle cx='200' cy='250' r='1.5'/%3E%3Ccircle cx='250' cy='250' r='1'/%3E%3Ccircle cx='25' cy='275' r='1'/%3E%3Ccircle cx='75' cy='275' r='1.5'/%3E%3Ccircle cx='125' cy='275' r='2'/%3E%3Ccircle cx='175' cy='275' r='1'/%3E%3Ccircle cx='225' cy='275' r='1.5'/%3E%3Ccircle cx='275' cy='275' r='2'/%3E%3C/g%3E%3C/svg%3E");
    scroll-behavior: smooth;
}

/* ---- Messages ---- */
.message {
    display: flex;
    margin-bottom: 4px;
}

.message.usuario {
    justify-content: flex-end;
}

.message.ia {
    justify-content: flex-start;
}

.message.system {
    justify-content: center;
}

.message-bubble {
    max-width: 80%;
    padding: 6px 10px 4px;
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
    font-size: 14.2px;
}

/* User bubble - right, green */
.message.usuario .message-bubble {
    background: #dcf8c6;
    border-top-right-radius: 0;
    color: #303030;
}

.message.usuario .message-bubble::after {
    content: '';
    position: absolute;
    top: 0;
    right: -8px;
    width: 0;
    height: 0;
    border-left: 8px solid #dcf8c6;
    border-bottom: 8px solid transparent;
}

/* IA bubble - left, white */
.message.ia .message-bubble {
    background: #fff;
    border-top-left-radius: 0;
    color: #303030;
}

.message.ia .message-bubble::after {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-right: 8px solid #fff;
    border-bottom: 8px solid transparent;
}

/* System bubble */
.message.system .message-bubble {
    background: #e1f3fb;
    border-radius: 8px;
    font-size: 12.5px;
    color: #555;
    padding: 8px 14px;
    max-width: 85%;
    text-align: center;
}

.message-bubble p {
    margin: 0;
}

.message-time {
    display: block;
    text-align: right;
    font-size: 11px;
    color: #999;
    margin-top: 2px;
}

/* ---- Typing indicator ---- */
#typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 16px 6px;
    font-size: 12px;
    color: #666;
    background: transparent;
}

#typing-indicator.hidden {
    display: none;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.4s infinite both;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ---- Input area ---- */
#chat-input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: #f0f0f0;
    padding: 8px 10px;
    z-index: 10;
    flex-shrink: 0;
}

#chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

#chat-input {
    flex: 1;
    padding: 10px 14px;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    background: #fff;
    color: #333;
}

#chat-input::placeholder {
    color: #999;
}

#chat-send {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #075e54 0%, #128c7e 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

#chat-send:active {
    opacity: 0.7;
}

#chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---- Responsive ---- */
@media (min-width: 601px) {
    #chat-app {
        border-left: 1px solid #ccc;
        border-right: 1px solid #ccc;
    }
}

@media (max-width: 400px) {
    .message-bubble {
        max-width: 88%;
    }

    #header-nombre {
        font-size: 15px;
    }
}

/* Admin messages */
.message.admin {
    justify-content: center;
}

.message.admin .message-bubble {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: 10px;
    max-width: 85%;
    text-align: left;
}

.message-author-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #1565c0;
    margin-bottom: 4px;
}
