:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e3e7ec;
  --text: #16202b;
  --muted: #677586;
  --accent: #0f766e;
  --accent-soft: #e6f4f2;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b;
    --surface: #161e27;
    --border: #26313d;
    --text: #e6edf3;
    --muted: #8b98a7;
    --accent: #2dd4bf;
    --accent-soft: #123330;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, sans-serif; }
[hidden] { display: none !important; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 18px; margin: 2px 0 0; font-weight: 600; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 0 10px; display: flex; gap: 8px; align-items: center; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
h3 select { width: auto; padding: 3px 6px; font-size: 12px; text-transform: none; letter-spacing: 0; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }

.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-small { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand-lg { font-size: 28px; justify-content: center; }
.logo { width: 32px; height: 32px; border-radius: 8px; background: url("brand/logo-icon.svg") center/contain no-repeat; flex: none; }
.brand-lg .logo { width: 44px; height: 44px; border-radius: 12px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; display: grid; gap: 14px; box-shadow: var(--shadow); text-align: center; }
.login-card label { text-align: left; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.sysstatus { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: 1px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

.layout { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 57px); }
.sidebar { border-right: 1px solid var(--border); padding: 18px 12px; background: var(--surface); }
.sidebar-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 10px 8px; }
.sidebar ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sidebar li { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.sidebar li:hover { background: var(--bg); }
.sidebar li.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar li .count { color: var(--muted); font-size: 12px; }
.site-form { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 14px; }
.site-form input { padding: 6px 8px; font-size: 12px; }

.main { padding: 22px 24px; min-width: 0; }
.main-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.summary { display: flex; gap: 16px; color: var(--muted); font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 12px; cursor: pointer; transition: border-color .15s; }
.card:hover { border-color: var(--accent); }
.card.offline { opacity: .65; }
.card-head { display: flex; justify-content: space-between; gap: 8px; }
.card-name { font-weight: 600; font-size: 15px; }
.card-kind { font-size: 12px; color: var(--muted); }
.card-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.card-points { display: grid; gap: 8px; }
.pt { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pt-label { color: var(--muted); }
.pt-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.card-foot { font-size: 11px; color: var(--muted); }
.empty { color: var(--muted); padding: 40px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

.switch { position: relative; width: 42px; height: 24px; flex: none; border: none; border-radius: 12px; background: var(--border); cursor: pointer; padding: 0; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }
.switch:disabled { opacity: .5; cursor: default; }
.switch.busy { opacity: .6; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: var(--surface); border-left: 1px solid var(--border); z-index: 10; display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-kind { font-size: 12px; color: var(--muted); }
.drawer-body { padding: 16px 20px 32px; overflow-y: auto; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.points { display: grid; gap: 10px; margin-top: 18px; }
.points .pt { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.points select { width: auto; }
.chart { height: 170px; border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .empty { border: none; padding: 50px 0; }
.cmds { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 12px; }
.cmds li { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); }
.cmds .bad { color: var(--bad); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20; font-size: 13px; }

/* ---- alarmas ---- */
:root { --crit: #dc2626; --crit-soft: #fdecec; --warn-soft: #fff4e5; }
@media (prefers-color-scheme: dark) { :root { --crit-soft: #3a1618; --warn-soft: #3a2a12; } }
.bell { position: relative; border: none; background: transparent; cursor: pointer; padding: 6px; border-radius: 8px; }
.bell:hover { background: var(--bg); }
.bell-icon { display: block; width: 20px; height: 20px; background: var(--muted); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9'/%3E%3Cpath d='M10.3 21a1.94 1.94 0 0 0 3.4 0'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9'/%3E%3Cpath d='M10.3 21a1.94 1.94 0 0 0 3.4 0'/%3E%3C/svg%3E") center/contain no-repeat; }
.bell.active .bell-icon { background: var(--crit); }
.bell-count { position: absolute; top: 0; right: 0; min-width: 17px; height: 17px; border-radius: 9px; background: var(--crit); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
.nav-top { margin-bottom: 14px !important; }
.nav-top .count { background: var(--crit); color: #fff !important; border-radius: 9px; padding: 0 7px; font-weight: 600; }
.nav-top .count.zero { background: transparent; color: var(--muted) !important; font-weight: 400; }

.banner { display: grid; gap: 8px; margin-bottom: 16px; }
.alarm-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; border: 1px solid; background: var(--warn-soft); border-color: var(--warn); }
.alarm-row.critical { background: var(--crit-soft); border-color: var(--crit); }
.alarm-row.cleared { background: var(--surface); border-color: var(--border); }
.alarm-row .a-main { flex: 1; min-width: 0; cursor: pointer; }
.alarm-row .a-title { font-weight: 600; }
.alarm-row .a-meta { font-size: 12px; color: var(--muted); }
.sev { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 6px; background: var(--warn); color: #fff; white-space: nowrap; }
.sev.critical { background: var(--crit); }
.sev.ok { background: var(--ok); }
.card.alarm-warning { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
.card.alarm-critical { border-color: var(--crit); box-shadow: 0 0 0 1px var(--crit); }
.card-alarm { font-size: 12px; font-weight: 600; color: var(--crit); }
.card.alarm-warning .card-alarm { color: var(--warn); }

.rules { display: grid; gap: 8px; }
.rule { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.rule.off { opacity: .55; }
.rule-name { font-weight: 500; }
.rule-name small { display: block; color: var(--muted); font-weight: 400; }
.rule input { width: 64px; padding: 4px 6px; text-align: right; }
.rule .unit { font-size: 12px; color: var(--muted); }
.av-section { margin-bottom: 24px; }
.av-section .alarm-row { margin-bottom: 8px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .sidebar ul { display: flex; overflow-x: auto; gap: 6px; }
  .sidebar li { white-space: nowrap; gap: 6px; }
  .sidebar-title, .site-form { display: none; }
  .nav-top { margin-bottom: 6px !important; }
  .alarm-row { flex-wrap: wrap; }
  .main { padding: 16px; }
  .sysstatus { display: none; }
  .topbar { padding: 10px 16px; }
}

/* ---- multi-cliente ---- */
.org-badge { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.org-badge:empty { display: none; }
.whoami { font-size: 13px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 6px; }
.nav-section:first-child { padding-top: 0; }
.nav-org { font-size: 11px; color: var(--muted); padding: 8px 10px 2px; font-weight: 600; }
.sidebar ul + .nav-section { margin-top: 4px; }

.site-block { margin-bottom: 28px; }
.site-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.site-head h2 { font-size: 16px; }
.site-head .muted { font-size: 12px; }

.el-top { display: flex; justify-content: space-between; gap: 8px; }
.el-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); flex: none; display: grid; place-items: center; }
.el-icon i { width: 18px; height: 18px; background: var(--accent); display: block; -webkit-mask: var(--ic) center/contain no-repeat; mask: var(--ic) center/contain no-repeat; }
.el-title { display: flex; gap: 10px; align-items: center; min-width: 0; }
.el-name { font-weight: 600; font-size: 15px; }
.el-type { font-size: 12px; color: var(--muted); }
.el-state { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.el-state small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.el-state.on { color: var(--accent); }
.el-body { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; }
.gauge { height: 10px; border-radius: 6px; background: var(--border); overflow: hidden; }
.gauge > span { display: block; height: 100%; border-radius: 6px; background: var(--accent); transition: width .4s; }
.gauge.warn > span { background: var(--warn); } .gauge.crit > span { background: var(--crit); }

.btn-act { font-weight: 600; min-width: 96px; }
.btn-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--crit); border-color: var(--crit); color: #fff; }

.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: min(460px, 100%); max-height: 90vh; overflow-y: auto; padding: 22px; display: grid; gap: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal h2 { margin: 0; }
.modal textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; min-height: 70px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.warnbox { background: var(--warn-soft); border: 1px solid var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 18px; font-weight: 700; letter-spacing: .06em; background: var(--bg); border: 1px dashed var(--border); border-radius: 8px; padding: 10px; text-align: center; user-select: all; }
.checks { display: grid; gap: 6px; max-height: 180px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.checks label { display: flex; flex-direction: row; gap: 8px; align-items: center; font-size: 13px; color: var(--text); }
.checks input, .chk input { width: auto; }
.chk { display: flex !important; flex-direction: row !important; gap: 8px; align-items: center; color: var(--text) !important; font-size: 13px !important; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { font: inherit; background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 14px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h3 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl td select, .tbl td input { padding: 4px 6px; font-size: 12px; width: auto; }
.tbl .row-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: var(--ok); } .pill.bad { color: var(--bad); border-color: var(--bad); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.big-state { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; margin-top: 16px; }
@media (max-width: 760px) {
  .org-badge { display: none; }
  .whoami { display: none; }
  .nav-section, .nav-org { display: none; }
}

/* ---- celular: sin scroll horizontal, menú en una sola fila deslizable ---- */
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .main, .sidebar { min-width: 0; }
  .sidebar { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar ul { display: flex; flex: none; gap: 6px; margin: 0 !important; }
  .sidebar li { padding: 6px 10px; background: var(--bg); }
  .sidebar li.nav-org { display: none; }
  .topbar { gap: 8px; }
  .main-head { margin-bottom: 12px; }
  h1 { font-size: 18px; }
  .el-state { font-size: 20px; }
  .drawer-body { padding: 14px 16px 28px; }
  .field-row { grid-template-columns: 1fr; }
  .rule { grid-template-columns: auto 1fr; }
  .rule > span { grid-column: 2; }
  .modal { padding: 18px; }
  .tabs button { padding: 8px 10px; }
}
@media (max-width: 760px) {
  .alarm-row { flex-wrap: wrap; gap: 8px 10px; }
  .alarm-row .a-main { flex: 1 1 100%; order: 3; }
  .alarm-row .btn { margin-left: auto; }
}

/* ---- marca ---- */
.login-brand { display: grid; justify-items: center; gap: 10px; margin-bottom: 2px; }
.login-logo { width: 88px; height: 88px; border-radius: 20px; }
.login-name { font-size: 32px; font-weight: 700; letter-spacing: -.02em; }
.brand-text { display: grid; line-height: 1.1; }
.brand-text small { font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: .02em; }
.login-name { font-size: 28px; }
.login-by { font-size: 13px; font-weight: 500; color: var(--muted); margin-top: -8px; letter-spacing: .03em; }
@media (max-width: 760px) { .brand { font-size: 16px; } }

/* ---- colores por tipo de elemento (ícono) ---- */
.el-icon { width: 38px; height: 38px; border-radius: 10px; }
.el-icon i { width: 22px; height: 22px; background: var(--ic-fg, var(--accent)); }
.el-icon { background: var(--ic-bg, var(--accent-soft)); }
.t-pump     { --ic-fg: #2563eb; --ic-bg: #e0eaff; }
.t-level    { --ic-fg: #0891b2; --ic-bg: #dcf5fb; }
.t-light    { --ic-fg: #d97706; --ic-bg: #fdf1dc; }
.t-elevator { --ic-fg: #7c3aed; --ic-bg: #ede6fe; }
.t-gate     { --ic-fg: #475569; --ic-bg: #e7ecf2; }
.t-sensor   { --ic-fg: #16a34a; --ic-bg: #dff5e6; }
.t-other    { --ic-fg: #64748b; --ic-bg: #eceff3; }
@media (prefers-color-scheme: dark) {
  .t-pump     { --ic-fg: #7aa7ff; --ic-bg: #16254a; }
  .t-level    { --ic-fg: #4fd4ee; --ic-bg: #0f3440; }
  .t-light    { --ic-fg: #fbbf24; --ic-bg: #3a2c10; }
  .t-elevator { --ic-fg: #b69cff; --ic-bg: #2a1f4a; }
  .t-gate     { --ic-fg: #a9b8cc; --ic-bg: #243040; }
  .t-sensor   { --ic-fg: #4ade80; --ic-bg: #123524; }
  .t-other    { --ic-fg: #a3aebd; --ic-bg: #252d38; }
}
@media (max-width: 760px) { .layout { grid-template-rows: auto 1fr; } }

/* ---- instalar como app ---- */
.install-btn { width: 100%; }
.install-banner { position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 25;
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.install-banner img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.install-banner .ib-text { display: grid; flex: 1; min-width: 0; font-size: 13px; line-height: 1.3; }
.install-banner .ib-text span { color: var(--muted); font-size: 12px; }
.ios-steps { display: grid; gap: 12px; }
.ios-steps p { margin: 0; display: flex; gap: 10px; align-items: flex-start; line-height: 1.5; }
.ios-steps p > span:last-child { flex: 1; }
.ios-steps svg { color: var(--accent); vertical-align: -3px; }
.step { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; flex: none; }
/* Instalada: respetar la muesca y la barra de estado del teléfono */
.topbar { padding-top: max(12px, env(safe-area-inset-top)); }
.login { padding-top: max(16px, env(safe-area-inset-top)); }
@media (display-mode: standalone) { .toast { bottom: max(20px, env(safe-area-inset-bottom)); } }

/* ---- alarmas reconocidas: siguen activas pero ya no reclaman atención ---- */
.alarm-row.acked { background: var(--surface); border-style: dashed; }
.sev.ack { background: var(--border); color: var(--text); }
.card.acked { box-shadow: none; border-style: dashed; }
.card.acked .card-alarm { color: var(--muted) !important; font-weight: 500; }
.bell-count.muted-count { background: var(--muted); }
