/* Numerario Brand Identity (cirugía 2026-05-07; nombres `--ti-*` preservados
   para minimizar blast radius, valores ahora apuntan a Numerario tokens)
   Primary:   #1B3A5C (Tinta Senado)  |  #1F3A5F (Acero Verificado, CTA)
   Surface:   #F4EFE6 / #FBF8F1 (Pergamino)
   Accent:    #2F5D4F (Verde Erario)  |  #6B7385 (Stone)
   Typography: IBM Plex Sans body + EB Garamond display + IBM Plex Mono code

   Light theme (default — Pergamino) + Dark theme via [data-theme="dark"] on <html>.
   Source of truth: ~/Research/finops-research-2025/06-lanzamiento/MARCA-Y-BRANDING.md §7
*/

:root {
    /* Brand primaries — Numerario tokens, kept in --ti-* names for compat */
    --ti-dark-teal: #1B3A5C;     /* Tinta Senado */
    --ti-light-teal: #1F3A5F;    /* Acero Verificado (CTA digital) */
    --ti-sky: #2F5D4F;           /* Verde Erario (success / verificado FOCUS) */
    --ti-gray: #6B7385;          /* Stone (texto secundario) */

    /* Light theme tokens — Pergamino canvas */
    --ti-bg: #F4EFE6;            /* Pergamino */
    --ti-surface: #FBF8F1;       /* Pergamino-50 */
    --ti-ink: #1B3A5C;           /* Tinta Senado */
    --ti-muted: #6B7385;         /* Stone */
    --ti-border: #E6DFD0;        /* Pergamino-warm border */
    --ti-user-bubble: var(--ti-light-teal);  /* Acero Verificado */
    --ti-user-ink: #FBF8F1;
    --ti-assistant-bubble: #FBF8F1;
    --ti-code-bg: rgba(31, 58, 95, 0.08);
    --ti-pre-bg: #F4EFE6;
    --ti-logo-plate: transparent;
    --ti-shadow: 0 6px 24px rgba(14, 27, 44, 0.08);
}

[data-theme="dark"] {
    --ti-bg: #0E1B2C;            /* Tinta Senado dense */
    --ti-surface: #142235;       /* Slightly lighter panel */
    --ti-ink: #F4EFE6;           /* Pergamino on dark */
    --ti-muted: #8FA1B6;
    --ti-border: #1F3047;
    --ti-user-bubble: var(--ti-light-teal);
    --ti-user-ink: #0E1B2C;
    --ti-assistant-bubble: #1A2940;
    --ti-code-bg: rgba(244, 239, 230, 0.10);
    --ti-pre-bg: #0F1D31;
    --ti-logo-plate: transparent;
    --ti-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

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

html, body { height: 100%; }

body {
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-weight: 400;
    background: var(--ti-bg);
    color: var(--ti-ink);
    display: flex;
    justify-content: center;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.container {
    width: 100%;
    max-width: 860px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--ti-surface);
    box-shadow: var(--ti-shadow);
}

/* ─── Header ───
   Light theme: teal gradient (color logo pops on it).
   Dark theme : solid dark header (per brand manual p.13 — gray/white
                logo should sit on a dark background, not on the
                teal gradient where it looks washed out).
*/
header {
    padding: 18px 28px;
    background: linear-gradient(90deg, var(--ti-dark-teal) 0%, var(--ti-light-teal) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

[data-theme="dark"] header {
    background: #0a1416;                       /* deeper than chat bg for contrast */
    border-bottom: 1px solid #1f2e33;
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.logo {
    /* Gray/white logo sits directly on the header (teal gradient in light,
       solid dark in dark). No plate, no shadow. */
    height: 44px;
    width: auto;
    padding: 4px 6px;
    border-radius: 8px;
    background: var(--ti-logo-plate);
    transition: background-color 0.2s ease;
}

.brand-text h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.2px;
    line-height: 1.2;
}

.subtitle {
    font-size: 0.82rem;
    font-weight: 300;
    opacity: 0.9;
    margin-top: 3px;
}

/* ─── Header action cluster (language + theme + clear) ─── */
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.icon-btn,
.pill-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
    flex-shrink: 0;
    font-family: inherit;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
}

.pill-btn {
    padding: 0 12px;
    height: 36px;
    border-radius: 18px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
}

.icon-btn:hover,
.pill-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.55);
}
.icon-btn:active,
.pill-btn:active { transform: translateY(1px); }

/* Export dropdown */
.export-wrapper {
    position: relative;
    display: inline-block;
}
.export-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 200px;
    background: var(--ti-surface);
    border: 1px solid var(--ti-border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding: 6px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
[data-theme="dark"] .export-menu {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.export-menu[hidden] { display: none; }
.export-menu-item {
    background: transparent;
    border: none;
    color: var(--ti-ink);
    padding: 9px 12px;
    font-size: 0.88rem;
    font-family: inherit;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s ease, color 0.1s ease;
}
.export-menu-item:hover {
    background: rgba(67, 164, 188, 0.12);
    color: var(--ti-light-teal);
}

/* Theme button: show sun in light mode, moon in dark mode */
#theme-btn .icon-moon { display: none; }
[data-theme="dark"] #theme-btn .icon-sun { display: none; }
[data-theme="dark"] #theme-btn .icon-moon { display: inline; }

/* ─── Chat area ─── */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--ti-bg);
}

.message {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    position: relative;
}
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

/* Message action cluster (copy + download) on assistant bubbles */
.msg-actions {
    display: inline-flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
    flex-shrink: 0;
    margin-bottom: 4px;
}
.message.assistant:hover .msg-actions { opacity: 1; }

.msg-action-btn {
    background: transparent;
    border: 1px solid var(--ti-border);
    color: var(--ti-muted);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.msg-action-btn:hover {
    background: rgba(67, 164, 188, 0.12);
    color: var(--ti-light-teal);
    border-color: var(--ti-light-teal);
}
.msg-action-btn.active {
    background: var(--ti-light-teal);
    border-color: var(--ti-light-teal);
    color: #fff;
}

.bubble {
    max-width: 82%;
    padding: 13px 18px;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.55;
    font-weight: 400;
}

.user .bubble {
    background: var(--ti-user-bubble);
    color: var(--ti-user-ink);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 6px rgba(31, 91, 101, 0.15);
}

.assistant .bubble {
    background: var(--ti-assistant-bubble);
    color: var(--ti-ink);
    border: 1px solid var(--ti-border);
    border-bottom-left-radius: 4px;
}

.bubble ul { margin: 8px 0 0 20px; }
.bubble li { margin: 5px 0; }
.bubble strong { font-weight: 700; color: var(--ti-light-teal); }
[data-theme="light"] .bubble strong,
:root:not([data-theme="dark"]) .bubble strong { color: var(--ti-dark-teal); }
.user .bubble strong { color: var(--ti-user-ink); }
.bubble a { color: var(--ti-light-teal); }

.bubble code {
    background: var(--ti-code-bg);
    color: var(--ti-light-teal);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
[data-theme="light"] .bubble code,
:root:not([data-theme="dark"]) .bubble code { color: var(--ti-dark-teal); }
.user .bubble code { background: rgba(255, 255, 255, 0.18); color: var(--ti-user-ink); }

.bubble pre {
    background: var(--ti-pre-bg);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    border-left: 3px solid var(--ti-light-teal);
}
.bubble pre code { background: none; padding: 0; color: var(--ti-ink); }

.bubble h1, .bubble h2, .bubble h3 {
    margin: 14px 0 6px;
    font-weight: 700;
    color: var(--ti-light-teal);
}
[data-theme="light"] .bubble h1, [data-theme="light"] .bubble h2, [data-theme="light"] .bubble h3,
:root:not([data-theme="dark"]) .bubble h1, :root:not([data-theme="dark"]) .bubble h2, :root:not([data-theme="dark"]) .bubble h3 { color: var(--ti-dark-teal); }
.user .bubble h1, .user .bubble h2, .user .bubble h3 { color: var(--ti-user-ink); }

.bubble h1 { font-size: 1.15rem; }
.bubble h2 { font-size: 1.05rem; }
.bubble h3 { font-size: 0.98rem; }

.bubble p { margin: 6px 0; }

.bubble .capability-list {
    list-style: none;
    margin-left: 0;
}

.bubble .capability-list li {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px;
}

.capability-chip {
    appearance: none;
    border: 1px solid var(--ti-border);
    border-radius: 999px;
    background: var(--ti-code-bg);
    color: var(--ti-light-teal);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    line-height: 1.2;
    padding: 3px 9px;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
}

[data-theme="light"] .capability-chip,
:root:not([data-theme="dark"]) .capability-chip {
    color: var(--ti-dark-teal);
}

.capability-chip:hover {
    background: var(--ti-surface);
    border-color: var(--ti-light-teal);
    color: var(--ti-light-teal);
}

[data-theme="light"] .capability-chip:hover,
:root:not([data-theme="dark"]) .capability-chip:hover {
    color: var(--ti-dark-teal);
}

.capability-chip:focus-visible,
.starter-card:focus-visible {
    outline: 2px solid var(--ti-light-teal);
    outline-offset: 2px;
}

.capability-chip:active,
.starter-card:active {
    transform: translateY(1px);
}

.starter-prompts {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    width: 100%;
}

.starter-card {
    appearance: none;
    min-height: 96px;
    padding: 14px;
    border: 1px solid var(--ti-border);
    border-radius: 8px;
    background: var(--ti-assistant-bubble);
    color: var(--ti-ink);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font: inherit;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.starter-card:hover {
    background: var(--ti-code-bg);
    border-color: var(--ti-light-teal);
}

.starter-card-label {
    color: var(--ti-light-teal);
    display: block;
    font-weight: 700;
    line-height: 1.25;
}

[data-theme="light"] .starter-card-label,
:root:not([data-theme="dark"]) .starter-card-label {
    color: var(--ti-dark-teal);
}

.starter-card-description {
    color: var(--ti-muted);
    display: block;
    font-size: 0.88rem;
    line-height: 1.35;
}

.bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 0.88em;
}
.bubble th, .bubble td {
    border: 1px solid var(--ti-border);
    padding: 8px 12px;
    text-align: left;
}
.bubble th { background: rgba(67, 164, 188, 0.10); color: var(--ti-light-teal); font-weight: 500; }
[data-theme="light"] .bubble th,
:root:not([data-theme="dark"]) .bubble th { color: var(--ti-dark-teal); }

/* ─── Input area ─── */
.input-area {
    padding: 16px 28px;
    border-top: 1px solid var(--ti-border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--ti-surface);
}

#user-input {
    flex: 1;
    padding: 12px 14px;
    border: 1.5px solid var(--ti-border);
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.2s ease, color 0.2s ease;
    color: var(--ti-ink);
    background: var(--ti-surface);
}

#user-input::placeholder { color: var(--ti-muted); opacity: 0.75; }

#user-input:focus {
    border-color: var(--ti-light-teal);
    box-shadow: 0 0 0 3px rgba(67, 164, 188, 0.18);
}

#send-btn {
    padding: 12px 26px;
    background: var(--ti-dark-teal);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.05s ease;
}

#send-btn:hover { background: var(--ti-light-teal); }
#send-btn:active { transform: translateY(1px); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Footer ─── */
.app-footer {
    padding: 8px 28px;
    border-top: 1px solid var(--ti-border);
    background: var(--ti-surface);
    color: var(--ti-muted);
    font-size: 0.75rem;
    font-weight: 300;
    text-align: center;
}

.app-footer a {
    color: var(--ti-light-teal);
    text-decoration: none;
    font-weight: 500;
}
.app-footer a:hover { text-decoration: underline; }

/* ─── Loading indicator ─── */
.loading .bubble::after {
    content: '...';
    animation: dots 1s steps(3, end) infinite;
    color: var(--ti-light-teal);
}

@keyframes dots {
    0% { content: '.'; }
    33% { content: '..'; }
    66% { content: '...'; }
}

/* ─── Mobile ─── */
@media (max-width: 600px) {
    header { padding: 12px 14px; gap: 8px; }
    .brand { gap: 10px; }
    .logo { height: 30px; padding: 2px 4px; }
    .brand-text h1 { font-size: 1.05rem; }
    .subtitle { display: none; }              /* conserve space */
    .header-actions { gap: 6px; }
    .icon-btn { width: 32px; height: 32px; }
    .pill-btn { height: 32px; padding: 0 10px; font-size: 0.72rem; }
    .chat-area { padding: 14px 16px; }
    .input-area { padding: 12px 16px; }
    .bubble { max-width: 88%; font-size: 0.92rem; }
    .msg-actions { opacity: 1; }
    .starter-prompts { grid-template-columns: 1fr; }
    .starter-card { min-height: auto; }
}

@media (min-width: 601px) and (max-width: 760px) {
    .starter-prompts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
