/*
 * Panel de operación.
 *
 * Tokens de color tomados de la paleta de referencia de visualización de datos
 * y validados para ambos modos: las dos series (fotocasa / pisos) dan ΔE CVD
 * 24,7 en claro y 26,8 en oscuro, muy por encima del umbral de 8.
 *
 * El modo oscuro son pasos elegidos para el fondo oscuro, no una inversión
 * automática del claro.
 */

:root {
    color-scheme: light;

    --plane: #f9f9f7;
    --surface: #fcfcfb;

    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;

    --gridline: #e1e0d9;
    --baseline: #c3c2b7;
    --border: rgba(11, 11, 11, 0.1);

    --series-1: #2a78d6;
    --series-2: #eb6834;

    --good: #0ca30c;
    --warning: #fab219;
    --critical: #d03b3b;
    --success-text: #006300;

    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --plane: #0d0d0d;
        --surface: #1a1a19;

        --text-primary: #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted: #898781;

        --gridline: #2c2c2a;
        --baseline: #383835;
        --border: rgba(255, 255, 255, 0.1);

        --series-1: #3987e5;
        --series-2: #d95926;

        --success-text: #0ca30c;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --plane: #0d0d0d;
    --surface: #1a1a19;

    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;

    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);

    --series-1: #3987e5;
    --series-2: #d95926;

    --success-text: #0ca30c;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--plane);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: inherit;
}

/* ---------- Estructura ---------- */

.shell {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.brand {
    font-weight: 650;
    font-size: 15px;
    padding: 0 10px 18px;
    letter-spacing: -0.01em;
}

.brand small {
    display: block;
    font-weight: 400;
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0;
}

.nav-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 13.5px;
}

.nav-link:hover {
    background: color-mix(in srgb, var(--text-primary) 6%, transparent);
    color: var(--text-primary);
}

.nav-link[aria-current="page"] {
    background: color-mix(in srgb, var(--series-1) 12%, transparent);
    color: var(--text-primary);
    font-weight: 550;
}

.nav-link .count {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.main {
    padding: 26px 30px 60px;
    max-width: 1500px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

h1 {
    font-size: 21px;
    margin: 0;
    letter-spacing: -0.015em;
}

.page-head p {
    margin: 4px 0 0;
    color: var(--text-secondary);
    font-size: 13px;
}

h2 {
    font-size: 14px;
    margin: 0;
    font-weight: 600;
}

/* ---------- Tarjetas ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 14px;
}

.card-head .sub {
    font-size: 12px;
    color: var(--text-muted);
}

.grid {
    display: grid;
    gap: 14px;
    margin-bottom: 20px;
}

.grid-tiles {
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}

.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
}

/* ---------- Tiles de métrica ---------- */

.tile .label {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.045em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.tile .value {
    font-size: 26px;
    font-weight: 620;
    letter-spacing: -0.02em;
    line-height: 1.15;
}

.tile .value .unit {
    font-size: 14px;
    font-weight: 450;
    color: var(--text-secondary);
    margin-left: 2px;
}

.tile .foot {
    margin-top: 5px;
    font-size: 12px;
    color: var(--text-secondary);
}

.tile .foot.good {
    color: var(--success-text);
}

/* ---------- Tablas ---------- */

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    text-align: left;
    font-weight: 550;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0 12px 8px 0;
    border-bottom: 1px solid var(--gridline);
    white-space: nowrap;
}

td {
    padding: 9px 12px 9px 0;
    border-bottom: 1px solid var(--gridline);
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover td {
    background: color-mix(in srgb, var(--text-primary) 3%, transparent);
}

.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.muted {
    color: var(--text-muted);
}

.secondary {
    color: var(--text-secondary);
}

.truncate {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Distintivos ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 500;
    border: 1px solid var(--border);
    white-space: nowrap;
}

.badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

/* El punto de color nunca va solo: siempre acompañado del texto del estado. */
.badge-good {
    color: var(--success-text);
}

.badge-warning {
    color: #8a5a00;
}

.badge-critical {
    color: var(--critical);
}

.badge-neutral {
    color: var(--text-secondary);
}

.badge-neutral::before {
    background: var(--text-muted);
}

.dot-fotocasa,
.dot-pisos {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.dot-fotocasa::before,
.dot-pisos::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 2px;
    flex: none;
}

.dot-fotocasa::before {
    background: var(--series-1);
}

.dot-pisos::before {
    background: var(--series-2);
}

/* ---------- Leyenda ---------- */

.legend {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    flex-wrap: wrap;
}

/* ---------- Barras de progreso ---------- */

.meter {
    height: 6px;
    background: var(--gridline);
    border-radius: 3px;
    overflow: hidden;
    min-width: 90px;
}

.meter span {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: var(--series-1);
}

.meter span.over {
    background: var(--critical);
}

/* ---------- Filtros ---------- */

.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 16px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

input,
select {
    font: inherit;
    font-size: 13px;
    padding: 6px 9px;
    border-radius: 7px;
    border: 1px solid var(--baseline);
    background: var(--surface);
    color: var(--text-primary);
    min-width: 120px;
}

input:focus,
select:focus {
    outline: 2px solid var(--series-1);
    outline-offset: -1px;
}

.btn {
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: 7px;
    border: 1px solid transparent;
    background: var(--series-1);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--baseline);
}

/* ---------- Paginación ---------- */

.pagination {
    display: flex;
    gap: 5px;
    margin-top: 16px;
    flex-wrap: wrap;
    align-items: center;
    font-size: 13px;
}

.pagination a,
.pagination span {
    padding: 5px 10px;
    border-radius: 7px;
    text-decoration: none;
    color: var(--text-secondary);
    border: 1px solid transparent;
}

.pagination a:hover {
    border-color: var(--baseline);
    color: var(--text-primary);
}

.pagination .current {
    background: var(--series-1);
    color: #fff;
    font-weight: 550;
}

.pagination .disabled {
    color: var(--text-muted);
    opacity: 0.5;
}

/* ---------- Estado vacío ---------- */

.empty {
    padding: 34px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ---------- Login ---------- */

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 340px;
}

.login-card .field {
    margin-bottom: 12px;
}

.login-card input {
    width: 100%;
}

.error {
    color: var(--critical);
    font-size: 12.5px;
    margin-top: 6px;
}

/* ---------- Diagnóstico de un rastreo ---------- */

.verdict {
    border-radius: var(--radius);
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-left-width: 4px;
    background: var(--surface);
}

.verdict h2 {
    font-size: 16px;
    margin: 0 0 8px;
}

.verdict p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 13.5px;
    line-height: 1.55;
}

.verdict .action {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--gridline);
    color: var(--text-primary);
    font-size: 13px;
}

.verdict .action strong {
    font-weight: 600;
}

.verdict--good {
    border-left-color: var(--good);
}

.verdict--warning {
    border-left-color: var(--warning);
}

.verdict--critical {
    border-left-color: var(--critical);
}

.verdict--neutral {
    border-left-color: var(--baseline);
}

/* ---------- Consola en vivo ---------- */

.console {
    background: #0d0d0d;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.console__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 14px;
    background: #191918;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #c3c2b7;
    font-size: 12px;
}

.console__live {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.console__live::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--good);
    /* A steady dot reads as a screenshot; the pulse is what says "still
       moving" when a slow sweep goes a minute between lines. */
    animation: console-pulse 1.4s ease-in-out infinite;
}

.console__live--idle::before {
    background: #6b6b6b;
    animation: none;
}

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

.console__out {
    margin: 0;
    padding: 12px 14px;
    max-height: 420px;
    overflow-y: auto;
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-size: 12.5px;
    line-height: 1.75;
    color: #d8d7cf;
    white-space: pre-wrap;
    word-break: break-word;
}

.console__line {
    display: flex;
    gap: 10px;
}

.console__time {
    color: #6f6f6a;
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
}

.console__line--warn .console__text {
    color: #f0c674;
}

.console__line--error .console__text {
    color: #e88b8b;
}

.console__empty {
    color: #6f6f6a;
    font-style: italic;
}

/* ---------- Galería de fotos ---------- */

.gallery {
    display: grid;
    gap: 10px;
}

.gallery__stage {
    position: relative;
    background: color-mix(in srgb, var(--text-primary) 6%, transparent);
    border-radius: var(--radius);
    overflow: hidden;
    /* Fixed ratio so the layout does not jump as images of different
       proportions load in. 3:2 rather than 4:3 keeps it shorter, and the cap
       stops a wide monitor turning the photos into a billboard that pushes the
       actual data below the fold. */
    aspect-ratio: 3 / 2;
    max-height: 340px;
}

.gallery__stage img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    cursor: zoom-in;
}

.gallery__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    opacity: 0.9;
}

.gallery__nav:hover {
    opacity: 1;
}

.gallery__nav:disabled {
    opacity: 0.3;
    cursor: default;
}

.gallery__nav--prev {
    left: 10px;
}

.gallery__nav--next {
    right: 10px;
}

.gallery__counter {
    position: absolute;
    right: 10px;
    bottom: 10px;
    padding: 3px 9px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--text-primary) 78%, transparent);
    color: var(--surface);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
}

/* Thumbnails scroll horizontally rather than wrapping: with thirty photos a
   wrapped grid would push the rest of the record off the screen. */
.gallery__thumbs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
}

.gallery__thumb {
    flex: 0 0 auto;
    width: 58px;
    height: 44px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    background: none;
    padding: 0;
    cursor: pointer;
}

.gallery__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery__thumb[aria-current="true"] {
    border-color: var(--series-1);
}

.gallery__thumb:focus-visible {
    outline: 2px solid var(--series-1);
    outline-offset: 1px;
}

/* ---------- Lightbox ---------- */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.88);
    display: none;
    place-items: center;
    padding: 24px;
}

.lightbox[open],
.lightbox.is-open {
    display: grid;
}

.lightbox img {
    max-width: 100%;
    max-height: calc(100vh - 96px);
    object-fit: contain;
    border-radius: 6px;
}

.lightbox__close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
}

.lightbox__caption {
    position: absolute;
    bottom: 18px;
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255, 255, 255, 0.75);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}

/* ---------- Gráficos ---------- */

.chart {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.chart .grid-line {
    stroke: var(--gridline);
    stroke-width: 1;
}

.chart .axis-line {
    stroke: var(--baseline);
    stroke-width: 1;
}

.chart text {
    font-family: var(--font);
    fill: var(--text-muted);
    font-size: 10.5px;
}

.chart .bar-label {
    fill: var(--text-secondary);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.chart .value-label {
    fill: var(--text-primary);
    font-size: 11px;
    font-weight: 550;
    font-variant-numeric: tabular-nums;
}

/* El hueco de 2px entre segmentos usa el color de la tarjeta, no negro,
   para que la separación funcione igual en claro y oscuro. */
.chart .seg-gap {
    stroke: var(--surface);
    stroke-width: 2;
}

.chart .s1 {
    fill: var(--series-1);
}

.chart .s2 {
    fill: var(--series-2);
}

.chart .bar-hit {
    fill: transparent;
}

.chart .bar-hit:hover + .bar-tip,
.chart .bar-hit:focus + .bar-tip {
    opacity: 1;
}

.chart .bar-tip {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.08s;
}

.chart .bar-tip rect {
    fill: var(--text-primary);
    rx: 5;
}

.chart .bar-tip text {
    fill: var(--surface);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 820px) {
    .shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .main {
        padding: 20px 16px 50px;
    }
}
