:root {
  --bg: #f5f5f4; --surface: #ffffff; --ink: #141414; --muted: #5f5f5c; --line: #e2e0dc;
  --brand: #111111; --accent: #d63000; --accent-bg: #d63000; --accent-ink: #ffffff; --orange: #ff4000; --brand-rgb: 255, 64, 0; --danger: #b3261e; --warn: #b26a00; --ok: #17803d;
  --shadow: 0 6px 24px rgba(20, 20, 20, .14);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101010; --surface: #1a1a1a; --ink: #f2f2f0; --muted: #a3a29e; --line: #2c2c2a;
    --brand: #111111; --accent: #ff5a26; --accent-bg: #ff5a26; --accent-ink: #160600; --orange: #ff4000; --danger: #ff6b5e; --warn: #f0b429; --ok: #4cc27a;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
h2 { margin: 0 0 4px; font-size: 20px; }
.muted { color: var(--muted); margin: 4px 0 10px; }
.error { color: var(--danger); margin: 8px 0 0; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-lg { justify-content: center; }
.logo { display: block; flex: none; height: 32px; width: auto; max-width: 140px; object-fit: contain; }
.wordmark { font-family: var(--wordmark-font, "Michroma"), "Segoe UI", system-ui, sans-serif; font-size: 20px; letter-spacing: .12em; line-height: 1; display: grid; gap: 5px; }
.wordmark small { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.wordmark { -webkit-text-stroke: .04em currentColor; }
.wordmark small { -webkit-text-stroke: 0; }
.brand-lg { margin-bottom: 4px; }
.brand-lg .logo { height: 48px; max-width: 200px; }
.brand-lg .wordmark { font-size: 30px; color: var(--ink); }
.brand-lg .wordmark small { font-size: 11px; }

.btn { font: inherit; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; min-height: 44px; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent-bg); color: var(--accent-ink); border-color: var(--accent-bg); font-weight: 600; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); font-weight: 600; width: 100%; }
.btn.danger.restore { background: var(--ok); border-color: var(--ok); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; min-height: 36px; }
.btn:disabled { opacity: .6; cursor: default; }

.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(120% 90% at 100% 0%, rgba(var(--brand-rgb), .35), transparent 55%), #111111; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); padding: 28px 24px; border-radius: 18px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card .muted { text-align: center; margin: -6px 0 4px; }
.login-card label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
input { font: inherit; padding: 11px 12px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; }

#app { position: fixed; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.topbar { z-index: 1000; display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.conn { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.conn.on::before { background: var(--ok); }

.alert { position: absolute; z-index: 1100; top: 62px; left: 50%; transform: translateX(-50%); width: min(94vw, 520px); display: flex; gap: 12px; justify-content: space-between; align-items: center; background: var(--danger); color: #fff; padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); }
.alert .btn { color: #fff; border-color: rgba(255,255,255,.6); }

.workspace { display: grid; grid-template-columns: 380px minmax(0, 1fr); min-height: 0; }
.panel { grid-column: 1; grid-row: 1; background: var(--surface); border-right: 1px solid var(--line); overflow: auto; padding: 14px; min-height: 0; }
.mapwrap { grid-column: 2; grid-row: 1; position: relative; min-width: 0; min-height: 0; }
#map { position: absolute; inset: 0; z-index: 1; }
.leaflet-container { font: inherit; background: var(--bg); }
.panel-hidden .workspace { grid-template-columns: 0 minmax(0, 1fr); }
.panel-hidden .panel { display: none; }
.topbar-left { display: flex; align-items: center; gap: 12px; }

.mapctl { position: absolute; z-index: 500; top: 12px; right: 12px; display: grid; gap: 8px; justify-items: end; }
.mapbtn { font: inherit; font-size: 14px; font-weight: 600; padding: 8px 14px; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; box-shadow: var(--shadow); }
.mapbtn:hover, .mapbtn[aria-pressed="true"] { border-color: var(--accent); }
.mapbtn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (max-width: 760px) {
  .topbar { padding-left: 8px; padding-right: 8px; gap: 6px; flex-wrap: wrap; }
  .topbar-left, .topbar-right { gap: 4px; min-width: 0; }
  .topbar-right { flex: 1 1 100%; justify-content: space-between; flex-wrap: wrap; }
  .topbar-right .btn.small { flex: 1 1 auto; padding: 6px 4px; }
  .topbar .btn.small { font-size: 13px; }
  .brand .wordmark { font-size: 17px; }
  .brand .logo { height: 26px; max-width: 90px; }
  .brand-lg .logo { height: 48px; max-width: 200px; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 44%); }
  .mapwrap { grid-column: 1; grid-row: 1; }
  .panel { grid-column: 1; grid-row: 2; border-right: 0; border-top: 1px solid var(--line); padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .panel-hidden .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 0; }
  .brand .wordmark small { display: none; }
  .conn { display: none; }
}

.summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.fchip { font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; min-height: 36px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
.fchip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.fchip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#search { margin-bottom: 10px; }

.cards { display: grid; gap: 8px; }
.card { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; text-align: left; width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; cursor: pointer; }
.card:hover, .card.sel { border-color: var(--accent); }
.card .name { font-weight: 700; }
.card .sub { color: var(--muted); font-size: 13px; grid-column: 1 / -1; }
.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 99px; background: var(--line); color: var(--muted); }
.chip.online { background: color-mix(in srgb, var(--ok) 22%, transparent); color: var(--ok); }
.chip.offline { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.empty { color: var(--muted); padding: 8px 2px; }

.detail-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; margin-bottom: 12px; position: sticky; top: 0; z-index: 5; background: var(--surface); padding: 2px 0 8px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px 12px; display: grid; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-weight: 700; font-size: 17px; }
.block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.block-title { font-weight: 700; margin-bottom: 6px; }
details.block summary.block-title {
  cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; margin-bottom: 0;
}
details.block summary.block-title::-webkit-details-marker { display: none; }
details.block summary.block-title::after { content: "›"; font-size: 20px; line-height: 1; color: var(--muted); transform: rotate(90deg); transition: transform .15s; }
details.block[open] summary.block-title::after { transform: rotate(270deg); }
details.block[open] summary.block-title { margin-bottom: 8px; }
details.block > *:not(summary) { margin-top: 8px; }
.row2 { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; align-items: center; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.dates { display: grid; grid-template-columns: 1fr 1fr; }
.dates label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.presets { display: flex; gap: 8px; margin-bottom: 8px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; margin: 0 0 4px; }
.addr { font-weight: 600; margin: 0 0 2px; }
.share-active input[readonly] { font-size: 12px; margin-bottom: 8px; cursor: text; }
.geo-devices { display: grid; gap: 6px; max-height: 160px; overflow: auto; margin-bottom: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
.geo-devices .check { margin-top: 0; }
.detail label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; margin-bottom: 10px; }
textarea { font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; resize: vertical; }
.detail label.check { display: flex; font-weight: 400; margin-bottom: 0; }
.events li.warn { color: var(--warn); }
.events li.bad { color: var(--danger); }
.events li .row2 { grid-column: 1 / -1; margin: 4px 0 0; }
.events li .sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.events li .sub.warn { color: var(--warn); }
.events li .sub.bad { color: var(--danger); }
.events li .sub b { color: var(--ink); }
.events .t { display: inline-flex; gap: 4px; align-items: center; }
.rtpin { width: 28px; height: 28px; border-radius: 50%; background: var(--orange); color: #fff; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.45); display: grid; place-items: center; font: 700 13px/1 system-ui, sans-serif; }
.rtpin.start { background: #111; }
.rtpin.pend { background: #8a97a5; }
select { font: inherit; padding: 11px 12px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); width: 100%; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; min-height: 36px; cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--accent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tab { font: inherit; font-weight: 600; padding: 10px 14px; min-height: 44px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--orange); }
.tab:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
#routeStats { margin-top: 10px; }
.dlg { border: 0; border-radius: 18px; padding: 0; width: min(92vw, 400px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(0, 0, 0, .55); }
.dlg-body { display: grid; gap: 12px; padding: 24px; }
.dlg-body label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.dlg-body .muted { margin: 0; }
#pwMsg { margin: 0; font-weight: 600; }
#pwMsg.err { color: var(--danger); }
#pwMsg.ok { color: var(--ok); }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.events li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 10px 12px; border-radius: 12px; background: var(--bg); }
.events .t { font-size: 12px; color: var(--muted); }
.events .sos { color: var(--danger); font-weight: 700; }

.pin { position: relative; width: 22px; height: 22px; }
.pin i { position: absolute; inset: 0; border-radius: 50%; background: var(--orange); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.pin.offline i { background: #8a97a5; }
.pin::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--orange); opacity: 0; animation: pulse 2.2s infinite; }
.pin.offline::after { display: none; }
.pin.sos i { background: var(--danger); }
@keyframes pulse { 0% { transform: scale(.6); opacity: .8; } 100% { transform: scale(1.5); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pin::after { animation: none; } }

/* ojito para ver la contraseña */
.pw { position: relative; display: block; }
.pw > input { width: 100%; padding-right: 50px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; padding: 0; }
.pw-eye:hover, .pw-eye[aria-pressed="true"] { color: var(--ink); }
.pw-eye svg { width: 22px; height: 22px; }
