:root {
  color-scheme: light dark;
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #5b6475;
  --border: #e2e7f0;
  --primary: #2563eb;
  --primary-press: #1d4ed8;
  --on-primary: #ffffff;
  --soft: #e7eeff;
  --soft-text: #1d4ed8;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 6px 20px rgba(15, 23, 42, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #131b2e;
    --text: #e6ebf5;
    --muted: #9aa5b8;
    --border: #253049;
    --primary: #3b82f6;
    --primary-press: #2563eb;
    --soft: #1b2a4a;
    --soft-text: #93c5fd;
    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0 16px;
}

.logo { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.top-text { min-width: 0; }
.top h1 { margin: 0; font-size: 18px; line-height: 1.2; }

.presence {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}

.presence[data-kind="online"] { color: var(--ok); }
.presence[data-kind="online"] .dot { opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.presence[data-kind="offline"] { color: var(--warn); }
.presence[data-kind="offline"] .dot { opacity: 1; }
.presence[data-kind="never"] { color: var(--bad); }
.presence[data-kind="never"] .dot { opacity: 1; }

.icon-btn {
  margin-left: auto;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 22px;
  line-height: 1;
}

button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 12px;
  box-shadow: var(--shadow);
}

.card-title { margin: 0 0 10px; font-size: 18px; }
.muted { color: var(--muted); margin: 0 0 14px; }
.fatal { color: var(--bad); font-weight: 600; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
}

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:active { background: var(--primary-press); }
.btn-soft { background: var(--soft); color: var(--soft-text); }
.btn-danger { background: var(--bad); color: #fff; margin-bottom: 8px; }
.btn-big { min-height: 64px; margin-bottom: 12px; border-radius: var(--radius); font-size: 18px; box-shadow: var(--shadow); }
.btn:disabled { opacity: 0.6; }

.label { display: block; margin: 0 0 8px; font-size: 14px; font-weight: 600; color: var(--muted); }

textarea,
input[type="url"],
input[type="text"] {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
}

textarea { min-height: 96px; margin: 0 0 10px; resize: vertical; }
textarea:focus, input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 0 0 12px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 16px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.tile:active { background: var(--soft); }
.tile-icon { font-size: 30px; line-height: 1.2; }
.tile small { font-weight: 400; font-size: 12px; color: var(--muted); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  opacity: 0;
}

.install p { margin: 0 0 10px; color: var(--muted); }
.install p:last-child { margin: 0; }

.section-title {
  margin: 18px 4px 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.history {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
}

.item-media {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border-radius: 10px;
  background: var(--soft);
  font-size: 22px;
}

.item-media img { width: 100%; height: 100%; object-fit: cover; }
.item-label { margin: 0; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.item-detail { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.item[data-status="delivered"] .item-detail { color: var(--ok); }
.item[data-status="error"] .item-detail { color: var(--bad); }

.bar {
  height: 4px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--soft);
}

.bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.retry {
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: var(--soft);
  color: var(--soft-text);
  font-size: 14px;
  font-weight: 600;
}

.steps { margin: 0 0 16px; padding-left: 22px; }
.steps li { margin: 4px 0; }

.scan-box { margin: 12px 0 0; }

.scan-frame {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  background: #000;
  aspect-ratio: 1;
}

.scan-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-guide {
  position: absolute;
  inset: 18%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35);
}

.scan-status {
  margin: 8px 0 0;
  font-size: 14px;
  text-align: center;
  color: var(--muted);
}

.link-btn {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  padding: 8px;
  border: 0;
  background: none;
  color: var(--soft-text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-form { margin-top: 16px; }

.code-form { display: flex; gap: 8px; margin: 14px 0 0; }
.code-input {
  flex: 1;
  min-width: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.code-form .btn { width: auto; flex: none; margin: 0; }
.code-status { min-height: 1.3em; margin: 8px 0 10px; font-size: 14px; color: var(--muted); }
.code-status[data-kind="error"] { color: var(--danger, #b91c1c); font-weight: 600; }

.pair-code {
  margin: 4px 0 0;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.pair-code[data-off] { color: var(--muted); }
.pair-code-info { text-align: center; margin-top: 0; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; }
.inline .btn { width: auto; flex: none; }

.menu {
  width: min(420px, calc(100% - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
}

.menu::backdrop { background: rgba(2, 6, 23, 0.55); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-size: 15px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.small { font-size: 13px; }
.menu .btn + .btn { margin-top: 8px; }

/* En pantallas anchas: enviar a la izquierda, recibir a la derecha */
.col { min-width: 0; }
.top, #pair-view, #fatal { max-width: 560px; margin-left: auto; margin-right: auto; }

.sep { margin: 18px 0; border: 0; border-top: 1px solid var(--border); }

summary {
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

summary::-webkit-details-marker { display: none; }
details[open] summary { margin-bottom: 12px; }

.device-list {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.device-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}

.device-list small { color: var(--muted); margin-left: auto; }
.device-list li { align-items: center; }
.device-list .quitar {
  flex: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ── Elegir modo ─────────────────────────────────────────────── */

.role-title { margin: 6px 4px 12px; font-size: 20px; }

.roles {
  display: grid;
  gap: 12px;
  margin: 0 0 12px;
}

.role-card {
  display: grid;
  grid-template-columns: 48px 1fr;
  grid-template-rows: auto auto;
  column-gap: 14px;
  align-items: center;
  width: 100%;
  padding: 18px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  text-align: left;
  box-shadow: var(--shadow);
}

.role-card:active, .role-card:hover { border-color: var(--primary); }
.role-icon { grid-row: span 3; font-size: 38px; line-height: 1; text-align: center; }
.role-name { font-size: 18px; font-weight: 700; }
.role-desc { color: var(--muted); font-size: 14px; }
.role-hint { justify-self: start; margin-top: 6px; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--soft-text); font-size: 12px; font-weight: 700; }

.download p { margin: 0 0 10px; }
.download p:last-child { margin: 10px 0 0; }
.download .btn { text-decoration: none; }

/* ── Modo computador ─────────────────────────────────────────── */

.grid {
  display: grid;
  gap: 12px;
  align-items: start;
}

@media (min-width: 900px) {
  .grid { grid-template-columns: 1fr 1fr; }
}

.qr-box {
  display: inline-block;
  margin: 4px 0 10px;
  padding: 10px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
}

.qr-canvas { display: block; width: 256px; height: 256px; image-rendering: pixelated; }

.status-box {
  margin: 0 0 6px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--soft);
  color: var(--soft-text);
  font-weight: 700;
}

.status-box[data-kind="online"] { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.status-box[data-kind="offline"], .status-box[data-kind="other-tab"] { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  font-size: 14px;
  cursor: pointer;
}

.check input { width: 18px; height: 18px; accent-color: var(--primary); }

.history .empty {
  padding: 18px 8px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.item-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.item-actions button {
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: var(--soft);
  color: var(--soft-text);
  font-size: 14px;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .toast, .bar span { transition: none; }
}

/* Zona de arrastrar y soltar (Drag and Drop) */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(5px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop-card {
  background: var(--card);
  border: 3px dashed var(--primary);
  border-radius: var(--radius);
  padding: 38px 48px;
  text-align: center;
  box-shadow: 0 20px 45px rgba(0,0,0,0.3);
  animation: popIn 0.18s ease-out;
  max-width: 90%;
}
.drop-icon {
  font-size: 52px;
  display: block;
  margin-bottom: 12px;
}
.drop-title {
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 6px;
  color: var(--text);
}
.drop-subtitle {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
}
@keyframes popIn {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
