*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --border:   #334155;
  --text:     #f1f5f9;
  --muted:    #94a3b8;
  --accent:   #3b82f6;
  --accent-h: #2563eb;
  --success:  #22c55e;
  --danger:   #ef4444;
  --warning:  #f59e0b;
  --radius:   12px;
  --shadow:   0 4px 24px rgba(0,0,0,.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Layout ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
header .logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -.5px;
}
header .logo span { color: var(--accent); }
header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: .9rem;
  padding: 6px 14px;
  border-radius: 8px;
  transition: background .2s, color .2s;
}
header nav a:hover, header nav a.active {
  background: var(--border);
  color: var(--text);
}

main { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* ── Gate grid ── */
.gate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color .2s, transform .15s;
}
.gate-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.gate-card .gate-icon {
  width: 48px; height: 48px;
  background: rgba(59,130,246,.15);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
}
.gate-card .gate-name { font-size: 1.05rem; font-weight: 600; }
.gate-card .gate-account { font-size: .8rem; color: var(--accent); font-weight: 500; }
.gate-card .gate-address { font-size: .8rem; color: var(--muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s, opacity .2s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--accent-h); }

.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

.btn-danger   { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover:not(:disabled)  { background: rgba(239,68,68,.1); }

.btn-ghost    { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)   { background: var(--border); color: var(--text); }

.btn-open {
  width: 100%;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  padding: 12px;
  font-size: 1rem;
}
.btn-open:hover:not(:disabled) { background: var(--accent-h); }
.btn-open.loading { background: var(--border); cursor: not-allowed; }
.btn-open.success { background: var(--success); }
.btn-open.error   { background: var(--danger); }

/* ── Form ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: .85rem; color: var(--muted); font-weight: 500; }
.form-group input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: .95rem;
  transition: border-color .2s;
}
.form-group input:focus { outline: none; border-color: var(--accent); }

/* ── QR section ── */
.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 32px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-align: center;
}
.qr-box img { border-radius: 8px; border: 4px solid #fff; }
.qr-steps { text-align: left; }
.qr-steps ol { padding-left: 1.2rem; }
.qr-steps li { margin-bottom: 6px; font-size: .9rem; color: var(--muted); }
.qr-steps li strong { color: var(--text); }

/* ── Status badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-pending { background: rgba(245,158,11,.15); color: var(--warning); }
.badge-success { background: rgba(34,197,94,.15);  color: var(--success); }
.badge-error   { background: rgba(239,68,68,.15);  color: var(--danger);  }

/* ── Account list ── */
.account-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}
.account-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}
.account-title { font-size: 1.05rem; font-weight: 600; }
.account-sub   { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.account-actions { display: flex; gap: 8px; }

.device-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 8px;
  font-size: .85rem;
  color: var(--muted);
}
.device-row span { color: var(--text); }

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 32px; right: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  font-size: .9rem;
  box-shadow: var(--shadow);
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 9999;
  max-width: 360px;
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { opacity:0; transform:translateY(12px); } }
#toast.visible { display: flex; }
#toast.toast-success { border-color: var(--success); }
#toast.toast-error   { border-color: var(--danger); }

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--muted);
}
.empty .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty p { margin-bottom: 20px; }

/* ── Section title ── */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Pulse animation for QR waiting ── */
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.pulse { animation: pulse 1.5s ease-in-out infinite; }

/* ── Responsive ── */
@media (max-width: 600px) {
  main { padding: 16px; }
  header { padding: 12px 16px; }
  .gate-grid { grid-template-columns: 1fr; }
  #toast { bottom: 16px; right: 16px; left: 16px; }
}
