/* ============================================================
   TOKENS
   ============================================================ */
:root {
  --bg: #121110;
  --bg-panel: #1c1a17;
  --bg-elevated: #262320;
  --border: #35312b;

  --accent: #ff7a33;       /* sinal / cobre */
  --accent-dim: #7a4526;
  --ok: #3fd1c0;            /* conectado */
  --danger: #ff5c5c;

  --text: #f3ece1;
  --text-muted: #9c9186;
  --text-faint: #6b6459;

  --font-display: "Fraunces", ui-serif, Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --font-body: "Inter", system-ui, sans-serif;

  --radius: 14px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

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

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #241f19 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  padding: 32px 16px 48px;
  -webkit-font-smoothing: antialiased;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.console { position: relative; z-index: 1; }

::selection { background: var(--accent); color: #1a1512; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.console {
  max-width: 760px;
  margin: 0 auto;
}

.console__header {
  text-align: center;
  margin-bottom: 40px;
  position: relative;
}

.identity {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-faint);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 6px 5px 12px;
  margin-bottom: 22px;
}

.identity__name {
  color: var(--text);
  font-weight: 500;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity__edit {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--accent);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 3px 9px;
  border-radius: 999px;
  transition: background 0.2s ease;
}

.identity__edit:hover { background: var(--bg-panel); }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.title {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  margin: 6px 0 8px;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.98rem;
  max-width: 40ch;
  margin: 0 auto;
}

/* ---- Elemento assinatura: ponte de sinal ---- */
.signal-bridge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 32px auto 0;
  max-width: 380px;
}

.node {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease;
}

.node__icon { width: 24px; height: 24px; }

.signal-bridge__waves {
  position: relative;
  flex: 1;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.4s ease, box-shadow 0.4s ease;
  z-index: 1;
}

.wave {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--text-faint);
  opacity: 0;
  transition: border-color 0.4s ease;
}

body[data-state="idle"] .wave { animation: none; opacity: 0; }

body[data-state="connecting"] .wave { animation: ping 1.8s ease-out infinite; border-color: var(--accent); }
body[data-state="connecting"] .wave:nth-child(2) { animation-delay: 0.5s; }
body[data-state="connecting"] .wave:nth-child(3) { animation-delay: 1s; }
body[data-state="connecting"] .pulse-dot { background: var(--accent); box-shadow: 0 0 12px var(--accent); }
body[data-state="connecting"] .node { color: var(--accent); border-color: var(--accent-dim); }

body[data-state="connected"] .wave { animation: ping 2.4s ease-out infinite; border-color: var(--ok); }
body[data-state="connected"] .wave:nth-child(2) { animation-delay: 0.6s; }
body[data-state="connected"] .wave:nth-child(3) { animation-delay: 1.2s; }
body[data-state="connected"] .pulse-dot { background: var(--ok); box-shadow: 0 0 14px var(--ok); }
body[data-state="connected"] .node { color: var(--ok); border-color: var(--ok); box-shadow: 0 0 0 3px rgba(63, 209, 192, 0.12); }

body[data-state="error"] .pulse-dot { background: var(--danger); }
body[data-state="error"] .node { color: var(--danger); border-color: var(--danger); }

@keyframes ping {
  0%   { transform: scale(1);   opacity: 0.9; }
  100% { transform: scale(3.6); opacity: 0; }
}

/* ============================================================
   PANELS
   ============================================================ */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.panel__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.panel__index {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  padding: 2px 7px;
}

.panel__title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.15rem;
}

.sublabel {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 22px 0 10px;
}

/* ---- QR / link ---- */
.qr-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.qr-block__img {
  width: 148px;
  height: 148px;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  box-shadow: 0 0 0 1px var(--border);
}

.qr-block__caption {
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: 12px;
  max-width: 30ch;
}

.qr-block__link {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-muted);
  word-break: break-all;
  margin-top: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}

/* ---- Lista de dispositivos ("frequências") ---- */
.freq-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.freq-list li:not(.freq-empty) {
  position: relative;
  padding: 12px 14px 12px 34px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  transition: border-color 0.2s ease, transform 0.15s ease, background 0.2s ease;
}

.freq-list li:not(.freq-empty)::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.freq-list li:not(.freq-empty):hover {
  border-color: var(--accent-dim);
  transform: translateX(2px);
}

.freq-list li.selected {
  background: rgba(63, 209, 192, 0.1);
  border-color: var(--ok);
}

.freq-list li.selected::before {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.freq-empty {
  font-size: 0.85rem;
  color: var(--text-faint);
  font-style: italic;
  padding: 10px 4px;
}

/* ============================================================
   SWITCH (botão conectar)
   ============================================================ */
.switch {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px;
  cursor: pointer;
  transition: border-color 0.25s ease, background 0.25s ease;
}

.switch__knob {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

.switch__label {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.switch:hover .switch__knob { transform: scale(1.06); }

body[data-state="connecting"] .switch__knob { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
body[data-state="connecting"] .switch__label { color: var(--accent); }

body[data-state="connected"] .switch { border-color: var(--ok); }
body[data-state="connected"] .switch__knob { background: var(--ok); transform: translateX(0); box-shadow: 0 0 10px var(--ok); }
body[data-state="connected"] .switch__label { color: var(--ok); }

.switch:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---- Readout de status ---- */
.readout {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 16px 0 4px;
  min-height: 20px;
}

.readout__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

body[data-state="connecting"] .readout__dot { background: var(--accent); animation: blink 1s ease-in-out infinite; }
body[data-state="connected"] .readout__dot { background: var(--ok); }
body[data-state="error"] .readout__dot { background: var(--danger); }

@keyframes blink { 50% { opacity: 0.25; } }

/* ============================================================
   TRANSFER BLOCK
   ============================================================ */
.transfer-block { margin-top: 22px; }

.file-drop {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.86rem;
  transition: border-color 0.2s ease, color 0.2s ease;
  position: relative;
}

.file-drop:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.5;
}

.file-drop:not(:has(input:disabled)):hover {
  border-color: var(--accent);
  color: var(--text);
}

.file-drop__icon { width: 18px; height: 18px; flex-shrink: 0; }

.file-drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ---- Medidor (progress reskinado) ---- */
.meter {
  position: relative;
  margin-top: 16px;
  height: 22px;
}

.meter__native { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }

.meter__bars {
  position: absolute;
  inset: 0;
  display: flex;
  gap: 3px;
  pointer-events: none;
}

.meter__bars span {
  flex: 1;
  border-radius: 2px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.meter__bars span.lit {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 6px rgba(255, 122, 51, 0.5);
}

body[data-state="connected"] .meter__bars span.lit {
  background: var(--ok);
  border-color: var(--ok);
  box-shadow: 0 0 6px rgba(63, 209, 192, 0.5);
}

/* ============================================================
   FOOTER
   ============================================================ */
.console__footer {
  text-align: center;
  margin-top: 32px;
  color: var(--text-faint);
  font-size: 0.78rem;
}

/* ============================================================
   MODAL — nomeação do dispositivo
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 9, 8, 0.72);
  backdrop-filter: blur(6px);
  transition: opacity 0.25s ease;
}

.modal[aria-hidden="true"] {
  opacity: 0;
  pointer-events: none;
}

.modal__card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: modal-in 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  margin: 6px 0 10px;
}

.modal__hint {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 20px;
}

.modal__form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal__form input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
}

.modal__form input:focus {
  border-color: var(--accent);
  outline: none;
}

.modal__form input::placeholder { color: var(--text-faint); }

.switch--solid {
  background: var(--accent);
  border-color: var(--accent);
  justify-content: center;
  padding: 12px 6px;
}

.switch--solid .switch__label {
  color: #1a1310;
  font-weight: 600;
}

.switch--solid:hover { filter: brightness(1.08); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 680px) {
  .panels { grid-template-columns: 1fr; }
  .signal-bridge { max-width: 280px; }
  body { padding: 24px 14px 40px; }
}
