/* Conversión de video — Vívaro Digital
   El interruptor del logotipo de Vívaro es el motivo visual: cada video tiene un interruptor
   que se "enciende" cuando su enlace HLS está listo, y el progreso es una píldora con perilla. */

:root {
    --paper: #f4f3f7;
    --surface: #ffffff;
    --ink: #231e2b;
    --muted: #625c6e;
    --rule: #e2dee8;
    --violet: #7752a8;
    --violet-deep: #5d3d8b;
    --violet-tint: #ece6f4;
    --green: #1d7a50;
    --green-tint: #e2f1e9;
    --red: #b3261e;
    --red-tint: #f8e4e2;
    --amber: #855600;
    --amber-tint: #f5ebd6;
    --knob: #ffffff;
    --focus: #7752a8;

    --font: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
    --radius: 10px;
    --page-width: 1080px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #17141c;
        --surface: #201c27;
        --ink: #efecf3;
        --muted: #a7a0b3;
        --rule: #342e3d;
        --violet: #a688d1;
        --violet-deep: #c2abe3;
        --violet-tint: #2f2640;
        --green: #6cc79a;
        --green-tint: #1d3329;
        --red: #f08a82;
        --red-tint: #3d2224;
        --amber: #e0b062;
        --amber-tint: #3a2f1c;
        --knob: #f4f1f8;
        --focus: #c2abe3;
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
}

/* Porcentaje con cifras de ancho fijo para que no "baile" (en el resto espaciaría la puntuación). */
.job-progress-text strong { font-variant-numeric: tabular-nums; }

h1, h2, h3, p, dl, dd, ol { margin: 0; }
ol { padding: 0; list-style: none; }

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: 4px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ------------------------------------------------------------------ botones */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 0 16px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.button:hover { border-color: var(--violet); }
.button:disabled { opacity: .55; cursor: progress; }

.button-primary {
    background: var(--violet);
    border-color: var(--violet);
    color: #fff;
}
.button-primary:hover { background: var(--violet-deep); border-color: var(--violet-deep); }
@media (prefers-color-scheme: dark) {
    .button-primary { color: #17141c; }
}

.button-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.button-quiet:hover { color: var(--ink); border-color: var(--rule); }
.button-wide { width: 100%; min-height: 46px; font-size: 16px; }

/* ------------------------------------------------------------------ inicio de sesión */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 16px;
}

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

.login-logo { width: 150px; height: auto; margin-bottom: 36px; }

.login h1 {
    font-size: 34px;
    line-height: 1.1;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.login-lede { margin-top: 10px; color: var(--muted); }

.login-form {
    display: grid;
    gap: 6px;
    margin-top: 32px;
}
.login-form label { font-weight: 600; font-size: 15px; margin-top: 12px; }
.login-form input {
    width: 100%;
    height: 46px;
    padding: 0 14px;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}
.login-form input:focus { border-color: var(--violet); outline: none; box-shadow: 0 0 0 3px var(--violet-tint); }
.login-form .button-wide { margin-top: 24px; }

.password-field { position: relative; }
.password-field input { padding-right: 96px; }
.password-toggle {
    position: absolute;
    right: 6px; top: 6px; bottom: 6px;
    padding: 0 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.password-toggle:hover { color: var(--ink); background: var(--paper); }

.form-error {
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--red-tint);
    color: var(--red);
    font-weight: 600;
    font-size: 15px;
}

/* ------------------------------------------------------------------ barra superior */

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
}
.topbar-inner {
    max-width: var(--page-width);
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    text-decoration: none;
    font-weight: 700;
}
.account { display: flex; align-items: center; gap: 4px; min-width: 0; }
.account-name {
    color: var(--muted);
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ------------------------------------------------------------------ página */

.page {
    max-width: var(--page-width);
    margin: 0 auto;
    padding: 36px 16px 64px;
}

.overview {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 20px 40px;
    align-items: end;
    padding-bottom: 28px;
    border-bottom: 1px solid var(--rule);
}

.overview h1 {
    font-size: 44px;
    line-height: 1;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.worker-state {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 15px;
}
.worker-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--rule);
    flex: none;
}
.worker-state[data-state="online"] .worker-dot { background: var(--green); }
.worker-state[data-state="offline"] { color: var(--red); font-weight: 600; }
.worker-state[data-state="offline"] .worker-dot { background: var(--red); }

.facts {
    display: flex;
    gap: 32px;
}
.facts dt { font-size: 14px; color: var(--muted); }
.facts dd {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
    display: flex;
    align-items: center;
    gap: 10px;
}
.facts dd[data-low="true"] { color: var(--red); }

.disk-meter {
    width: 64px; height: 8px;
    border-radius: 999px;
    background: var(--violet-tint);
    overflow: hidden;
}
.disk-meter span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--violet);
    border-radius: inherit;
}
.disk-meter[data-low="true"] span { background: var(--red); }

.ftp-help { grid-column: 1 / -1; }
.ftp-help summary {
    cursor: pointer;
    color: var(--violet-deep);
    font-weight: 600;
    width: fit-content;
}
.ftp-help-body {
    margin-top: 14px;
    max-width: 68ch;
    display: grid;
    gap: 14px;
}
.ftp-credentials {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 20px;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
}
.ftp-credentials dt { color: var(--muted); }
.ftp-credentials dd { font-weight: 600; overflow-wrap: anywhere; }
.hint { color: var(--muted); font-size: 15px; }

/* ------------------------------------------------------------------ filtros */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 0 8px;
}
.filters { display: flex; flex-wrap: wrap; gap: 4px; }
.filter {
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    font-size: 15px;
    padding: 7px 12px;
    border-radius: 999px;
    cursor: pointer;
}
.filter:hover { color: var(--ink); }
.filter[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.filter-count { font-weight: 500; opacity: .75; }
.filter-count:empty { display: none; }
.filter[data-filter="failed"] .filter-count:not(:empty):not([data-zero]) { color: var(--red); opacity: 1; }
.filter[data-filter="failed"][aria-selected="true"] .filter-count { color: inherit; }

.search input {
    height: 38px;
    width: 240px;
    max-width: 100%;
    padding: 0 14px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 15px;
}
.search input:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px var(--violet-tint); }

.connection-error {
    margin: 8px 0;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--amber-tint);
    color: var(--amber);
    font-weight: 600;
}

/* ------------------------------------------------------------------ lista de videos */

.job {
    position: relative;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    column-gap: 16px;
    row-gap: 6px;
    padding: 20px 0;
    border-bottom: 1px solid var(--rule);
}
.job > * { grid-column: 2; }

/* El interruptor de estado, tomado del logotipo. */
.job::before {
    content: "";
    grid-column: 1;
    grid-row: 1;
    align-self: start;
    width: 44px;
    height: 26px;
    border-radius: 999px;
    background: var(--rule);
}
.job::after {
    content: "";
    position: absolute;
    top: 23px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--knob);
    box-shadow: 0 1px 2px rgba(35, 30, 43, .25);
    transition: transform .35s cubic-bezier(.3, .7, .3, 1), background-color .35s;
}
.job[data-status="receiving"]::before { background: var(--amber-tint); box-shadow: inset 0 0 0 2px var(--amber); }
.job[data-status="queued"]::before { background: var(--rule); }
.job[data-status="processing"]::before { background: var(--violet-tint); box-shadow: inset 0 0 0 2px var(--violet); }
.job[data-status="processing"]::after { transform: translateX(9px); background: var(--violet); }
.job[data-status="done"]::before { background: var(--violet); }
.job[data-status="done"]::after { transform: translateX(18px); }
.job[data-status="failed"]::before { background: var(--red-tint); box-shadow: inset 0 0 0 2px var(--red); }
.job[data-status="failed"]::after { background: var(--red); }

.job-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    grid-row: 1;
    min-height: 26px;
}
.job-name {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
.job-status {
    flex: none;
    font-size: 14px;
    font-weight: 700;
    color: var(--muted);
}
.job[data-status="processing"] .job-status { color: var(--violet-deep); }
.job[data-status="done"] .job-status { color: var(--green); }
.job[data-status="failed"] .job-status { color: var(--red); }
.job[data-status="receiving"] .job-status { color: var(--amber); }

.job-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 18px;
    color: var(--muted);
    font-size: 14px;
}
.job-meta:empty { display: none; }
.job-wait { color: var(--amber); }

/* Progreso: misma píldora con perilla. */
.job-progress {
    display: none;
    align-items: center;
    gap: 14px;
    margin-top: 6px;
}
.job[data-status="processing"] .job-progress,
.job[data-status="receiving"] .job-progress { display: flex; }

.pill {
    --p: 0;
    position: relative;
    flex: 1;
    max-width: 560px;
    height: 22px;
    border-radius: 999px;
    background: var(--violet-tint);
    overflow: hidden;
}
.pill-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: calc(22px + (100% - 22px) * var(--p) / 100);
    border-radius: inherit;
    background: var(--violet);
    transition: width 1.8s linear;
}
.pill-knob {
    position: absolute;
    top: 3px;
    left: calc(3px + (100% - 22px) * var(--p) / 100);
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--knob);
    transition: left 1.8s linear;
}
/* Mientras llega por FTP no se sabe el tamaño final: rayas en movimiento. */
.job[data-status="receiving"] .pill {
    background: repeating-linear-gradient(
        -45deg, var(--amber-tint) 0 10px, transparent 10px 20px
    ), var(--surface);
    box-shadow: inset 0 0 0 1px var(--amber-tint);
    background-size: 28px 28px;
    animation: receiving 1.4s linear infinite;
}
.job[data-status="receiving"] .pill-fill,
.job[data-status="receiving"] .pill-knob { display: none; }
@keyframes receiving { to { background-position: 28px 0; } }

.job-progress-text {
    font-size: 14px;
    color: var(--muted);
    min-width: 0;
}
.job-progress-text strong { color: var(--ink); font-weight: 700; margin-right: 6px; }

/* Resultado: los enlaces son lo que el usuario vino a buscar. */
.job-result {
    display: none;
    gap: 8px;
    margin-top: 8px;
}
.job[data-status="done"] .job-result { display: grid; }
.job-asset {
    display: flex;
    align-items: center;
    gap: 8px;
}
.job-asset[hidden] { display: none; }
.job-asset-label {
    flex: none;
    width: 84px;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
}
.job-asset-note { color: var(--muted); font-size: 14px; }
.job-link {
    flex: 1;
    min-width: 0;
    max-width: 620px;
    height: 38px;
    padding: 0 14px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    text-overflow: ellipsis;
}
.job-link:focus { outline: none; border-color: var(--violet); }
.button[data-copied] { background: var(--green); border-color: var(--green); }

.job-error { display: none; margin-top: 4px; }
.job[data-status="failed"] .job-error {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 16px;
    align-items: start;
}
.job-error-message { color: var(--red); font-weight: 500; max-width: 70ch; }
.job-error [data-action="retry"][hidden] { display: none; }
.job-error-detail { grid-column: 1 / -1; font-size: 14px; }
.job-error-detail summary { cursor: pointer; color: var(--muted); width: fit-content; }
.job-error-detail pre {
    margin: 8px 0 0;
    padding: 12px 14px;
    max-height: 240px;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    font-size: 13px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Un video que cambia de estado se marca un instante para que se note. */
.job[data-flash] { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--violet-tint); } to { background: transparent; } }

.empty {
    padding: 64px 0;
    text-align: center;
}
.empty-title { font-size: 20px; font-weight: 700; }
.empty p:not(.empty-title) { color: var(--muted); margin-top: 6px; }

/* ------------------------------------------------------------------ reproductor */

.player {
    width: min(960px, calc(100vw - 32px));
    padding: 0;
    border: 0;
    border-radius: 14px;
    background: var(--surface);
    color: var(--ink);
    overflow: hidden;
}
.player::backdrop { background: rgba(23, 20, 28, .72); }
.player-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 10px 10px 18px;
}
.player-head h2 {
    font-size: 16px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.player video {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
}
.player[data-kind="mp3"] video { aspect-ratio: auto; height: 72px; background: var(--paper); }
.player-error { padding: 14px 18px; color: var(--red); font-weight: 600; }

/* ------------------------------------------------------------------ móvil */

@media (max-width: 760px) {
    .page { padding-top: 24px; }
    .overview { grid-template-columns: 1fr; }
    .overview h1 { font-size: 36px; }
    .facts { gap: 24px; flex-wrap: wrap; }
    .facts dd { font-size: 20px; }
    .search, .search input { width: 100%; }
    .filters { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
    .filter { flex: none; }
    .job-progress { flex-wrap: wrap; gap: 6px; }
    .pill { flex-basis: 100%; }
    .job { grid-template-columns: 36px minmax(0, 1fr); column-gap: 12px; }
    .job::before { width: 36px; height: 22px; }
    .job::after { width: 16px; height: 16px; }
    .job[data-status="processing"]::after { transform: translateX(7px); }
    .job[data-status="done"]::after { transform: translateX(14px); }
    .job-head { flex-direction: column; gap: 2px; }
    .job-asset { flex-wrap: wrap; }
    .job-asset-label { width: 100%; }
    .job-link { flex-basis: 100%; max-width: none; }
    .job[data-status="failed"] .job-error { grid-template-columns: 1fr; }
    .job-error [data-action="retry"] { justify-self: start; }
    .account-name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}
