:root {
    --bg: #ffffff;
    --bg-sidebar: #f0f4f9;
    --bg-elevated: #f0f4f9;
    --bg-hover: #e4ebf3;
    --text: #1f1f1f;
    --text-soft: #575b5f;
    --text-faint: #8a8f94;
    --border: #dde3ea;
    --user-bubble: #e8f0fe;
    --accent: #4285f4;
    --grad: linear-gradient(74deg, #4285f4 0%, #9b72cb 45%, #d96570 100%);
    --radius-lg: 28px;
    --radius-md: 18px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 14px rgba(0, 0, 0, .05);
    --font: "Google Sans", "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1b1c1d;
        --bg-sidebar: #1e1f20;
        --bg-elevated: #282a2c;
        --bg-hover: #333537;
        --text: #e3e3e3;
        --text-soft: #c4c7c5;
        --text-faint: #969ba1;
        --border: #333537;
        --user-bubble: #333537;
    }
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

.safe-pt { padding-top: env(safe-area-inset-top); }

/* ---------- App shell ---------- */
.app {
    display: flex;
    height: 100dvh;
    overflow: hidden;
}

/* ---------- Sidebar (drawer) ---------- */
.sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    padding: 12px 8px;
    transition: transform .25s cubic-bezier(.16, 1, .3, 1);
}

.sidebar-top {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px 12px;
}

.icon-btn {
    width: 44px; height: 44px;
    border-radius: 50%;
    display: grid; place-items: center;
    font-size: 22px; color: var(--text-soft);
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); }

.new-chat {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 12px 18px;
    background: var(--bg-elevated);
    border-radius: 999px;
    font-size: 15px; font-weight: 500;
    color: var(--text-soft);
    align-self: flex-start;
    margin: 4px 8px 16px;
    box-shadow: var(--shadow);
}
.new-chat:hover { background: var(--bg-hover); }

.conv-label {
    font-size: 14px; color: var(--text-soft);
    padding: 8px 16px 6px; font-weight: 500;
}

.conv-list { flex: 1; overflow-y: auto; padding: 0 4px; }

.conv-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px;
    border-radius: 999px;
    font-size: 14px; color: var(--text-soft);
    cursor: pointer;
    white-space: nowrap; overflow: hidden;
    position: relative;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--user-bubble); color: var(--text); }
.conv-item .conv-title { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.conv-item .conv-del {
    opacity: 0; font-size: 18px; color: var(--text-faint);
    flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-item .conv-del:hover { background: var(--bg); color: var(--text); }

.sidebar-foot {
    padding: 10px 14px; font-size: 13px; color: var(--text-faint);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-foot a { color: var(--text-faint); text-decoration: none; }
.sidebar-foot a:hover { color: var(--accent); }

/* ---------- Main ---------- */
.main {
    flex: 1;
    display: flex; flex-direction: column;
    min-width: 0;
    position: relative;
}

.topbar {
    display: flex; align-items: center; gap: 6px;
    padding: 10px 12px;
}
.topbar .menu-btn { display: none; }

.model-pick {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 12px; border-radius: 999px;
    font-size: 18px; font-weight: 500; color: var(--text);
}
.model-pick:hover { background: var(--bg-hover); }
.model-pick select {
    border: none; background: transparent; font: inherit; color: var(--text);
    cursor: pointer; outline: none; padding-right: 4px;
}
.model-pick select option { color: #1f1f1f; background: #ffffff; }

.spacer { flex: 1; }

.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--grad); color: #fff;
    display: grid; place-items: center; font-weight: 600; font-size: 15px;
}

/* ---------- Chat scroll ---------- */
.chat {
    flex: 1; overflow-y: auto;
    padding: 8px 0 16px;
    scroll-behavior: smooth;
}
.chat-inner { max-width: 760px; margin: 0 auto; padding: 0 20px; }

/* Empty / greeting */
.greeting {
    height: 100%;
    display: flex; flex-direction: column; justify-content: center;
    padding-bottom: 12vh;
}
.greeting h1 {
    font-size: clamp(2.2rem, 7vw, 3.4rem);
    font-weight: 500; line-height: 1.1;
    background: var(--grad);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.greeting p { font-size: clamp(1.6rem, 5vw, 2.4rem); color: var(--text-faint); font-weight: 500; }

/* Messages */
.msg { padding: 14px 0; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Mensaje del usuario: burbuja alineada a la derecha, sin íconos. */
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .body {
    background: var(--user-bubble); color: var(--text);
    padding: 12px 18px; border-radius: 20px 20px 6px 20px;
    max-width: 86%; min-width: 0;
}
.msg.user .body p { margin: 0; }

/* Respuesta de la IA: marca de la app + etiqueta de modelo + texto. */
.msg.ai { display: flex; gap: 14px; }
.msg.ai .who {
    width: 30px; height: 30px; flex-shrink: 0; border-radius: 50%;
    display: grid; place-items: center; font-size: 15px;
    background: var(--grad); color: #fff;
}
.model-tag {
    font-size: 12px; font-weight: 600; letter-spacing: .03em;
    color: var(--text-faint); text-transform: uppercase; margin-bottom: 6px;
}

.msg .body { flex: 1; min-width: 0; padding-top: 3px; }
.msg .body p { margin: 0 0 12px; line-height: 1.7; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body pre {
    background: var(--bg-elevated); padding: 14px; border-radius: 12px;
    overflow-x: auto; margin: 12px 0; font-size: 13.5px;
}
.msg .body code {
    font-family: "Roboto Mono", ui-monospace, monospace;
    background: var(--bg-elevated); padding: 2px 6px; border-radius: 6px; font-size: 13.5px;
}
.msg .body pre code { background: none; padding: 0; }
.msg .body ul, .msg .body ol { margin: 0 0 12px; padding-left: 22px; line-height: 1.7; }

.typing { display: inline-flex; gap: 4px; padding-top: 6px; }
.typing span {
    width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint);
    animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- Composer ---------- */
.composer { padding: 6px 16px calc(14px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: 760px; margin: 0 auto; }

.input-pill {
    display: flex; align-items: flex-end; gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    padding: 8px 8px 8px 20px;
    transition: border-color .15s;
}
.input-pill:focus-within { border-color: var(--border); }

.input-pill textarea {
    flex: 1; border: none; background: none; resize: none; outline: none;
    font: inherit; font-size: 16px; color: var(--text);
    max-height: 180px; line-height: 1.5; padding: 9px 0;
}
.input-pill textarea::placeholder { color: var(--text-faint); }

.send-btn {
    width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
    display: grid; place-items: center; font-size: 20px;
    background: var(--bg-hover); color: var(--text-faint);
    transition: background .15s, color .15s;
}
.send-btn.ready { background: var(--accent); color: #fff; }
.send-btn:disabled { opacity: .5; cursor: default; }

.disclaimer { text-align: center; font-size: 12px; color: var(--text-faint); padding: 8px 0 2px; }

/* ---------- Drawer overlay (mobile) ---------- */
.scrim {
    position: fixed; inset: 0; background: rgba(0, 0, 0, .35);
    opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 20;
}

@media (max-width: 820px) {
    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0; z-index: 30;
        transform: translateX(-100%);
        box-shadow: 2px 0 16px rgba(0, 0, 0, .15);
    }
    .app.drawer-open .sidebar { transform: translateX(0); }
    .app.drawer-open .scrim { opacity: 1; pointer-events: auto; }
    .topbar .menu-btn { display: grid; }
}

/* ---------- Login ---------- */
.login-body {
    display: grid; place-items: center; min-height: 100dvh;
    background: radial-gradient(120% 120% at 50% 0%, #eaf1ff 0%, var(--bg) 55%);
    padding: 24px;
}
.login-card {
    width: 100%; max-width: 360px; text-align: center;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 24px; padding: 36px 28px; box-shadow: var(--shadow);
}
.login-logo {
    width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%;
    background: var(--grad); color: #fff; display: grid; place-items: center; font-size: 30px;
}
.login-card h1 { font-size: 26px; font-weight: 500; }
.login-sub { color: var(--text-faint); margin-bottom: 22px; }
.login-card label { display: block; text-align: left; font-size: 13px; color: var(--text-soft); margin-bottom: 14px; }
.login-card input {
    width: 100%; margin-top: 6px; padding: 13px 16px;
    border: 1px solid var(--border); border-radius: 14px;
    font: inherit; font-size: 16px; background: var(--bg); color: var(--text); outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
    width: 100%; margin-top: 8px; padding: 14px;
    background: var(--accent); color: #fff; border-radius: 14px;
    font-size: 16px; font-weight: 500;
}
.login-card button:hover { filter: brightness(1.05); }
.login-error {
    background: #fce8e6; color: #c5221f; padding: 10px 14px;
    border-radius: 12px; font-size: 14px; margin-bottom: 18px;
}
@media (prefers-color-scheme: dark) {
    .login-body { background: radial-gradient(120% 120% at 50% 0%, #1e2533 0%, var(--bg) 55%); }
    .login-error { background: #3b1f1d; color: #f2b8b5; }
}
