/* ============================================================
   P2P Share — Apple-inspired glassmorphism UI
   Dark theme is default; [data-theme="light"] overrides.
   ============================================================ */

:root {
  --bg: #0e0e17;
  --bg-soft: #14141f;
  --card: rgba(255, 255, 255, 0.055);
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #f2f3f7;
  --text-muted: #9aa0b4;
  --accent-1: #6366f1;
  --accent-2: #22d3ee;
  --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #22d3ee 100%);
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font: "Segoe UI", "SF Pro Display", -apple-system, BlinkMacSystemFont,
          "Noto Kufi Arabic", "Cairo", Tahoma, sans-serif;
}

[data-theme="light"] {
  --bg: #f2f4fb;
  --bg-soft: #e9ecf7;
  --card: rgba(255, 255, 255, 0.72);
  --card-border: rgba(20, 25, 60, 0.08);
  --text: #171a2b;
  --text-muted: #5b6178;
  --shadow: 0 18px 50px rgba(30, 40, 90, 0.12);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- Animated background orbs ---------- */
.bg-orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.bg-orbs span {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
  animation: drift 22s ease-in-out infinite alternate;
}
.bg-orbs span:nth-child(1) { width: 46vw; height: 46vw; background: #6366f1; top: -12%; inset-inline-start: -8%; }
.bg-orbs span:nth-child(2) { width: 38vw; height: 38vw; background: #22d3ee; bottom: -14%; inset-inline-end: -6%; animation-delay: -7s; }
.bg-orbs span:nth-child(3) { width: 26vw; height: 26vw; background: #8b5cf6; top: 40%; inset-inline-start: 55%; animation-delay: -14s; }
[data-theme="light"] .bg-orbs span { opacity: 0.18; }

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(4vw, -5vh) scale(1.15); }
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(16px, 4vw, 40px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { border-radius: 10px; box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35); }
.brand-name { font-size: 1.25rem; font-weight: 700; letter-spacing: 0.3px; }
.brand-name em { font-style: normal; background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.topbar-actions { display: flex; gap: 10px; }

.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  font-family: inherit; font-size: 0.88rem; font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 0.15s ease, background 0.2s ease;
}
.chip-btn:hover { transform: translateY(-1px); background: rgba(255,255,255,0.12); }
[data-theme="light"] .chip-btn:hover { background: rgba(255,255,255,0.95); }
.chip-btn.icon-only { padding: 8px 10px; }

/* ---------- Layout ---------- */
.container {
  width: min(1060px, 100% - 32px);
  margin-inline: auto;
  flex: 1;
  padding-bottom: 40px;
}

.hero { text-align: center; margin: clamp(10px, 4vh, 44px) 0 34px; }
.hero h1 {
  font-size: clamp(1.7rem, 4.5vw, 2.9rem);
  margin: 0 0 12px;
  background: linear-gradient(120deg, var(--text) 30%, var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { color: var(--text-muted); max-width: 560px; margin: 0 auto; font-size: 1.02rem; line-height: 1.6; }

.pairing-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}
@media (max-width: 780px) { .pairing-grid { grid-template-columns: 1fr; } }

/* ---------- Cards (glassmorphism) ---------- */
.card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--card-border);
  background: var(--card);
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 28px);
  animation: cardIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.glass {
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.card-head h2 { margin: 0; font-size: 1.12rem; font-weight: 700; }
.muted { color: var(--text-muted); font-size: 0.92rem; }

/* ---------- Code display ---------- */
.timer-pill {
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem; font-weight: 700;
  padding: 4px 12px; border-radius: 999px;
  background: rgba(99, 102, 241, 0.16);
  color: var(--accent-2);
  border: 1px solid rgba(99, 102, 241, 0.25);
}
.timer-pill.expiring { color: var(--warning); border-color: rgba(251,191,36,0.4); background: rgba(251,191,36,0.12); }

.code-display {
  display: flex; justify-content: center; gap: clamp(6px, 1.4vw, 12px);
  direction: ltr;
  margin: 6px 0 18px;
}
.code-display .digit {
  width: clamp(38px, 6vw, 52px);
  height: clamp(50px, 8vw, 66px);
  display: grid; place-items: center;
  font-size: clamp(1.5rem, 3.4vw, 2.1rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-border);
  animation: digitIn 0.35s ease both;
}
[data-theme="light"] .code-display .digit { background: rgba(255,255,255,0.85); }
.code-display .digit:nth-child(2) { animation-delay: 0.04s; }
.code-display .digit:nth-child(3) { animation-delay: 0.08s; }
.code-display .digit:nth-child(4) { animation-delay: 0.12s; }
.code-display .digit:nth-child(5) { animation-delay: 0.16s; }
.code-display .digit:nth-child(6) { animation-delay: 0.2s; }
@keyframes digitIn { from { opacity: 0; transform: scale(0.7); } to { opacity: 1; transform: none; } }

.code-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- QR ---------- */
.qr-wrap { margin-top: 20px; text-align: center; }
.qr-box {
  width: 168px; height: 168px;
  margin-inline: auto;
  border-radius: var(--radius-md);
  background: #fff;
  padding: 8px;
  display: grid; place-items: center;
  box-shadow: 0 8px 26px rgba(0,0,0,0.25);
}
.qr-box img, .qr-box svg { width: 100%; height: 100%; border-radius: 6px; }
.qr-skeleton {
  width: 100%; height: 100%; border-radius: 8px;
  background: linear-gradient(100deg, #eee 40%, #f9f9f9 50%, #eee 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.qr-hint { color: var(--text-muted); font-size: 0.85rem; margin-top: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius-md);
  border: none;
  font-family: inherit; font-size: 0.95rem; font-weight: 700;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.2s ease, opacity 0.2s;
  color: var(--text);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-gradient {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}
.btn-gradient:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(99, 102, 241, 0.5); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--card-border);
}
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.08); }
[data-theme="light"] .btn-ghost:hover:not(:disabled) { background: rgba(0,0,0,0.05); }

.btn-danger-ghost {
  background: transparent;
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: var(--danger);
  padding: 9px 16px;
  font-size: 0.88rem;
}
.btn-danger-ghost:hover { background: rgba(248, 113, 113, 0.12); }

.btn-block { width: 100%; margin-top: 18px; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }

/* ---------- OTP input ---------- */
.otp-row { display: flex; gap: clamp(6px, 1.2vw, 10px); justify-content: center; margin-top: 18px; }
.otp {
  width: clamp(40px, 6vw, 52px);
  height: clamp(52px, 8vw, 64px);
  text-align: center;
  font-size: 1.5rem; font-weight: 800;
  font-family: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  caret-color: var(--accent-2);
}
[data-theme="light"] .otp { background: rgba(255,255,255,0.9); }
.otp:focus { border-color: var(--accent-1); box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18); }
.otp.filled { border-color: var(--accent-2); }

.feature-list {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 22px;
}
.feature-list span {
  font-size: 0.8rem; color: var(--text-muted);
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--card-border);
}

/* ---------- Peer card ---------- */
.peer-card {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.peer-info { display: flex; align-items: center; gap: 14px; }
.peer-avatar {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4);
}
.peer-label { margin: 0; font-size: 0.78rem; color: var(--text-muted); }
.peer-name { margin: 2px 0 0; font-weight: 700; font-size: 1.05rem; }
.peer-status { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.status-pill {
  padding: 6px 14px; border-radius: 999px;
  font-size: 0.82rem; font-weight: 700;
}
.st-connecting { background: rgba(251, 191, 36, 0.14); color: var(--warning); }
.st-connected  { background: rgba(52, 211, 153, 0.14); color: var(--success); }
.st-offline    { background: rgba(248, 113, 113, 0.14); color: var(--danger); }

.st-connecting::before, .st-connected::before, .st-offline::before {
  content: "●"; margin-inline-end: 6px; font-size: 0.7em;
}
.st-connecting::before { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

.quality { display: flex; align-items: flex-end; gap: 3px; height: 18px; }
.quality span {
  width: 5px; border-radius: 3px;
  background: var(--card-border);
  transition: background 0.3s;
}
.quality span:nth-child(1) { height: 25%; }
.quality span:nth-child(2) { height: 50%; }
.quality span:nth-child(3) { height: 75%; }
.quality span:nth-child(4) { height: 100%; }
.quality.q1 span:nth-child(-n+1),
.quality.q2 span:nth-child(-n+2),
.quality.q3 span:nth-child(-n+3),
.quality.q4 span:nth-child(-n+4) { background: var(--success); }
.quality.q1 span:nth-child(-n+1) { background: var(--danger); }
.quality.q2 span:nth-child(-n+2) { background: var(--warning); }

/* ---------- Drop zone ---------- */
.drop-zone {
  border: 2px dashed var(--card-border);
  border-radius: var(--radius-md);
  padding: clamp(26px, 5vw, 48px) 20px;
  text-align: center;
  color: var(--text-muted);
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
  cursor: pointer;
  outline: none;
}
.drop-zone:focus-visible { border-color: var(--accent-1); }
.drop-zone.dragover {
  border-color: var(--accent-2);
  background: rgba(34, 211, 238, 0.07);
  transform: scale(1.01);
}
.drop-zone svg { color: var(--accent-1); margin-bottom: 8px; }
.dz-title { font-size: 1.08rem; font-weight: 700; color: var(--text); margin: 4px 0; }
.dz-sub { font-size: 0.85rem; margin: 0 0 18px; }
.dz-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.save-mode { margin-top: 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Transfers ---------- */
.tx-summary { display: flex; gap: 14px; }
.stat {
  font-size: 0.85rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
}
.tx-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }

.tx-item {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  animation: cardIn 0.35s ease both;
}
.tx-row { display: flex; align-items: center; gap: 12px; }
.tx-icon {
  width: 38px; height: 38px; flex: none;
  border-radius: 10px;
  display: grid; place-items: center;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-1);
  font-size: 1.1rem;
}
.tx-meta { flex: 1; min-width: 0; }
.tx-name {
  font-weight: 600; font-size: 0.93rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  direction: ltr; text-align: start;
}
.tx-sub { font-size: 0.78rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tx-actions { display: flex; gap: 6px; }
.tx-btn {
  width: 32px; height: 32px;
  border-radius: 9px; border: 1px solid var(--card-border);
  background: transparent; color: var(--text-muted);
  cursor: pointer; display: grid; place-items: center;
  transition: color 0.15s, border-color 0.15s;
}
.tx-btn:hover { color: var(--text); border-color: var(--text-muted); }
.tx-btn.cancel:hover { color: var(--danger); border-color: var(--danger); }

.progress-track {
  height: 7px; border-radius: 99px;
  background: rgba(127, 127, 160, 0.18);
  margin-top: 10px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  border-radius: 99px;
  background: var(--accent-grad);
  transition: width 0.25s linear;
}
.tx-item.done .progress-fill { background: var(--success); }
.tx-item.error .progress-fill, .tx-item.cancelled .progress-fill { background: var(--danger); }
.tx-item.paused .progress-fill { background: var(--warning); }

/* ---------- Nearby devices ---------- */
.nearby-card { margin-top: 22px; }

.pulse-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--success);
  position: relative;
}
.pulse-dot::after {
  content: ""; position: absolute; inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--success);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  from { transform: scale(0.6); opacity: 0.9; }
  to   { transform: scale(1.7); opacity: 0; }
}

.nearby-list {
  display: flex; flex-wrap: wrap; gap: 12px;
  margin-top: 16px;
}
.nearby-device {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  min-width: 108px;
  padding: 16px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
  background: transparent;
  color: var(--text);
  font-family: inherit; font-size: 0.82rem; font-weight: 600;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.2s, background 0.2s;
  animation: cardIn 0.3s ease both;
}
.nearby-device:hover {
  transform: translateY(-3px);
  border-color: var(--accent-1);
  background: rgba(99, 102, 241, 0.08);
}
.nearby-device .nd-avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.4rem;
  background: var(--accent-grad);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}
.nearby-device .nd-name {
  max-width: 120px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nearby-device.inviting { opacity: 0.55; pointer-events: none; }
.nearby-empty { color: var(--text-muted); font-size: 0.85rem; margin: 14px 0 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(8, 8, 16, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: toastIn 0.2s ease both;
}
.modal {
  width: min(400px, calc(100vw - 40px));
  text-align: center;
}
.modal-icon { font-size: 2.4rem; margin-bottom: 8px; }
.invite-text { font-size: 1.02rem; font-weight: 600; margin: 0 0 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  bottom: 22px; inset-inline-end: 22px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 44px));
}
.toast {
  padding: 13px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.9rem; font-weight: 600;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.toast.out { animation: toastOut 0.25s ease forwards; }
.toast.success { border-inline-start: 4px solid var(--success); }
.toast.error   { border-inline-start: 4px solid var(--danger); }
.toast.info    { border-inline-start: 4px solid var(--accent-1); }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  padding: 18px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  .peer-card { flex-direction: column; align-items: flex-start; }
  .peer-status { width: 100%; justify-content: space-between; }
  .toasts { inset-inline: 16px; bottom: 16px; max-width: none; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
