/* ============================================================
   Lialo IA · Estilos
   Mobile-first: la base es el celular; los @media amplían
   a tablet (≥ 768px) y escritorio (≥ 1024px).
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
    --bg:        #f6f6f9;
    --surface:   #ffffff;
    --surface-2: #eeeef3;
    --border:    #e2e2ea;
    --text:      #15161c;
    --text-2:    #5d5f6e;
    --text-3:    #8f91a0;

    --chat:      #6d4dff;
    --chat-soft: #6d4dff1a;
    --img:       #ff6a3d;
    --img-soft:  #ff6a3d1a;

    --accent:      var(--img);
    --accent-soft: var(--img-soft);

    --radius:    18px;
    --radius-sm: 12px;
    --shadow:    0 10px 30px -12px rgb(20 20 40 / .18);
    --shadow-up: 0 -8px 30px -14px rgb(20 20 40 / .2);

    --sidebar-w: 284px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:        #0e0f13;
        --surface:   #17181e;
        --surface-2: #20222a;
        --border:    #2a2c36;
        --text:      #f1f1f5;
        --text-2:    #a6a8b6;
        --text-3:    #6e7080;
        --chat:      #8b73ff;
        --chat-soft: #8b73ff22;
        --img:       #ff8059;
        --img-soft:  #ff805922;
        --shadow:    0 10px 30px -12px rgb(0 0 0 / .6);
        --shadow-up: 0 -8px 30px -14px rgb(0 0 0 / .7);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg:        #0e0f13;
    --surface:   #17181e;
    --surface-2: #20222a;
    --border:    #2a2c36;
    --text:      #f1f1f5;
    --text-2:    #a6a8b6;
    --text-3:    #6e7080;
    --chat:      #8b73ff;
    --chat-soft: #8b73ff22;
    --img:       #ff8059;
    --img-soft:  #ff805922;
    --shadow:    0 10px 30px -12px rgb(0 0 0 / .6);
    --shadow-up: 0 -8px 30px -14px rgb(0 0 0 / .7);
    color-scheme: dark;
}

/* El acento cambia según el modo activo */
body[data-mode="chat"]   { --accent: var(--chat); --accent-soft: var(--chat-soft); }
body[data-mode="imagen"] { --accent: var(--img);  --accent-soft: var(--img-soft); }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;            /* el scroll vive en .content */
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* Visibilidad por dispositivo */
.only-desktop { display: none !important; }

/* Textos y bloques que dependen del modo */
.mode-text, .mode-block { display: none; }
body[data-mode="chat"]   [data-for="chat"],
body[data-mode="imagen"] [data-for="imagen"] { display: revert; }
body[data-mode="chat"] .model-list[data-for="chat"],
body[data-mode="imagen"] .model-list[data-for="imagen"] { display: flex; }
body[data-mode="chat"] .img-only { display: none; }

/* Iconos del botón de tema */
.theme-light-icon { display: none; }
:root[data-theme="dark"] .theme-dark-icon { display: none; }
:root[data-theme="dark"] .theme-light-icon { display: inline; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-dark-icon { display: none; }
    :root:not([data-theme="light"]) .theme-light-icon { display: inline; }
}

/* ---------- Layout ---------- */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ---------- Botones genéricos ---------- */
.icon-btn {
    width: 42px; height: 42px;
    display: inline-grid; place-items: center;
    border-radius: 12px;
    font-size: 20px;
    color: var(--text-2);
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-2); color: var(--text); }

.btn-primary {
    width: 100%;
    margin-top: 22px;
    padding: 15px;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 16px;
}

/* ---------- Marca ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-mark {
    width: 36px; height: 36px;
    display: grid; place-items: center;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--chat), var(--img));
    color: #fff;
    font-size: 17px;
    box-shadow: 0 6px 16px -6px var(--chat);
}
.brand-mark.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 14px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-name b {
    background: linear-gradient(90deg, var(--chat), var(--img));
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
}

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: calc(8px + var(--safe-t)) 10px 8px;
    flex-shrink: 0;
}
.topbar-spacer { flex: 1; }

.credit-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 12px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.credit-chip i { color: #f5b301; }

/* ---------- Sidebar (drawer en móvil) ---------- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(86vw, var(--sidebar-w));
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: calc(14px + var(--safe-t)) 14px calc(14px + var(--safe-b));
    background: var(--surface);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
    overflow-y: auto;
}
body.drawer-open .sidebar { transform: none; box-shadow: var(--shadow); }

.scrim {
    position: fixed; inset: 0; z-index: 35;
    background: rgb(0 0 0 / .45);
    opacity: 0; pointer-events: none;
    transition: opacity .25s;
}
body.drawer-open .scrim { opacity: 1; pointer-events: auto; }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 4px; }

.btn-new {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 13px;
    border-radius: 14px;
    background: var(--text);
    color: var(--bg);
    font-weight: 700;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a, .side-list a, .foot-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px;
    border-radius: 12px;
    color: var(--text-2);
    font-weight: 500;
}
.side-nav a:hover, .side-list a:hover, .foot-link:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-nav i { font-size: 18px; }

.side-section { flex: 1; min-height: 0; overflow-y: auto; }
.side-label { padding: 6px 12px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.side-list a { padding: 9px 12px; font-size: 14px; }
.side-list span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-list i { color: var(--text-3); }

.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }
.credit-card {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--chat-soft), var(--img-soft));
    border: 1px solid var(--border);
}
.credit-card > i { font-size: 26px; color: #f5b301; }
.credit-label { font-size: 12px; color: var(--text-2); }
.credit-value { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.foot-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.foot-row form { flex: 1; min-width: 0; }
/* Pie con "Salir" + "Ajustes" + tema (inicio): en dos filas para que no se encimen */
.foot-row-3 { flex-wrap: wrap; }
.foot-row-3 form { flex: 1 1 100%; }
.foot-row-3 .foot-link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-row .foot-link { width: 100%; font-size: 14px; }
.inline { display: inline; }

/* ---------- Contenido scrollable ---------- */
.content {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.content-inner {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 8px 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 26px;
}

/* Saludo */
.hero { padding-top: 6px; }
.hero-kicker { color: var(--text-2); font-weight: 500; margin-bottom: 4px; }
.hero-title { font-size: clamp(26px, 7.4vw, 40px); line-height: 1.12; font-weight: 800; letter-spacing: -.025em; }
.hero-title em { font-style: normal; color: var(--accent); }

/* Accesos rápidos: 2×2 en móvil */
.quick-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.quick-card {
    display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
    padding: 14px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    text-align: left;
    transition: transform .12s, border-color .15s;
    min-height: 112px;
}
.quick-card:active { transform: scale(.97); }
.quick-card:hover { border-color: var(--text-3); }
.quick-icon {
    width: 38px; height: 38px;
    display: grid; place-items: center;
    border-radius: 11px;
    font-size: 18px;
}
.quick-icon.is-img  { background: var(--img-soft);  color: var(--img); }
.quick-icon.is-chat { background: var(--chat-soft); color: var(--chat); }
.quick-text { display: flex; flex-direction: column; }
.quick-text strong { font-size: 15px; font-weight: 700; }
.quick-text small { font-size: 13px; color: var(--text-2); }

/* Bloques */
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.block-head h2 { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.link-more { font-size: 13px; font-weight: 600; color: var(--accent); display: inline-flex; align-items: center; gap: 2px; }

/* Galería: tira horizontal con snap en móvil */
.gallery-strip {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 16px;
    margin: 0 -16px;
    padding: 0 16px 4px;
    scrollbar-width: none;
}
.gallery-strip::-webkit-scrollbar { display: none; }

.tile {
    flex: 0 0 auto;
    width: 46vw;
    max-width: 210px;
    scroll-snap-align: start;
    display: flex; flex-direction: column; gap: 8px;
}
.tile-img {
    position: relative;
    display: block;
    aspect-ratio: 3 / 4;                 /* altura uniforme en la tira */
    border-radius: var(--radius-sm);
    background:
        radial-gradient(circle at 30% 25%, rgb(255 255 255 / .35), transparent 45%),
        linear-gradient(150deg, var(--g1), var(--g2));
    overflow: hidden;
}
.tile-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.muted-block { color: var(--text-2); font-size: 14px; padding: 4px 2px; }
.tile-badge {
    position: absolute; left: 8px; top: 8px;
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgb(0 0 0 / .55);
    backdrop-filter: blur(6px);
    color: #fff;
    font-size: 11px; font-weight: 600;
}
.tile-badge i { animation: spin 1.2s linear infinite; }
.tile-meta { display: flex; flex-direction: column; min-width: 0; }
.tile-prompt {
    font-size: 13px; font-weight: 600;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile-sub { font-size: 12px; color: var(--text-3); }

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

/* Lista de chats */
.chat-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.chat-list li + li { border-top: 1px solid var(--border); }
.chat-item { display: flex; gap: 12px; padding: 14px; transition: background .15s; }
.chat-item:active, .chat-item:hover { background: var(--surface-2); }
.chat-avatar {
    width: 40px; height: 40px; flex-shrink: 0;
    display: grid; place-items: center;
    border-radius: 12px;
    background: var(--chat-soft); color: var(--chat);
    font-size: 17px;
}
.chat-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.chat-top { display: flex; justify-content: space-between; gap: 8px; }
.chat-top strong { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-top time { font-size: 12px; color: var(--text-3); flex-shrink: 0; }
.chat-preview { font-size: 13.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-model { font-size: 11.5px; color: var(--text-3); font-weight: 600; }

/* ---------- Composer ---------- */
.composer-wrap {
    flex-shrink: 0;
    padding: 8px 10px calc(8px + var(--safe-b));
    background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer-inner { max-width: 860px; margin: 0 auto; }

.option-row {
    display: flex; align-items: center; gap: 8px;
    overflow-x: auto;
    padding: 2px 24px 8px 2px;
    scrollbar-width: none;
    /* desvanecido a la derecha: indica que se puede deslizar */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
            mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}
.option-row::-webkit-scrollbar { display: none; }

.segmented {
    display: inline-flex;
    padding: 3px;
    border-radius: 999px;
    background: var(--surface-2);
    flex-shrink: 0;
}
.segmented button {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 13px;
    border-radius: 999px;
    font-size: 13.5px; font-weight: 600;
    color: var(--text-2);
    transition: background .2s, color .2s;
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 4px rgb(0 0 0 / .12); }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 13.5px; font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}
.chip > i:first-child { color: var(--accent); }
.chip .chev { font-size: 11px; color: var(--text-3); }

.composer {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 6px;
    box-shadow: var(--shadow-up);
    transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-up); }

.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer-btn { width: 44px; height: 44px; border-radius: 50%; }

.composer textarea {
    flex: 1;
    min-width: 0;
    resize: none;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 16px;               /* ≥16px evita el zoom automático en iOS */
    line-height: 1.4;
    padding: 11px 4px;
    max-height: 168px;
}
.composer textarea::placeholder { color: var(--text-3); }

.send-btn {
    width: 44px; height: 44px; flex-shrink: 0;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 20px;
    transition: transform .12s, opacity .15s, background .2s;
}
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { background: var(--surface-2); color: var(--text-3); cursor: default; }

.attach-preview {
    display: flex; align-items: center; gap: 10px;
    margin: 4px 4px 6px;
    padding: 6px 6px 6px 6px;
    border-radius: 14px;
    background: var(--surface-2);
    width: fit-content;
}
.attach-preview[hidden] { display: none; }
.attach-thumb { width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, #43cea2, #185a9d); }
.attach-name { font-size: 13px; font-weight: 600; }
.attach-remove { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); }

.composer-hint { text-align: center; font-size: 12px; color: var(--text-3); padding-top: 6px; }
.composer-hint b { color: var(--text-2); font-weight: 600; }

/* ---------- Bottom sheets ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.sheet-scrim {
    position: absolute; inset: 0;
    background: rgb(0 0 0 / .45);
    opacity: 0;
    transition: opacity .25s;
}
.sheet-panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    max-height: 85dvh;
    overflow-y: auto;
    padding: 10px 18px calc(18px + var(--safe-b));
    background: var(--surface);
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { pointer-events: auto; }
.sheet.open .sheet-scrim { opacity: 1; }
.sheet.open .sheet-panel { transform: none; }

.sheet-grabber { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 14px; }
.sheet h3 { font-size: 18px; font-weight: 700; margin-bottom: 14px; }

.model-list { flex-direction: column; gap: 6px; }
.model-option {
    display: flex; align-items: center; gap: 12px;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid var(--border);
    text-align: left;
}
.model-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.model-icon {
    width: 40px; height: 40px; flex-shrink: 0;
    display: grid; place-items: center;
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--accent);
    font-size: 18px;
}
.model-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.model-text strong { font-size: 15px; }
.model-text small { font-size: 12.5px; color: var(--text-2); }
.model-cost { font-size: 12px; font-weight: 600; color: var(--text-3); white-space: nowrap; }
.model-check { display: none; color: var(--accent); font-size: 18px; }
.model-option.selected .model-check { display: inline; }
.model-option.selected .model-cost { display: none; }

.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 16px 0 8px; }
.field-label:first-of-type { margin-top: 0; }

.ratio-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.ratio-opt {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px;
    height: 84px;
    padding: 10px 4px;
    border-radius: 14px;
    border: 1px solid var(--border);
    font-size: 12.5px; font-weight: 600;
}
.ratio-shape {
    --max: 34px;
    width:  calc(var(--max) * min(1, var(--w) / var(--h)));
    height: calc(var(--max) * min(1, var(--h) / var(--w)));
    border: 2px solid currentColor;
    border-radius: 5px;
    opacity: .7;
}
.ratio-shape.ratio-auto { --w: 1; --h: 1; border-style: dashed; }
.ratio-opt.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.pill-group { display: flex; gap: 8px; }
.pill {
    flex: 1;
    padding: 11px;
    border-radius: 12px;
    border: 1px solid var(--border);
    font-weight: 600;
}
.pill.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%; top: calc(14px + var(--safe-t));
    z-index: 80;
    transform: translate(-50%, -20px);
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg);
    font-size: 13.5px; font-weight: 600;
    opacity: 0; pointer-events: none;
    transition: opacity .2s, transform .2s;
    white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================================================
   Tablet (≥ 768px)
   ============================================================ */
@media (min-width: 768px) {
    .content-inner { padding: 16px 28px 32px; gap: 32px; }
    .quick-grid { grid-template-columns: repeat(4, 1fr); }
    .tile { width: 200px; }
    .composer-wrap { padding: 10px 24px calc(14px + var(--safe-b)); }
    .option-row { -webkit-mask-image: none; mask-image: none; }

    /* El sheet se vuelve un diálogo centrado */
    .sheet-panel {
        left: 50%; bottom: 50%;
        width: min(480px, calc(100vw - 48px));
        border-radius: 24px;
        transform: translate(-50%, 60%) scale(.96);
        opacity: 0;
        transition: transform .25s, opacity .2s;
    }
    .sheet.open .sheet-panel { transform: translate(-50%, 50%); opacity: 1; }
    .sheet-grabber { display: none; }
}

/* ============================================================
   Escritorio (≥ 1024px): sidebar fija
   ============================================================ */
@media (min-width: 1024px) {
    .only-mobile  { display: none !important; }
    .only-desktop { display: inline-grid !important; }

    .sidebar {
        position: static;
        transform: none;
        width: var(--sidebar-w);
        flex-shrink: 0;
        background: var(--bg);
    }
    .scrim { display: none; }

    .topbar { padding: 14px 24px 6px; }

    /* Galería en cuadrícula en vez de tira */
    .gallery-strip {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        margin: 0; padding: 0;
        overflow: visible;
    }
    .tile { width: auto; max-width: none; }
    .tile-img { transition: transform .2s; }
    .tile:hover .tile-img { transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
