/* =========================
   CHAT LAYOUT PRINCIPAL
========================= */
.chat-layout {
    width: 100%;
    height: calc(100vh - 140px);
    display: flex;
    padding: 20px 30px 30px;
    box-sizing: border-box;
}

/* =========================
   ÁREA PRINCIPAL DEL CHAT
========================= */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* =========================
   HEADER — Título + Selector
========================= */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    position: relative;
    z-index: 2;
}

.chat-header h2 {
    color: #fff;
    font-size: 28px;
    margin: 0;
    font-weight: 700;
}

.model-selector,
.chat-header select {
    max-width: 260px;
    appearance: none;
    -webkit-appearance: none;
    background: #161b22;
    color: #fff;
    border: 1px solid #30363d;
    border-radius: 10px;
    padding: 10px 36px 10px 16px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23D4A017' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: all 0.2s;
}

.model-selector:hover,
.chat-header select:hover {
    border-color: rgba(0, 242, 254, 0.4);
}

.model-selector:focus,
.chat-header select:focus {
    border-color: #D4A017;
    box-shadow: 0 0 0 3px rgba(0, 242, 254, 0.12);
}

/* =========================
   MENSAJES / BURBUJAS
========================= */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: #0d1117;
    border: 1px solid rgba(48, 54, 61, 0.9);
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 200px;
}

.chat-msg {
    display: flex;
    max-width: 80%;
    animation: fadeIn 0.25s ease;
}

.chat-msg.ai {
    justify-content: flex-start;
    margin-right: auto;
    max-width: 100%;
    width: 100%;
    flex: 1;
}

.chat-msg.user {
    justify-content: flex-end;
    margin-left: auto;
}

.chat-msg .bubble {
    padding: 14px 20px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-msg.ai .bubble {
    background: #1c2128;
    border: 1px solid rgba(48, 54, 61, 0.6);
    color: #c9d1d9;
    border-bottom-left-radius: 6px;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

.chat-msg.user .bubble {
    background: linear-gradient(135deg, #F5D061, #D4A017);
    color: #fff;
    border: none;
    border-bottom-right-radius: 6px;
}

/* =========================
   COMPOSER (Input + Botón)
========================= */
.chat-composer {
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 10px 14px;
    background: #0b1220;
    border: 1px solid #1e293b;
    border-radius: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 0 0 1px #111827, 0 8px 24px rgba(0, 0, 0, 0.4);
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.chat-composer:focus-within {
    border-color: rgba(6, 182, 212, 0.4);
    box-shadow: 0 0 0 1px #111827, 0 8px 24px rgba(0, 0, 0, 0.4), 0 0 0 3px rgba(6, 182, 212, 0.08);
}

.chat-composer input {
    flex: 1;
    min-width: 0;
    height: 44px;
    background: transparent;
    color: #fff;
    border: none;
    padding: 0 8px;
    font-size: 15px;
    outline: none;
    font-family: inherit;
}

.chat-composer input::placeholder {
    color: #64748b;
}

.chat-composer button {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border: none;
    background: #D4A017;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-composer button:hover {
    transform: scale(1.08);
    box-shadow: 0 0 18px rgba(6, 182, 212, 0.5);
    background: #22d3ee;
}

.chat-composer button:active {
    transform: scale(0.96);
}

/* =========================
   ANIMACIONES
========================= */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* =========================
   RESPONSIVE
========================= */
@media (max-width: 768px) {
    .chat-layout {
        flex-direction: column;
        height: auto;
        padding: 15px;
    }
    .chat-header h2 {
        font-size: 22px;
    }
    .chat-composer {
        margin: 0 5px;
    }
    .chat-msg {
        max-width: 92%;
    }
}

/* Refuerzo: asegurar expansión total del contenedor de mensajes */
.chat-main {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
}
.chat-messages {
    flex: 1 1 auto !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* =========================
   SIDEBAR DE CHATS (estilo ChatGPT, paleta JAMC)
========================= */
.chat-layout {
    gap: 20px;
}

.chat-sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #11161d;
    border: 1px solid rgba(48, 54, 61, 0.9);
    border-radius: 16px;
    padding: 16px 12px;
    height: 100%;
    box-sizing: border-box;
    overflow-y: auto;
}

.chat-sidebar-newbtn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 18px;
    background: linear-gradient(135deg, #F5D061, #D4A017, #B8860B);
    color: #2a1e05;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-sidebar-newbtn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(212, 160, 23, 0.40);
}

.chat-sidebar-section {
    margin-bottom: 18px;
}

.chat-sidebar-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #8b949e;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 4px 10px 8px;
}

.chat-sidebar-section-title .add-project-btn {
    background: none;
    border: none;
    color: #8b949e;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 6px;
    transition: all 0.2s;
}

.chat-sidebar-section-title .add-project-btn:hover {
    color: #00f2fe;
    background: rgba(0, 242, 254, 0.08);
}

.chat-sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 10px;
    color: #c9d1d9;
    font-size: 13.5px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s ease, color 0.15s ease;
    margin-bottom: 2px;
}

.chat-sidebar-item i {
    font-size: 13px;
    color: #8b949e;
    flex-shrink: 0;
}

.chat-sidebar-item:hover {
    background: rgba(48, 54, 61, 0.5);
    color: #fff;
}

.chat-sidebar-item.active {
    background: rgba(0, 242, 254, 0.12);
    color: #00f2fe;
}

.chat-sidebar-item.active i {
    color: #00f2fe;
}

.chat-sidebar-empty {
    color: #8b949e;
    font-size: 12.5px;
    padding: 8px 10px;
    font-style: italic;
}

.chat-sidebar-project-group {
    margin-bottom: 6px;
}

@media (max-width: 900px) {
    .chat-sidebar {
        display: none;
    }
}

/* =========================
   AJUSTE: sidebar pegado al borde (solo en vista Chat)
========================= */
#content:has(.chat-layout) {
    padding: 0;
}
.chat-layout {
    height: calc(100vh - 70px);
    padding: 0;
    gap: 0;
}
.chat-sidebar {
    height: 100%;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
}
.chat-main {
    padding: 20px 30px 30px;
    box-sizing: border-box;
}

/* =========================
   MENU DE 3 PUNTOS EN CADA CHAT
========================= */
.chat-sidebar-item {
    position: relative;
    padding-right: 30px;
}

.chat-sidebar-item-menu-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #8b949e;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 15px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.chat-sidebar-item:hover .chat-sidebar-item-menu-btn {
    opacity: 1;
}

.chat-sidebar-item-menu-btn:hover {
    background: rgba(0, 242, 254, 0.12);
    color: #00f2fe;
}

.chat-item-popover {
    position: fixed;
    z-index: 999;
    min-width: 190px;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.chat-item-popover button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    background: none;
    border: none;
    color: #c9d1d9;
    font-size: 13.5px;
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    font-family: inherit;
}

.chat-item-popover button:hover {
    background: rgba(48, 54, 61, 0.6);
}

.chat-item-popover button.danger {
    color: #f85149;
}

.chat-item-popover button.danger:hover {
    background: rgba(248, 81, 73, 0.12);
}

.chat-item-popover hr {
    border: none;
    border-top: 1px solid #30363d;
    margin: 4px 0;
}

.chat-item-popover-submenu {
    max-height: 160px;
    overflow-y: auto;
}

/* =========================
   MENU DE 3 PUNTOS EN CADA CHAT
========================= */
.chat-sidebar-item {
    position: relative;
    padding-right: 30px;
}

.chat-sidebar-item-menu-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #8b949e;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 15px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.chat-sidebar-item:hover .chat-sidebar-item-menu-btn {
    opacity: 1;
}

.chat-sidebar-item-menu-btn:hover {
    background: rgba(0, 242, 254, 0.12);
    color: #00f2fe;
}

.chat-item-popover {
    position: fixed;
    z-index: 999;
    min-width: 190px;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.chat-item-popover button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    background: none;
    border: none;
    color: #c9d1d9;
    font-size: 13.5px;
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    font-family: inherit;
}

.chat-item-popover button:hover {
    background: rgba(48, 54, 61, 0.6);
}

.chat-item-popover button.danger {
    color: #f85149;
}

.chat-item-popover button.danger:hover {
    background: rgba(248, 81, 73, 0.12);
}

.chat-item-popover hr {
    border: none;
    border-top: 1px solid #30363d;
    margin: 4px 0;
}

.chat-item-popover-submenu {
    max-height: 160px;
    overflow-y: auto;
}


/* acordeon-proyectos */
.chat-sidebar-project-head { cursor: pointer; }
.chat-sidebar-chevron {
    transition: transform 0.2s ease;
    font-size: 12px;
    opacity: 0.7;
}
.chat-sidebar-project-head.open .chat-sidebar-chevron {
    transform: rotate(90deg);
}
.chat-sidebar-project-chats {
    margin-left: 14px;
    padding-left: 8px;
    border-left: 1px solid rgba(255,255,255,.08);
}
.chat-sidebar-subitem {
    font-size: 13px;
    opacity: 0.92;
}
