/*
|--------------------------------------------------------------------------
| M.IA - Estilos
|--------------------------------------------------------------------------
|
| 1. Tokens de diseño  <- la identidad visual (colores, tipografía, radios)
|                         se cambia SOLO aquí.
| 2. Base
| 3. Componentes (botones, formularios, tarjetas, alertas, insignias)
| 4. Páginas de acceso (login, registro)
| 5. Páginas de cuenta (memorias, perfil, preferencias)
| 6. Chat
| 7. Markdown de las respuestas
| 8. Responsive
|
*/

/* 1. Tokens ------------------------------------------------------------ */
/*
   Paleta extraída del logo de M.IA:
     menta claro  #9CDBAE   (parte alta del degradado de "m.ia")
     menta        #6CC29F   (color principal, parte baja del degradado)
     verde texto  #2F855F   (versión oscurecida para texto/enlaces: contraste AA sobre blanco)
     pizarra      #36424A   (pantalla/cara de la mascota)
   Tipografía: Nunito (redondeada, como las letras del logo).
*/

:root {
    color-scheme: light;

    --mint-light: #9cdbae;
    --mint: #6cc29f;
    --mint-dark: #5ab18d;
    --green-text: #2f855f;
    --slate: #36424a;

    --brand: var(--mint);
    --brand-hover: var(--mint-dark);
    --brand-contrast: var(--slate);      /* texto sobre menta: contraste 4.8:1 */
    --brand-gradient: linear-gradient(180deg, var(--mint-light) 0%, var(--mint) 100%);
    --link: var(--green-text);
    --focus: var(--green-text);
    --accent: #f5b83d;

    --bg: #f5f8f6;
    --surface: #ffffff;
    --surface-2: #eef4f0;
    --text: #26303a;
    --muted: #6b7a77;
    --border: #e1eae5;

    --ok-bg: #e8f7ef;
    --ok-text: #1f6f4e;
    --error-bg: #fdf0ef;
    --error-text: #b42318;
    --highlight-bg: #fff8e6;

    --user-bubble: #e3f5ea;
    --user-bubble-text: var(--slate);
    --assistant-bubble: #ffffff;

    --badge-user-bg: #e3f5ea;
    --badge-user-text: #1f6f4e;

    --code-bg: #2b343a;
    --code-head: #36424a;
    --code-text: #e8eeeb;

    --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(38, 48, 58, .04), 0 6px 20px rgba(38, 48, 58, .05);

    --sidebar-width: 290px;
}

/* Modo oscuro automático según el dispositivo */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;

        --brand: var(--mint);
        --brand-hover: var(--mint-light);
        --brand-contrast: #13201a;
        --link: #8fd9ae;
        --focus: #8fd9ae;

        --bg: #151b1e;
        --surface: #1c2427;
        --surface-2: #263034;
        --text: #e6edea;
        --muted: #97a6a2;
        --border: #2e393d;

        --ok-bg: #173327;
        --ok-text: #9ee2bb;
        --error-bg: #3a1e1c;
        --error-text: #ffb4ab;
        --highlight-bg: #3a3120;

        --user-bubble: #24483a;
        --user-bubble-text: #e6f5ec;
        --assistant-bubble: #1c2427;

        --badge-user-bg: #24483a;
        --badge-user-text: #bdebd0;

        --code-bg: #0f1416;
        --code-head: #1a2226;

        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    }
}

/* 2. Base -------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

h1, h2, h3 { font-weight: 800; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }

.muted { color: var(--muted); }

.container { max-width: 880px; margin: 0 auto; padding: 28px 18px 64px; }
.container.narrow { max-width: 560px; }

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.brand-mark { width: 34px; height: 34px; }

.brand-name {
    font-size: 1.45rem;
    font-weight: 900;
    letter-spacing: -.02em;
    line-height: 1;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.logo { display: block; width: fit-content; margin: 0 auto 8px; }
.logo img { display: block; width: 220px; max-width: 70vw; height: auto; }

/* 3. Componentes ------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .95rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s, transform .1s;
}

.btn:active { transform: translateY(1px); }

.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger { color: var(--error-text); }
.btn-sm { padding: 5px 11px; font-size: .85rem; }
.btn-block { width: 100%; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-size: 1.15rem;
    cursor: pointer;
}

.icon-btn:hover { background: var(--surface-2); }

.form { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: .9rem; font-weight: 600; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .95rem;
}

textarea { min-height: 72px; resize: vertical; }

input:focus, select:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible, a:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

.form-actions { display: flex; gap: 10px; justify-content: flex-end; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 20px;
    box-shadow: var(--shadow);
}

.card-highlight { border-color: var(--accent); background: var(--highlight-bg); }

.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: .92rem; margin: 14px 0; }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }

.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    font-size: .75rem;
    line-height: 1.6;
}

.badge-user { background: var(--badge-user-bg); color: var(--badge-user-text); }
.badge-alert { background: var(--accent); color: #26303a; font-weight: 800; margin-left: 6px; }

/* 4. Acceso ------------------------------------------------------------ */

.page-center {
    display: grid;
    place-items: center;
    min-height: 100%;
    padding: 24px 16px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 28px;
    box-shadow: var(--shadow);
}

.auth-card { text-align: center; }
.auth-card h1 { font-size: 1.45rem; margin-top: 10px; }
.auth-card .form { text-align: left; }
.auth-switch a { color: var(--link); font-weight: 700; }
.auth-card .form { margin-top: 20px; }
.auth-switch { margin: 20px 0 0; font-size: .92rem; color: var(--muted); text-align: center; }

/* 5. Cuenta ------------------------------------------------------------ */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }

.topbar-nav a {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: .93rem;
    color: var(--muted);
    white-space: nowrap;
}

.topbar-nav a:hover { background: var(--surface-2); color: var(--text); }
.topbar-nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.topbar-logout { margin: 0; }

.memory { padding: 14px 0; border-top: 1px solid var(--border); }
.memory:first-of-type { border-top: none; }
.memory-text { font-size: .98rem; }
.memory-meta { margin-top: 6px; font-size: .8rem; color: var(--muted); }
.memory-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; margin-top: 10px; }
.memory-actions form { margin: 0; }
.memory-inactive .memory-text { color: var(--muted); }
.memory-group { margin: 22px 0 2px; font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.memory-grid { display: grid; grid-template-columns: 1fr 190px 110px; gap: 10px; }
.memory-edit { width: 100%; }
.memory-edit summary { list-style: none; }
.memory-edit summary::-webkit-details-marker { display: none; }
.memory-edit[open] summary { margin-bottom: 10px; }
.memory-edit:not([open]) { width: auto; }

.change-old { color: var(--muted); text-decoration: line-through; }
.change-new { font-weight: 600; }

.details-title { cursor: pointer; font-weight: 600; }

/* 6. Chat -------------------------------------------------------------- */

/* El chat ocupa la pantalla completa debajo del menú superior. */
.page-chat { overflow: hidden; display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.page-chat .topbar { flex-shrink: 0; }

.chat-app { display: flex; flex: 1; min-height: 0; }

.sidebar-title { font-weight: 800; font-size: .95rem; color: var(--muted); }

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: var(--sidebar-width);
    flex-shrink: 0;
    padding: 16px 12px;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

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

.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }

.conv-item {
    display: block;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: .92rem;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); font-weight: 600; }
.conv-empty { padding: 8px 12px; font-size: .88rem; color: var(--muted); }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 10px; display: grid; gap: 2px; }
.sidebar-footer form { margin: 0; }

.sidebar-link {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 9px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    font-size: .92rem;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.sidebar-link:hover { background: var(--surface-2); }
.sidebar-logout { color: var(--error-text); }

.sidebar-backdrop { display: none; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.menu-toggle {
    display: none;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
}

.menu-toggle svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

.menu-toggle:hover { background: var(--surface-2); }

.welcome-recent { display: grid; gap: 8px; margin: 22px auto 0; max-width: 360px; text-align: left; }
.welcome-recent-title { margin: 0; font-size: .8rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); text-align: center; }
.welcome-recent-item {
    display: block;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: .92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.welcome-recent-item:hover { border-color: var(--mint); }
.welcome-recent-all { border: none; background: none; color: var(--link); font: inherit; font-weight: 700; font-size: .88rem; cursor: pointer; padding: 4px; }

.chat-title {
    flex: 1;
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-actions { display: flex; gap: 4px; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px max(18px, calc((100% - 820px) / 2));
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
}

.welcome { margin: auto; text-align: center; max-width: 480px; }
.welcome-mascot { width: 120px; height: auto; margin-bottom: 10px; animation: mia-float 4s ease-in-out infinite; }

@keyframes mia-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
    .welcome-mascot, .typing .dot { animation: none; }
}
.welcome-title { font-size: 1.6rem; margin: 0 0 8px; }
.welcome-text { color: var(--muted); margin: 0; }

.message { display: flex; flex-direction: column; max-width: 100%; }
.message-user { align-items: flex-end; }
.message-assistant { align-items: flex-start; flex-direction: row; gap: 10px; }
.message-assistant .message-body { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: 100%; }
.avatar { width: 32px; height: 32px; flex-shrink: 0; margin-top: 2px; }

.bubble {
    max-width: min(760px, 88%);
    padding: 11px 15px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.message-user .bubble {
    background: var(--user-bubble);
    color: var(--user-bubble-text);
    border-bottom-right-radius: 5px;
    white-space: pre-wrap;
}

.message-assistant .bubble {
    background: var(--assistant-bubble);
    border: 1px solid var(--border);
    border-bottom-left-radius: 5px;
    max-width: min(820px, 100%);
}

.bubble-error { background: var(--error-bg) !important; color: var(--error-text); border-color: transparent !important; }
.message-error { margin-top: 6px; font-size: .85rem; color: var(--error-text); }

.message-actions { display: flex; gap: 4px; margin-top: 4px; opacity: .7; }
.message-actions:hover { opacity: 1; }

.message-action {
    padding: 3px 8px;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: .8rem;
    cursor: pointer;
}

.message-action:hover { background: var(--surface-2); color: var(--text); }

.typing { display: inline-flex; gap: 5px; align-items: center; min-height: 44px; }

.typing .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--brand);
    animation: mia-blink 1.2s infinite ease-in-out;
}

.typing .dot:nth-child(2) { animation-delay: .2s; }
.typing .dot:nth-child(3) { animation-delay: .4s; }

@keyframes mia-blink {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.composer {
    padding: 12px max(18px, calc((100% - 820px) / 2)) max(12px, env(safe-area-inset-bottom));
    background: var(--bg);
}

.composer-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.composer-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(108, 194, 159, .18); }

.composer textarea {
    flex: 1;
    min-height: 40px;
    max-height: 220px;
    padding: 9px 8px;
    border: none;
    background: transparent;
    resize: none;
    line-height: 1.45;
}

.composer textarea:focus { outline: none; }

.composer-send { border-radius: 12px; }
.send-icon { display: none; width: 20px; height: 20px; fill: currentColor; }
.composer.is-sending .composer-send { opacity: .55; }
.composer-hint { margin: 6px 0 0; text-align: center; font-size: .75rem; color: var(--muted); }
.composer-hint.hint-warning { display: block !important; }

/* 7. Markdown ---------------------------------------------------------- */

.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 .75em; }
.markdown h3, .markdown h4, .markdown h5, .markdown h6 { margin: 1.1em 0 .5em; line-height: 1.3; }
.markdown h3 { font-size: 1.2rem; }
.markdown h4 { font-size: 1.08rem; }
.markdown h5, .markdown h6 { font-size: 1rem; }
.markdown ul, .markdown ol { margin: 0 0 .75em; padding-left: 1.4em; }
.markdown li { margin: .2em 0; }
.markdown li.task { list-style: none; margin-left: -1.2em; }
.markdown a { color: var(--link); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }

.markdown blockquote {
    margin: 0 0 .75em;
    padding: 4px 14px;
    border-left: 3px solid var(--border);
    color: var(--muted);
}

.markdown code {
    font-family: var(--font-mono);
    font-size: .88em;
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--surface-2);
}

.code-block {
    margin: 0 0 .9em;
    border-radius: 12px;
    overflow: hidden;
    background: var(--code-bg);
    color: var(--code-text);
}

.code-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--code-head);
    font-size: .78rem;
    color: #b9c6c1;
}

.code-copy {
    padding: 2px 8px;
    border: 1px solid #54636b;
    border-radius: 6px;
    background: transparent;
    color: #dbe5e1;
    font: inherit;
    cursor: pointer;
}

.code-copy:hover { background: #45545c; }

.code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.code-block code { padding: 0; background: none; color: inherit; font-size: .86rem; line-height: 1.55; }

.table-wrap { overflow-x: auto; margin: 0 0 .9em; }
.markdown table { border-collapse: collapse; font-size: .92rem; min-width: 60%; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; vertical-align: top; overflow-wrap: normal; word-break: normal; }
.markdown th { background: var(--surface-2); font-weight: 600; }

/* 7a. Páginas públicas (inicio, legales) y acceso ---------------------- */

.public-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 18px 20px;
}

.public-actions { display: flex; gap: 8px; }

.hero {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    align-items: center;
    gap: 32px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 48px 20px 32px;
}

.hero h1 { font-size: clamp(2rem, 4.5vw, 3.2rem); font-weight: 900; line-height: 1.12; margin-bottom: 18px; }
.hero-lead { font-size: 1.15rem; color: var(--muted); max-width: 560px; margin: 0 0 28px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.hero-art { text-align: center; }
.hero-art img { width: min(300px, 70vw); height: auto; animation: mia-float 4s ease-in-out infinite; }

.text-brand {
    background: linear-gradient(180deg, var(--mint) 0%, var(--green-text) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.btn-lg { padding: 13px 24px; font-size: 1.05rem; border-radius: 12px; }

.features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 56px;
}

.feature {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}

.feature h2 { font-size: 1.1rem; margin-bottom: 6px; }
.feature p { margin: 0; color: var(--muted); }

.legal h2 { font-size: 1.1rem; margin: 28px 0 8px; }
.legal p, .legal li { line-height: 1.65; }
.legal a { color: var(--link); }
.legal ul { padding-left: 1.3em; }

.notice {
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: var(--highlight-bg);
    border: 1px solid var(--accent);
}

.legal-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    padding: 24px 16px;
    font-size: .85rem;
    color: var(--muted);
}

.legal-footer a { color: var(--muted); }
.auth-card .legal-footer { padding: 18px 0 0; }

.auth-mascot { width: 110px; height: auto; }

.form-link { margin: -4px 0 0; text-align: right; font-size: .88rem; }
.login-options { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.login-options .form-link { margin: 0; color: var(--link); }
.form-link a { color: var(--link); }
.form-inline-center { display: flex; justify-content: center; margin-top: 8px; }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; color: var(--muted); }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--mint); flex-shrink: 0; }
.check a { color: var(--link); }

.info-list { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; margin: 0; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.card-danger { border-color: var(--error-text); }
.card-danger h2 { color: var(--error-text); }

.chat-notice { margin: 12px max(18px, calc((100% - 820px) / 2)) 0; }
.hint-warning { color: var(--error-text) !important; font-weight: 700; }

/* 7c. Administración --------------------------------------------------- */

.container.wide { max-width: 1120px; }
.admin-tag {
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--slate);
    color: #fff;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 20px; }

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}

.stat-value { font-size: 1.7rem; font-weight: 900; line-height: 1.1; color: var(--text); }
.stat-label { margin-top: 4px; font-size: .85rem; color: var(--muted); font-weight: 700; }
.stat-hint { margin-top: 2px; font-size: .78rem; color: var(--muted); }

.chart { width: 100%; height: auto; display: block; }
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-bar { fill: var(--mint-light); }
.chart-bar-today { fill: var(--mint); }
.chart-value { fill: var(--text); font-size: 11px; font-weight: 700; font-family: var(--font); }
.chart-label { fill: var(--muted); font-size: 10px; font-family: var(--font); }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; white-space: nowrap; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-link { color: var(--link); font-weight: 700; text-decoration: none; }
.table-link:hover { text-decoration: underline; }
.table .badge { margin-left: 6px; }

.card-flush { padding: 0; overflow: hidden; }
.card-flush .table th:first-child, .card-flush .table td:first-child { padding-left: 18px; }
.pad { padding: 18px; margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.filters input[type="search"] { flex: 1; min-width: 200px; }
.filters select { width: auto; }
input[type="search"] {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .95rem;
}

.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; }

.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.admin-grid .card { margin-top: 20px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.admin-actions form { margin: 0; }

.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.checklist li { display: flex; gap: 10px; align-items: baseline; }
.check-ok span { color: var(--green-text); font-weight: 900; }
.check-fail { color: var(--error-text); font-weight: 700; }

.text-error { color: var(--error-text); font-weight: 700; }
.small { font-size: .82rem; }

.log-entry { border-bottom: 1px solid var(--border); }
.log-entry summary {
    display: flex;
    gap: 12px;
    align-items: baseline;
    padding: 10px 18px;
    cursor: pointer;
    font-size: .88rem;
    list-style: none;
}
.log-entry summary::-webkit-details-marker { display: none; }
.log-entry summary:hover { background: var(--surface-2); }
.log-level { width: 72px; flex-shrink: 0; font-size: .72rem; font-weight: 900; }
.log-error .log-level { color: var(--error-text); }
.log-warning .log-level { color: #b7791f; }
.log-info .log-level { color: var(--green-text); }
.log-time { flex-shrink: 0; color: var(--muted); }
.log-ref { flex-shrink: 0; }
.log-message { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-detail {
    margin: 0;
    padding: 12px 18px 16px;
    background: var(--code-bg);
    color: var(--code-text);
    font-size: .8rem;
    overflow-x: auto;
}

/* 7e. Herramientas: búsqueda en internet ------------------------------- */

.tool-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: .85rem;
    font-weight: 700;
}

.tool-status::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--mint);
    border-top-color: transparent;
    animation: mia-spin .8s linear infinite;
}

.sources {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    max-width: min(820px, 100%);
}

.sources-title { font-size: .78rem; font-weight: 800; color: var(--muted); margin-right: 2px; }

.source-chip {
    max-width: 220px;
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--link);
    font-size: .8rem;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.source-chip:hover { border-color: var(--mint); }

.search-suggestions {
    display: block;
    width: min(820px, 100%);
    height: 64px;
    margin-top: 6px;
    border: 0;
    background: transparent;
}

/* 7d. Voz ------------------------------------------------------------- */

.composer-mic, .composer-voice { width: 40px; height: 40px; color: var(--muted); flex-shrink: 0; }
.composer-mic svg, .composer-voice svg { width: 22px; height: 22px; fill: currentColor; }
.composer-mic:hover, .composer-voice:hover { color: var(--green-text); }

.composer-mic.is-listening {
    color: #fff;
    background: var(--error-text);
    animation: mia-pulse 1.2s ease-in-out infinite;
}

@keyframes mia-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(180, 35, 24, .45); }
    50% { box-shadow: 0 0 0 8px rgba(180, 35, 24, 0); }
}

.message-action.is-speaking { color: var(--green-text); font-weight: 800; }

.voice-active { overflow: hidden; }

.voice-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
    background: radial-gradient(circle at 50% 40%, var(--surface) 0%, var(--bg) 70%);
}

.voice-top { display: flex; justify-content: space-between; align-items: center; }

.voice-settings {
    align-self: flex-end;
    width: min(320px, 100%);
    margin-top: 8px;
    padding: 14px;
    display: grid;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.voice-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    text-align: center;
}

.voice-orb {
    position: relative;
    width: 210px;
    height: 210px;
    border: none;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 10px 40px rgba(108, 194, 159, .35);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: transform .2s ease;
    -webkit-tap-highlight-color: transparent;
}

.voice-orb img { width: 150px; height: auto; pointer-events: none; }

.voice-orb::before {
    content: "";
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    border: 4px solid var(--mint);
    opacity: 0;
}

.voice-overlay[data-state="listening"] .voice-orb::before { opacity: 1; animation: mia-ring 1.4s ease-out infinite; }
.voice-overlay[data-state="thinking"] .voice-orb::before {
    opacity: 1;
    border-color: var(--mint) transparent var(--mint-light) transparent;
    animation: mia-spin 1s linear infinite;
}
.voice-overlay[data-state="speaking"] .voice-orb { animation: mia-talk .9s ease-in-out infinite; }
.voice-overlay[data-state="paused"] .voice-orb { opacity: .75; box-shadow: var(--shadow); }

@keyframes mia-ring {
    0% { transform: scale(.92); opacity: .9; }
    100% { transform: scale(1.18); opacity: 0; }
}

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

@keyframes mia-talk {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.voice-status { margin: 0; font-size: 1.4rem; font-weight: 900; }

.voice-transcript {
    margin: 0;
    max-width: 560px;
    min-height: 3em;
    font-size: 1.05rem;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.voice-hint { margin: 0; text-align: center; font-size: .82rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
    .voice-orb, .voice-orb::before, .composer-mic.is-listening { animation: none !important; }
}

/* 7f. Planes y pagos --------------------------------------------------- */

.plans-intro { text-align: center; max-width: 640px; margin: 0 auto; }
.plan-current-note { margin: 10px 0 0; }

.plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
    margin-top: 28px;
}

.plan-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.plan-card h2 { margin: 0; font-size: 1.25rem; }
.plan-card .btn { margin-top: auto; }
.plan-card-paid { border-color: var(--mint); }
.plan-price { margin: 0; font-size: 1.9rem; font-weight: 900; }
.plan-period { font-size: .95rem; font-weight: 600; color: var(--muted); }
.plan-features { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.plan-features li { padding-left: 24px; position: relative; }
.plan-features li::before { content: "✓"; position: absolute; left: 0; color: var(--green-text); font-weight: 900; }
.plans-empty { text-align: center; margin-top: 24px; }

.checkout-price { font-size: 1.5rem; font-weight: 900; margin: 4px 0 0; }
.payment-qr { text-align: center; margin-bottom: 16px; }
.payment-qr img { width: 260px; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.payment-instructions {
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.receipt-image { display: block; max-width: 100%; max-height: 520px; border: 1px solid var(--border); border-radius: 10px; }
.reject-form { margin-top: 18px; }
.plan-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; align-items: end; }
.sidebar-upgrade { color: var(--green-text); font-weight: 800; }
.filters input[type="number"] { width: 210px; }

/* 7g. App instalable -------------------------------------------------- */

.install-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px max(18px, calc((100% - 820px) / 2)) 0;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--mint);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.install-banner img { width: 40px; height: 40px; flex-shrink: 0; }
.install-banner-text { flex: 1; display: grid; font-size: .88rem; line-height: 1.35; }
.install-banner-text span { color: var(--muted); }

@media (min-width: 861px) {
    .install-banner { display: none !important; }
}

.install-hero { text-align: center; margin-bottom: 10px; }
.install-hero img { width: 130px; height: auto; }
.install-steps { margin: 0; padding-left: 1.3em; display: grid; gap: 8px; line-height: 1.5; }
.install-note { text-align: center; margin-top: 20px; }
.install-guide .install-steps { font-size: .95rem; }
.hero-install { margin: 18px 0 0; }
.hero-install a { color: var(--link); font-weight: 700; }

/* 7h. Agenda ---------------------------------------------------------- */

.agenda-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.agenda-top h1 { margin: 0; }

.agenda-views { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 999px; }
.agenda-views a { padding: 6px 14px; border-radius: 999px; text-decoration: none; font-size: .9rem; font-weight: 700; color: var(--muted); }
.agenda-views a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.agenda-add { padding: 0; }
.agenda-add-summary { padding: 14px 18px; cursor: pointer; font-weight: 800; color: var(--green-text); list-style: none; }
.agenda-add-summary::-webkit-details-marker { display: none; }
.agenda-add[open] .agenda-add-summary { border-bottom: 1px solid var(--border); }
.agenda-add .agenda-form, .agenda-add > p { padding: 0 18px; }
.agenda-add .agenda-form { padding-top: 14px; }
.agenda-add > p { padding-bottom: 14px; }

.kind-switch { display: flex; gap: 8px; }
.kind-switch label { flex: 1; }
.kind-switch input { position: absolute; opacity: 0; pointer-events: none; }
.kind-switch span {
    display: block;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    font-weight: 700;
    cursor: pointer;
}
.kind-switch input:checked + span { border-color: var(--mint); background: var(--badge-user-bg); color: var(--badge-user-text); }
.kind-switch input:focus-visible + span { outline: 2px solid var(--focus); }

.agenda-form-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 10px; }
.agenda-more summary { cursor: pointer; font-size: .88rem; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.agenda-more[open] { display: grid; gap: 12px; }
input[type="date"], input[type="time"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .95rem;
}

.agenda-nav { display: flex; align-items: center; gap: 8px; margin: 26px 0 8px; }
.agenda-heading { flex: 1; margin: 0; font-size: 1.15rem; text-align: center; }

.agenda-day { display: flex; align-items: center; gap: 8px; margin: 22px 0 6px; font-size: .95rem; }
.agenda-day a { color: var(--text); text-decoration: none; }
.agenda-day.is-today a { color: var(--green-text); }
.agenda-day.is-overdue { color: var(--error-text); }
.agenda-empty { margin: 6px 0 12px; color: var(--muted); font-size: .92rem; }

.agenda-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.agenda-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--mint);
    border-radius: var(--radius-sm);
}

.agenda-item.agenda-task { border-left-color: var(--accent); }
.agenda-item.is-done { opacity: .6; }
.agenda-item.is-done .agenda-title { text-decoration: line-through; }

.agenda-time { min-width: 52px; font-weight: 800; font-variant-numeric: tabular-nums; font-size: .92rem; line-height: 1.3; }
.agenda-time small { display: block; font-weight: 600; color: var(--muted); }
.agenda-body { flex: 1; min-width: 0; }
.agenda-title { font-weight: 700; overflow-wrap: anywhere; }
.agenda-meta { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.agenda-notes { font-size: .88rem; margin-top: 6px; color: var(--muted); }
.agenda-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; align-items: flex-start; }
.agenda-actions form { margin: 0; }
.agenda-edit { width: 100%; }
.agenda-edit:not([open]) { width: auto; }
.agenda-edit summary { list-style: none; }
.agenda-edit summary::-webkit-details-marker { display: none; }
.agenda-edit[open] summary { margin-bottom: 10px; }

.agenda-check { margin: 0; }
.check-btn {
    width: 26px;
    height: 26px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    background: var(--surface);
    color: #fff;
    font-weight: 900;
    cursor: pointer;
    line-height: 1;
}
.agenda-item.is-done .check-btn { background: var(--mint); border-color: var(--mint); }

.agenda-changes { display: grid; gap: 6px; margin-top: 8px; max-width: min(820px, 100%); }
.agenda-change {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid var(--mint);
    border-radius: var(--radius-sm);
    background: var(--surface);
    text-decoration: none;
    color: var(--text);
    font-size: .88rem;
}
.agenda-change:hover { background: var(--surface-2); }
.agenda-change-icon { font-size: 1.2rem; }
.agenda-change-text { display: grid; }
.agenda-change-text span { color: var(--muted); font-size: .82rem; }
.agenda-deleted { border-color: var(--border); opacity: .75; }

@media (max-width: 640px) {
    .agenda-form-grid { grid-template-columns: 1fr 1fr; }
    .agenda-form-grid .field:first-child { grid-column: 1 / -1; }
}

/* 7i. Verificación anti-bots ----------------------------------------- */

/* Campo trampa: fuera de la vista de las personas, visible para los bots. */
.hp-field { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.captcha-box { min-height: 65px; display: flex; justify-content: center; }

/* 7j. Notificaciones -------------------------------------------------- */

.push-status { font-weight: 700; margin: 0 0 12px; }
.push-ios { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--highlight-bg); margin-bottom: 12px; }
.push-ios p { margin: 0 0 10px; }
.push-actions { justify-content: flex-start; flex-wrap: wrap; }

.agenda-push-cta {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 16px;
    padding: 12px 14px;
    border: 1px dashed var(--mint);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: .92rem;
}
.agenda-push-cta span:first-child { font-size: 1.4rem; }
.agenda-push-cta:hover { background: var(--surface-2); }

/* 7k. Calendarios externos -------------------------------------------- */

.agenda-sync-link { font-size: .88rem; font-weight: 700; color: var(--link); text-decoration: none; margin-left: auto; }
.calendar-buttons { display: grid; gap: 10px; margin-bottom: 18px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: .8rem; }

/* 7l. Notas ----------------------------------------------------------- */

.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-top: 18px; align-items: start; }

.note-card {
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 4px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    scroll-margin-top: 80px;
}

.note-card:target { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(108, 194, 159, .25); }
.note-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.note-head h2 { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }

.note-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.note-lines form { margin: 0; }

.note-line {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    width: 100%;
    padding: 7px 6px;
    border: none;
    border-radius: 8px;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: .95rem;
    text-align: left;
    cursor: pointer;
}

.note-line:hover { background: var(--surface-2); }

.note-check {
    flex-shrink: 0;
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    margin-top: 1px;
    border: 2px solid var(--accent);
    border-radius: 6px;
    color: #fff;
    font-size: .75rem;
    font-weight: 900;
}

.note-text { overflow-wrap: anywhere; white-space: pre-wrap; }
.note-lines .is-done .note-check { background: var(--mint); border-color: var(--mint); }
.note-lines .is-done .note-text { text-decoration: line-through; color: var(--muted); }
.note-meta { margin: 10px 0 0; font-size: .78rem; color: var(--muted); }
.note-card .agenda-edit form { display: grid; gap: 8px; }

/* 7b. Diálogos -------------------------------------------------------- */

.dialog {
    width: min(420px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}

.dialog::backdrop { background: rgba(21, 27, 30, .45); }
.dialog form { display: grid; gap: 16px; padding: 22px; margin: 0; }
.dialog-message { margin: 0; font-size: 1rem; font-weight: 600; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn-danger-solid { background: var(--error-text); border-color: var(--error-text); color: #fff; }
.btn-danger-solid:hover { opacity: .9; background: var(--error-text); }

/* 8. Responsive -------------------------------------------------------- */

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 30;
        width: min(86vw, var(--sidebar-width));
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, .15);
    }

    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-close { display: inline-grid; }
    .menu-toggle { display: inline-grid; }

    .sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 20;
        background: rgba(0, 0, 0, .35);
    }

    .chat-header { padding: 8px 10px; }
    .messages { padding: 18px 12px; }
    .composer { padding-left: 10px; padding-right: 10px; }
    .bubble { max-width: 92%; }
    .composer-hint { display: none; }
    .composer-send { width: 44px; height: 40px; padding: 0; }
    .send-text { display: none; }
    .send-icon { display: block; }
    .composer-mic, .composer-voice { width: 36px; }
}

@media (max-width: 760px) {
    .admin-grid { grid-template-columns: 1fr; }
    .topbar-admin .btn-ghost { display: none; }
    .log-entry summary { flex-wrap: wrap; gap: 4px 10px; }
    .log-message { white-space: normal; width: 100%; }
    .hero { grid-template-columns: 1fr; text-align: center; padding-top: 24px; }
    .hero-lead { margin-left: auto; margin-right: auto; }
    .hero-actions { justify-content: center; }
    .hero-art { order: -1; }
    .hero-art img { width: 180px; }
    .features { grid-template-columns: 1fr; }
    .public-header .btn-ghost { display: none; }
}

@media (max-width: 640px) {
    .stats { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 1.4rem; }
    .memory-grid { grid-template-columns: 1fr; }
    .info-list { grid-template-columns: 1fr; gap: 2px; }
    .info-list dd { margin-bottom: 10px; }
    .markdown table { font-size: .85rem; }
    .markdown th, .markdown td { padding: 5px 7px; }
    /* Menú superior en una sola fila deslizable (todas las páginas, también el chat). */
    .topbar { gap: 6px; padding: 8px 10px; }
    .topbar .brand-name { display: none; }
    .topbar .admin-tag { display: none; }
    .topbar-nav {
        flex: 1;
        min-width: 0;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 16px), transparent 100%);
    }
    .topbar-nav::-webkit-scrollbar { display: none; }
    .topbar-nav a { padding: 7px 10px; }
    .topbar-logout .btn { padding: 6px 8px; font-size: .88rem; }
    .chat-actions .btn { padding: 5px 8px; }
}
