:root {
  --bg:       #e0e0e0;
  --panel:    #e8e8e8;
  --border:   #d6d6d6;
  --text:     #1a1a1a;
  --muted:    #5a5a5a;
  --accent:   #22c55e;
  --danger:   #dc2626;
  --shadow-raised:  6px 6px 12px rgba(0,0,0,0.15), -6px -6px 12px rgba(255,255,255,0.8);
  --shadow-inset:   inset 1px 1px 3px rgba(0,0,0,0.1), inset -1px -1px 3px rgba(255,255,255,0.5);
  --shadow-subtle:  3px 3px 6px rgba(0,0,0,0.1), -3px -3px 6px rgba(255,255,255,0.7);
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

header {
  padding: 2rem 1.5rem 1rem;
  text-align: center;
}

header h1 {
  margin: 0;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.subtitle {
  color: var(--muted);
  margin: 0.3rem 0 0;
}

main.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1.5rem 3rem;
  display: grid;
  grid-template-columns: 330px 1fr 330px;
  align-items: start;
  gap: 1.25rem;
}

.sidebar, .content {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

@media (max-width: 1100px) {
  main.layout {
    grid-template-columns: 330px 1fr;
  }
  .live-panel { display: none; }
}

@media (max-width: 760px) {
  main.layout {
    grid-template-columns: 1fr;
  }
}

/* ── Live panel ──────────────────────────────────────────────── */
.live-panel {
  position: sticky;
  top: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  max-height: calc(100vh - 2rem);
  overflow: hidden;
  box-shadow: var(--shadow-raised);
}

.live-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.live-panel-header h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
}

.sse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sse-dot.online  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.sse-dot.offline { background: var(--danger); }
.sse-dot.checking { background: var(--muted); }

.live-card-banner {
  background: var(--bg);
  border-radius: 8px;
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}

.live-balance {
  font-size: 1.4rem;
}

.live-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.live-feed::-webkit-scrollbar { width: 4px; }
.live-feed::-webkit-scrollbar-track { background: transparent; }
.live-feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.live-item {
  background: var(--bg);
  border-radius: 8px;
  padding: .6rem .85rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .4rem .75rem;
  animation: slideIn .25s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.live-item-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.live-item-body {
  min-width: 0;
}

.live-item-uid {
  font-family: "SF Mono", Consolas, monospace;
  font-size: .8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-item-time {
  font-size: .72rem;
  color: var(--muted);
}

.live-item-amount {
  font-weight: 700;
  font-size: .95rem;
  text-align: right;
}

.live-item-amount.debit  { color: var(--danger); }
.live-item-amount.topup  { color: var(--accent); }
.live-item-amount.gold   { color: #f5c542; }

.live-item-balance {
  grid-column: 2 / -1;
  font-size: .78rem;
  color: var(--muted);
}

.live-empty {
  color: var(--muted);
  font-size: .85rem;
  text-align: center;
  margin: 1rem 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-raised);
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  color: var(--text);
}

.row {
  display: flex;
  gap: 0.6rem;
}

input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.95rem;
  box-shadow: var(--shadow-inset);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-subtle);
}

button:hover { filter: brightness(1.08); }

.field-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.75rem 0 0.3rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.75rem 0 0.3rem;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent, #4f8ef7);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

#enroll-section select,
#enroll-section input,
#enroll-section button {
  width: 100%;
}

#enroll-section select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.95rem;
}

#enroll-section button {
  margin-top: 1rem;
}

#services-section input {
  width: 100%;
}

#svc-resource-id, #svc-name, #svc-price {
  display: block;
}

#btn-guardar-servicio {
  width: 100%;
  margin-top: 1rem;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: transparent;
  color: #e55;
  border: 1px solid #e55;
}
.btn-danger:hover {
  background: #e55;
  color: #fff;
}

.badge-row {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-gold {
  background: #fef3c7;
  color: #92400e;
}

.badge-standard {
  background: var(--bg);
  color: var(--muted);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.section-header h2 { margin: 0; }

.action-btn {
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
}

.card-info { margin-top: 1rem; }

.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1rem;
}

.label { color: var(--muted); }

.mono { font-family: "SF Mono", Consolas, monospace; }

.balance {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
}

.balance-result {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
}

.balance-big { font-size: 2rem; }

.error { color: var(--danger); margin-top: 0.75rem; }
.msg { color: var(--accent); margin-top: 0.75rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: -0.5rem; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; }

tr.tx-debit td.tx-amount { color: var(--danger); }
tr.tx-topup td.tx-amount { color: var(--accent); }

footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
}

footer a { color: var(--muted); text-decoration: none; }
footer a:hover { color: var(--accent); }

/* ── Bridge status bar ─────────────────────────────────────── */
.bridge-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.bridge-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse 2s infinite;
}

.bridge-dot.checking  { background: var(--muted); animation: none; }
.bridge-dot.online    { background: var(--accent); animation: none; }
.bridge-dot.offline   { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* ── Bridge install banner ─────────────────────────────────── */
.bridge-install {
  max-width: 1080px;
  margin: 0.75rem auto 0;
  padding: 0.9rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-raised);
}

.bridge-install-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.bridge-install-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.bridge-install-text {
  flex: 1;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.bridge-install-text strong {
  color: var(--text);
}

.bridge-install-text span {
  color: var(--muted);
  font-size: 0.85rem;
}

.bridge-install-btns {
  display: flex;
  gap: 0.6rem;
  flex-shrink: 0;
}

.bridge-btn {
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
  display: inline-block;
  background: var(--accent);
  color: #0b0f0c;
  border: none;
  cursor: pointer;
}

.bridge-btn.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.bridge-install-hint {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0.6rem 0 0;
}

.bridge-install-hint code {
  background: var(--bg);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-family: "SF Mono", Consolas, monospace;
}

/* ─── Modal eliminar / factory reset ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: var(--panel);
  border-radius: 16px;
  padding: 2rem;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-raised);
}
.modal-box h3 {
  margin: 0 0 0.5rem;
  color: var(--text);
  font-size: 1.15rem;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.25rem;
}
.modal-actions button {
  width: 100%;
}
.msg-error {
  color: var(--danger);
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

/* ─── Balance section auto-detect ─── */
.balance-no-card {
  text-align: center;
  padding: 1.5rem 0;
  color: var(--muted);
}
.balance-no-card-icon {
  font-size: 2rem;
  display: block;
}
.balance-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

/* ── Panel Tab Navigation ────────────────────────────────── */
.panel-tabs {
  display: flex;
  gap: 0.5rem;
  max-width: 1400px;
  margin: 0.75rem auto 0;
  padding: 0 1.5rem;
}

.tab-btn {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.55rem 1.25rem;
  border-radius: 10px 10px 0 0;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: var(--shadow-subtle);
  transition: background 0.15s, color 0.15s;
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: none;
}

.tab-btn:hover:not(.active) {
  color: var(--text);
  background: var(--bg);
}

/* ── NFC Admin Section ───────────────────────────────────── */
.nfc-admin {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1.5rem 3rem;
}

.nfc-admin-grid {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 1.25rem;
  align-items: start;
}

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

.nfc-form-card input,
.nfc-form-card textarea {
  width: 100%;
}

.nfc-slug-preview {
  display: flex;
  align-items: center;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--muted);
  font-family: "SF Mono", Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  box-shadow: var(--shadow-inset);
}

/* ── Foto de perfil — admin upload ───────────────────────── */
.nfc-photo-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.nfc-photo-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border);
  box-shadow: var(--shadow-inset);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  overflow: hidden;
}
.nfc-photo-btns {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.nfc-photo-upload-label {
  display: inline-block;
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0.4rem 0.9rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-subtle);
  user-select: none;
}
.nfc-photo-upload-label:hover { filter: brightness(0.97); }

/* ── NFC Card Grid (lista admin) ──────────────────────────── */
.nfc-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.nfc-card-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Header con miniatura + meta */
.nfc-card-item-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.1rem;
}
.nfc-card-thumb {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--border);
}
.nfc-card-thumb-ini {
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}
.nfc-card-item-meta { flex: 1; min-width: 0; }

.nfc-card-item-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.nfc-card-item-sub {
  font-size: 0.82rem;
  color: var(--muted);
}

.nfc-card-item-slug {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.78rem;
  color: var(--accent);
  margin-top: 0.25rem;
}

.nfc-card-item-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.65rem;
  flex-wrap: wrap;
}

.nfc-card-item-actions button,
.nfc-card-item-actions a {
  font-size: 0.78rem;
  padding: 0.3rem 0.65rem;
}

.nfc-btn-escribir {
  width: 100%;
  margin-top: 0.6rem;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-subtle);
  text-align: center;
}
.nfc-btn-escribir:hover { background: var(--bg); filter: brightness(0.97); }

.nfc-write-status {
  font-size: 0.8rem;
  margin-top: 0.4rem;
  line-height: 1.5;
}

/* ── Compat badges tras escritura NFC ─────────────────────── */
.nfc-compat-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  vertical-align: middle;
  margin-left: 0.35rem;
}
.nfc-compat-android {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #86efac;
}
.nfc-compat-all {
  background: #dbeafe;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
}

.nfc-badge-inactive {
  display: inline-block;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  margin-left: 0.3rem;
}

/* ─── Auto-scan badge ─── */
.as-badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 600;
  background: var(--bg);
  box-shadow: var(--shadow-subtle);
}
.as-badge-ok     { color: var(--accent); }
.as-badge-danger { color: var(--danger); }
