:root {
  --bg: #DCE2E6;        /* concreto */
  --panel: #F3F5F6;
  --raise: #FFFFFF;
  --ink: #16212A;
  --muted: #586874;
  --line: #BAC4CB;
  --stage: #1A242C;     /* acero */
  --amber: #E5A600;     /* amarillo maquinaria */
  --amber-ink: #6E5000;
  --signal: #1C977D;
  --alert: #C0402B;
  --focus: #2F6FDE;
  --font: "Barlow", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --num: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141C23;
    --panel: #1C262F;
    --raise: #24313B;
    --ink: #E3E9ED;
    --muted: #93A3AF;
    --line: #33424E;
    --stage: #0D1318;
    --amber: #F2B705;
    --amber-ink: #F2B705;
    --signal: #3CC4A5;
    --alert: #F0745E;
    --focus: #7AA7FF;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--font);
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

/* ------------------------------------------------ login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  display: flex; flex-direction: column; gap: 10px;
}
.login-mark { width: 120px; height: 20px; }
.login-card h1 { font: 600 34px/1 var(--num); margin-top: 6px; }
.login-card p { margin: 0 0 10px; color: var(--muted); }
.login-card label { font-weight: 500; font-size: 14px; }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--raise);
}
.err { color: var(--alert); min-height: 1.4em; font-size: 14px; }

/* ------------------------------------------------ botones */
.btn, .primary, .tool, .link {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
  font-size: 15px;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px;
  white-space: nowrap;
}
a.btn { color: var(--ink); }
.btn:hover, .tool:hover { background: var(--raise); }
.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); justify-content: center; }
.primary:hover { opacity: .9; }
.link { border: 0; background: none; padding: 4px 6px; color: var(--muted); }
.tool { width: 40px; height: 40px; padding: 0; justify-content: center; }
.tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ------------------------------------------------ estructura */
.app { display: grid; grid-template-columns: 272px minmax(0, 1fr); height: 100%; }
.fleet { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.fleet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 14px 10px 18px; gap: 8px; }
.fleet-actions { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
.brand { font: 600 22px/1 var(--num); letter-spacing: .01em; }
.device-list { list-style: none; margin: 0; padding: 4px 8px 16px; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.device {
  width: 100%;
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; column-gap: 10px; align-items: center;
  text-align: left; padding: 10px; border: 0; border-radius: 8px; background: none; cursor: pointer;
}
.device:hover { background: var(--raise); }
.device.active { background: var(--raise); box-shadow: inset 3px 0 0 var(--amber); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); grid-row: 1 / 3; }
.dot.on { background: var(--signal); }
.dname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dsub { grid-column: 2; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pwr {
  grid-column: 3; grid-row: 1 / 3;
  font: 600 12px/1 var(--num); letter-spacing: .02em;
  color: var(--amber-ink);
  background: color-mix(in srgb, var(--amber) 22%, transparent);
  border-radius: 4px; padding: 4px 6px;
}
.fleet-empty { padding: 8px 18px; color: var(--muted); font-size: 14px; }

.work { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 18px 22px 24px; gap: 14px; overflow: auto; }
.work-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; justify-content: space-between; }
.title-block { min-width: 0; }
h2 { font: 600 30px/1.05 var(--num); }
.meta { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { font-size: 13px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.chip.ok { border-color: var(--signal); color: var(--signal); }
.chip.warn { border-color: var(--alert); color: var(--alert); }
.tabs { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs button { border: 0; background: var(--panel); padding: 8px 18px; font-weight: 500; cursor: pointer; }
.tabs button + button { border-left: 1px solid var(--line); }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); }
.tab { display: flex; flex-direction: column; gap: 14px; flex-shrink: 0; }
.tab > *, .work > * { flex-shrink: 0; }

/* ------------------------------------------------ pantalla */
.stage {
  position: relative;
  background: var(--stage);
  border-radius: 10px;
  display: flex; justify-content: center; align-items: center;
  min-height: 260px;
  padding: 10px;
}
#screen {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 340px);
  min-height: 0;
  width: auto; height: auto;
  min-width: 0;
  flex: 0 1 auto;
  border-radius: 4px;
  background: #000;
}
.stage.ctrl-on #screen { cursor: crosshair; touch-action: none; box-shadow: 0 0 0 2px var(--amber); }
.stage-msg {
  position: absolute; inset: 0;
  display: grid; place-items: center; text-align: center;
  padding: 24px;
  color: #E3E9ED;
  font-size: 17px;
  background: color-mix(in srgb, var(--stage) 82%, transparent);
  border-radius: 10px;
}
.stage-msg span { max-width: 46ch; }
.stage:fullscreen { border-radius: 0; }
.stage:fullscreen #screen { max-height: 100vh; }

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.group { display: flex; gap: 4px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; padding: 6px 4px; }
.switch input { width: 18px; height: 18px; accent-color: var(--amber); }
.select { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; }
.select select { padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); }
.live-info { margin-left: auto; font: 500 15px var(--num); color: var(--muted); }

/* ------------------------------------------------ tacógrafo */
.tacho { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 10px; }
.tacho-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.tacho-head strong { font: 600 26px/1 var(--num); color: var(--ink); white-space: nowrap; }
.tacho svg { width: 100%; height: 28px; display: block; border-radius: 3px; }
.t-bg { fill: var(--line); opacity: .45; }
.t-on { fill: var(--muted); opacity: .55; }
.t-mach { fill: var(--amber); }
.t-tick { stroke: var(--panel); stroke-width: 3; }
.t-now { fill: var(--ink); }
.tacho-scale { display: flex; justify-content: space-between; font: 500 13px var(--num); color: var(--muted); margin-top: 4px; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.sw { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.sw.mach { background: var(--amber); }
.sw.on { background: var(--muted); opacity: .55; margin-left: 10px; }

/* ------------------------------------------------ archivos */
.files-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cur-path {
  flex: 1 1 220px; min-width: 0;
  padding: 8px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);
  overflow-x: auto; white-space: nowrap; font-size: 14px;
}
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
td { padding: 9px 14px; border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent); }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-family: var(--num); font-size: 16px; white-space: nowrap; }
.files td:first-child { width: 60%; }
.entry { border: 0; background: none; padding: 0; cursor: pointer; text-align: left; display: inline-flex; gap: 8px; align-items: center; }
.entry:hover span { text-decoration: underline; }
.entry svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.entry.dir svg { fill: color-mix(in srgb, var(--amber) 35%, transparent); stroke: var(--amber-ink); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.progress { position: relative; height: 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.progress div { position: absolute; inset: 0 auto 0 0; width: 0; background: color-mix(in srgb, var(--amber) 45%, transparent); }
.progress span { position: relative; font-size: 13px; padding: 0 10px; line-height: 26px; }

/* ------------------------------------------------ horas */
.hours-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 10px; }
h3 { font: 600 22px/1.1 var(--num); }
.chart-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; overflow-x: auto; }
#bars { width: 100%; min-width: 520px; height: auto; display: block; }
.bar-tab { fill: var(--muted); opacity: .25; }
.bar-mach { fill: var(--amber); }
.bar-hit { fill: transparent; cursor: pointer; }
.bar-hit:hover { fill: var(--ink); opacity: .05; }
.bar-sel { fill: var(--ink); opacity: .08; }
.bar-val { font: 600 13px var(--num); fill: var(--ink); text-anchor: middle; }
.bar-day { font: 500 12px var(--num); fill: var(--muted); text-anchor: middle; }
.grid-line { stroke: var(--line); stroke-dasharray: 2 4; }
.grid-lbl { font: 500 11px var(--num); fill: var(--muted); }

/* ------------------------------------------------ modal */
.modal-back { position: fixed; inset: 0; background: rgba(10, 16, 20, .55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { width: min(640px, 100%); max-height: 88vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font: 600 24px/1 var(--num); }
.modal-body { padding: 18px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-body label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
.modal-body input, .modal-body select { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--raise); }
.field + .field { margin-top: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }
.user-row:last-child { border-bottom: 0; }
.user-row .who { flex: 1; min-width: 0; }
.user-row .who b { display: block; }
.user-row .who span { font-size: 13px; color: var(--muted); }
.badge { font: 600 11px/1 var(--num); letter-spacing: .03em; padding: 3px 7px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.badge.admin { border-color: var(--amber); color: var(--amber-ink); background: color-mix(in srgb, var(--amber) 16%, transparent); }
.checks { display: flex; flex-direction: column; gap: 6px; max-height: 190px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.checks label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); margin: 0; }
.checks input { width: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.sep { height: 1px; background: var(--line); margin: 4px 0; }
.sub { font-size: 13px; color: var(--muted); margin: 0; }

/* ------------------------------------------------ avisos */
.toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; z-index: 10; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 14px; animation: toast-in .18s ease-out; }
.toast.bad { background: var(--alert); color: #fff; }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ------------------------------------------------ móvil */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .fleet { border-right: 0; border-bottom: 1px solid var(--line); }
  .fleet-head { padding: 12px 12px 6px 14px; }
  .device-list { flex-direction: row; overflow-x: auto; padding: 0 8px 10px; gap: 6px; }
  .device-list li { flex: 0 0 auto; width: 210px; }
  .device { background: var(--raise); }
  .work { padding: 12px; }
  h2 { font-size: 24px; }
  #screen { max-height: 62vh; max-width: 100%; }
  .stage { min-height: 180px; padding: 6px; }
  .live-info { margin-left: 0; width: 100%; }
  .tabs { width: 100%; }
  .tabs button { flex: 1; }
}

/* ---- Ubicación y datos */
.loc-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr); gap: 16px; align-items: start; }
.map-wrap { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.map { width: 100%; height: 440px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); z-index: 0; }
.map-msg { margin: 0; color: var(--muted); }
.data-grid { display: grid; grid-template-columns: auto 1fr; margin: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--raise); overflow: hidden; }
.data-grid dt, .data-grid dd { margin: 0; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.data-grid dt { color: var(--muted); font-size: 14px; }
.data-grid dd { font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }
.data-grid dt:nth-last-of-type(1), .data-grid dd:last-of-type { border-bottom: 0; }
.data-grid .sec { grid-column: 1 / -1; background: var(--panel); font-family: var(--num); letter-spacing: .04em; text-transform: uppercase; font-size: 13px; color: var(--muted); padding: 6px 12px; border-bottom: 1px solid var(--line); }
.data-grid .ok { color: var(--signal); }
.data-grid .warn { color: var(--alert); }
.signal-bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; margin-right: 6px; vertical-align: -1px; }
.signal-bars i { width: 3px; background: var(--line); border-radius: 1px; }
.signal-bars i.on { background: currentColor; }
.link.danger { color: var(--alert); padding-left: 0; margin-top: 6px; }
.retired-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.retired-row .who { flex: 1; display: flex; flex-direction: column; }
.retired-row .who span { color: var(--muted); font-size: 13px; }
@media (max-width: 900px) { .loc-grid { grid-template-columns: 1fr; } .map { height: 320px; } }

/* ---- Incrustado en MAQUITOP SFA: solo la máquina elegida, sin la lista ni la cuenta */
body.embed .app { grid-template-columns: minmax(0, 1fr); }
body.embed .fleet, body.embed #retireBtn { display: none !important; }

/* Grabación local de la pantalla en vivo */
.btn.rec { display: inline-flex; align-items: center; gap: 8px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--alert); flex: none; }
.btn.rec.on { background: var(--alert); color: #fff; border-color: var(--alert); }
.btn.rec.on .rec-dot { background: #fff; animation: rec-blink 1s steps(2, start) infinite; }
.rec-badge {
  position: absolute; top: 12px; left: 12px; display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 6px; background: rgba(0, 0, 0, .62); color: #fff;
  font: 600 15px var(--num); letter-spacing: .04em; pointer-events: none;
}
.rec-badge .rec-dot { animation: rec-blink 1s steps(2, start) infinite; }
@keyframes rec-blink { to { visibility: hidden; } }
.stage-msg .btn { margin-top: 12px; }
.stage-msg { flex-direction: column; }
body.solo-ver .controls .group, body.solo-ver #textBtn, body.solo-ver .switch,
body.solo-ver [data-tab="files"] { display: none !important; }
