:root {
  /* Colores Yalitech: rojo #FF0015 y verde #6CB800 (del logo). */
  --yt-red: #ff0015;
  --yt-green: #6cb800;
  --bg: #f5f6f2;
  --surface: #ffffff;
  --ink: #1e2620;
  --muted: #66706a;
  --line: #e2e6df;
  --brand: #3f7d00;          /* verde Yalitech oscurecido: botones y enlaces legibles */
  --brand-hover: #336600;
  --brand-ink: #ffffff;
  --brand-soft: #eef6e2;
  --ok: #3f7d00;
  --warn: #a86400;
  --warn-soft: #fff4e0;
  --bad: #c8102e;            /* rojo de alerta */
  --bad-soft: #fdecee;
  --tandd: #1f6f8b;
  --dezem: #7a4fa0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 20, .05), 0 4px 14px rgba(20, 30, 20, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.hidden { display: none !important; }

/* ----- barra superior ----- */
.topbar {
  display: flex; align-items: center; gap: 30px;
  padding: 0 28px; height: 66px;
  background: #fff; color: var(--ink);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .02);
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { display: flex; align-items: center; gap: 11px; white-space: nowrap; text-decoration: none; color: var(--ink); }
.topbar .brand img { width: 40px; height: 40px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 1.08rem; font-weight: 750; letter-spacing: -.01em; }
.brand-text strong em { font-style: normal; color: var(--yt-red); }
.brand-text small { font-size: .78rem; color: var(--muted); font-weight: 550; }
.topbar nav { display: flex; gap: 6px; }
.topbar nav a {
  color: var(--muted); text-decoration: none; padding: 8px 16px; border-radius: 999px;
  font-weight: 600; font-size: .95rem; transition: background .15s, color .15s;
}
.topbar nav a:hover { color: var(--ink); background: #f1f3ee; }
.topbar nav a.active { color: var(--brand); background: var(--brand-soft); }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: .88rem; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.topbar .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: .85rem; text-transform: uppercase; }
.topbar button.link { color: var(--muted); }
.topbar button.link:hover { color: var(--ink); }

main { max-width: 1280px; margin: 0 auto; padding: 26px 28px 60px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.subtabs { display: flex; gap: 6px; margin-bottom: 18px; }
.subtabs a {
  padding: 7px 14px; border-radius: 999px; text-decoration: none; color: var(--muted);
  background: transparent; border: 1px solid var(--line); font-size: .9rem; font-weight: 550;
}
.subtabs a.active { background: var(--ink); color: #fff; border-color: var(--ink); }

section.block { margin-bottom: 30px; }
section.block > .block-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
section.block > .block-head .spacer { flex: 1; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px 20px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

/* ----- botones y formularios ----- */
button, .btn {
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none;
}
button:hover { border-color: #b9c0b9; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
button.danger { color: var(--bad); }
button.danger:hover { border-color: var(--bad); }
button.link { background: none; border: none; padding: 4px 6px; color: var(--brand); font-weight: 550; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small { padding: 5px 10px; font-size: .82rem; }
button.star { border: none; background: none; padding: 2px 4px; font-size: 1.2rem; line-height: 1; color: #c3c8c2; }
button.star.on { color: #e0a100; }

label { display: block; font-size: .84rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select {
  font: inherit; font-size: .92rem; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus { outline: 3px solid rgba(108, 184, 0, .28); outline-offset: 0; border-color: var(--brand); }
.field { margin-bottom: 14px; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; }
.inline-check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--ink); font-size: .9rem; }
.inline-check input { width: auto; }
.radio-row { display: flex; gap: 18px; margin-bottom: 10px; }
.radio-row label { display: flex; gap: 6px; align-items: center; color: var(--ink); font-weight: 500; margin: 0; }
.radio-row input { width: auto; }
.error-msg { color: var(--bad); font-size: .88rem; margin: 8px 0; }
.ok-msg { color: var(--ok); font-size: .88rem; margin: 8px 0; }

/* ----- tablas ----- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; background: #fafbf9; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7f9f7; }
.table-wrap { overflow-x: auto; }

/* ----- insignias ----- */
.badge { display: inline-block; font-size: .74rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.tandd { background: #e1f0f5; color: var(--tandd); }
.badge.dezem { background: #efe6f6; color: var(--dezem); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: #e5f3ea; color: var(--ok); }
.badge.neutral { background: #eceeea; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--ok); }
.dot.bad { background: var(--bad); }

/* ----- tarjetas de favoritos ----- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 18px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; }
.card.alerting { border-color: #e9a29d; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; }
.card-head h3 { flex: 1; font-size: 1.04rem; }
.card-device { padding: 10px 16px 12px; border-top: 1px solid var(--line); cursor: pointer; }
.card-device:hover { background: #f8faf8; }
.card-device .dev-title { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.card-device .dev-title strong { font-weight: 600; flex: 1; }
.var-line { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; }
.var-line .vname { color: var(--muted); font-size: .86rem; min-width: 90px; }
.var-line .vval { font-size: 1.22rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.var-line .vval.bad { color: var(--bad); }
.var-line .vunit { color: var(--muted); font-size: .86rem; }
.var-line .vtime { margin-left: auto; color: var(--muted); font-size: .78rem; white-space: nowrap; }
.no-readings { color: var(--warn); font-size: .88rem; font-style: italic; padding: 2px 0; }

/* ----- alertas ----- */
.alert-cond { font-weight: 600; }
.alert-cond.bajo_minimo, .alert-cond.sobre_maximo { color: var(--bad); }
.alert-cond.sin_medicion { color: var(--warn); }

/* ----- ficha de equipo ----- */
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 22px; }
.meta-grid .k { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; margin-bottom: 3px; }
.meta-grid .v { font-size: .94rem; }
.latest-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.latest-tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.latest-tile .lname { color: var(--muted); font-size: .86rem; font-weight: 600; }
.latest-tile .lval { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.latest-tile .lval.bad { color: var(--bad); }
.latest-tile .lval small { font-size: .95rem; color: var(--muted); font-weight: 600; margin-left: 4px; }
.latest-tile .lrange { font-size: .8rem; color: var(--muted); }
.notice { border-radius: var(--radius); padding: 14px 18px; background: var(--warn-soft); color: #6d4200; border: 1px solid #f0d3a4; margin-bottom: 18px; }
.notice.info { background: var(--brand-soft); color: #2d5200; border-color: #d3e8b6; }
.notice.bad { background: var(--bad-soft); color: #7d1a14; border-color: #f2c1bd; }

.range-bar { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.range-bar .presets { display: flex; gap: 4px; }
.range-bar .presets button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.range-bar input { width: auto; }
.chart-box { margin-bottom: 18px; padding: 14px 16px 8px; }
.chart-box .chart-title { display: flex; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.chart-box svg { width: 100%; height: auto; display: block; }
.chart-box .axis text { font-size: 11px; fill: var(--muted); }
.chart-box .grid line { stroke: #edf0eb; }
.chart-box .series { fill: none; stroke: #5aa300; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart-box .area { opacity: .9; }
.chart-box .band { fill: var(--yt-green); opacity: .16; }
.chart-box .limit { stroke: var(--bad); stroke-width: 1.3; stroke-dasharray: 6 4; }
.chart-box .limit-label { font-size: 11px; fill: var(--bad); font-weight: 650; }
.chart-box .hover-line { stroke: #9aa39e; stroke-width: 1; }
.chart-box .hover-dot { fill: #5aa300; stroke: #fff; stroke-width: 2.5; }
.chart-box .tip-bg { fill: #1d2422; opacity: .92; }
.chart-box .tip-text { fill: #fff; font-size: 12px; }
.limits-table input { width: 120px; }

/* ----- modal ----- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 28, 25, .42); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0, 0, 0, .22); }
.modal-head { display: flex; align-items: center; padding: 18px 22px 8px; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 10px 22px 6px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 22px 20px; }
.preview { background: #f7f9f7; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; font-size: .9rem; }
.preview dl { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; margin: 0; }
.preview dt { color: var(--muted); }
.preview dd { margin: 0; }

/* ----- conexiones ----- */
.conn-list { display: grid; gap: 14px; }
.conn { padding: 16px 18px; }
.conn-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.conn-head h3 { font-size: 1.02rem; }
.conn-head .spacer { flex: 1; }
.conn .facts { display: flex; gap: 22px; flex-wrap: wrap; font-size: .87rem; color: var(--muted); }
.conn .facts b { color: var(--ink); font-weight: 600; }

/* ----- login ----- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1000px 520px at 85% -10%, #eef7e0 0%, transparent 60%), radial-gradient(800px 480px at -10% 110%, #fff0f1 0%, transparent 55%), var(--bg);
}
.login { width: 100%; max-width: 390px; padding: 34px 32px 30px; }
.login .brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; margin-bottom: 26px; }
.login .brand img { width: 92px; height: 92px; }
.login .brand .brand-text { align-items: center; }
.login .brand .brand-text strong { font-size: 1.5rem; }
.login .brand .brand-text small { font-size: .92rem; margin-top: 4px; }
.login button { width: 100%; justify-content: center; padding: 11px; font-size: .95rem; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(30px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: .9rem; opacity: 0; transition: all .2s; pointer-events: none; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); }

@media (max-width: 720px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .brand span, .topbar .user { display: none; }
  .topbar nav a { padding: 0 10px; }
  main { padding: 18px 14px 40px; }
  .cards { grid-template-columns: 1fr; }
}

/* ----- selección de columnas (Dezem) ----- */
.col-group { border: 1px solid var(--line); border-radius: 8px; background: #fff; margin: 10px 0; padding: 8px 12px; }
.col-group-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.col-item { display: grid; grid-template-columns: 20px 1fr auto; gap: 2px 8px; align-items: center; font-weight: 500; color: var(--ink); font-size: .88rem; margin: 6px 0; }
.col-item input { width: auto; }
.col-item > span:nth-of-type(3) { grid-column: 2 / 4; }
.col-item.taken { opacity: .55; }
.modal { max-width: 620px; }

/* ----- tema Yalitech: detalles más amables ----- */
.panel, .card, .latest-tile { border-radius: var(--radius); }
.card { transition: box-shadow .15s, transform .15s; }
.card:hover { box-shadow: 0 2px 4px rgba(20, 30, 20, .06), 0 10px 26px rgba(20, 30, 20, .08); }
.card-head { border-top: 4px solid var(--yt-green); border-radius: var(--radius) var(--radius) 0 0; padding-top: 14px; }
.card.alerting .card-head { border-top-color: var(--bad); }
.card-device:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.latest-tile { border-left: 4px solid var(--yt-green); }
.latest-tile.bad { border-left-color: var(--bad); }
button { border-radius: 10px; }
.subtabs a.active { background: var(--brand); border-color: var(--brand); }
.range-bar .presets button.on { background: var(--brand); border-color: var(--brand); }
th { background: #f8faf5; }
.welcome { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.welcome h1 { font-size: 1.6rem; }
.welcome .sub { color: var(--muted); margin-top: 4px; }
.welcome .spacer { flex: 1; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; }
.stat .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.15rem; background: var(--brand-soft); color: var(--brand); flex: none; }
.stat.bad .ico { background: var(--bad-soft); color: var(--bad); }
.stat.warn .ico { background: var(--warn-soft); color: var(--warn); }
.stat .num { font-size: 1.5rem; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: .82rem; color: var(--muted); font-weight: 550; }
.empty-ok { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--ok); font-weight: 600; padding: 22px; }
@media (max-width: 720px) {
  .brand-text small { display: none; }
  .topbar .user span { display: none; }
}

/* ----- indicadores (gauges) en tarjetas de favoritos ----- */
.gauges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px 10px; margin: 4px 0 2px; }
.gauge-box { text-align: center; }
.gauge-name { font-size: .84rem; font-weight: 650; color: var(--muted); margin-bottom: -2px; }
.gauge { width: 100%; max-width: 170px; height: auto; display: block; margin: 0 auto; }
.gauge .g-track { fill: none; stroke: #e4e7e1; stroke-width: 15; }
.gauge .g-zone { fill: none; stroke-width: 15; }
.gauge .g-zone.warn { stroke: #f6e2b8; }
.gauge .g-zone.danger { stroke: #f6cdd3; }
.gauge .g-value { fill: none; stroke: var(--yt-green); stroke-width: 15; transition: stroke .2s; }
.gauge .g-value.warn { stroke: #e8a317; }
.gauge .g-value.danger { stroke: var(--bad); }
.gauge .g-limit { stroke: var(--bad); stroke-width: 2.5; stroke-linecap: round; }
.gauge .g-scale { font-size: 11px; fill: #8a938c; font-weight: 600; }
.gauge .g-num { font-size: 24px; font-weight: 750; fill: var(--ink); font-variant-numeric: tabular-nums; }
.gauge .g-num.warn { fill: #b07800; }
.gauge .g-num.danger { fill: var(--bad); }
.gauge .g-unit { font-size: 12px; fill: var(--muted); font-weight: 600; }
.status-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 2px; }
.status-chip { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; padding: 3px 10px; border-radius: 999px; background: #f2f5ee; color: var(--muted); }
.status-chip strong { color: var(--ink); }
.status-chip .sdot { width: 8px; height: 8px; border-radius: 50%; background: var(--yt-green); }
.status-chip.bad { background: var(--bad-soft); color: var(--bad); }
.status-chip.bad .sdot { background: var(--bad); }
.dev-time { font-size: .78rem; color: var(--muted); margin-top: 8px; }
.card-head .link.small { font-size: .82rem; }
.gauge-dev { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.gauge-dev-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.gauge-table th, .gauge-table td { padding: 6px 8px; }
.gauge-table input { width: 100px; }

.modal.wide { max-width: 880px; }
.gauge-table input { width: 100px; }
.gauge-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin: 4px 0 12px; }
.gauge-legend i { display: inline-block; width: 18px; height: 8px; border-radius: 4px; margin-right: 5px; vertical-align: middle; }
.gauge-legend .lg-ok { background: var(--yt-green); } .gauge-legend .lg-warn { background: #e8a317; } .gauge-legend .lg-bad { background: var(--bad); }

/* ----- resumen anclado al fondo (Inicio) ----- */
.stat-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  margin: 0; padding: 10px max(28px, calc((100vw - 1280px) / 2 + 28px));
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(6px);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(20, 30, 20, .07);
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px;
}
.stat-dock .stat { box-shadow: none; padding: 8px 14px; border-radius: 12px; background: #fafbf8; }
.stat-dock .stat .ico { width: 32px; height: 32px; border-radius: 10px; font-size: 1rem; }
.stat-dock .stat .num { font-size: 1.25rem; }
body.has-dock main { padding-bottom: 110px; }
@media (max-width: 720px) {
  .stat-dock { grid-template-columns: repeat(2, 1fr); padding: 8px 12px; }
  .stat-dock .stat .lbl { font-size: .74rem; }
  body.has-dock main { padding-bottom: 170px; }
}

/* ----- edición de nombres ----- */
.rename-table { margin: 4px 0 8px; }
.rename-table th, .rename-table td { padding: 6px 8px; }
.rename-table td:first-child { white-space: nowrap; }
.rename-table input.unit-in { width: 80px; }
.field.rename { margin-top: 12px; }
.col-item .col-name { padding: 4px 8px; font-size: .88rem; width: auto; min-width: 180px; }
