:root {
    --navy: #14425f;
    --navy-dark: #0d2c40;
    --cyan: #5fb3c9;
    --ink: #10171c;
    --muted: #5a6a72;
    --faint: #8a979e;
    --rule: #dde3e6;
    --rule-soft: #f0f3f4;
    --bg: #f4f6f7;
    --green: #1c7c54;
    --green-soft: #e2f0ea;
    --amber: #7d6127;
    --amber-soft: #f3eee6;
    --blue-soft: #e7f0f5;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- cabecera */
.appbar {
    background: var(--navy);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 0 24px;
    height: 56px;
}

.marca { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.marca .logo {
    width: 26px;
    height: 26px;
    border-radius: 5px;
    background: #fff;
    color: var(--navy);
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
}

.nav { display: flex; gap: 2px; height: 100%; }

.nav a {
    display: flex;
    align-items: center;
    padding: 0 16px;
    color: #b9cfdc;
    text-decoration: none;
    font-size: 14px;
    border-bottom: 3px solid transparent;
}

.nav a:hover { color: #fff; }

.nav a.activo { color: #fff; border-bottom-color: var(--cyan); font-weight: 600; }

/* ---------------------------------------------------------------- contenido */
main { padding: 26px 30px 60px; max-width: 1360px; margin: 0 auto; }

h1 { font-size: 22px; margin: 0 0 3px; font-weight: 600; letter-spacing: -0.01em; }
h2.titulo-seccion { font-size: 20px; margin: 34px 0 3px; font-weight: 600; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }

/* ---------------------------------------------------------------- campos */
.fila-ruta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    max-width: 720px;
    margin-bottom: 18px;
}

.campo label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}

.sel {
    width: 100%;
    height: 40px;
    border: 1px solid #c9d2d6;
    border-radius: 5px;
    background: #fff;
    padding: 0 12px;
    font-size: 15px;
    color: var(--ink);
    font-family: inherit;
}

.sel:disabled { background: #f7f9f9; color: var(--faint); }
.sel:focus-visible { outline: 2px solid var(--navy); outline-offset: 1px; }

.pista { font-size: 12px; color: #77858c; margin: 6px 0 0; line-height: 1.45; }
.pista b { color: var(--amber); }

/* ---------------------------------------------------------------- tarjetas */
.tarjeta { background: #fff; border: 1px solid var(--rule); border-radius: 7px; }

.tarjeta > header {
    padding: 13px 18px;
    border-bottom: 1px solid #e7ebed;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tarjeta > header h2 {
    font-size: 13px;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--muted);
    font-weight: 600;
}

.tarjeta .cuerpo { padding: 18px; }

.etiqueta {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 3px;
    background: #eef2f4;
    color: var(--muted);
}

/* ---------------------------------------------------------------- tabla de palets */
table.palets { width: 100%; border-collapse: collapse; font-size: 14px; }

table.palets th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #77858c;
    font-weight: 600;
    padding: 0 10px 9px;
    border-bottom: 1px solid #e7ebed;
}

table.palets td { padding: 6px 10px; border-bottom: 1px solid var(--rule-soft); }
table.palets tr:last-child td { border-bottom: 0; }
table.palets td.apagado { color: #c3cbcf; }

.num { text-align: right; font-variant-numeric: tabular-nums; }

.celda {
    width: 100%;
    height: 34px;
    border: 1px solid #dbe2e5;
    border-radius: 4px;
    padding: 0 9px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: inherit;
    font-size: 14px;
}

.celda:focus-visible { outline: 2px solid var(--navy); outline-offset: -1px; }

.tag {
    display: inline-block;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 3px;
    white-space: nowrap;
}

.tag.pw { background: var(--blue-soft); color: #1a5578; }
.tag.on { background: var(--amber-soft); color: var(--amber); }
.tag.malo { background: #f7e6e5; color: #9e2b25; }

.totales {
    display: flex;
    gap: 32px;
    padding: 14px 18px;
    background: #f7f9f9;
    border-top: 1px solid #e7ebed;
    font-size: 14px;
}

.totales b { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- acciones */
.fila-accion {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 18px;
    align-items: start;
    margin-top: 18px;
}

.botones { padding-top: 26px; display: flex; gap: 8px; }

.btn {
    height: 42px;
    padding: 0 22px;
    border-radius: 5px;
    background: var(--navy);
    color: #fff;
    font-size: 14.5px;
    font-weight: 600;
    border: 0;
    cursor: pointer;
    font-family: inherit;
}

.btn:hover:not(:disabled) { background: var(--navy-dark); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.fantasma {
    background: #fff;
    color: var(--navy);
    border: 1px solid #c2ced4;
    font-weight: 500;
}

.btn.fantasma:hover { background: #f7f9f9; }

/* ---------------------------------------------------------------- comparativa */
.ruta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid var(--rule);
    border-radius: 7px;
    padding: 12px 18px;
    margin-bottom: 18px;
    font-size: 14px;
}

.ruta .flecha { color: var(--faint); }

.ruta .chip {
    background: #eef2f4;
    border-radius: 4px;
    padding: 3px 9px;
    font-size: 12.5px;
    color: var(--muted);
}

.ranking { display: flex; flex-direction: column; gap: 10px; }

.opcion {
    background: #fff;
    border: 1px solid var(--rule);
    border-radius: 7px;
    padding: 15px 18px;
    display: grid;
    grid-template-columns: 34px 1fr auto;
    gap: 16px;
    align-items: center;
}

.opcion.mejor { border-color: var(--green); box-shadow: 0 0 0 1px var(--green); }

.pos {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #eef2f4;
    color: var(--muted);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.opcion.mejor .pos { background: var(--green); color: #fff; }

.nombre { font-size: 16.5px; font-weight: 600; display: flex; align-items: center; gap: 9px; }

.insignia {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    padding: 3px 7px;
    border-radius: 3px;
    background: var(--green-soft);
    color: var(--green);
}

.meta { font-size: 12.5px; color: #77858c; margin-top: 3px; }

.precio { text-align: right; }

.precio .grande {
    font-size: 23px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

.precio .pequeno {
    font-size: 12px;
    color: #77858c;
    font-variant-numeric: tabular-nums;
    margin-top: 1px;
}

/* ---------------------------------------------------------------- no aplican */
.no-aplican { margin-top: 20px; }

.na { display: flex; gap: 14px; align-items: baseline; padding: 7px 0; font-size: 13.5px; }
.na b { min-width: 160px; font-weight: 600; color: var(--muted); }
.na span { color: var(--faint); }

/* ---------------------------------------------------------------- errores */
#blazor-error-ui {
    background: #fff3cd;
    border-top: 1px solid #ffe69c;
    bottom: 0;
    box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.1);
    display: none;
    left: 0;
    padding: 0.8rem 1.4rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.blazor-error-boundary::after { content: "Ha ocurrido un error."; }

/* ---------------------------------------------------------------- cobertura y tarifas */
.dos-columnas {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 18px;
    align-items: start;
}

.tarjeta.lateral { position: sticky; top: 18px; }
.tarjeta .cuerpo.lista { padding: 8px; display: flex; flex-direction: column; gap: 2px; }

/* Son botones, no enlaces: la navegación mejorada de Blazor intercepta los
   <a href="#"> y se los lleva a la raíz. */
.lista button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 13px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.lista button:hover { background: #f4f6f7; }
.lista button.activo { background: var(--blue-soft); color: var(--navy); font-weight: 600; }
.lista button.apagado { color: var(--faint); }
.lista button .estado { font-size: 11px; color: #77858c; }
.lista button:focus-visible { outline: 2px solid var(--navy); outline-offset: -2px; }

.cuerpo.desliza { overflow-x: auto; }

/* Con 19 zonas, width:100% aplasta las columnas y los precios salen cortados.
   Mejor que la tabla desborde y el contenedor se desplace en horizontal. */
table.matriz { width: auto; min-width: 100%; border-collapse: collapse; font-size: 14px; }
table.matriz td .celda { min-width: 76px; }
table.matriz th, table.matriz td { white-space: nowrap; }
table.matriz td:first-child, table.matriz th:first-child {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 1;
}
table.matriz thead th:first-child { background: #fff; }

table.matriz th {
    text-align: right;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #77858c;
    font-weight: 600;
    padding: 0 10px 9px;
    border-bottom: 1px solid #e7ebed;
    white-space: nowrap;
}

table.matriz th:first-child { text-align: left; }
table.matriz td { padding: 6px 10px; border-bottom: 1px solid var(--rule-soft); }
table.matriz td:first-child { font-weight: 600; font-size: 13.5px; }
table.matriz tr:last-child td { border-bottom: 0; }
table.matriz .vacio { color: #c3cbcf; }

.interruptor {
    width: 36px;
    height: 20px;
    border-radius: 11px;
    background: #cfd7db;
    position: relative;
    display: inline-block;
    border: 0;
    padding: 0;
    cursor: pointer;
    vertical-align: middle;
}

.interruptor::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: left 0.12s ease;
}

.interruptor.on { background: var(--green); }
.interruptor.on::after { left: 18px; }
.interruptor.nulo { background: #eceff0; cursor: default; }
.interruptor.nulo::after { background: #dfe4e6; }

.leyenda {
    display: flex;
    gap: 20px;
    font-size: 12.5px;
    color: #77858c;
    margin-top: 14px;
    align-items: center;
    flex-wrap: wrap;
}

.leyenda span { display: flex; align-items: center; gap: 7px; }

.nota { font-size: 12px; color: var(--faint); margin-top: 16px; }

.selector-origen {
    display: flex;
    align-items: center;
    gap: 18px;
    border-bottom: 1px solid var(--rule-soft);
    flex-wrap: wrap;
}

.selector-origen .pista { max-width: 460px; margin: 0; }
.etiqueta-campo { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.etiqueta.aviso { background: var(--amber-soft); color: var(--amber); font-weight: 600; }

.regla {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 13px 0;
    border-bottom: 1px solid var(--rule-soft);
}

.regla:last-child { border-bottom: 0; }
.regla .pct { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 62px; }

.regla .pct-editable {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 104px;
    flex: none;
}

.regla .pct-editable .celda { width: 82px; min-width: 82px; }
.regla .pct-editable span { font-size: 14px; color: var(--muted); font-weight: 600; }
.regla .txt { font-size: 13.5px; line-height: 1.5; }

.regla .condicion,
.regla .ambito {
    display: inline-block;
    margin-top: 5px;
    margin-left: 6px;
    font-size: 11.5px;
    padding: 2px 7px;
    border-radius: 3px;
}

.regla .condicion { background: var(--amber-soft); color: var(--amber); }
.regla .ambito { background: #eef2f4; color: var(--muted); }

.totales .btn { height: 36px; font-size: 13.5px; }

/* ---------------------------------------------------------------- usuario y arranque (WASM) */
.appbar .usuario {
    margin-left: auto;
    font-size: 13px;
    color: #c7d8e2;
    display: flex;
    align-items: center;
    gap: 8px;
}

.arranque {
    max-width: 460px;
    margin: 12vh auto 0;
    padding: 0 24px;
    text-align: center;
}

.arranque .marca-grande {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-size: 24px;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 28px;
}

.arranque .marca-grande .logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--navy);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 15px;
    font-weight: 700;
}

.arranque h1 { font-size: 22px; margin: 0 0 12px; }
.arranque p { color: var(--muted); line-height: 1.6; }

/* ---------------------------------------------------------------- pantalla de carga (mientras baja el WASM) */
.cargando {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 16vh;
    font-family: "Segoe UI", system-ui, sans-serif;
}

.cargando-marca {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 24px;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 28px;
}

.cargando-marca .logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--navy);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 15px;
    font-weight: 700;
}

.loading-progress {
    width: 5rem;
    height: 5rem;
}

.loading-progress circle {
    fill: none;
    stroke: #e3e8ea;
    stroke-width: 6;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--navy);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.08s ease-in-out;
}

.loading-progress-text {
    margin-top: 12px;
    font-size: 13px;
    color: var(--muted);
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Cargando…");
}
