/* ========================================
   NEOBRUTALISM CHAT UI - VERSIÓN CORREGIDA
   Negro y Blanco | Sin scrolls en main
   ======================================== */

:root {
    --color-bg-dark: #000000;
    --color-bg-light: #ffffff;
    --color-text-dark: #000000;
    --color-text-light: #ffffff;
    --border-thick: 4px;
    --border-thin: 3px;
    --shadow-offset: 6px;
    --shadow-hover: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    background: var(--color-bg-light);
    color: var(--color-text-dark);
    font-family: "Space Mono", "IBM Plex Mono", "Courier New", monospace;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
}

#app {
    width: 100%;
    height: 100%;
}

/* ========================================
   ANIMACIONES
   ======================================== */

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes dots {
    0%, 20% { content: "..."; }
    40% { content: ".."; }
    60% { content: "."; }
    80%, 100% { content: ""; }
}

@keyframes typing {
    0% { content: "..."; }
    25% { content: "."; }
    50% { content: ".."; }
    75% { content: "..."; }
    100% { content: "..."; }
}

@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ========================================
   LAYOUT PRINCIPAL - SIN SCROLL
   ======================================== */

.chat-app {
    display: grid;
    grid-template-columns: 320px 1fr;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* ========================================
   SIDEBAR - FONDO BLANCO, TEXTO NEGRO
   ======================================== */

.chat-sidebar {
    background: var(--color-bg-light);
    border-right: var(--border-thick) solid var(--color-text-dark);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: var(--border-thin) solid var(--color-text-dark);
    background: var(--color-bg-light);
    flex-shrink: 0;
}

.sidebar-header > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.sidebar-header h2 {
    color: var(--color-text-dark);
    font-size: 0.95rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.sidebar-header span {
    color: var(--color-text-dark);
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
    border: 2px solid var(--color-text-dark);
    background: transparent;
    font-weight: 900;
}

.ghost-btn {
    border: var(--border-thin) solid var(--color-text-dark);
    background: var(--color-bg-light);
    color: var(--color-text-dark);
    padding: 0.4rem 0.8rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.15s ease;
    box-shadow: 3px 3px 0 var(--color-text-dark);
    font-family: inherit;
}

.ghost-btn:hover:not(:disabled) {
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0 var(--color-text-dark);
}

.ghost-btn:active:not(:disabled) {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0 var(--color-text-dark);
}

.ghost-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ========================================
   LISTA DE SESIONES - SCROLL INTERNO
   ======================================== */

.session-list {
    flex: 1;
    list-style: none;
    padding: 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    scrollbar-width: thin;
    scrollbar-color: var(--color-text-dark) var(--color-bg-light);
}

.session-list::-webkit-scrollbar {
    width: 6px;
}

.session-list::-webkit-scrollbar-track {
    background: var(--color-bg-light);
}

.session-list::-webkit-scrollbar-thumb {
    background: var(--color-text-dark);
    border: 1px solid var(--color-bg-light);
}

.session-item {
    border: var(--border-thin) solid var(--color-text-dark);
    background: var(--color-bg-light);
    color: var(--color-text-dark);
    padding: 0.85rem;
    cursor: pointer;
    transition: all 0.12s ease;
    box-shadow: 3px 3px 0 var(--color-text-dark);
    animation: slideIn 0.3s ease;
}

.session-item:hover {
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0 var(--color-text-dark);
}

.session-item:active {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0 var(--color-text-dark);
}

.session-item.active {
    background: var(--color-text-dark);
    color: var(--color-text-light);
    border-color: var(--color-text-dark);
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5);
    transform: translate(-2px, -2px);
}

.session-item.active:hover {
    transform: translate(-3px, -3px);
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.6);
}

.session-title {
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1.4;
    word-break: break-word;
    color: inherit;
}

.session-meta {
    display: none;
}

.sidebar-hint {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--color-text-dark);
    opacity: 0.6;
    font-size: 0.8rem;
    line-height: 1.5;
}

/* ========================================
   WORKSPACE - ÁREA DE CHAT BLANCA
   ======================================== */

.chat-workspace {
    display: flex;
    flex-direction: column;
    background: var(--color-bg-light);
    color: var(--color-text-dark);
    height: 100vh;
    overflow: hidden;
}

.chat-workspace__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: var(--border-thick) solid var(--color-text-dark);
    background: var(--color-bg-light);
    flex-shrink: 0;
    gap: 1rem;
}

.hamburger-btn {
    display: none;
    background: transparent;
    border: var(--border-thin) solid var(--color-text-dark);
    padding: 0.5rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    transition: all 0.15s ease;
    box-shadow: 3px 3px 0 var(--color-text-dark);
}

.hamburger-btn:hover {
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0 var(--color-text-dark);
}

.hamburger-btn:active {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0 var(--color-text-dark);
}

.hamburger-icon {
    display: block;
    position: relative;
    width: 100%;
    height: 2px;
    background: var(--color-text-dark);
}

.hamburger-icon::before,
.hamburger-icon::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 2px;
    background: var(--color-text-dark);
    left: 0;
}

.hamburger-icon::before {
    top: -6px;
}

.hamburger-icon::after {
    top: 6px;
}

.chat-title-block {
    flex: 1;
    min-width: 0;
}

.chat-title-block h1 {
    font-size: 1.3rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-header-actions .ghost-btn {
    border-color: var(--color-text-dark);
    color: var(--color-text-dark);
    box-shadow: 3px 3px 0 var(--color-text-dark);
}

.chat-header-actions .ghost-btn:hover:not(:disabled) {
    box-shadow: 5px 5px 0 var(--color-text-dark);
}

/* ========================================
   FEED DE MENSAJES - SCROLL INTERNO
   ======================================== */

.chat-feed {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    scrollbar-width: thin;
    scrollbar-color: var(--color-text-dark) var(--color-bg-light);
}

.chat-feed::-webkit-scrollbar {
    width: 8px;
}

.chat-feed::-webkit-scrollbar-track {
    background: var(--color-bg-light);
    border-left: 2px solid var(--color-text-dark);
}

.chat-feed::-webkit-scrollbar-thumb {
    background: var(--color-text-dark);
    border: 2px solid var(--color-bg-light);
}

.feed-hint {
    text-align: center;
    padding: 3rem 2rem;
    opacity: 0.4;
    font-size: 0.85rem;
    line-height: 1.6;
}

.feed-error {
    padding: 1rem 1.5rem;
    background: var(--color-bg-light);
    color: var(--color-text-dark);
    border: var(--border-thick) solid var(--color-text-dark);
    box-shadow: 4px 4px 0 var(--color-text-dark);
    font-weight: 700;
    text-align: center;
    animation: slideIn 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.feed-error p {
    margin: 0;
}

.retry-btn {
    border: var(--border-thin) solid var(--color-text-dark);
    background: var(--color-bg-light);
    color: var(--color-text-dark);
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s ease;
    box-shadow: 3px 3px 0 var(--color-text-dark);
}

.retry-btn:hover {
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0 var(--color-text-dark);
}

.retry-btn:active {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0 var(--color-text-dark);
}

/* ========================================
   BURBUJAS - TODO BLANCO CON BORDES NEGROS
   ======================================== */

.bubble {
    max-width: 75%;
    border: var(--border-thick) solid var(--color-text-dark);
    background: var(--color-bg-light);
    color: var(--color-text-dark);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    transition: transform 0.1s ease;
    box-shadow: var(--shadow-offset) var(--shadow-offset) 0 var(--color-text-dark);
}

.bubble:hover {
    transform: translate(-1px, -1px);
    box-shadow: var(--shadow-hover) var(--shadow-hover) 0 var(--color-text-dark);
}

.bubble header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 0.65rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding-bottom: 0.45rem;
    border-bottom: 2px solid currentColor;
    opacity: 0.8;
}

.bubble.user {
    align-self: flex-start;
    animation: slideInLeft 0.4s ease-out;
}

.bubble.ai {
    align-self: flex-end;
    animation: slideInRight 0.4s ease-out;
}

/* Animación especial para mensaje "escribiendo..." */
.bubble.typing-indicator {
    align-self: flex-end; /* Alineado a la derecha como IA */
    animation: slideInRight 0.3s ease-out, pulse 1.5s ease-in-out infinite;
}

.typing-dots {
    display: flex;
    align-items: center;
    justify-content: flex-end; /* Alinear dots a la derecha */
    gap: 0.4rem;
    height: 1.5rem;
    margin: 0;
}

.typing-dots .dot {
    width: 8px;
    height: 8px;
    background: currentColor;
    border-radius: 50%;
    display: inline-block;
    animation: typingDot 1.4s infinite ease-in-out;
}

.typing-dots .dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dots .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots .dot:nth-child(3) {
    animation-delay: 0.4s;
}

.bubble-body {
    font-size: 0.9rem;
    line-height: 1.6;
    word-wrap: break-word;
}

.bubble-body p {
    margin: 0 0 0.65rem 0;
}

.bubble-body p:last-child {
    margin-bottom: 0;
}

.bubble-body pre {
    background: rgba(0, 0, 0, 0.05);
    border: 2px solid var(--color-text-dark);
    padding: 0.65rem;
    overflow-x: auto;
    font-size: 0.8rem;
    margin: 0.5rem 0;
}

.bubble-body code {
    font-family: inherit;
    background: rgba(0, 0, 0, 0.08);
    padding: 0.15rem 0.3rem;
    border: 1px solid var(--color-text-dark);
}

.bubble-body pre code {
    background: transparent;
    border: none;
    padding: 0;
}

.bubble-body ul, .bubble-body ol {
    margin: 0.5rem 0 0.5rem 1.25rem;
}

.bubble-body li {
    margin: 0.2rem 0;
}

.bubble-body strong {
    font-weight: 900;
}

.bubble-body a {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 2px;
}

.bubble-body a:hover {
    text-decoration-thickness: 3px;
}

.bubble-body blockquote {
    border-left: 4px solid currentColor;
    padding-left: 1rem;
    margin: 0.5rem 0;
    opacity: 0.8;
}

.bubble-body hr {
    border: none;
    border-top: 2px solid currentColor;
    margin: 0.75rem 0;
    opacity: 0.3;
}

.spacer {
    height: 1px;
    min-height: 1px;
}

/* ========================================
   COMPOSER - INPUT DE UNA LÍNEA
   ======================================== */

.composer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: var(--border-thick) solid var(--color-text-dark);
    background: var(--color-bg-light);
    align-items: center;
    flex-shrink: 0;
}

.composer-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.composer-input {
    flex: 1;
    border: var(--border-thick) solid var(--color-text-dark);
    background: var(--color-bg-light);
    color: var(--color-text-dark);
    padding: 0.85rem 1rem;
    padding-right: 6rem;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.4;
    box-shadow: 4px 4px 0 var(--color-text-dark);
    transition: all 0.15s ease;
    height: 50px;
}

.composer-input:focus {
    outline: none;
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--color-text-dark);
}


.composer-input::placeholder {
    color: var(--color-text-dark);
    opacity: 0.4;
    font-size: 0.85rem;
}

.character-count {
    position: absolute;
    right: 1rem;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.25rem 0.5rem;
    border: 2px solid currentColor;
    background: var(--color-bg-light);
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.character-count.text-error {
    color: #d32f2f;
    border-color: #d32f2f;
}

.character-count.text-warning {
    color: #f57c00;
    border-color: #f57c00;
}

.character-count.text-ok {
    color: #388e3c;
    border-color: #388e3c;
}

/* Botón de enviar móvil (dentro del input) - oculto por defecto */
.composer-send-mobile {
    display: none;
}

/* Botón de enviar desktop (fuera del input) */
.composer-send-desktop {
    border: var(--border-thick) solid var(--color-text-dark);
    background: var(--color-bg-light);
    color: var(--color-text-dark);
    padding: 0.85rem 1.5rem;
    font-family: inherit;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s ease;
    box-shadow: 4px 4px 0 var(--color-text-dark);
    white-space: nowrap;
    height: 50px;
}

.composer-send-desktop:hover:not(:disabled) {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--color-text-dark);
}

.composer-send-desktop:active:not(:disabled) {
    transform: translate(1px, 1px);
    box-shadow: 2px 2px 0 var(--color-text-dark);
}

.composer-send-desktop:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: var(--color-bg-light);
    color: var(--color-text-dark);
}

.composer.sending {
    opacity: 0.7;
    pointer-events: none;
}

/* ========================================
   RESPONSIVE
   ======================================== */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

@media (max-width: 960px) {
    .chat-app {
        grid-template-columns: 280px 1fr;
    }

    .bubble {
        max-width: 85%;
    }
    
    .chat-title-block h1 {
        font-size: 1.1rem;
    }
}

@media (max-width: 768px) {
    .hamburger-btn {
        display: block;
    }

    .chat-app {
        grid-template-columns: 1fr;
        position: relative;
    }

    .chat-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        width: 280px;
        z-index: 999;
        transition: left 0.3s ease;
        box-shadow: 4px 0 8px rgba(0, 0, 0, 0.3);
    }

    .chat-sidebar.open {
        left: 0;
    }

    .sidebar-overlay {
        display: block;
    }

    /* Workspace con flexbox: header fijo, feed scroll, composer fijo */
    .chat-workspace {
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        position: relative;
        overflow: hidden; /* Sin scroll externo */
    }

    .chat-workspace__header {
        padding: 0.75rem 1rem;
        flex-shrink: 0; /* No se achica */
    }

    /* Feed con scroll independiente */
    .chat-feed {
        flex: 1; /* Crece para llenar espacio */
        overflow-y: auto; /* SOLO el feed tiene scroll */
        overflow-x: hidden;
        padding: 1rem;
        padding-bottom: 0.5rem;
        min-height: 0; /* Permite que se achique con flex */
        -webkit-overflow-scrolling: touch; /* Smooth scroll en iOS */
    }

    /* Composer fijo abajo, sin scroll */
    .composer {
        padding: 0.65rem 1rem;
        gap: 0;
        flex-shrink: 0; /* No se achica */
        border-top: var(--border-thick) solid var(--color-text-dark);
    }

    /* Input más ancho, el botón está dentro */
    .composer-input-wrapper {
        width: 100%;
    }

    .composer-input {
        font-size: 16px; /* Previene zoom en iOS */
        padding: 0.75rem;
        padding-right: 4.5rem; /* Espacio para contador + botón */
        height: 48px;
    }

    /* Contador más pequeño */
    .character-count {
        font-size: 0.6rem;
        padding: 0.2rem 0.35rem;
        right: 3.2rem; /* Más a la izquierda por el botón */
        top: 50%;
        transform: translateY(-50%);
    }

    /* Ocultar botón desktop */
    .composer-send-desktop {
        display: none;
    }

    /* Mostrar botón móvil dentro del input */
    .composer-send-mobile {
        display: flex;
        position: absolute;
        right: 0.5rem;
        top: 50%;
        transform: translateY(-50%);
        border: 2px solid var(--color-text-dark);
        background: var(--color-bg-light);
        color: var(--color-text-dark);
        padding: 0.5rem 0.65rem;
        font-size: 1rem;
        cursor: pointer;
        transition: all 0.15s ease;
        box-shadow: 2px 2px 0 var(--color-text-dark);
        align-items: center;
        justify-content: center;
        line-height: 1;
    }

    .composer-send-mobile:active:not(:disabled) {
        transform: translateY(-50%) translate(1px, 1px);
        box-shadow: 1px 1px 0 var(--color-text-dark);
    }

    .composer-send-mobile:disabled {
        opacity: 0.3;
        cursor: not-allowed;
    }

    .chat-title-block h1 {
        font-size: 1rem;
    }

    .ghost-btn {
        font-size: 0.7rem;
        padding: 0.4rem 0.7rem;
    }


    .bubble {
        max-width: 90%;
        padding: 0.85rem;
    }

    .bubble header {
        font-size: 0.6rem;
    }

    .bubble-body {
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .chat-sidebar {
        width: 85vw;
        max-width: 280px;
    }

    .chat-title-block h1 {
        font-size: 0.9rem;
    }

    .composer-input {
        font-size: 16px; /* Previene zoom en iOS */
    }

    .bubble {
        max-width: 95%;
    }
}

/* Específico para iOS Safari */
@supports (-webkit-touch-callout: none) {
    .chat-workspace {
        height: -webkit-fill-available;
    }
    
    .composer {
        padding-bottom: env(safe-area-inset-bottom, 0.75rem);
    }
}

/* Mejoras para cuando el teclado está visible */
@media (max-height: 500px) {
    .chat-feed {
        padding: 0.5rem;
    }
    
    .bubble {
        padding: 0.65rem;
        margin-bottom: 0.5rem;
    }
    
    .composer {
        padding: 0.5rem 0.75rem;
    }
}

