:root {
  --base-black: #08010f;
  --base-ink: #0d0618;
  --base-panel: rgba(18, 8, 30, .78);
  --base-panel-strong: rgba(16, 7, 27, .94);
  --base-border: rgba(240, 236, 239, .13);
  --base-white: #f0ecef;
  --base-muted: #a398a5;
  --base-soft: #cdb1ca;
  --base-purple: #58205e;
  --base-purple-dark: #37164a;
  --base-magenta: #ff2dbf;
  --base-blue: #51d7ff;
  --base-green: #3dff9b;
  --base-yellow: #ffd166;
  --base-red: #ff4d6d;
  --shadow: 0 24px 80px rgba(0,0,0,.48);
  --radius-xl: 32px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --font-title: "Montserrat", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--base-black);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--base-white);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 45, 191, .20), transparent 34rem),
    radial-gradient(circle at 88% 5%, rgba(81, 215, 255, .16), transparent 28rem),
    linear-gradient(145deg, #08010f 0%, #0b0416 42%, #16091f 100%);
  font-family: var(--font-body);
  overflow-x: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.background-glow {
  position: fixed;
  inset: -20%;
  pointer-events: none;
  z-index: -2;
  background:
    radial-gradient(circle at 52% 5%, rgba(240, 236, 239, .08), transparent 20rem),
    radial-gradient(circle at 15% 70%, rgba(88, 32, 94, .42), transparent 28rem),
    radial-gradient(circle at 87% 78%, rgba(81, 215, 255, .10), transparent 24rem);
  animation: breatheGlow 9s ease-in-out infinite alternate;
  will-change: opacity, transform;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  z-index: -1;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 18%, black, transparent 82%);
}

@keyframes breatheGlow {
  from { opacity: .82; transform: scale(1); }
  to { opacity: 1; transform: scale(1.035); }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px clamp(16px, 4vw, 44px);
  backdrop-filter: blur(18px);
  background: linear-gradient(180deg, rgba(8,1,15,.86), rgba(8,1,15,.48));
  border-bottom: 1px solid rgba(240,236,239,.08);
}

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

.brand img {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: 0 0 28px rgba(255, 45, 191, .22);
}

.brand strong {
  display: block;
  font-family: var(--font-title);
  font-weight: 900;
  letter-spacing: -.04em;
  text-transform: uppercase;
}

.brand small {
  display: block;
  color: var(--base-muted);
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link {
  color: var(--base-soft);
  font-weight: 800;
  font-size: .92rem;
  padding: 10px 12px;
  border-radius: 999px;
}

.nav-link:hover {
  background: rgba(240,236,239,.08);
  color: var(--base-white);
}

.shell,
.dashboard-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 80px;
}

.hero-card,
.dashboard-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: clamp(22px, 4vw, 42px);
  margin: 20px 0 22px;
  border: 1px solid var(--base-border);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, rgba(255,45,191,.14), transparent 30%),
    linear-gradient(90deg, rgba(8,1,15,.92), rgba(43, 18, 58, .62)),
    var(--base-panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hero-card::after,
.dashboard-hero::after {
  content: "";
  position: absolute;
  width: 220px;
  height: 220px;
  right: -80px;
  top: -80px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(240,236,239,.16), transparent 70%);
  filter: blur(6px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--base-soft);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .18em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.hero-copy h1,
.dashboard-hero h1 {
  margin: 0 0 10px;
  font-family: var(--font-title);
  font-size: clamp(2.7rem, 9vw, 6.2rem);
  line-height: .82;
  letter-spacing: -.08em;
  text-transform: uppercase;
  font-weight: 900;
  font-style: italic;
  text-shadow: 0 2px 0 rgba(255,45,191,.45), 0 0 30px rgba(81,215,255,.15);
}

.hero-copy h1 span {
  display: block;
}

.hero-copy p,
.dashboard-hero p {
  max-width: 680px;
  color: rgba(240,236,239,.74);
  line-height: 1.6;
  margin-bottom: 0;
}

.operator-pill {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-top: 22px;
  padding: 10px 14px;
  border: 1px solid rgba(240,236,239,.13);
  border-radius: 999px;
  background: rgba(8,1,15,.52);
}

.operator-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--base-black);
  background: linear-gradient(135deg, var(--base-white), var(--base-soft));
  font-weight: 900;
}

.operator-pill small {
  display: block;
  color: var(--base-muted);
  font-size: .72rem;
}

.operator-pill strong {
  display: block;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-panel,
.dashboard-source {
  width: min(100%, 330px);
  padding: 18px;
  border: 1px solid rgba(240,236,239,.12);
  border-radius: var(--radius-lg);
  background: rgba(8,1,15,.54);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 8px;
}

.status-panel p,
.dashboard-source small {
  margin: 0;
  color: var(--base-muted);
  line-height: 1.4;
}

.pulse-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--base-green);
  box-shadow: 0 0 0 rgba(61,255,155,.5);
  animation: pulse 1.8s ease-out infinite;
}

.pulse-dot.pending { background: var(--base-yellow); }
.pulse-dot.error { background: var(--base-red); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 currentColor; opacity: .9; }
  72% { box-shadow: 0 0 0 12px transparent; opacity: 1; }
  100% { box-shadow: 0 0 0 0 transparent; opacity: .9; }
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(330px, .75fr);
  gap: 22px;
  align-items: start;
}

.registration-card,
.device-card,
.panel,
.metric-card {
  border: 1px solid var(--base-border);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(240,236,239,.055), transparent 38%),
    rgba(14, 5, 24, .74);
  box-shadow: var(--shadow);
}

.registration-card,
.device-card {
  padding: clamp(18px, 3vw, 28px);
}

.section-title h2,
.panel h2 {
  margin: 0;
  font-family: var(--font-title);
  font-size: clamp(1.35rem, 2.6vw, 2rem);
  letter-spacing: -.045em;
  text-transform: uppercase;
  font-weight: 900;
}

.row-title,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.registration-form,
.gate-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

label {
  display: grid;
  gap: 8px;
  color: rgba(240,236,239,.88);
  font-size: .9rem;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  color: var(--base-white);
  border: 1px solid rgba(240,236,239,.14);
  outline: none;
  border-radius: 18px;
  background: rgba(8,1,15,.70);
  padding: 15px 16px;
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

textarea {
  resize: vertical;
  min-height: 118px;
}

input::placeholder,
textarea::placeholder {
  color: rgba(163,152,165,.72);
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(255,45,191,.62);
  box-shadow: 0 0 0 4px rgba(255,45,191,.12);
}

.btn {
  border: 0;
  color: var(--base-white);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 12px 16px;
  transition: transform .18s ease, filter .18s ease, background .18s ease, border-color .18s ease;
}

.btn:active {
  transform: scale(.98);
}

.btn-primary {
  color: #08010f;
  background:
    linear-gradient(135deg, var(--base-white) 0%, #ffdfff 46%, var(--base-magenta) 118%);
  box-shadow: 0 16px 42px rgba(255,45,191,.24);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-ghost {
  border: 1px solid rgba(240,236,239,.14);
  background: rgba(240,236,239,.06);
}

.btn-ghost:hover {
  background: rgba(240,236,239,.10);
}

.btn-full {
  width: 100%;
}

.btn-small {
  padding: 9px 12px;
  font-size: .82rem;
}

.btn-register {
  min-height: 58px;
  font-size: 1.04rem;
}

.btn-register strong {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(8,1,15,.14);
}

.autosave-note {
  margin: 0;
  color: var(--base-muted);
  font-size: .86rem;
  text-align: center;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 10px;
  margin: 20px 0;
}

.mini-stats div {
  border: 1px solid rgba(240,236,239,.10);
  border-radius: 18px;
  padding: 13px 10px;
  background: rgba(8,1,15,.48);
}

.mini-stats strong {
  display: block;
  font-family: var(--font-title);
  font-size: 1.35rem;
  font-weight: 900;
}

.mini-stats small {
  color: var(--base-muted);
  font-size: .78rem;
}

.local-list {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding-right: 4px;
}

.local-list.empty {
  border: 1px dashed rgba(240,236,239,.18);
  border-radius: 20px;
  padding: 22px;
  color: var(--base-muted);
  text-align: center;
}

.local-list.empty p {
  margin: 0;
}

.local-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 11px;
  padding: 13px;
  border: 1px solid rgba(240,236,239,.10);
  border-radius: 18px;
  background: rgba(8,1,15,.48);
}

.local-item strong {
  display: block;
  margin-bottom: 4px;
}

.local-item small {
  color: var(--base-muted);
  display: block;
  line-height: 1.35;
}

.lighthouse {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(240,236,239,.06);
  font-size: 1rem;
}

.lighthouse::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  border: 1px solid currentColor;
  opacity: .35;
}

.lighthouse.success { color: var(--base-green); }
.lighthouse.pending,
.lighthouse.sending { color: var(--base-yellow); }
.lighthouse.error { color: var(--base-red); }

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 5%, rgba(255,45,191,.18), transparent 28rem),
    rgba(8,1,15,.92);
  backdrop-filter: blur(18px);
}

.gate[hidden] {
  display: none;
}

.gate-card {
  width: min(100%, 450px);
  padding: 26px;
  border: 1px solid rgba(240,236,239,.14);
  border-radius: 30px;
  background:
    linear-gradient(160deg, rgba(240,236,239,.08), transparent 38%),
    rgba(14, 5, 24, .92);
  box-shadow: var(--shadow);
}

.gate-logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.gate-logo {
  width: 82px;
  height: 82px;
  object-fit: cover;
  border-radius: 24px;
  box-shadow: 0 0 50px rgba(255,45,191,.28);
}

.gate-card h1 {
  margin: 0 0 8px;
  font-family: var(--font-title);
  font-weight: 900;
  letter-spacing: -.06em;
  text-transform: uppercase;
}

.gate-subtitle {
  color: var(--base-muted);
  line-height: 1.5;
}

.toast-region {
  position: fixed;
  z-index: 110;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  width: min(680px, calc(100% - 28px));
  display: grid;
  gap: 10px;
  pointer-events: none;
}

.toast {
  padding: 12px 15px;
  border: 1px solid rgba(240,236,239,.14);
  border-radius: 18px;
  background: rgba(14,5,24,.92);
  box-shadow: 0 18px 50px rgba(0,0,0,.34);
  color: var(--base-white);
  animation: toastIn .18s ease-out;
}

.toast.success { border-color: rgba(61,255,155,.36); }
.toast.error { border-color: rgba(255,77,109,.42); }
.toast.pending { border-color: rgba(255,209,102,.42); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.confetti-piece {
  position: fixed;
  z-index: 95;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 14px;
  border-radius: 3px;
  pointer-events: none;
  animation: confettiPop .85s ease-out forwards;
  will-change: transform, opacity;
}

@keyframes confettiPop {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--r)) scale(.85);
  }
}

/* Dashboard */
.dashboard-shell {
  width: min(1280px, calc(100% - 28px));
}

.dashboard-hero {
  grid-template-columns: minmax(0,1fr) 280px;
}

.dashboard-source span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  color: #08010f;
  font-size: .82rem;
  font-weight: 900;
  background: var(--base-white);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-card {
  padding: 18px;
  min-height: 136px;
}

.metric-card span {
  color: var(--base-muted);
  font-size: .84rem;
  font-weight: 800;
}

.metric-card strong {
  display: block;
  margin: 12px 0 4px;
  font-family: var(--font-title);
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: .9;
  letter-spacing: -.06em;
  font-weight: 900;
}

.metric-card small {
  color: var(--base-muted);
}

.dashboard-layout {
  display: grid;
  grid-template-columns: 1.4fr .8fr;
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  padding: 18px;
}

.panel-large {
  grid-row: span 2;
}

.panel-header {
  margin-bottom: 18px;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: rgba(8,1,15,.58);
  border: 1px solid rgba(240,236,239,.10);
}

.segment {
  border: 0;
  color: var(--base-muted);
  background: transparent;
  border-radius: 999px;
  padding: 9px 12px;
  font-weight: 900;
  cursor: pointer;
}

.segment.active {
  color: #08010f;
  background: var(--base-white);
}

.bar-chart {
  display: grid;
  gap: 12px;
  min-height: 360px;
}

.bar-row {
  display: grid;
  grid-template-columns: 88px 1fr 44px;
  gap: 12px;
  align-items: center;
}

.bar-label,
.bar-value {
  color: var(--base-muted);
  font-size: .82rem;
  font-weight: 800;
}

.bar-value {
  text-align: right;
  color: var(--base-white);
}

.bar-track {
  height: 18px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(240,236,239,.08);
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--base-white), var(--base-magenta));
  box-shadow: 0 0 22px rgba(255,45,191,.22);
}

.segment-bars {
  display: grid;
  gap: 12px;
}

.segment-bar {
  display: grid;
  gap: 6px;
}

.segment-bar-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--base-muted);
  font-size: .82rem;
  font-weight: 800;
}

.segment-bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(240,236,239,.08);
  overflow: hidden;
}

.segment-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--base-blue), var(--base-magenta));
}

.table-panel {
  margin-bottom: 80px;
}

.table-toolbar {
  align-items: end;
}

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filters input,
.filters select {
  min-width: 220px;
  padding: 11px 13px;
  border-radius: 14px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 13px 12px;
  border-bottom: 1px solid rgba(240,236,239,.08);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--base-muted);
  font-size: .76rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.data-table td {
  color: rgba(240,236,239,.88);
  font-size: .9rem;
}

.status-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
}

.empty-state {
  color: var(--base-muted);
  padding: 24px;
  text-align: center;
}

@media (max-width: 980px) {
  .form-grid,
  .dashboard-hero,
  .hero-card,
  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0,1fr));
  }

  .status-panel,
  .dashboard-source {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 14px;
  }

  .brand img {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .brand small {
    display: none;
  }

  .top-actions {
    gap: 6px;
  }

  .nav-link,
  .btn-ghost {
    font-size: .78rem;
    padding: 9px 10px;
  }

  .hero-card,
  .dashboard-hero,
  .registration-card,
  .device-card,
  .panel,
  .metric-card {
    border-radius: 24px;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .row-title,
  .panel-header,
  .table-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .filters {
    justify-content: stretch;
  }

  .filters input,
  .filters select,
  .filters .btn {
    min-width: 100%;
    width: 100%;
  }

  .bar-row {
    grid-template-columns: 64px 1fr 34px;
  }

  .gate-card {
    padding: 20px;
  }
}
