/* =========================================================
   Panel — estilo BLOOD IA (negro profundo + rojo sangre)
   ========================================================= */

:root {
    --bg: #070608;
    --bg-2: #0d0a0d;
    --panel: #110d10;
    --panel-2: #1a1216;
    --border: #2a1a1f;
    --border-hi: #4a1f28;
    --text: #f1e9ea;
    --muted: #9a868b;
    --accent: #e0163a;
    --accent-2: #ff3b5c;
    --accent-dark: #7a0b1f;
    --accent-soft: rgba(224, 22, 58, .14);
    --glow: 0 0 18px rgba(224, 22, 58, .45), 0 0 40px rgba(224, 22, 58, .18);
    --ok: #22c55e;
    --warn: #f59e0b;
    --err: #ff3b5c;
    --radius: 12px;
    --shadow: 0 2px 6px rgba(0, 0, 0, .6), 0 8px 24px rgba(0, 0, 0, .45);
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --ease: cubic-bezier(.2, .8, .2, 1);
}

/* Tema "light" = variante menos oscura, pero sigue siendo Blood */
[data-theme="light"] {
    --bg: #120c0f;
    --bg-2: #1a1216;
    --panel: #1d1419;
    --panel-2: #271a20;
    --border: #3a2229;
    --border-hi: #5c2a35;
    --text: #f7f0f1;
    --muted: #b09ca2;
}

* { box-sizing: border-box; }

html {
    background: var(--bg);
}

html, body {
    margin: 0;
    height: 100%;
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* el body queda transparente para que se vea el canvas neuronal detrás */
body {
    background: transparent;
}

/* canvas de red neuronal (lo dibuja neural.js) */
#neural {
    position: fixed;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: block;
}

/* fondo vivo: nebulosa roja que respira, detrás de la red */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    background:
        radial-gradient(1000px 600px at 15% -10%, rgba(224, 22, 58, .22), transparent 60%),
        radial-gradient(800px 600px at 100% 110%, rgba(122, 11, 31, .32), transparent 60%),
        radial-gradient(1200px 800px at 50% 50%, rgba(40, 6, 14, .6), transparent 70%),
        var(--bg);
    animation: breathe 9s ease-in-out infinite alternate;
}

@keyframes breathe {
    from { opacity: .75; transform: scale(1); }
    to   { opacity: 1;   transform: scale(1.04); }
}

::selection { background: var(--accent); color: #fff; }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dark); }

.app {
    display: grid;
    grid-template-columns: 236px 1fr;
    height: 100vh;
}

/* ---------- barra lateral ---------- */

.sidebar {
    background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.sidebar::after {
    content: "";
    position: absolute;
    top: 0; right: -1px;
    width: 1px; height: 100%;
    background: linear-gradient(180deg, transparent, var(--accent) 40%, transparent 80%);
    opacity: .5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    color: #fff;
    flex: none;
}

/* ---- logo: ojo rojo con tomoe giratorios ---- */
.brand-mark .eye { display: block; width: 100%; height: 100%; }
.eye .spin-cw { transform-origin: 24px 24px; animation: jspin 8s linear infinite; }
.eye .pulse   { transform-origin: 24px 24px; animation: jpulse 2.6s ease-in-out infinite; }

@keyframes jspin  { to { transform: rotate(360deg); } }
@keyframes jpulse {
    0%, 100% { opacity: .9;  transform: scale(1); }
    50%      { opacity: 1;   transform: scale(1.12); }
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; letter-spacing: .04em; }
.brand-text span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; }

.nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 9px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background .2s var(--ease), color .2s, transform .2s var(--ease), border-color .2s;
}

.nav-item:hover { background: var(--panel-2); color: var(--text); transform: translateX(3px); }

.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent-2);
    font-weight: 600;
    border-color: rgba(224, 22, 58, .35);
}

.nav-item.active::before {
    content: "";
    position: absolute;
    left: -8px; top: 20%;
    width: 3px; height: 60%;
    border-radius: 3px;
    background: var(--accent);
    box-shadow: var(--glow);
}

.nav-item .ico { width: 18px; text-align: center; opacity: .85; }

.sidebar-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-top: 1px solid var(--border);
}

.version { font-size: 11px; color: var(--muted); font-family: var(--mono); }

/* ---------- principal ---------- */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 22px;
    background: rgba(17, 13, 16, .75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.device-picker { display: flex; align-items: center; gap: 10px; }
.device-picker label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }

select, .input {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: 8px 11px;
    font: inherit;
    min-width: 180px;
    transition: border-color .2s, box-shadow .2s;
}

select:focus, .input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input { min-width: 0; width: 100%; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.pill {
    font-size: 12px;
    padding: 4px 11px;
    border-radius: 999px;
    background: var(--panel-2);
    color: var(--muted);
    border: 1px solid var(--border);
    transition: all .3s;
}

.pill.on  { background: rgba(34, 197, 94, .12); color: var(--ok);  border-color: rgba(34, 197, 94, .35); }
.pill.off { background: var(--accent-soft);      color: var(--err); border-color: rgba(255, 59, 92, .35); }

.dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--muted);
    position: relative;
}

.dot::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid currentColor;
    opacity: 0;
}

.dot.online  { background: var(--ok);  color: var(--ok); }
.dot.offline { background: var(--err); color: var(--err); }
.dot.online::after, .dot.offline::after { animation: ping 1.8s ease-out infinite; }

@keyframes ping {
    0%   { transform: scale(.6); opacity: .8; }
    100% { transform: scale(1.8); opacity: 0; }
}

.view {
    flex: 1;
    overflow-y: auto;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: view-in .35s var(--ease);
}

@keyframes view-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

/* ---------- tarjetas ---------- */

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: border-color .25s, transform .25s var(--ease), box-shadow .25s;
    animation: view-in .4s var(--ease) both;
}

.card:hover { border-color: var(--border-hi); box-shadow: var(--shadow), 0 0 0 1px rgba(224, 22, 58, .15); }

/* escalonado al aparecer */
.view > :nth-child(1) { animation-delay: .02s; }
.view > :nth-child(2) { animation-delay: .07s; }
.view > :nth-child(3) { animation-delay: .12s; }
.view > :nth-child(4) { animation-delay: .17s; }
.view > :nth-child(5) { animation-delay: .22s; }

.card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(90deg, rgba(224, 22, 58, .07), transparent 60%);
}

.card-head h2 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.card-head h2::before {
    content: "";
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 8px;
    vertical-align: middle;
    box-shadow: var(--glow);
}

.card-head .spacer { flex: 1; }
.card-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.stat {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform .25s var(--ease), border-color .25s;
    animation: view-in .4s var(--ease) both;
}

.stat::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: linear-gradient(180deg, var(--accent-2), var(--accent-dark));
}

.stat:hover { transform: translateY(-3px); border-color: var(--border-hi); }

.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-family: var(--mono); color: var(--text); }

/* ---------- controles ---------- */

.btn {
    position: relative;
    background: linear-gradient(135deg, var(--accent-2), var(--accent));
    color: #fff;
    border: 0;
    border-radius: 9px;
    padding: 9px 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 0 0 rgba(224, 22, 58, 0);
    transition: transform .15s var(--ease), box-shadow .25s, filter .2s;
    overflow: hidden;
}

.btn::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, .25) 50%, transparent 70%);
    transform: translateX(-120%);
    transition: transform .6s var(--ease);
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--glow); }
.btn:hover::after { transform: translateX(120%); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; transform: none; }

.ghost-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: 7px 13px;
    font: inherit;
    cursor: pointer;
    transition: border-color .2s, background .2s, color .2s;
}

.ghost-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }

/* ---------- salida ---------- */

.out {
    position: relative;
    background: #050405;
    color: #e6d9dc;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 12px 14px;
    font: 12px/1.6 var(--mono);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 320px;
    overflow: auto;
    margin: 0;
    box-shadow: inset 0 0 30px rgba(224, 22, 58, .05);
}

.out::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), transparent);
}

.out.tall { max-height: 460px; }

/* cursor parpadeante opcional: <span class="cursor"></span> al final del .out */
.cursor {
    display: inline-block;
    width: 7px; height: 13px;
    background: var(--accent);
    vertical-align: -2px;
    animation: blink 1s steps(2) infinite;
}

@keyframes blink { to { opacity: 0; } }

/* ---------- tablas ---------- */

.table-wrap { overflow: auto; max-height: 460px; border: 1px solid var(--border); border-radius: 9px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }

.table th {
    position: sticky; top: 0;
    background: var(--panel-2);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
}

.table tr { transition: background .15s; }
.table tr:hover td { background: var(--accent-soft); }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; font-family: var(--mono); font-size: 12.5px; }

.muted { color: var(--muted); }

/* ---------- archivos ---------- */

.filelist { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }

.file-row {
    display: grid;
    grid-template-columns: 1fr 90px 150px auto;
    gap: 10px;
    align-items: center;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background .15s, padding-left .2s var(--ease);
}

.file-row:last-child { border-bottom: 0; }
.file-row:hover { background: var(--panel-2); padding-left: 16px; }
.file-row .name { cursor: pointer; }
.file-row .name.dir { font-weight: 600; color: var(--accent-2); }

/* ---------- medios ---------- */

.media {
    max-width: 100%;
    border-radius: 9px;
    border: 1px solid var(--border-hi);
    background: #000;
    box-shadow: var(--shadow);
}

/* ---------- avisos ---------- */

.toasts {
    position: fixed;
    right: 18px;
    bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 50;
}

.toast {
    background: var(--panel);
    border: 1px solid var(--border-hi);
    border-left: 3px solid var(--accent);
    border-radius: 9px;
    padding: 10px 14px;
    box-shadow: var(--shadow), var(--glow);
    font-size: 13px;
    max-width: 340px;
    animation: toast-in .35s var(--ease);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: none; }
}

.toast.ok  { border-left-color: var(--ok);  box-shadow: var(--shadow), 0 0 18px rgba(34, 197, 94, .25); }
.toast.err { border-left-color: var(--err); }

/* ---------- varios ---------- */

.hidden { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    color: var(--muted);
    transition: all .2s;
}

.chip:hover { border-color: var(--border-hi); color: var(--text); }
.chip input { margin: 0; accent-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }

/* esqueleto de carga: <div class="skeleton" style="height:14px"></div> */
.skeleton {
    border-radius: 6px;
    background: linear-gradient(90deg, var(--panel-2) 25%, var(--border-hi) 50%, var(--panel-2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (max-width: 820px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .view { padding: 14px; }
}