:root {
  --navy: #0f2c4f;
  --blue: #1d4f91;
  --blue-soft: #e8eff8;
  --green: #1e7a46;
  --green-soft: #e4f3ea;
  --amber: #f2b33d;
  --amber-soft: #fdf0d5;
  --on-amber: #7a4b00;
  --red: #b3261e;
  --red-soft: #fbe9e7;
  --ink: #14202e;
  --muted: #556274;
  --ground: #f4f6f9;
  --line: #dce2ea;
  --card: #ffffff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--ground);
}

* { box-sizing: border-box; }
body { margin: 0; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { background: var(--blue-soft); padding: 0 .3em; border-radius: 4px; }
[hidden] { display: none !important; }

.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: .75rem 1.25rem; background: var(--navy); color: #fff;
}
.brand { display: flex; gap: .75rem; align-items: center; }
.brand .sub { display: block; font-size: .8rem; opacity: .8; }
.logo {
  width: 38px; height: 38px; border-radius: 10px; background: var(--amber); color: var(--navy);
  display: grid; place-items: center; font-weight: 800;
}
.who { display: flex; gap: .75rem; align-items: center; font-size: .9rem; }

main { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.narrow { max-width: 460px; margin: 3rem auto; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
@media (max-width: 800px) { .grid { grid-template-columns: 1fr; } }

button {
  font: inherit; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: .55rem 1rem; cursor: pointer;
}
button:hover { border-color: var(--blue); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
button.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); padding: .35rem .8rem; }

input, textarea {
  font: inherit; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; margin-top: .25rem;
}
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: .75rem; }

.bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }
.bar input { max-width: 340px; margin: 0; }
.count { color: var(--muted); font-weight: 400; }
.summary { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.card .table-wrap { border: none; border-radius: 0; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
table.devices tbody tr { cursor: pointer; }
table.devices tbody tr:hover { background: var(--blue-soft); }
td .main { font-weight: 600; }
td .small, .muted { color: var(--muted); font-size: .85rem; }
tr.stuck { background: var(--amber-soft); }

.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--green-soft); color: var(--green); }
.pill.warn { background: var(--amber-soft); color: var(--on-amber); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.info { background: var(--blue-soft); color: var(--blue); }

.back { display: inline-block; margin-bottom: .75rem; color: var(--blue); text-decoration: none; }
.device-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.hint { color: var(--muted); min-height: 1.2em; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; }

.alerts { margin: 0; padding-left: 1.2rem; }
.alerts li { margin-bottom: .35rem; white-space: pre-line; }

.log { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow-y: auto; }
.log li { display: grid; grid-template-columns: 9.5rem 11rem 1fr; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.log li:last-child { border-bottom: none; }
@media (max-width: 700px) { .log li { grid-template-columns: 1fr; gap: .1rem; } }
.log .when { color: var(--muted); }
.log .type { font-weight: 600; }
.log .type.bad { color: var(--red); }

.error { color: var(--red); }
.ok { color: var(--green); margin-left: .5rem; }
a { color: var(--blue); }

/* ---------- Acciones y configuración ---------- */
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; }
select { font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: .45rem .6rem; background: #fff; margin-top: .25rem; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: .6rem .8rem; margin: 0; }
legend { color: var(--muted); font-size: .9rem; padding: 0 .3rem; }
label.inline { display: flex; align-items: center; gap: .5rem; color: var(--ink); margin-bottom: .4rem; }
label.inline input { width: auto; margin: 0; }
.hours { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.hours select { margin: 0; }
.small-note { margin: .75rem 0 0; }
.row-start { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
button.link { background: none; border: none; padding: 0; color: var(--blue); text-decoration: underline; }
.danger-text { color: var(--red) !important; }
.apk-list { list-style: none; margin: 0 0 .5rem; padding: 0; max-height: 50vh; overflow-y: auto; }
.apk-list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.apk-list li:last-child { border-bottom: none; }
.row-end { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }

.action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .6rem; }
.action-grid button { text-align: left; padding: .7rem .9rem; }
.action-grid button strong { display: block; }
.action-grid button span { display: block; color: var(--muted); font-size: .82rem; margin-top: .15rem; }
.action-grid button.danger strong { color: var(--red); }

.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .9rem; }
.cfg-grid label { margin: 0; }
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .25rem .9rem; }
.apps label { margin: 0; }
.apps .pkg { color: var(--muted); font-size: .75rem; display: block; }

.wifi { list-style: none; margin: 0 0 .6rem; padding: 0; }
.wifi li { display: flex; justify-content: space-between; align-items: center; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.wifi li:last-child { border-bottom: none; }
.wifi-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: .5rem; }
.wifi-add input { margin: 0; }
@media (max-width: 700px) { .wifi-add { grid-template-columns: 1fr; } }

.commands { list-style: none; margin: 0; padding: 0; }
.commands li { display: grid; grid-template-columns: 9.5rem 1fr auto; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; align-items: start; }
.commands li:last-child { border-bottom: none; }
.commands .what { font-weight: 600; }
.commands .detail { color: var(--muted); white-space: pre-line; }
@media (max-width: 700px) { .commands li { grid-template-columns: 1fr auto; } .commands .when { grid-column: 1 / -1; } }

td.check, th.check { width: 2.2rem; padding-right: 0; }
td.check input, th.check input { width: 1.1rem; height: 1.1rem; margin: 0; }
tr.selected { background: var(--blue-soft); }

.bulk {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--navy); color: #fff; padding: .7rem 1.25rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; box-shadow: 0 -4px 16px rgba(0,0,0,.15);
}
.bulk-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.bulk button { padding: .45rem .8rem; }
.bulk .ghost-dark { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
body.has-bulk main { padding-bottom: 7rem; }

dialog { border: none; border-radius: 16px; padding: 1.25rem 1.4rem; width: min(520px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 44, 79, .45); }
dialog h2 { margin-bottom: .25rem; }
#dlg-body label { margin-bottom: .6rem; }
#login-form button { width: 100%; }
#dlg-body .choice { display: flex; gap: .5rem; align-items: flex-start; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; color: var(--ink); }
#dlg-body .choice input { width: auto; margin: .2rem 0 0; }
#dlg-body .choice span { display: block; color: var(--muted); font-size: .85rem; }
.progress { font-size: .9rem; color: var(--muted); }

/* ---------- Celular ---------- */
@media (max-width: 760px) {
  main { padding: .9rem; }
  .top { padding: .6rem .9rem; }
  .who-email { display: none; }
  .bar input { max-width: none; }
  table.devices thead { display: none; }
  table.devices, table.devices tbody { display: block; }
  table.devices tbody tr {
    display: grid; grid-template-columns: 2rem 1fr auto; gap: .2rem .6rem;
    padding: .75rem .8rem; border-bottom: 1px solid var(--line);
  }
  table.devices td { border: none; padding: 0; }
  table.devices td.check { grid-row: span 3; padding-top: .15rem; }
  table.devices td.c-name { grid-column: 2; }
  table.devices td.c-state { grid-column: 3; text-align: right; }
  table.devices td.c-report, table.devices td.c-signal { grid-column: 2 / -1; font-size: .88rem; }
  table.devices td.c-battery, table.devices td.c-versions { display: none; }
  table.devices td.c-alerts { grid-column: 2 / -1; }
  table.devices td.c-alerts div { display: inline-block; margin-right: .3rem; }
  .device-head h1 { font-size: 1.3rem; }
  dl { grid-template-columns: 1fr; gap: .1rem; }
  dd { margin-bottom: .45rem; }
  .bulk { padding: .6rem .8rem; }
  .bulk-actions button { flex: 1 1 auto; }
}
