/* =========================================================================
   FileDrop — shared design system
   Two-tone directional palette: teal = outgoing (Send), coral = incoming
   (Receive). The page sets body.page-send / body.page-receive, which remaps
   --accent/--accent-2 for every component below — so the same button/progress
   bar/badge rules automatically pick up the right color on each page.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root, html[data-theme="dark"] {
  --bg: #090b10;
  --card: #12151d;
  --card-2: #181c27;
  --border: #242938;
  --border-strong: #333a4d;

  --send: #22d3c0;
  --send-2: #7fe9dd;
  --receive: #ff8b5e;
  --receive-2: #ffbe93;

  --warn: #ffb454;
  --danger: #ff5c7a;

  --text: #eef0f6;
  --text-dim: #8a91a6;
  --text-faint: #565d70;

  --shadow: 0 24px 60px rgba(0,0,0,0.35);
}

html[data-theme="light"] {
  --bg: #f2f4f9;
  --card: #ffffff;
  --card-2: #eef1f7;
  --border: #dfe3ee;
  --border-strong: #c7cddc;

  --send: #0d9488;
  --send-2: #14b8a6;
  --receive: #e0592a;
  --receive-2: #f2794a;

  --warn: #b56a08;
  --danger: #dc2626;

  --text: #161a22;
  --text-dim: #656d80;
  --text-faint: #97a0b3;

  --shadow: 0 16px 40px rgba(30,35,55,0.10);
}

/* Directional accent — set per page via body class */
body.page-send { --accent: var(--send); --accent-2: var(--send-2); }
body.page-receive { --accent: var(--receive); --accent-2: var(--receive-2); }
body:not(.page-send):not(.page-receive) { --accent: var(--send); --accent-2: var(--send-2); }

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Manrope', -apple-system, 'Segoe UI', sans-serif;
  background:
    radial-gradient(ellipse 900px 500px at 50% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(20px, 5vw, 40px) 16px 60px;
  transition: background-color 0.2s, color 0.2s;
}

.mono {
  font-family: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

/* ---------- Focus & motion ---------- */
button:focus-visible, [tabindex]:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- Header ---------- */
.top-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; max-width: 440px; margin-bottom: 10px; position: relative;
}
.brand {
  display: flex; align-items: center; gap: 9px; font-size: 1.18rem;
  font-weight: 800; letter-spacing: -0.02em; color: var(--text);
}
.brand-mark { color: var(--accent); flex-shrink: 0; }
.icon-btn {
  background: var(--card-2); border: 1px solid var(--border);
  color: var(--text-dim); width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: 0.15s; flex-shrink: 0;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn-group { position: absolute; right: 0; top: 0; display: flex; gap: 6px; }
.icon-btn.history-btn { position: absolute; left: 0; top: 0; }

/* ---------- Mode switch ---------- */
.mode-switch {
  display: flex; gap: 4px; background: var(--card-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px; margin-bottom: 22px; width: 100%; max-width: 440px;
}
.mode-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  background: none; border: none; color: var(--text-dim); padding: 10px 14px;
  border-radius: 999px; font-family: inherit; font-size: 0.85rem; font-weight: 700; cursor: pointer; transition: 0.15s;
}
.mode-btn svg { width: 16px; height: 16px; }
.mode-btn.active { color: #fff; }
.mode-btn.active.send-tab { background: var(--send); box-shadow: 0 4px 14px color-mix(in srgb, var(--send) 45%, transparent); }
.mode-btn.active.receive-tab { background: var(--receive); box-shadow: 0 4px 14px color-mix(in srgb, var(--receive) 45%, transparent); }
.mode-btn:not(.active):hover { color: var(--text); background: color-mix(in srgb, var(--card-2) 60%, var(--text) 8%); }

/* ---------- Card ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 22px;
  padding: clamp(20px, 6vw, 30px); width: 100%; max-width: 440px; text-align: center;
  box-shadow: var(--shadow);
}
.card-icon {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}
.card-icon svg { width: 26px; height: 26px; }
h1 { margin: 0 0 20px; font-size: 1.22rem; font-weight: 800; letter-spacing: -0.01em; color: var(--text); }

/* ---------- Dropzone ---------- */
#dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: 16px; padding: 38px 20px;
  cursor: pointer; transition: 0.2s;
}
#dropzone:hover, #dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--card-2) 50%, var(--accent) 6%);
}
.dz-icon { color: var(--accent); margin-bottom: 10px; }
.dz-icon svg { width: 30px; height: 30px; }
#dropzone p.dz-title { font-size: 1rem; font-weight: 700; }
#dropzone p.dz-sub { font-size: 0.8rem; color: var(--text-dim); margin-top: 6px; }
#fileInput { display: none; }

/* ---------- QR ---------- */
#qrBox { margin-top: 24px; display: none; }
.qr-frame {
  background: #fff; padding: 14px; border-radius: 16px; display: inline-block;
  max-width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}
.qr-frame img, .qr-frame canvas, .qr-frame table { width: 100% !important; height: auto !important; max-width: 240px; display: block; }
.qr-hint {
  margin-top: 14px; font-size: 0.82rem; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap;
}
.qr-hint svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--accent); }

/* ---------- Signature element: beam pulse (the "live P2P link" indicator) --- */
.beam-track {
  position: relative; height: 2px; width: 100%; max-width: 200px; margin: 18px auto 4px;
  background: var(--border); border-radius: 2px; overflow: hidden;
}
.beam-track::before, .beam-track::after {
  content: ''; position: absolute; top: 50%; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); transform: translateY(-50%);
}
.beam-track::before { left: -1px; }
.beam-track::after { right: -1px; }
.beam-pulse {
  position: absolute; top: 0; left: 0; height: 100%; width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: beamMove 1.8s ease-in-out infinite;
}
@keyframes beamMove {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* ---------- Progress / stats HUD ---------- */
.progress-wrap {
  width: 100%; background: var(--card-2); border: 1px solid var(--border); border-radius: 999px;
  height: 8px; margin-top: 18px; overflow: hidden; display: none;
}
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0%; transition: width 0.15s; border-radius: 999px;
}
.progress-meta {
  display: none; justify-content: space-between; font-size: 0.74rem; color: var(--text-dim); margin-top: 8px;
}
.progress-meta span { font-family: 'JetBrains Mono', monospace; }
.speed {
  font-family: 'JetBrains Mono', monospace; font-size: 0.76rem; color: var(--accent);
  margin-top: 8px; font-weight: 500;
}
.filename { font-weight: 700; margin-top: 12px; color: var(--text); word-break: break-all; font-size: 0.95rem; }
.file-list { margin-top: 10px; text-align: left; max-height: 140px; overflow-y: auto; }
.file-list-item {
  display: flex; justify-content: space-between; gap: 8px; font-size: 0.78rem;
  color: var(--text-dim); padding: 6px 0; border-bottom: 1px solid var(--border);
}
.file-list-item:last-child { border-bottom: none; }
.file-list-item.active { color: var(--accent); font-weight: 700; }
.file-list-item.done { color: var(--text-faint); text-decoration: line-through; }

/* ---------- Status line ---------- */
#status {
  margin-top: 18px; font-size: 0.87rem; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center; gap: 7px; text-align: center; line-height: 1.45;
}
#status svg { width: 15px; height: 15px; flex-shrink: 0; }
#status.error { color: var(--danger); font-weight: 600; }
#status.warn { color: var(--warn); font-weight: 600; }
#status.success { color: var(--accent); font-weight: 700; }

/* ---------- Buttons ---------- */
.transfer-controls { display: none; gap: 10px; margin-top: 16px; }
.ctrl-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--border); background: var(--card-2); color: var(--text);
  font-family: inherit; padding: 12px; border-radius: 12px; cursor: pointer;
  font-size: 0.85rem; font-weight: 700; transition: 0.15s; min-height: 44px;
}
.ctrl-btn svg { width: 16px; height: 16px; }
.ctrl-btn:hover { border-color: var(--accent); }
.ctrl-btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.ctrl-btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, var(--card-2)); }

.downloadBtn {
  margin-top: 22px; display: none; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff; border: none; padding: 14px 20px; border-radius: 12px;
  font-family: inherit; font-size: 0.92rem; font-weight: 700; cursor: pointer; width: 100%; min-height: 46px;
  transition: 0.15s;
}
.downloadBtn svg { width: 17px; height: 17px; }
.downloadBtn:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* ---------- Offline mode ---------- */
.offline-panel { display: none; margin-top: 22px; text-align: center; flex-direction: column; align-items: center; }
.offline-badge {
  display: inline-flex; align-items: center; gap: 7px; font-size: 0.78rem; font-weight: 600;
  color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  padding: 7px 14px; border-radius: 999px; margin-bottom: 18px;
}
.offline-badge svg { width: 14px; height: 14px; }
.offline-card { background: var(--card-2); border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: 100%; }
.offline-qr-wrap { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; max-width: 100%; }
.offline-qr-wrap img, .offline-qr-wrap canvas, .offline-qr-wrap table { width: 100% !important; height: auto !important; max-width: 220px; }
.offline-hint { font-size: 0.8rem; color: var(--text-dim); margin: 14px 0; line-height: 1.5; }

.btn-scan {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--accent); color: #fff; border: none; padding: 14px; font-family: inherit;
  border-radius: 12px; cursor: pointer; font-size: 0.92rem; font-weight: 700; transition: 0.15s; min-height: 46px;
}
.btn-scan svg { width: 17px; height: 17px; }
.btn-scan:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-scan:disabled { opacity: 0.5; cursor: default; transform: none; }
@keyframes scanPulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 35%, transparent); }
  50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--accent) 0%, transparent); }
}
.btn-scan.pulse { animation: scanPulse 2.2s ease-out infinite; }

.manual-toggle {
  margin-top: 16px; font-size: 0.76rem; color: var(--text-dim); text-decoration: underline;
  cursor: pointer; background: none; border: none; font-family: inherit;
}
.manual-toggle:hover { color: var(--text); }
.manual-box { display: none; margin-top: 12px; text-align: left; }
.manual-box textarea {
  width: 100%; height: 64px; font-family: 'JetBrains Mono', monospace; font-size: 0.68rem;
  background: var(--bg); color: var(--accent); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px; resize: none; margin-bottom: 8px;
}
.manual-box textarea.input, .manual-box textarea.output { color: var(--accent); }
.manual-box button {
  width: 100%; background: var(--card-2); color: var(--text); border: 1px solid var(--border);
  padding: 11px; border-radius: 10px; cursor: pointer; font-family: inherit; font-size: 0.82rem; font-weight: 600;
  min-height: 42px;
}
.manual-box button:hover { border-color: var(--accent); }

.scan-entry { display: none; flex-direction: column; align-items: center; margin-top: 4px; gap: 4px; }
.scan-caption { font-size: 0.79rem; color: var(--text-dim); margin-bottom: 16px; line-height: 1.55; max-width: 300px; }

/* ---------- History panel ---------- */
.history-panel {
  display: none; width: 100%; max-width: 440px; margin-top: 16px; background: var(--card);
  border: 1px solid var(--border); border-radius: 18px; padding: 20px; text-align: left;
  box-shadow: var(--shadow);
}
.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.history-header h2 { font-size: 0.9rem; font-weight: 700; color: var(--text); }
.history-clear { font-size: 0.72rem; color: var(--text-dim); background: none; border: none; cursor: pointer; text-decoration: underline; font-family: inherit; }
.history-clear:hover { color: var(--danger); }
.history-list { max-height: 280px; overflow-y: auto; }

/* ---------- Settings panel (reuses history-panel look) ---------- */
.settings-panel { display: none; }
.settings-body { display: flex; flex-direction: column; gap: 12px; }
.settings-note { font-size: 0.78rem; color: var(--text-dim); line-height: 1.5; }
.history-empty { color: var(--text-dim); font-size: 0.8rem; padding: 14px 0; text-align: center; }
.history-item { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.history-item:last-child { border-bottom: none; }
.history-icon {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.history-icon svg { width: 15px; height: 15px; }
.history-icon.sent { background: color-mix(in srgb, var(--send) 16%, transparent); color: var(--send); }
.history-icon.received { background: color-mix(in srgb, var(--receive) 16%, transparent); color: var(--receive); }
.history-info { flex: 1; min-width: 0; }
.history-name { font-size: 0.82rem; font-weight: 600; color: var(--text); word-break: break-all; }
.history-meta { font-size: 0.7rem; color: var(--text-dim); margin-top: 2px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.history-status-tag { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.history-status-tag.cancelled { color: var(--warn); }
.history-status-tag.failed { color: var(--danger); }
.history-status-tag svg { width: 11px; height: 11px; }

/* ---------- Camera scan overlay ---------- */
.qr-scan-overlay {
  position: fixed; inset: 0; background: rgba(4,5,8,0.97); z-index: 9999;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.qr-scan-card { text-align: center; max-width: 340px; width: 100%; }
.qr-scan-title { color: #fff; font-size: 0.95rem; margin-bottom: 20px; font-weight: 600; }
.qr-scan-frame {
  position: relative; width: min(280px, 78vw); height: min(280px, 78vw); margin: 0 auto;
  border-radius: 22px; overflow: hidden; background: #000; cursor: pointer;
}
.qr-scan-frame video { width: 100%; height: 100%; object-fit: cover; }
.qr-scan-corner { position: absolute; width: 26px; height: 26px; border: 3px solid var(--accent); }
.qr-scan-corner.tl { top: 10px; left: 10px; border-right: none; border-bottom: none; border-radius: 8px 0 0 0; }
.qr-scan-corner.tr { top: 10px; right: 10px; border-left: none; border-bottom: none; border-radius: 0 8px 0 0; }
.qr-scan-corner.bl { bottom: 10px; left: 10px; border-right: none; border-top: none; border-radius: 0 0 0 8px; }
.qr-scan-corner.br { bottom: 10px; right: 10px; border-left: none; border-top: none; border-radius: 0 0 8px 0; }
.qr-scan-laser {
  position: absolute; left: 10px; right: 10px; height: 2px; top: 10px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 10px 1px color-mix(in srgb, var(--accent) 70%, transparent);
  animation: laserSweep 2.1s ease-in-out infinite;
}
@keyframes laserSweep {
  0%, 100% { top: 10px; opacity: 0.9; }
  50% { top: calc(100% - 12px); opacity: 0.9; }
}
.qr-scan-status { color: rgba(255,255,255,0.65); font-size: 0.82rem; margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 7px; }
.qr-scan-status svg { width: 14px; height: 14px; }
.qr-scan-actions { display: flex; gap: 10px; margin-top: 18px; }
.qr-scan-cancel, .qr-scan-gallery {
  background: #1a1d28; color: #fff; border: 1px solid #2c3140; padding: 11px 20px; border-radius: 11px;
  cursor: pointer; font-size: 0.85rem; font-family: inherit; font-weight: 600; display: flex; align-items: center; gap: 7px;
  min-height: 42px;
}
.qr-scan-cancel:hover, .qr-scan-gallery:hover { border-color: var(--accent); }
.qr-scan-cancel svg, .qr-scan-gallery svg { width: 15px; height: 15px; }

/* ---------- Small-screen refinement ---------- */
@media (max-width: 380px) {
  body { padding: 16px 12px 48px; }
  .card { padding: 18px; border-radius: 18px; }
  h1 { font-size: 1.1rem; }
  #dropzone { padding: 30px 14px; }
  .ctrl-btn, .btn-scan, .downloadBtn { font-size: 0.82rem; }
}

@media (min-width: 640px) {
  .top-row, .mode-switch, .card, .history-panel { max-width: 460px; }
}
