:root {
  --blue: #0f61f2;
  --blue-deep: #0e4cb8;
  --ink: #0a0a0a;
  --panel: rgba(255, 255, 255, 0.03);
  --panel-hover: rgba(255, 255, 255, 0.05);
  --line: rgba(255, 255, 255, 0.085);
  --muted: #8290a4;
  --text: #f7f9fc;
  --danger: #e5484d;
  --good: #3ecf8e;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  font-family: "Poppins", "Avenir Next", Avenir, Inter, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: radial-gradient(circle at 50% -10%, rgba(15, 97, 242, 0.16), transparent 32rem),
    var(--ink);
}

::selection {
  background: rgba(15, 97, 242, 0.35);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

button {
  font-family: inherit;
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---- topbar ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.btn-primary {
  border: none;
  border-radius: 12px;
  color: #fff;
  font-weight: 650;
  font-size: 14px;
  background: var(--blue);
  box-shadow: 0 12px 28px rgba(15, 97, 242, 0.26);
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.btn-primary:hover {
  background: var(--blue-deep);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-ghost {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  padding: 12px 18px;
  cursor: pointer;
  transition: 0.15s ease;
}

.btn-ghost:hover {
  border-color: rgba(15, 97, 242, 0.4);
  background: rgba(15, 97, 242, 0.07);
}

/* ---- stats row ---- */

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.stat-tile {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stat-value.small {
  font-size: 15px;
  font-weight: 600;
}

/* ---- grid / cards ---- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
}

.qr-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: 0.18s ease;
}

.qr-card:hover {
  border-color: rgba(15, 97, 242, 0.35);
  background: var(--panel-hover);
}

.qr-card-top {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.qr-thumb {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  background: #fff;
  padding: 6px;
  flex-shrink: 0;
  display: block;
}

.qr-thumb img {
  width: 100%;
  height: 100%;
  display: block;
}

.qr-info {
  min-width: 0;
  flex: 1;
}

.qr-name {
  margin: 0;
  font-size: 15.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qr-target {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qr-link-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.qr-link {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #79a9ff;
  background: rgba(15, 97, 242, 0.08);
  border: 1px solid rgba(15, 97, 242, 0.2);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  flex-shrink: 0;
}

.status-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.status-pill.active {
  color: var(--good);
  border-color: rgba(62, 207, 142, 0.3);
  background: rgba(62, 207, 142, 0.08);
}

.status-pill.active .dot {
  background: var(--good);
}

.qr-metrics {
  display: flex;
  align-items: baseline;
  gap: 18px;
}

.qr-metric-value {
  font-size: 20px;
  font-weight: 700;
}

.qr-metric-label {
  font-size: 11.5px;
  color: var(--muted);
  display: block;
  margin-top: 1px;
}

.qr-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: 0.15s ease;
  font-size: 16px;
}

.icon-btn:hover {
  border-color: rgba(15, 97, 242, 0.55);
  color: #fff;
  background: rgba(15, 97, 242, 0.22);
  transform: translateY(-1px);
}

.icon-btn.danger {
  background: rgba(229, 72, 77, 0.1);
  border-color: rgba(229, 72, 77, 0.28);
  color: #ff8a8d;
}

.icon-btn.danger:hover {
  border-color: rgba(229, 72, 77, 0.55);
  color: #fff;
  background: rgba(229, 72, 77, 0.28);
}

.qr-actions .icon-btn {
  flex: 1;
  width: auto;
  height: 40px;
}

/* ---- empty state ---- */

.empty {
  border: 1px dashed var(--line);
  border-radius: 18px;
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
}

.empty p {
  margin: 0 0 16px;
}

/* ---- modal ---- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 420px;
  padding: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}

.modal.wide {
  max-width: 560px;
  max-height: 85dvh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.field input {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}

.field input:focus {
  border-color: rgba(15, 97, 242, 0.5);
}

.field-hint {
  min-height: 16px;
  margin: -4px 0 10px;
  font-size: 12.5px;
  color: var(--danger);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* ---- stats modal ---- */

.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.tc-section-label {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 90px;
  margin-bottom: 22px;
  padding: 0 2px;
}

.bar {
  flex: 1;
  background: rgba(15, 97, 242, 0.25);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
  position: relative;
}

.bar.has-scans {
  background: var(--blue);
}

.scan-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.scan-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12.5px;
  background: rgba(255, 255, 255, 0.02);
}

.scan-row .device {
  color: var(--text);
  font-weight: 600;
}

.scan-row .ref {
  color: var(--muted);
}

.scan-row time {
  color: var(--muted);
  white-space: nowrap;
}

.no-scans {
  color: var(--muted);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}

/* ---- toast ---- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 12px);
  background: #17171c;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 100;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

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

@media (max-width: 560px) {
  .stats-row,
  .stats-summary {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }
}
