/* =========================================================================
   NEARBY — design tokens
   Palette: graphite base, vibrant teal (connection/primary), soft green
   (success), warm amber (pending), muted red (failure), indigo (self/local).
   Type: Inter for interface text, IBM Plex Mono for figures & metadata —
   the mono face is reserved for anything measured (sizes, %, speed, ids),
   which gives the transfer numbers a distinct "readout" feel.
   ========================================================================= */

:root {
  /* surfaces */
  --bg-base: #0a0c0e;
  --bg-surface: #131619;
  --bg-elevated: #1a1e22;
  --bg-elevated-hover: #21262b;
  --bg-inset: #0e1113;

  /* borders */
  --border-subtle: #23282d;
  --border-strong: #333a41;

  /* text */
  --text-primary: #edf0f2;
  --text-secondary: #9aa4ac;
  --text-tertiary: #666f77;

  /* accents */
  --teal: #34d6b4;
  --teal-dim: rgba(52, 214, 180, 0.13);
  --teal-strong: #1fae8f;
  --green: #8ee7a4;
  --green-dim: rgba(142, 231, 164, 0.13);
  --amber: #eeb163;
  --amber-dim: rgba(238, 177, 99, 0.13);
  --red: #ef6e63;
  --red-dim: rgba(239, 110, 99, 0.14);
  --indigo: #8b93f5;
  --indigo-dim: rgba(139, 147, 245, 0.14);

  /* type */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Menlo, monospace;

  /* geometry */
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  /* motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 15% -10%, rgba(52, 214, 180, 0.07), transparent 45%),
    radial-gradient(circle at 90% 10%, rgba(139, 147, 245, 0.05), transparent 40%);
  background-attachment: fixed;
}

/* The [hidden] attribute must always win over any element-specific
   `display:` rule below (e.g. .modal-overlay, .transfer-toast, .staged-file
   all set display:flex, which otherwise ties in specificity with [hidden]
   and — since it's declared later in the file — overrides it). */
[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

a, button { font-family: inherit; }

::selection { background: var(--teal-dim); color: var(--text-primary); }

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

/* very faint grain so large flat panels don't look flat-CSS-generic */
.noise-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.025;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%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");
}

/* =========================================================================
   SHELL / HEADER
   ========================================================================= */

.app-shell {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 24px 80px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-mark { display: inline-flex; }
.mark-node--a { fill: var(--indigo); }
.mark-node--b { fill: var(--teal); }
.mark-line { stroke: var(--border-strong); stroke-width: 1.5; }

.brand-name {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.identity-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

.signal-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px 7px 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 12.5px;
  color: var(--text-secondary);
}

.signal-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
  transition: background 0.3s var(--ease-standard);
}

.signal-pill[data-state="online"] .signal-dot {
  background: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-dim);
}
.signal-pill[data-state="online"] { color: var(--text-primary); }

.signal-pill[data-state="connecting"] .signal-dot {
  background: var(--amber);
  animation: pulse-dot 1.1s ease-in-out infinite;
}

.signal-pill[data-state="offline"] .signal-dot { background: var(--red); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.device-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.2s var(--ease-standard), background 0.2s var(--ease-standard);
}
.device-chip:hover { border-color: var(--border-strong); background: var(--bg-elevated); }

.device-chip__avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--indigo), var(--teal));
  flex-shrink: 0;
}

.device-chip__name {
  font-size: 13.5px;
  font-weight: 600;
}

.device-chip__edit { color: var(--text-tertiary); }

/* =========================================================================
   INTRO
   ========================================================================= */

.intro {
  margin: 56px 0 32px;
  text-align: center;
}

.intro-title {
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0 0 10px;
  background: linear-gradient(180deg, #fff, #c9d0d5 140%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.intro-sub {
  color: var(--text-secondary);
  font-size: 15.5px;
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.55;
}

/* =========================================================================
   DROPZONE
   ========================================================================= */

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  padding: 36px 24px;
  cursor: pointer;
  transition: border-color 0.25s var(--ease-standard), background 0.25s var(--ease-standard), transform 0.2s var(--ease-standard);
}

.dropzone:hover {
  border-color: var(--teal-strong);
  background: var(--bg-elevated);
}

.dropzone.is-dragover {
  border-color: var(--teal);
  background: var(--teal-dim);
  transform: scale(1.008);
}

.dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.dropzone-icon {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--teal);
  transition: transform 0.25s var(--ease-out);
}
.dropzone.is-dragover .dropzone-icon { transform: translateY(-3px); }

.dropzone-text { font-size: 15px; color: var(--text-secondary); }
.dropzone-text strong { color: var(--text-primary); font-weight: 600; }
.dropzone-link { color: var(--teal); text-decoration: underline; text-underline-offset: 3px; }
.dropzone-hint { font-size: 12.5px; color: var(--text-tertiary); }

/* staged file summary */
.staged-file {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--teal-dim);
  border: 1px solid rgba(52, 214, 180, 0.28);
  animation: rise-in 0.3s var(--ease-out);
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.staged-file__icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  color: var(--teal);
  flex-shrink: 0;
}

.staged-file__meta { min-width: 0; flex: 1; }
.staged-file__name {
  font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.staged-file__size {
  font-family: var(--font-mono);
  font-size: 12px; color: var(--text-secondary);
}

.staged-file__clear {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.staged-file__clear:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }

.staged-file__cta {
  font-size: 12px;
  color: var(--teal);
  flex-shrink: 0;
  display: none;
}
@media (min-width: 560px) { .staged-file__cta { display: block; } }

/* =========================================================================
   PEERS
   ========================================================================= */

.peers-section { margin-top: 44px; }

.peers-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.peers-heading h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin: 0;
}
.peers-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-tertiary);
}

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

.peer-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  text-align: left;
  color: inherit;
  transition: transform 0.2s var(--ease-out), border-color 0.2s var(--ease-standard), background 0.2s var(--ease-standard);
  overflow: hidden;
}

.peer-card::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 20% 0%, rgba(52,214,180,0.09), transparent 60%);
  opacity: 0;
  transition: opacity 0.25s;
}

.peer-card:hover {
  transform: translateY(-2px);
  border-color: var(--teal-strong);
  background: var(--bg-elevated);
}
.peer-card:hover::before { opacity: 1; }

.peer-card.is-dragtarget {
  border-color: var(--teal);
  background: var(--teal-dim);
  transform: scale(1.02);
}

.peer-card__top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.peer-card__avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
  color: var(--bg-base);
}

.peer-card__name {
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.peer-card__status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
}
.peer-card__status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-dim);
}

.peer-card__send {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--teal);
  font-weight: 600;
}

/* empty state */
.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 56px 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, var(--bg-surface), var(--bg-base));
}
.empty-state.is-visible { display: flex; }

.empty-state h3 { font-size: 16px; margin: 18px 0 4px; font-weight: 700; }
.empty-state p { font-size: 13.5px; color: var(--text-secondary); max-width: 320px; line-height: 1.5; margin: 0; }

.radar {
  position: relative;
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
}
.radar-core {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 14px 2px rgba(52,214,180,0.5);
}
.radar-ring {
  position: absolute;
  border: 1.5px solid var(--teal);
  border-radius: 50%;
  opacity: 0;
  animation: radar-expand 2.4s var(--ease-out) infinite;
}
.radar-ring--1 { animation-delay: 0s; }
.radar-ring--2 { animation-delay: 0.8s; }
.radar-ring--3 { animation-delay: 1.6s; }

@keyframes radar-expand {
  0% { width: 10px; height: 10px; opacity: 0.55; }
  100% { width: 64px; height: 64px; opacity: 0; }
}

/* =========================================================================
   ACTIVITY LOG
   ========================================================================= */

.activity-section { margin-top: 40px; }

.ghost-btn {
  background: none; border: none;
  color: var(--text-tertiary);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
}
.ghost-btn:hover { color: var(--text-primary); }

.activity-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  animation: rise-in 0.25s var(--ease-out);
}

.activity-item__icon {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.activity-item__icon--success { background: var(--green-dim); color: var(--green); }
.activity-item__icon--failure { background: var(--red-dim); color: var(--red); }
.activity-item__icon--sent { background: var(--teal-dim); color: var(--teal); }
.activity-item__icon--received { background: var(--indigo-dim); color: var(--indigo); }

.activity-item__body { min-width: 0; flex: 1; }
.activity-item__title { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-item__meta { font-size: 12px; color: var(--text-tertiary); font-family: var(--font-mono); }

/* =========================================================================
   FOOTER
   ========================================================================= */

.app-footer {
  margin-top: auto;
  padding-top: 60px;
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* =========================================================================
   TOAST (incoming transfer notice)
   ========================================================================= */

.transfer-toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 20px 40px -12px rgba(0,0,0,0.6);
  font-size: 13.5px;
  z-index: 500;
  opacity: 0;
  transition: opacity 0.25s var(--ease-out), transform 0.25s var(--ease-out);
}
.transfer-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =========================================================================
   MODAL / TRANSFER BEAM
   ========================================================================= */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(6, 8, 9, 0.72);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 600;
  padding: 20px;
  animation: fade-in 0.2s var(--ease-standard);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%; max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 32px 28px 28px;
  position: relative;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.7);
  animation: modal-in 0.28s var(--ease-out);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
  position: absolute; top: 16px; right: 16px;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--text-primary); }

.beam-stage {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 22px;
}

.beam-node { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 74px; }

.beam-node__avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--indigo), var(--teal));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; color: var(--bg-base);
  box-shadow: 0 0 0 5px var(--bg-elevated);
}

.beam-node__label {
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 74px;
}

.beam-track {
  position: relative;
  flex: 1;
  height: 2px;
  background: var(--border-subtle);
  border-radius: 2px;
  overflow: visible;
}

.beam-progress {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--indigo), var(--teal));
  border-radius: 2px;
  transition: width 0.15s linear;
}

.beam-packet {
  position: absolute;
  top: 50%; left: 0;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 10px 2px rgba(52,214,180,0.7);
  transform: translate(-50%, -50%);
  opacity: 0;
}
.beam-track.is-active .beam-packet {
  opacity: 1;
  animation: packet-travel 1.1s linear infinite;
}
@keyframes packet-travel {
  0% { left: 0%; }
  100% { left: 100%; }
}

.modal-status {
  text-align: center;
  margin-bottom: 18px;
}
.modal-status__state {
  display: block;
  font-size: 15px; font-weight: 700;
  margin-bottom: 3px;
}
.modal-status__file {
  display: block;
  font-size: 12.5px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

.progress-shell { display: flex; flex-direction: column; gap: 8px; }

.progress-track {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--teal-strong), var(--teal));
  transition: width 0.15s var(--ease-standard);
}
.progress-fill.is-complete { background: linear-gradient(90deg, var(--green), var(--teal)); }
.progress-fill.is-failed { background: var(--red); }

.progress-figures {
  display: flex; justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}
.progress-rate {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-tertiary);
  min-height: 14px;
}

.modal-icon-result {
  display: flex; justify-content: center; margin-top: 8px;
}
.modal-icon-result svg { width: 20px; height: 20px; }

/* state-specific modal accents */
.modal[data-state="success"] .modal-status__state { color: var(--green); }
.modal[data-state="failed"] .modal-status__state { color: var(--red); }
.modal[data-state="connecting"] .modal-status__state { color: var(--amber); }

/* =========================================================================
   RESPONSIVE
   ========================================================================= */

@media (max-width: 520px) {
  .app-shell { padding: 20px 16px 60px; }
  .intro { margin: 36px 0 26px; }
  .peers-grid { grid-template-columns: 1fr; }
  .beam-node { width: 60px; }
  .beam-node__label { max-width: 60px; }
}

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