/* Cerebro — panel HMI (oscuro industrial). Componentes propios; el layout usa Tailwind. */

:root {
    --bg: #0a0e13;
    --panel: #10161e;
    --panel2: #151d27;
    --line: #1f2b39;
    --line2: #2a3a4d;
    --ink: #d5dfe9;
    --mute: #7a8ca0;
    --ok: #22c55e;
    --warn: #f5a524;
    --err: #f0443a;
    --info: #38bdf8;
    --accent: #38bdf8;
}

[x-cloak] { display: none !important; }

html, body { background: var(--bg); color: var(--ink); }

body {
    font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    background-image:
        linear-gradient(rgba(56, 189, 248, .035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(56, 189, 248, .035) 1px, transparent 1px);
    background-size: 32px 32px;
}

.mono { font-family: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #3b5069; }

/* ---------- Tarjetas / instrumentos ---------- */
.card {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
}
.card::before {
    content: "";
    position: absolute;
    top: -1px; left: -1px;
    width: 26px; height: 2px;
    background: var(--accent);
    border-top-left-radius: 6px;
}
.card-h {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .55rem .9rem;
    border-bottom: 1px solid var(--line);
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
    color: var(--mute);
}
.card-b { padding: .9rem; }

.kpi-v { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 2rem; line-height: 1; font-weight: 600; letter-spacing: -.02em; }
.kpi-l { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--mute); }

/* ---------- LEDs ---------- */
.led { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: #3a4655; box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }
.led-ok { background: var(--ok); box-shadow: 0 0 8px 1px rgba(34,197,94,.7); }
.led-warn { background: var(--warn); box-shadow: 0 0 8px 1px rgba(245,165,36,.7); animation: ledpulse 1.6s ease-in-out infinite; }
.led-err { background: var(--err); box-shadow: 0 0 9px 2px rgba(240,68,58,.8); animation: ledpulse .9s ease-in-out infinite; }
.led-info { background: var(--info); box-shadow: 0 0 8px 1px rgba(56,189,248,.7); }
.led-off { background: #3a4655; }
@keyframes ledpulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Botones y campos ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .42rem .8rem; border-radius: 5px;
    border: 1px solid var(--line2); background: var(--panel2); color: var(--ink);
    font-size: 12.5px; font-weight: 500; line-height: 1.2; cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; border-color: var(--line2); color: var(--mute); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04121a; font-weight: 600; }
.btn-primary:hover { background: #7dd3fc; border-color: #7dd3fc; color: #04121a; }
.btn-danger { border-color: rgba(240,68,58,.5); color: #ff8a82; }
.btn-danger:hover { background: rgba(240,68,58,.15); border-color: var(--err); color: #ffb0aa; }
.btn-ok { border-color: rgba(34,197,94,.5); color: #7ee2a3; }
.btn-ok:hover { background: rgba(34,197,94,.14); border-color: var(--ok); color: #b4f0c9; }
.btn-sm { padding: .25rem .55rem; font-size: 11.5px; }

.inp {
    width: 100%; padding: .45rem .6rem; border-radius: 5px;
    background: #0b1118; color: var(--ink);
    border: 1px solid var(--line2); font-size: 13.5px;
}
.inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56,189,248,.2); }
.inp::placeholder { color: #51647a; }
select.inp { appearance: auto; }
textarea.inp { resize: vertical; min-height: 4.5rem; }
.lbl { display: block; margin-bottom: .25rem; font-family: ui-monospace, Consolas, monospace; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--mute); }
.err-t { color: #ff8a82; font-size: 12px; margin-top: .25rem; }

.switch { position: relative; display: inline-block; width: 38px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #2a3646; border-radius: 20px; cursor: pointer; transition: .15s; border: 1px solid var(--line2); }
.switch span::before { content: ""; position: absolute; height: 14px; width: 14px; left: 3px; top: 2px; background: #9fb1c4; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: rgba(34,197,94,.3); border-color: var(--ok); }
.switch input:checked + span::before { transform: translateX(18px); background: var(--ok); }

/* ---------- Chips de clasificación / estado ---------- */
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .08rem .5rem; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.chip-urgente { background: rgba(240,68,58,.14); color: #ff8a82; border-color: rgba(240,68,58,.4); }
.chip-requiere_respuesta { background: rgba(245,165,36,.14); color: #fbbf5c; border-color: rgba(245,165,36,.4); }
.chip-informativo { background: rgba(56,189,248,.12); color: #7dd3fc; border-color: rgba(56,189,248,.35); }
.chip-ruido { background: rgba(122,140,160,.12); color: #94a3b8; border-color: rgba(122,140,160,.3); }
.chip-sin_clasificar { background: transparent; color: var(--mute); border-color: var(--line2); }
.chip-err { background: rgba(240,68,58,.14); color: #ff8a82; border-color: rgba(240,68,58,.4); }
.chip-ok { background: rgba(34,197,94,.14); color: #7ee2a3; border-color: rgba(34,197,94,.4); }
.chip-warn { background: rgba(245,165,36,.14); color: #fbbf5c; border-color: rgba(245,165,36,.4); }
.chip-off { background: rgba(122,140,160,.12); color: #94a3b8; border-color: rgba(122,140,160,.3); }

.bar-track { height: 8px; background: #0b1118; border: 1px solid var(--line); border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 1px; transition: width .4s; }
.bar-urgente { background: var(--err); }
.bar-requiere_respuesta { background: var(--warn); }
.bar-informativo { background: var(--info); }
.bar-ruido { background: #64748b; }
.bar-sin_clasificar { background: #334155; }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 34px; }
.spark i { display: block; width: 7px; min-height: 2px; background: rgba(56,189,248,.55); border-radius: 1px; }
.spark i:last-child { background: var(--accent); }

/* ---------- Navegación ---------- */
.nav-link {
    display: flex; align-items: center; gap: .7rem;
    padding: .55rem .9rem; border-left: 2px solid transparent;
    color: var(--mute); font-size: 13.5px; text-decoration: none;
}
.nav-link:hover { color: var(--ink); background: rgba(255,255,255,.03); }
.nav-link.active { color: #fff; border-left-color: var(--accent); background: rgba(56,189,248,.08); }
.nav-link svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Tablas y listas ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; padding: .45rem .7rem; font-family: ui-monospace, Consolas, monospace; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--mute); border-bottom: 1px solid var(--line); font-weight: 500; }
.tbl td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:hover td { background: rgba(255,255,255,.02); }

.row-item { display: block; width: 100%; text-align: left; padding: .6rem .85rem; border-bottom: 1px solid var(--line); background: transparent; color: inherit; cursor: pointer; }
.row-item:hover { background: rgba(255,255,255,.03); }
.row-item.sel { background: rgba(56,189,248,.09); box-shadow: inset 2px 0 0 var(--accent); }

.tab { padding: .45rem .9rem; font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--mute); border-bottom: 2px solid transparent; cursor: pointer; background: none; }
.tab:hover { color: var(--ink); }
.tab.on { color: #fff; border-bottom-color: var(--accent); }

/* ---------- Modal y avisos ---------- */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(3, 7, 12, .75); backdrop-filter: blur(2px); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; overflow-y: auto; }
.modal { width: 100%; max-width: 640px; background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal-b { padding: 1rem; }
.modal-f { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1rem; border-top: 1px solid var(--line); }

#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 80; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, 92vw); }
.toast { padding: .6rem .85rem; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line2); border-left-width: 3px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.5); word-break: break-word; animation: toastin .18s ease-out; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.info { border-left-color: var(--info); }
@keyframes toastin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Calendario ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal-dow { padding: .35rem .5rem; font-family: ui-monospace, Consolas, monospace; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--mute); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cal-cell { min-height: 98px; padding: .3rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; overflow: hidden; }
.cal-cell:hover { background: rgba(255,255,255,.03); }
.cal-cell.out { opacity: .4; }
.cal-cell.today .cal-day { background: var(--accent); color: #04121a; }
.cal-cell.sel { background: rgba(56,189,248,.09); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-day { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 .3rem; border-radius: 4px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.cal-ev { display: block; margin-top: 3px; padding: 1px 5px; border-radius: 3px; font-size: 11px; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: rgba(56,189,248,.16); color: #bfe9fb; border-left: 2px solid var(--info); }
.cal-ev.proposed { background: transparent; border: 1px dashed var(--warn); color: #fbbf5c; }

/* ---------- Varios ---------- */
.body-text { white-space: pre-wrap; word-break: break-word; font-size: 13.5px; line-height: 1.6; }
.truncate-1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--line); }
a.link { color: var(--accent); text-decoration: none; }
a.link:hover { text-decoration: underline; }

    /* =====================================================================
       Equipo digital (v0.3.1): componentes de agentes. Ver DESIGN_SYSTEM.md
       Sin colores nuevos: todo sale de :root (color-mix sobre los tokens).
       ===================================================================== */

    /* Avatar con iniciales (agente) */
    .avatar { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: none; border: 1px solid var(--line2); background: var(--panel2); border-radius: 6px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; letter-spacing: .05em; color: #fff; }
    .avatar::after { content: ""; position: absolute; left: -1px; bottom: -1px; width: 12px; height: 2px; background: var(--accent); }
    .avatar-sm { width: 28px; height: 28px; font-size: 10.5px; }
    .avatar-lg { width: 64px; height: 64px; font-size: 20px; }

    /* Tarjeta de agente: card clickeable */
    .agent-card { display: block; color: inherit; text-decoration: none; transition: border-color .12s, background .12s; }
    .agent-card:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 4%, var(--panel)); }

    /* Chips: marcador de IA y empresa */
    .chip-ia { gap: .3rem; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; }
    .chip-ia svg { width: 12px; height: 12px; flex: none; }
    .chip-co { background: transparent; color: var(--ink); border-color: var(--line2); }
    .chip-co::before { content: ""; width: 6px; height: 6px; border-radius: 1px; background: var(--mute); }

    /* Barra de métricas: celdas separadas por 1 px de línea */
    .metric-bar { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
    .metric { background: var(--panel); padding: .7rem .85rem; min-width: 0; }
    .metric-v { margin-top: .3rem; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 1.4rem; line-height: 1.1; font-weight: 600; color: #fff; font-variant-numeric: tabular-nums; }
    .metric-s { margin-top: .2rem; font-size: 11px; color: var(--mute); }
    .metric.warn .metric-v { color: var(--warn); }
    .metric.err .metric-v { color: #ff8a82; }

    /* Chat: burbujas. Persona a la derecha, agente a la izquierda con borde de acento */
    .bubble { max-width: min(46rem, 94%); padding: .65rem .85rem; border-radius: 8px; border: 1px solid var(--line2); background: var(--panel2); font-size: 13.5px; line-height: 1.55; word-break: break-word; }
    .bubble-me { margin-left: auto; background: color-mix(in srgb, var(--accent) 9%, var(--panel2)); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
    .bubble-ai { border-left: 3px solid var(--accent); }
    .bubble-ai.is-work { border-left-color: var(--warn); border-style: dashed; border-left-style: solid; }
    .bubble-ai.is-err { border-left-color: var(--err); }

    /* Editor de .md y vista previa (siempre texto) */
    textarea.md-area { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; line-height: 1.65; min-height: 22rem; tab-size: 2; white-space: pre-wrap; }
    .md-pane { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--line2); border-radius: 5px; padding: .6rem .7rem; min-height: 22rem; max-height: 60vh; overflow: auto; color: var(--ink); }

    /* Opción de a una (nivel de autonomía): seleccionada / bloqueada */
    .opt { display: flex; gap: .7rem; align-items: flex-start; padding: .7rem .85rem; border: 1px solid var(--line2); border-radius: 6px; background: var(--bg); }
    .opt input[type=radio] { accent-color: var(--accent); margin-top: .2rem; flex: none; }
    .opt.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
    .opt.locked { border-style: dashed; cursor: not-allowed; }
    .opt.locked .opt-t { opacity: .75; }

    /* Propuesta del agente (patrón "Propuesto" del DESIGN_SYSTEM hecho bloque) */
    .prop-item { padding: .8rem .9rem; border: 1px dashed var(--warn); border-radius: 6px; background: color-mix(in srgb, var(--warn) 6%, transparent); }
    .prop-item.confirmed { border-style: solid; border-color: color-mix(in srgb, var(--ok) 50%, transparent); background: color-mix(in srgb, var(--ok) 6%, transparent); }
    .prop-item.discarded { border-style: solid; border-color: var(--line2); background: transparent; }
    .prop-item.discarded .prop-title { color: var(--mute); }

    /* Pestañas de la ficha: una fila con scroll horizontal en pantallas chicas */
    .tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: thin; }
    .tabs .tab { flex: none; padding: .7rem .95rem; display: inline-flex; align-items: center; gap: .4rem; }

    /* Esqueleto de carga */
    .skel { display: block; height: .8rem; border-radius: 3px; background: linear-gradient(90deg, var(--panel2) 25%, var(--line2) 50%, var(--panel2) 75%); background-size: 200% 100%; animation: skel 1.4s linear infinite; }
    @keyframes skel { to { background-position: -200% 0; } }

    /* Botón con aspecto de enlace (acciones que no navegan) */
    .link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; }
    .link-btn:hover { text-decoration: underline; }

    /* Accesibilidad: foco visible en todo lo interactivo + movimiento reducido */
    .btn:focus-visible, .tab:focus-visible, .row-item:focus-visible, .nav-link:focus-visible, a.link:focus-visible, .agent-card:focus-visible, .link-btn:focus-visible, .switch input:focus-visible + span, .opt input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
    @media (prefers-reduced-motion: reduce) { .led-warn, .led-err, .skel { animation: none; } }

