:root {
    --ink: #1c1917;
    --muted: #5c5348;
    --paper: #f3eee4;
    --card: #fffcf7;
    --line: #e4d8c4;
    --wine: #7a2432;
    --wine-dark: #4f1520;
    --gold: #c4a35a;
    --slate: #24343d;
    --sage: #2f6b4f;
    --amber: #c9a227;
    --orange: #c05621;
    --red: #9b2c2c;
    --shadow: 0 18px 40px rgba(36, 22, 16, .08);
    --radius: 18px;
    --font: "Source Sans 3", "Segoe UI", sans-serif;
    --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--paper);
    min-height: 100vh;
}

a { color: var(--wine); }
code { font-size: .92em; background: #f0e6d4; padding: .1em .4em; border-radius: 6px; }

.app { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.sidebar {
    background: linear-gradient(180deg, var(--wine-dark), #2a1218 70%);
    color: #f8efe4;
    padding: 22px 18px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}
.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    text-decoration: none;
    color: inherit;
}
.brand-center { justify-content: center; margin-bottom: 12px; }
.brand-mark {
    width: 42px; height: 42px; border-radius: 12px;
    display: grid; place-items: center;
    background: var(--gold); color: var(--wine-dark);
    font-family: var(--display); font-weight: 700; font-size: 1.3rem;
}
.brand strong { display: block; font-family: var(--display); font-size: 1.25rem; }
.brand small { display: block; opacity: .75; font-size: .78rem; }

.nav { display: flex; flex-direction: column; gap: 6px; }
.nav a {
    color: #f4e9dc; text-decoration: none; padding: 10px 12px; border-radius: 12px;
    opacity: .82;
}
.nav a.activo, .nav a:hover { background: rgba(255,255,255,.08); opacity: 1; }

.sidebar-user {
    margin-top: auto; display: grid; grid-template-columns: auto 1fr auto;
    gap: 10px; align-items: center; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.12);
}
.sidebar-user strong, .sidebar-user small { display: block; }
.sidebar-user small { opacity: .7; font-size: .75rem; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--gold); color: var(--wine-dark);
    display: grid; place-items: center; font-weight: 700;
}
.salir { color: #f4e9dc; font-size: .82rem; }

.main { min-width: 0; }
.topbar {
    padding: 22px 28px 8px;
    display: flex; gap: 14px; align-items: flex-start;
}
.topbar h1 { margin: 0; font-family: var(--display); font-size: 1.7rem; font-weight: 600; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; color: var(--muted); }
.menu-btn { display: none; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.content { padding: 8px 28px 40px; display: flex; flex-direction: column; gap: 20px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stats article {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow);
}
.stats small { color: var(--muted); }
.stats strong { display: block; font-family: var(--display); font-size: 2rem; margin: 4px 0; }

.panel {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow);
}
.panel-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 1.15rem; font-family: var(--display); }
.panel-head p, .panel > p { color: var(--muted); }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card-prop {
    display: flex; flex-direction: column; gap: 8px;
    padding: 14px; border: 1px solid var(--line); border-radius: 14px;
    text-decoration: none; color: inherit; background: #fffaf2;
}
.card-prop:hover { border-color: var(--gold); }
.card-prop strong { font-family: var(--display); }

.badge {
    display: inline-block; padding: .2rem .55rem; border-radius: 999px;
    font-size: .78rem; font-weight: 600;
}
.badge-ambar { background: #f8e7b0; color: #6b4e00; }
.badge-verde { background: #d8efe3; color: #1d5a3c; }
.badge-rojo { background: #f8d4d4; color: #8a1f1f; }
.badge-naranja { background: #fde4cf; color: #9a3b10; }
.badge-pizarra { background: #e7ecef; color: #24343d; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    border-radius: 12px; padding: 9px 14px; cursor: pointer; text-decoration: none; font-weight: 600;
}
.btn-ok { background: var(--wine); color: #fff; border-color: var(--wine); }
.btn-sm { padding: 6px 10px; font-size: .85rem; }
.btn:hover { filter: brightness(1.05); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; }
.form input, .form select, .form textarea {
    font: inherit; padding: 10px 12px; border-radius: 12px;
    border: 1px solid var(--line); background: #fff;
}
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-form .full { grid-column: 1 / -1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); min-width: 180px; }

.alerta { padding: 12px 14px; border-radius: 12px; }
.alerta-ok { background: #d8efe3; color: #1d5a3c; }
.alerta-error { background: #f8d4d4; color: #8a1f1f; }
.vacio { color: var(--muted); }

.split { display: grid; grid-template-columns: 1.4fr .9fr; gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.ficha { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.ficha dt { color: var(--muted); font-size: .8rem; }
.ficha dd { margin: 0; font-weight: 600; }
.texto { white-space: pre-wrap; color: #3a332c; }
.etapa-actual {
    background: #fff6e4; border: 1px solid #ead7a2; border-radius: 14px; padding: 12px 14px; margin-bottom: 14px;
}

.pista { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.pista li {
    padding: 6px 10px; border-radius: 999px; background: #efe6d6; color: var(--muted); font-size: .82rem;
}
.pista li.hecho { background: #d8efe3; color: #1d5a3c; }
.pista li.ahora { background: var(--wine); color: #fff; }

.accion-opcion { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 500 !important; }
.chip { padding: 8px 10px; border-radius: 10px; display: inline-block; }
.chip-ok { background: #d8efe3; }
.chip-no { background: #f8d4d4; }

.lista-archivos, .comentarios { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 10px; }
.lista-archivos li, .comentarios article { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.lista-archivos small, .comentarios small { display: block; color: var(--muted); }

.timeline { list-style: none; padding: 0; margin: 0; border-left: 3px solid var(--gold); }
.timeline li { padding: 0 0 16px 16px; }
.timeline strong { display: block; }

.auth-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 10% 20%, rgba(196,163,90,.25), transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(122,36,50,.18), transparent 42%),
        var(--paper);
    display: grid; place-items: center; padding: 24px;
}
.auth-layout { width: min(1040px, 100%); display: grid; grid-template-columns: 1.1fr .9fr; gap: 24px; }
.auth-hero, .auth-card {
    background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 32px;
    box-shadow: var(--shadow);
}
.auth-hero h1 { font-family: var(--display); font-size: 2.2rem; margin: 8px 0 12px; }
.hero-steps { margin: 18px 0 0; padding-left: 18px; color: var(--muted); }
.install-card { width: min(460px, 100%); }
.demo-box { margin-top: 16px; color: var(--muted); }
.demo-box ul { list-style: none; padding: 0; max-height: 220px; overflow: auto; }
.demo-box li { margin: 8px 0; display: flex; flex-direction: column; }
.linkish {
    background: none; border: 0; color: var(--wine); cursor: pointer; text-align: left; padding: 0; font: inherit; font-weight: 700;
}

.flow-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.verde { background: #2f6b4f; }
.dot.ambar { background: #c9a227; }
.dot.naranja { background: #c05621; }
.dot.rojo { background: #9b2c2c; }
.dot.bypass { background: #3d6f8c; }

.flow-board {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 36px;
    padding: 12px 8px 20px;
    overflow: visible;
}
.flow-connectors {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none;
    z-index: 0;
    overflow: visible;
}
.flow-board > *:not(.flow-connectors) {
    position: relative;
    z-index: 1;
}
.flow-line {
    fill: none;
    stroke: #8a7360;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.flow-line-si { stroke: #2f6b4f; stroke-width: 2.25; }
.flow-line-no { stroke: #9b2c2c; stroke-width: 2.25; }
.flow-line-loop {
    stroke: #9b2c2c;
    stroke-width: 1.75;
    stroke-dasharray: 6 5;
    opacity: .9;
}
.flow-line-bypass {
    stroke: #3d6f8c;
    stroke-width: 2.25;
    stroke-dasharray: 7 5;
}
.flow-line-soft {
    stroke: #c4a882;
    stroke-width: 1.5;
    opacity: .85;
}
.flow-line-label {
    font-size: 11px;
    font-weight: 800;
    font-family: var(--font);
    paint-order: stroke;
    stroke: #fffcf7;
    stroke-width: 4px;
}
.flow-line-label-si { fill: #2f6b4f; }
.flow-line-label-no { fill: #9b2c2c; }
.flow-line-label-bypass { fill: #3d6f8c; }

.flow-stage,
.flow-spine {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
}
.flow-split {
    display: grid;
    grid-template-columns: 1.55fr .95fr;
    gap: 24px;
    align-items: stretch;
}
.flow-lane {
    border-radius: 18px;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    border: 1px solid var(--line);
}
.lane-completa { background: linear-gradient(180deg, #fff9ef, #faf6ee); }
.lane-bypass {
    background: linear-gradient(180deg, #edf5f8, #e7eef2);
    justify-content: center;
    border-style: dashed;
    border-color: #9bb6c4;
    min-height: 160px;
}
.flow-converge {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin-top: 4px;
}
.converge-label {
    margin: 0;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: #3d6f8c;
}
.flow-group {
    width: min(960px, 100%);
    margin: 0 auto;
    border: 1.5px solid var(--line);
    border-radius: 18px;
    background: #fffcf7;
    padding: 14px 12px 16px;
    box-shadow: 0 8px 24px rgba(36, 22, 16, .04);
}
.flow-group-title {
    text-align: center;
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--wine);
    margin-bottom: 10px;
}
.nodo {
    width: min(420px, 100%);
    text-align: center;
    padding: 12px 14px;
    border-radius: 16px;
    border: 2px solid transparent;
    font-weight: 600;
    line-height: 1.35;
    background-clip: padding-box;
}
.nodo small { display: block; font-weight: 400; opacity: .88; margin-top: 4px; }
.nodo.verde { background: #d8efe3; color: #1d5a3c; border-color: #b7dcc8; }
.nodo.ambar { background: #f8e7b0; color: #5c4300; border-color: #e6d08a; }
.nodo.naranja { background: #fde4cf; color: #9a3b10; border-color: #f0c39a; }
.nodo.rojo { background: #f8d4d4; color: #8a1f1f; border-color: #e8b0b0; }
.nodo.rombo { border-radius: 8px 28px; font-family: var(--display); }
.nodo.pill { border-radius: 999px; width: min(280px, 100%); }
.nodo.activo {
    outline: 3px solid var(--wine);
    box-shadow: 0 0 0 4px rgba(122, 36, 50, .12);
}
.bifurca {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    width: min(860px, 100%);
}
.bifurca.compacta { width: min(720px, 100%); }
.rama {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.grupo { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.grupo .nodo { width: auto; min-width: 180px; max-width: 280px; flex: 1 1 180px; }
.grupo.trio .nodo { max-width: 300px; }
.hint { color: var(--muted); font-size: .85rem; text-align: center; margin: 0; }
.hint.bucle { font-weight: 600; color: #8a1f1f; }
.ruta-label {
    font-weight: 800;
    margin: 0 0 4px;
    color: var(--wine);
    align-self: flex-start;
    width: 100%;
}
.lane-bypass .ruta-label { color: #3d6f8c; }

@media (max-width: 960px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; transform: translateX(-110%); z-index: 20; transition: .2s; }
    .sidebar.abierto { transform: none; }
    .menu-btn { display: inline-block; }
    .stats, .split, .grid-form, .auth-layout, .bifurca, .ficha { grid-template-columns: 1fr; }
    .flow-split { grid-template-columns: 1fr; }
    .content, .topbar { padding-left: 16px; padding-right: 16px; }
}
