:root {
    --bg: #0b0f14;
    --bg-soft: #111823;
    --panel: #151d29;
    --panel-2: #1b2533;
    --line: #24303f;
    --text: #e8edf3;
    --muted: #93a2b5;
    --accent: #ff8a3d;
    --accent-2: #ffc36b;
    --ok: #43d17a;
    --warn: #ffc857;
    --danger: #ff6b5e;
    --critical: #ff3b30;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.45);
}

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

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background:
        radial-gradient(1100px 600px at 12% -10%, rgba(255, 138, 61, 0.16), transparent 60%),
        radial-gradient(900px 500px at 95% 0%, rgba(90, 140, 255, 0.12), transparent 55%),
        var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app {
    max-width: 900px;
    height: 100dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

/* ------------------------------------------------------------ topbar */

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(11, 15, 20, 0.72);
    backdrop-filter: blur(14px);
    position: sticky; top: 0; z-index: 20;
}

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

.brand-logo {
    font-size: 1.9rem; line-height: 1;
    filter: drop-shadow(0 0 14px rgba(255, 138, 61, 0.45));
}

.brand-text h1 { font-size: 1.25rem; letter-spacing: -0.02em; }
.brand-text p { font-size: 0.78rem; color: var(--muted); }

.brand-status { display: flex; align-items: center; gap: 8px; }

.badge {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 0.72rem; font-weight: 600;
    padding: 6px 11px; border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--muted);
    white-space: nowrap;
}

.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-live { color: var(--ok); border-color: rgba(67, 209, 122, 0.35); }
.badge-sim { color: var(--accent-2); border-color: rgba(255, 195, 107, 0.35); }
.badge-error { color: var(--danger); border-color: rgba(255, 107, 94, 0.35); }
.badge-loading .dot { animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

.icon-btn {
    width: 36px; height: 36px; border-radius: 11px;
    border: 1px solid var(--line); background: var(--panel);
    color: var(--text); font-size: 1.15rem; cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
.icon-btn:hover { background: var(--panel-2); transform: translateY(-1px); }

/* ------------------------------------------------------- vehicle bar */

.vehicle-bar {
    border-bottom: 1px solid var(--line);
    background: rgba(17, 24, 35, 0.6);
    font-size: 0.85rem;
}

.vehicle-bar summary {
    display: flex; align-items: center; gap: 9px;
    padding: 11px 18px; cursor: pointer; color: var(--muted);
    list-style: none;
}
.vehicle-bar summary::-webkit-details-marker { display: none; }
.vehicle-bar summary:hover { color: var(--text); }
.vehicle-bar[open] .chev { transform: rotate(180deg); }
.chev { margin-left: auto; transition: transform 0.2s; }
.vehicle-summary-icon { font-size: 1rem; }
#vehicleSummary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.vehicle-form {
    display: grid; gap: 10px; padding: 4px 18px 16px;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.vehicle-form label {
    display: flex; flex-direction: column; gap: 5px;
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--muted); font-weight: 600;
}

.vehicle-form input, .vehicle-form select {
    font: inherit; font-size: 0.88rem; text-transform: none; letter-spacing: normal;
    padding: 9px 11px; border-radius: var(--radius-sm);
    border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
    outline: none; transition: border-color 0.15s;
}
.vehicle-form input:focus, .vehicle-form select:focus { border-color: var(--accent); }

/* ------------------------------------------------------------- chat */

.chat {
    flex: 1; overflow-y: auto; padding: 20px 18px 8px;
    display: flex; flex-direction: column; gap: 18px;
    scroll-behavior: smooth;
}

.welcome { text-align: center; padding: 26px 8px 10px; margin: auto 0; }
.welcome-logo { font-size: 3.4rem; filter: drop-shadow(0 0 24px rgba(255, 138, 61, 0.4)); }
.welcome h2 { font-size: 1.5rem; margin: 10px 0 8px; letter-spacing: -0.02em; }
.welcome p { color: var(--muted); max-width: 520px; margin: 0 auto; line-height: 1.55; font-size: 0.92rem; }

.examples {
    display: flex; flex-wrap: wrap; gap: 9px;
    justify-content: center; margin-top: 22px;
}

.chip {
    font: inherit; font-size: 0.8rem; text-align: left;
    padding: 9px 14px; border-radius: 999px; cursor: pointer;
    border: 1px solid var(--line); background: var(--panel); color: var(--muted);
    transition: all 0.16s; max-width: 100%;
}
.chip:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }

/* --------------------------------------------------------- mensajes */

.msg { display: flex; gap: 11px; animation: rise 0.28s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }

.msg-user { justify-content: flex-end; }
.msg-user .bubble {
    background: linear-gradient(135deg, var(--accent) 0%, #e8622a 100%);
    color: #1a0d03; font-weight: 500;
    border-radius: var(--radius) var(--radius) 4px var(--radius);
    max-width: min(78%, 620px);
}

.msg-bot .avatar {
    flex: 0 0 34px; width: 34px; height: 34px; border-radius: 11px;
    display: grid; place-items: center; font-size: 1.05rem;
    background: var(--panel-2); border: 1px solid var(--line);
}

.bubble-wrap { min-width: 0; flex: 1; }
.bubble { padding: 12px 15px; border-radius: var(--radius); line-height: 1.6; font-size: 0.92rem; overflow-wrap: anywhere; }
.msg-bot .bubble { background: var(--panel); border: 1px solid var(--line); border-top-left-radius: 4px; }

/* La tarjeta de diagnostico trae su propio marco: evita el doble padding. */
.msg-bot .bubble:has(> .diagnosis) { padding: 0; background: transparent; border: none; }
.msg-meta { font-size: 0.69rem; color: var(--muted); margin-top: 6px; }
.msg-user .msg-meta { text-align: right; }

.attach-preview { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 9px; }
.attach-preview img { width: 88px; height: 66px; object-fit: cover; border-radius: 9px; border: 1px solid var(--line); }

/* -------------------------------------------------------- diagnostico */

.diagnosis { display: flex; flex-direction: column; gap: 13px; }
.dx-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.urgency {
    font-size: 0.7rem; font-weight: 800; letter-spacing: 0.06em;
    text-transform: uppercase; padding: 5px 11px; border-radius: 999px;
    border: 1px solid currentColor;
}
.urgency-baja { color: var(--ok); background: rgba(67, 209, 122, 0.1); }
.urgency-media { color: var(--warn); background: rgba(255, 200, 87, 0.1); }
.urgency-alta { color: var(--accent); background: rgba(255, 138, 61, 0.12); }
.urgency-critica { color: var(--critical); background: rgba(255, 59, 48, 0.14); animation: critical 1.6s ease-in-out infinite; }

@keyframes critical {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.35); }
    50% { box-shadow: 0 0 0 7px rgba(255, 59, 48, 0); }
}

.confidence { font-size: 0.7rem; color: var(--muted); border: 1px solid var(--line); padding: 5px 10px; border-radius: 999px; }
.sim-tag { font-size: 0.68rem; color: var(--accent-2); border: 1px dashed rgba(255, 195, 107, 0.5); padding: 4px 9px; border-radius: 999px; }

.dx-summary { line-height: 1.65; }

.dx-block h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 7px; }
.dx-block ul, .dx-block ol { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; line-height: 1.55; font-size: 0.89rem; }

.dx-causes ul { list-style: none; padding-left: 0; }
.dx-causes li { padding: 9px 11px; border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--line); }
.cause-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.cause-name { font-weight: 600; }
.cause-why { font-size: 0.82rem; color: var(--muted); margin-top: 4px; line-height: 1.5; }

.prob { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 3px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.prob-alta { color: var(--danger); }
.prob-media { color: var(--warn); }
.prob-baja { color: var(--muted); }

.dx-avoid li::marker { color: var(--danger); }
.dx-actions li::marker { color: var(--ok); font-weight: 700; }

.dx-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 0.74rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
.dx-actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

.mini-btn {
    font: inherit; font-size: 0.76rem; padding: 6px 11px; cursor: pointer;
    border-radius: 999px; border: 1px solid var(--line);
    background: var(--panel-2); color: var(--muted); transition: all 0.15s;
}
.mini-btn:hover { color: var(--text); border-color: var(--accent); }

/* Escribiendo... */
.typing { display: inline-flex; gap: 5px; align-items: center; color: var(--muted); font-size: 0.85rem; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: bounce 1s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* --------------------------------------------------------- composer */

.composer {
    padding: 10px 18px 14px;
    border-top: 1px solid var(--line);
    background: rgba(11, 15, 20, 0.82);
    backdrop-filter: blur(14px);
    position: sticky; bottom: 0;
}

.attachments { display: flex; gap: 9px; flex-wrap: wrap; padding-bottom: 10px; }
.attachment { position: relative; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); }
.attachment img { display: block; width: 74px; height: 56px; object-fit: cover; }
.attachment button {
    position: absolute; top: 3px; right: 3px; width: 19px; height: 19px;
    border-radius: 50%; border: none; cursor: pointer; line-height: 1;
    background: rgba(0, 0, 0, 0.72); color: #fff; font-size: 0.72rem;
}

.composer-row {
    display: flex; align-items: flex-end; gap: 8px;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 7px;
    transition: border-color 0.16s;
}
.composer-row:focus-within { border-color: rgba(255, 138, 61, 0.6); }

.tool-btn {
    flex: 0 0 38px; width: 38px; height: 38px; border-radius: 11px;
    border: 1px solid transparent; background: var(--panel-2);
    color: var(--text); font-size: 1.02rem; cursor: pointer;
    transition: all 0.15s;
}
.tool-btn:hover { background: #223044; }
.tool-btn.recording { background: rgba(255, 59, 48, 0.18); border-color: var(--critical); animation: rec 1.1s infinite; }
@keyframes rec { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.4); } 50% { box-shadow: 0 0 0 8px rgba(255, 59, 48, 0); } }

#input {
    flex: 1; resize: none; border: none; outline: none; background: transparent;
    color: var(--text); font: inherit; font-size: 0.93rem; line-height: 1.5;
    max-height: 148px; padding: 9px 4px;
}

.send-btn {
    flex: 0 0 38px; width: 38px; height: 38px; border-radius: 11px; border: none;
    background: linear-gradient(135deg, var(--accent), #e8622a);
    color: #1a0d03; font-size: 1.02rem; cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
}
.send-btn:hover:not(:disabled) { transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.composer-foot {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 9px 3px 0; font-size: 0.74rem; color: var(--muted);
}

.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.switch input { accent-color: var(--accent); }

.voice-select {
    font: inherit; font-size: 0.74rem; max-width: 200px;
    padding: 4px 7px; border-radius: 8px;
    border: 1px solid var(--line); background: var(--bg-soft); color: var(--muted);
}

.hint { margin-left: auto; }
.hint.rec { color: var(--critical); font-weight: 600; }

.footer {
    padding: 9px 18px 11px; font-size: 0.69rem; color: var(--muted);
    text-align: center; border-top: 1px solid var(--line);
}
.footer-sep { margin: 0 6px; opacity: 0.5; }

/* Scrollbar */
.chat::-webkit-scrollbar { width: 9px; }
.chat::-webkit-scrollbar-thumb { background: var(--line); border-radius: 9px; }
.chat::-webkit-scrollbar-thumb:hover { background: #33445c; }

@media (max-width: 620px) {
    .topbar { padding: 11px 13px; }
    .brand-text p { display: none; }
    .chat { padding: 16px 13px 6px; }
    .composer { padding: 9px 13px 12px; }
    .welcome h2 { font-size: 1.25rem; }
    .dx-actions-row { width: 100%; }
}

@media print {
    .topbar, .composer, .vehicle-bar, .footer, .dx-actions-row { display: none !important; }
    body { background: #fff; color: #000; }
    .chat { overflow: visible; }
    .msg-user { display: none; }
    .bubble { border: 1px solid #ccc; }
}
