:root {
  --bg: #0e1014;
  --bg-2: #12151b;
  --card: #181b22;
  --card-2: #1e222b;
  --border: #272b36;
  --border-strong: #353b49;
  --text: #e8eaef;
  --muted: #8b91a0;
  --accent: #25d366;
  --accent-d: #1da851;
  --accent-ink: #05210f;
  --error: #ff6b6b;
  --error-bg: #3a2020;
  --warn: #f5c451;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 7px;

  /* Curvas fuertes (Emil): las nativas son débiles */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 100% -10%, #16331f22, transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, #1a2a4022, transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.2rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.02rem; margin: 0 0 0.85rem; letter-spacing: -0.01em; }
h3 { font-size: 0.95rem; margin: 0 0 0.6rem; }

.muted { color: var(--muted); font-size: 0.9rem; }
.small { font-size: 0.78rem; }
.hidden { display: none !important; }
.link { color: var(--accent); text-decoration: none; cursor: pointer; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* feedback inline (sin toasts): el texto cambia con un fade sutil */
.status, .error {
  min-height: 1.25em;
  font-size: 0.88rem;
  margin: 0.6rem 0 0;
  transition: color 200ms var(--ease-out);
  animation: statusIn 220ms var(--ease-out);
}
.status.ok { color: var(--accent); }
.status.err { color: var(--error); }
.error { color: var(--error); }
@keyframes statusIn {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Header ---------- */
header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
}
header .right { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
header #userName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 38vw; }

.badge {
  font-size: 0.76rem; padding: 0.28rem 0.62rem; border-radius: 999px;
  background: var(--error-bg); color: var(--error); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 0.35rem;
  transition: background 200ms var(--ease-out), color 200ms var(--ease-out);
}
.badge.ok { background: #16331f; color: var(--accent); }

/* ---------- Tabs ---------- */
.tabs {
  position: sticky; top: 56px; z-index: 15;
  display: flex; gap: 0.2rem;
  padding: 0.5rem 0.75rem 0;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto;
  width: auto; margin: 0;
  background: none; border: none; color: var(--muted);
  padding: 0.6rem 0.85rem 0.7rem; cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 0.92rem; font-weight: 600; white-space: nowrap;
  transition: color 160ms var(--ease-out);
  border-radius: 0;
}
.tabs button:active { transform: none; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-color: var(--accent); }

/* ---------- Layout ---------- */
main { padding: 1rem; max-width: 860px; margin: 0 auto; }
.tab { animation: tabIn 220ms var(--ease-out); }
@keyframes tabIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.center { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.center-text { text-align: center; }
.row { display: flex; align-items: center; gap: 0.75rem; }
.between { justify-content: space-between; }

/* ---------- Forms ---------- */
label { display: block; font-size: 0.82rem; color: var(--muted); margin: 0.85rem 0 0.3rem; }
input, select, textarea, button {
  font-family: inherit; font-size: 0.95rem;
}
input, select, textarea {
  width: 100%; padding: 0.65rem 0.8rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text);
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent-d);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
input::placeholder { color: #5b606e; }

button {
  width: 100%; padding: 0.7rem 0.85rem; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink); border: none; font-weight: 700;
  cursor: pointer; margin-top: 1rem;
  transition: transform 150ms var(--ease-out), background 160ms var(--ease-out), opacity 160ms var(--ease-out);
  touch-action: manipulation; user-select: none;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.55; cursor: default; transform: none; }

button.ghost {
  width: auto; background: var(--card-2); color: var(--text);
  border: 1px solid var(--border); margin: 0; padding: 0.45rem 0.75rem; font-weight: 600;
}
button.danger { background: var(--error-bg); color: var(--error); }
button.subtle { background: transparent; color: var(--muted); border: 1px solid var(--border); }
@media (hover: hover) and (pointer: fine) {
  button:hover:not(:disabled) { background: var(--accent-d); }
  button.ghost:hover, button.subtle:hover { background: var(--card-2); color: var(--text); border-color: var(--border-strong); }
  button.danger:hover { background: #4a2626; }
}

/* ---------- Dropzone ---------- */
.dropzone {
  position: relative;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 1.4rem 1rem; text-align: center; cursor: pointer; outline: none;
  background: var(--bg-2);
  transition: border-color 180ms var(--ease-out), background 180ms var(--ease-out), transform 150ms var(--ease-out);
}
.dropzone:active { transform: scale(0.99); }
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg-2)); }
@media (hover: hover) and (pointer: fine) {
  .dropzone:hover, .dropzone:focus-visible { border-color: var(--border-strong); background: var(--card-2); }
}
.dz-icon { font-size: 1.9rem; line-height: 1; }
.dz-empty p { margin: 0.45rem 0; }
.dz-preview { display: flex; align-items: center; gap: 0.85rem; text-align: left; }
.dz-thumb {
  width: 60px; height: 60px; object-fit: contain; flex: 0 0 auto;
  background: repeating-conic-gradient(#ffffff10 0% 25%, transparent 0% 50%) 50% / 14px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.dz-thumb.hidden { display: none; }
.dz-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.dz-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dz-clear {
  width: 34px; height: 34px; border-radius: var(--radius-sm); margin: 0; padding: 0;
  flex: 0 0 auto; font-size: 1.15rem; line-height: 1; display: grid; place-items: center;
}

/* ---------- Sticker grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 0.5rem; margin-top: 1rem; align-items: start;
}
.cell {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.3rem; text-align: center; display: flex; flex-direction: column; gap: 0.3rem;
  animation: cellIn 240ms var(--ease-out) both;
  transition: border-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .cell:hover { border-color: var(--border-strong); transform: translateY(-2px); }
}
@keyframes cellIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}
.cell img {
  width: 100%; height: auto; object-fit: contain; display: block;
  background: #ffffff08; border-radius: var(--radius-xs);
}
/* skeleton mientras carga: reserva espacio cuadrado + shimmer */
.cell img.sk {
  aspect-ratio: 1 / 1; height: auto;
  background:
    linear-gradient(100deg, transparent 30%, #ffffff12 50%, transparent 70%),
    var(--card-2);
  background-size: 200% 100%, 100% 100%;
  animation: shimmer 1.15s linear infinite;
}
@keyframes shimmer {
  from { background-position: 180% 0, 0 0; }
  to   { background-position: -180% 0, 0 0; }
}
.cell .id { font-weight: 700; font-size: 0.82rem; }
.cell .tags { font-size: 0.72rem; color: var(--muted); min-height: 1em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell .acts { display: flex; gap: 0.3rem; margin-top: auto; }
.cell .acts button { font-size: 0.74rem; padding: 0.35rem 0.3rem; margin: 0; }
.cell .acts button:first-child { flex: 1; }

#searchBox { width: clamp(140px, 40vw, 220px); margin: 0; padding: 0.5rem 0.7rem; }

/* ---------- Admin lists ---------- */
.list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.6rem; }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 0.6rem;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
  animation: cellIn 240ms var(--ease-out) both;
}
.item > div:first-child { min-width: 0; }
.item b { overflow: hidden; text-overflow: ellipsis; }
.item-acts { display: flex; gap: 0.3rem; flex: 0 0 auto; }
.item-acts button { width: auto; margin: 0; padding: 0.4rem 0.6rem; font-size: 0.8rem; }
.tag {
  font-size: 0.66rem; background: var(--accent-d); color: var(--accent-ink);
  padding: 0.08rem 0.42rem; border-radius: 999px; vertical-align: middle; font-weight: 700;
}

.adder summary {
  cursor: pointer; color: var(--accent); font-size: 0.9rem; font-weight: 600;
  padding: 0.5rem 0; list-style: none; user-select: none;
}
.adder summary::-webkit-details-marker { display: none; }
.adder[open] summary { color: var(--muted); }
.grid-form { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; margin-top: 0.4rem; }
.grid-form input { width: auto; flex: 1 1 160px; }
.grid-form .check { display: flex; align-items: center; gap: 0.4rem; width: auto; color: var(--muted); margin: 0; }
.grid-form .check input { width: auto; }
.grid-form button { width: auto; margin: 0; }

/* ---------- Conexión ---------- */
.connect-grid { display: flex; gap: 1.75rem; flex-wrap: wrap; justify-content: center; align-items: flex-start; }
.connect-grid > div { min-width: 200px; flex: 1; }
.connect-grid h3 { margin: 0.25rem 0 0.7rem; }
#qr img, #qr canvas { width: min(240px, 70vw); height: auto; aspect-ratio: 1; background: #fff; border-radius: var(--radius-sm); padding: 8px; }
#pairing {
  font-size: clamp(1.5rem, 7vw, 2rem); letter-spacing: 0.28rem; font-weight: 800; margin: 0.9rem 0;
  font-variant-numeric: tabular-nums;
}

/* ---------- Modal (reemplaza alert/confirm/prompt) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 1rem;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0; transition: opacity 200ms var(--ease-out);
}
.modal-backdrop.show { opacity: 1; }
.modal {
  width: min(420px, 100%);
  background: var(--card); border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 1.2rem; box-shadow: var(--shadow);
  transform: scale(0.96); opacity: 0;
  transition: transform 200ms var(--ease-out), opacity 200ms var(--ease-out);
  transform-origin: center; /* modal centrado, no anclado a trigger */
}
.modal-backdrop.show .modal { transform: scale(1); opacity: 1; }
.modal h3 { font-size: 1.05rem; margin-bottom: 0.4rem; }
.modal p { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.4rem; }
.modal label { margin-top: 0.7rem; }
.modal-acts { display: flex; gap: 0.6rem; margin-top: 1.1rem; }
.modal-acts button { margin: 0; flex: 1; }

/* ---------- Login ---------- */
.narrow { width: min(340px, 100%); }
.card.narrow { box-shadow: var(--shadow); }

/* ---------- Empty / spinner ---------- */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  display: inline-block; vertical-align: -3px; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  main { padding: 0.6rem; }
  .card { padding: 0.7rem; border-radius: 12px; }
  header { padding: 0.7rem 0.8rem; }
  h1 { font-size: 1.05rem; }
  .tabs { top: 52px; }
  .grid { grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
  .cell { padding: 0.25rem; gap: 0.25rem; }
  .cell .acts button { font-size: 0.72rem; padding: 0.3rem 0.25rem; }
  .item { flex-wrap: wrap; }
  .item-acts { width: 100%; justify-content: flex-end; }
  header #userName { max-width: 30vw; font-size: 0.82rem; }
}

/* pantallas muy angostas: 2 columnas más grandes */
@media (max-width: 360px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .badge, .status { transition: color 150ms ease; }
}
