:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.login-card h1 { font-size: 20px; margin: 0 0 24px; text-align: center; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.login-card .hint { font-weight: normal; }
.login-card input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.login-card button {
  width: 100%; margin-top: 20px; padding: 10px; border: none; border-radius: 6px;
  background: var(--primary); color: white; font-size: 14px; cursor: pointer;
}
.login-card button:hover { background: var(--primary-dark); }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 16px; }

/* App shell */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--panel); border-right: 1px solid var(--border);
  padding: 20px 16px; display: flex; flex-direction: column;
}
.sidebar h2 { font-size: 15px; margin: 0 0 20px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  color: var(--text); text-decoration: none; padding: 8px 10px; border-radius: 6px; font-size: 14px;
}
.sidebar nav a:hover { background: var(--bg); }
.sidebar nav a.active { background: var(--primary); color: white; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; font-size: 12px; color: var(--muted); }
.sidebar-footer button {
  width: 100%; margin-top: 8px; padding: 6px; border: 1px solid var(--border); border-radius: 6px;
  background: white; cursor: pointer; font-size: 12px;
}
#tenantSelectorWrap { margin-bottom: 16px; }
#tenantSelectorWrap label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
#tenantSelector { width: 100%; padding: 6px; border-radius: 6px; border: 1px solid var(--border); font-size: 13px; }

main { flex: 1; padding: 28px 32px; overflow-y: auto; }
.section { display: none; }
.section.active { display: block; }

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.section-header h1 { font-size: 18px; margin: 0; }

.btn {
  padding: 7px 14px; border: none; border-radius: 6px; background: var(--primary); color: white;
  font-size: 13px; cursor: pointer;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: white; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 12px; margin-right: 4px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; background: var(--bg); }
tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.ok, .badge.ready, .badge.pagado, .badge.success { background: #dcfce7; color: var(--success); }
.badge.warn, .badge.qr_ready, .badge.abierto, .badge.pending, .badge.processing { background: #fef3c7; color: var(--warn); }
.badge.error, .badge.failed, .badge.disconnected { background: #fee2e2; color: var(--danger); }
.badge.neutral, .badge.created, .badge.cerrado { background: #e5e7eb; color: var(--muted); }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-row { display: flex; gap: 24px; flex-wrap: wrap; }
.stat { min-width: 120px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 600; }

.empty-state { color: var(--muted); font-size: 13px; padding: 24px; text-align: center; }
.alert { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.alert.error { background: #fee2e2; color: var(--danger); }
.alert.success { background: #dcfce7; color: var(--success); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal { background: white; border-radius: var(--radius); padding: 24px; width: 100%; max-width: 420px; max-height: 85vh; overflow-y: auto; }
.modal h2 { font-size: 16px; margin: 0 0 16px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.modal input, .modal select { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal .qr-box { text-align: center; }
.modal .qr-box img { max-width: 240px; margin-top: 12px; }
.close-x { position: absolute; top: 16px; right: 16px; cursor: pointer; background: none; border: none; font-size: 16px; color: var(--muted); }
.modal { position: relative; }
