:root {
  --bg: #EDF0F3;
  --panel: #FFFFFF;
  --ink: #1C2733;
  --muted: #5B6B7C;
  --line: #D3DAE2;
  --brand: #1F5FBF;
  --ok: #1E8E5A;
  --upd: #2F6FD6;
  --warn: #B7791F;
  --down: #C23B33;
  --off: #9AA5B1;
  --ok-soft: #E3F3EB;
  --warn-soft: #FBF1DE;
  --down-soft: #FBE6E4;
  --upd-soft: #E4EDFB;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --cond: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.5 var(--body); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
h1, h2 { font-family: var(--cond); font-weight: 600; line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.85rem; }
h2 { font-size: 1.15rem; }
code { font-family: var(--mono); font-size: .86em; background: #E6EAEF; padding: 1px 4px; border-radius: 3px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.inline { display: inline; }
.right { text-align: right; }

/* barra superior */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  background: var(--ink); color: #fff; padding: .7rem max(16px, calc((100vw - 1240px) / 2)); }
.brand { color: #fff; font: 600 1.15rem var(--cond); }
.topbar nav { display: flex; gap: 1.2rem; align-items: center; }
.topbar nav a, .linklike { color: #C9D3DE; font: 500 .95rem/1.5 var(--body); background: none; border: 0; padding: 0; cursor: pointer; }
.topbar nav a[aria-current] { color: #fff; box-shadow: 0 2px 0 #fff; }
.topbar nav a:hover, .linklike:hover { color: #fff; text-decoration: none; }

.page { max-width: 1240px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.crumbs { margin: 0 0 .4rem; color: var(--muted); font-size: .9rem; }

/* la flota: una luz por instalación, como el frontal de un rack */
.fleet { background: var(--ink); color: #fff; border-radius: 6px; padding: 1.3rem 1.4rem 1.1rem; margin-bottom: 1rem; }
.fleet-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.fleet h1 { font-size: 1.6rem; margin: 0; }
.fleet .muted, .fleet .muted a { color: #A9B6C4; }
.rack { display: flex; flex-wrap: wrap; gap: 5px; margin: 1rem 0 1.1rem; padding: 10px; background: #121A23; border-radius: 4px; }
.led { width: 22px; height: 22px; border-radius: 3px; background: var(--off); display: block; }
.led:hover { transform: scale(1.15); text-decoration: none; }
.led-ok { background: var(--ok); }
.led-updates { background: var(--upd); }
.led-warn { background: var(--warn); }
.led-flaky { background: var(--warn); }
.led-down { background: var(--down); }
.led-unknown { background: #3A4756; }
.led-busy { box-shadow: 0 0 0 2px #121A23, 0 0 0 4px #fff; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .led-busy { animation: none; } .led:hover { transform: none; } }

.tally { display: flex; flex-wrap: wrap; gap: .4rem; }
.tally a { color: #C9D3DE; padding: .35rem .75rem; border-radius: 4px; border: 1px solid #344252; font-size: .95rem; }
.tally a b { font: 700 1.05rem var(--cond); color: #fff; margin-right: .15rem; }
.tally a:hover { text-decoration: none; border-color: #6B7C8E; }
.tally a[aria-current] { background: #fff; color: var(--ink); border-color: #fff; }
.tally a[aria-current] b { color: var(--ink); }
.tally .t-down b { color: #FF8F87; }
.tally .t-warn b { color: #F2C46D; }
.tally .t-upd b { color: #8DB4FF; }
.tally .t-php b { color: #F2C46D; }

/* botones */
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 1.4rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem .95rem;
  border: 1px solid #B9C4CF; background: var(--panel); color: var(--ink); border-radius: 4px;
  font: 500 .95rem var(--body); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--ink); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #184C99; border-color: #184C99; }
.btn-danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn-small { padding: .25rem .6rem; font-size: .88rem; }
.wide { width: 100%; margin-bottom: .5rem; }

/* avisos */
.flash { padding: .7rem 1rem; border-radius: 4px; margin: 0 0 1rem; border-left: 4px solid var(--ok); background: var(--ok-soft); }
.flash-warning { border-color: var(--warn); background: var(--warn-soft); }
.flash-danger { border-color: var(--down); background: var(--down-soft); }
.flash-info { border-color: var(--upd); background: var(--upd-soft); }
.note { margin: .5rem 0 0; padding: .45rem .7rem; border-radius: 3px; font-size: .93rem; }
.note-danger { background: var(--down-soft); color: #8A231D; }
.note-warning { background: var(--warn-soft); color: #7A4F0E; }
.note-info { background: #EEF1F5; color: var(--muted); }

/* tablas */
.server { margin-bottom: 1.8rem; }
.server h2 .muted { font-weight: 500; }
.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.grid th { text-align: left; font: 600 .82rem var(--body); color: var(--muted); padding: .55rem .75rem; background: #F6F8FA; border-bottom: 1px solid var(--line); }
.grid td { padding: .6rem .75rem; border-bottom: 1px solid #E7ECF1; vertical-align: top; }
.grid tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .ver { font: 600 1rem var(--cond); font-variant-numeric: tabular-nums; }
.grid .name a { font: 600 1.05rem var(--cond); color: var(--ink); }
.grid .name small { display: block; color: var(--muted); font-size: .82rem; }
.grid tbody tr { box-shadow: inset 4px 0 0 transparent; }
.grid tbody tr.row-ok { box-shadow: inset 4px 0 0 var(--ok); }
.grid tbody tr.row-updates { box-shadow: inset 4px 0 0 var(--upd); }
.grid tbody tr.row-warn, .grid tbody tr.row-flaky { box-shadow: inset 4px 0 0 var(--warn); }
.grid tbody tr.row-down { box-shadow: inset 4px 0 0 var(--down); background: #FFF8F7; }
.grid tbody tr.row-off { box-shadow: inset 4px 0 0 var(--off); color: var(--muted); }
.dim { color: var(--muted); }
.nowrap { white-space: nowrap; }
.fleet-table { table-layout: fixed; }
.fleet-table .w-name { width: 22%; }
.fleet-table .w-state { width: 16%; }
.fleet-table .w-ver { width: 8%; }
.fleet-table .w-ms { width: 9%; }
.fleet-table .w-when { width: 11%; }
.fleet-table .w-act { width: 76px; }
.fleet-table td { overflow-wrap: anywhere; }
small.err { display: block; color: var(--down); font-size: .82rem; }
a.busy { display: block; font-size: .82rem; }
.upd { display: inline-block; margin: 0 .3rem .2rem 0; padding: 0 .4rem; border-radius: 3px; background: var(--upd-soft); color: #1C4A99; font-size: .85rem; }
.php-bad { color: var(--down); }

.pill { display: inline-block; padding: .05rem .5rem; border-radius: 3px; font: 600 .82rem var(--body); white-space: nowrap; }
.pill-ok, .pill-job-ok { background: var(--ok-soft); color: #156B43; }
.pill-updates, .pill-job-running, .pill-job-queued { background: var(--upd-soft); color: #1C4A99; }
.pill-warn, .pill-flaky, .pill-job-rolled_back { background: var(--warn-soft); color: #7A4F0E; }
.pill-down, .pill-job-failed, .pill-job-rollback_failed, .pill-job-lost, .pill-job-interrupted { background: var(--down-soft); color: #8A231D; }
.pill-off, .pill-unknown { background: #E6EAEF; color: var(--muted); }

/* ficha de instalación */
.ihead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-left: 6px solid var(--off); border-radius: 6px; padding: 1rem 1.2rem; margin-bottom: 1rem; }
.ihead p { margin: 0; }
.ihead h1 { margin-bottom: .2rem; }
.ihead-ok, .ihead-job-ok { border-left-color: var(--ok); }
.ihead-updates, .ihead-job-running, .ihead-job-queued { border-left-color: var(--upd); }
.ihead-warn, .ihead-flaky, .ihead-job-rolled_back { border-left-color: var(--warn); }
.ihead-down, .ihead-job-failed, .ihead-job-rollback_failed, .ihead-job-lost { border-left-color: var(--down); }
.ihead-state { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.2rem; align-items: start; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }
.block { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 1rem 1.2rem; margin-bottom: 1.2rem; }
.block .grid { border-radius: 4px; }
.block-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .6rem; }
.block-head h2 { margin: 0; }
.backup-form { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem 1.2rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .85rem; }
.facts dd { margin: 0; }
.facts dd.big { font: 600 1.6rem var(--cond); }
.facts-list { grid-template-columns: 1fr; gap: .4rem; margin-bottom: 1rem; }
.facts-list div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid #EEF1F4; padding-bottom: .35rem; }

.history, .events { list-style: none; margin: 0; padding: 0; }
.history li { padding: .4rem 0; border-bottom: 1px solid #EEF1F4; display: flex; flex-wrap: wrap; gap: .3rem .5rem; align-items: baseline; }
.history small { flex-basis: 100%; }
.events li { padding: .35rem 0 .35rem .6rem; border-left: 3px solid var(--line); margin-bottom: .3rem; font-size: .9rem; }
.events small { display: block; color: var(--muted); }
.events .ev-ok { border-color: var(--ok); }
.events .ev-warning { border-color: var(--warn); }
.events .ev-danger { border-color: var(--down); }
.events .ev-info { border-color: var(--upd); }
.notes { white-space: pre-line; color: var(--muted); font-size: .9rem; margin: .4rem 0 0; }
.steps { padding-left: 1.2rem; margin: 0; }
.steps li { margin-bottom: .5rem; }

/* registro de operaciones */
.log { background: #121A23; color: #D5DEE8; font: .85rem/1.55 var(--mono); padding: 1rem 1.2rem; border-radius: 6px;
  max-height: 65vh; overflow: auto; white-space: pre-wrap; word-break: break-word; }

/* formularios */
.form label, dialog label, .login label { display: block; margin-bottom: .9rem; font-weight: 500; }
input:not([type=checkbox]):not([type=radio]), textarea { display: block; width: 100%; margin-top: .3rem; padding: .5rem .65rem;
  border: 1px solid #B9C4CF; border-radius: 4px; font: 400 .95rem var(--body); color: var(--ink); background: #fff; }
textarea { font-family: var(--mono); font-size: .85rem; }
label.check { display: flex; gap: .45rem; align-items: center; font-weight: 400; margin-bottom: .5rem; }
fieldset { border: 1px solid var(--line); border-radius: 4px; padding: .6rem .9rem .3rem; margin: 0 0 1rem; }
legend { padding: 0 .3rem; color: var(--muted); font-size: .88rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; }
dialog { border: 0; border-radius: 8px; padding: 1.3rem 1.4rem; max-width: 520px; width: calc(100% - 32px); color: var(--ink); }
dialog::backdrop { background: rgba(18, 26, 35, .55); }

.empty { background: var(--panel); border: 1px dashed #B9C4CF; border-radius: 6px; padding: 2rem; text-align: center; margin-bottom: 1.5rem; }
.empty p { max-width: 60ch; margin: .5rem auto 1rem; color: var(--muted); }
.import { margin-top: 2rem; }
.import summary { cursor: pointer; color: var(--brand); font-weight: 500; }
.import form { margin-top: .8rem; max-width: 760px; }
.import textarea { margin-bottom: .6rem; }

/* acceso */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: var(--ink); }
.login { background: var(--panel); border-radius: 8px; padding: 2rem; width: 100%; max-width: 380px; }
.login .btn { width: 100%; }

/* móvil: la tabla se convierte en fichas */
@media (max-width: 760px) {
  .server .grid thead { display: none; }
  .server .grid, .server .grid tbody, .server .grid tr, .server .grid td { display: block; width: 100%; }
  .server .grid tr { border-bottom: 1px solid var(--line); padding: .4rem 0; }
  .server .grid td { border: 0; padding: .15rem .9rem; }
  .server .grid td.num { text-align: left; }
  .server .grid td[data-label]::before { content: attr(data-label); display: inline-block; min-width: 6.5rem;
    color: var(--muted); font: 400 .85rem var(--body); }
  .fleet-table { table-layout: auto; }
  .fleet { padding: 1rem; }
  .led { width: 26px; height: 26px; }
}

/* copia al NAS */
.nas { display: inline-block; padding: 0 .4rem; border-radius: 3px; font-size: .85rem; white-space: nowrap; }
.nas-ok { background: var(--ok-soft); color: #156B43; }
.nas-warn, .nas-run { background: var(--warn-soft); color: #7A4F0E; }
.nas-run { background: var(--upd-soft); color: #1C4A99; }
.nas-bad { background: var(--down-soft); color: #8A231D; }
.inline-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.lead { max-width: 75ch; margin: 0 0 1.2rem; }
select { display: block; width: 100%; margin-top: .3rem; padding: .5rem .65rem; border: 1px solid #B9C4CF;
  border-radius: 4px; font: 400 .95rem var(--body); color: var(--ink); background: #fff; }
.point { align-items: flex-start; padding: .35rem 0; border-bottom: 1px solid #EEF1F4; }
.point:last-child { border-bottom: 0; }

/* acciones por fila */
.row-actions { white-space: nowrap; text-align: right; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0;
  border: 1px solid transparent; border-radius: 4px; background: none; color: var(--muted); cursor: pointer; vertical-align: middle; }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { border-color: #B9C4CF; color: var(--ink); text-decoration: none; }
.icon-danger:hover { border-color: var(--down); color: var(--down); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.btn-ghost-danger { color: var(--down); border-color: #E3B5B1; }
.btn-ghost-danger:hover { border-color: var(--down); }
@media (max-width: 760px) { .row-actions { text-align: left; } }

/* v4: alta de cada cliente en el NAS */
.nas-setup { background: #E6EAEF; color: var(--muted); text-decoration: none; }
a.nas-setup:hover { color: var(--text, #1d2733); }
div.nas-setup { background: var(--upd-soft); color: inherit; border-radius: 8px; padding: 12px 16px; margin-bottom: 12px; }
div.nas-setup .steps li { margin-bottom: 6px; }
.btn-xs { padding: 1px 8px; font-size: 12px; line-height: 1.6; }
code.secret { user-select: all; }
.nas-access { margin-top: 12px; }
.nas-access summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.nas-fields { border: 1px solid #DCE2E9; border-radius: 8px; padding: 8px 14px 4px; margin: 8px 0 14px; }
.nas-fields legend { font-weight: 600; padding: 0 6px; }
.stack-actions { display: grid; gap: 8px; margin: 12px 0 6px; }
.stack-actions form { margin: 0; }
a.btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.pill-job-partial { background: var(--warn-soft); color: #7A4F0E; }
.upd-manual { opacity: .75; text-decoration: line-through dotted; }
.manual-note { font-weight: normal; font-size: 12px; color: var(--muted); margin-top: 4px; max-width: 46ch; white-space: normal; }
.manual-list { margin: 6px 0 0 18px; } .manual-list li { margin: 3px 0; }
