/* Transferly: mobile-first, dark by default */
:root {
  --bg: #0b0e14;
  --bg-2: #121722;
  --surface: #171d2a;
  --surface-2: #1f2737;
  --border: #2a3346;
  --text: #e8ecf4;
  --muted: #8d97ab;
  --accent: #6d8bff;
  --accent-2: #9a6bff;
  --accent-text: #fff;
  --ok: #3ccf91;
  --warn: #f5b648;
  --err: #ff6b7a;
  --radius: 16px;
  --shadow: 0 12px 40px rgb(0 0 0 / 0.45);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-2: #e9edf6;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --border: #d8deea;
  --text: #141a26;
  --muted: #5d6779;
  --accent: #4c6ef5;
  --accent-2: #7c4dff;
  --shadow: 0 12px 40px rgb(20 30 60 / 0.15);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(120% 80% at 50% 45%, var(--bg-2), var(--bg) 70%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.92em; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.ic { width: 22px; height: 22px; flex: none; display: block; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn .ic { width: 18px; height: 18px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: var(--accent-text); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--border); }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 0.85rem; border-radius: 10px; }
.icon-btn {
  position: relative;
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  border: 0; background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn-small { width: 32px; height: 32px; border-radius: 10px; }
.icon-btn-small .ic { width: 18px; height: 18px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}

/* ------------------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-t)) 12px 8px 16px;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.top-actions { display: flex; gap: 2px; }

.banners { display: flex; flex-direction: column; gap: 8px; padding: 0 12px; z-index: 4; }
.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  max-width: 640px; width: 100%; margin: 0 auto;
}
.banner.accent { border-color: var(--accent); }

/* ------------------------------------------------------------ stage */
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.radar { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.radar span {
  position: absolute; width: 140px; height: 140px; border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  animation: ripple 4.5s ease-out infinite;
  opacity: 0;
}
.radar span:nth-child(2) { animation-delay: 1.5s; }
.radar span:nth-child(3) { animation-delay: 3s; }
@keyframes ripple {
  0% { transform: scale(0.4); opacity: 0.7; }
  100% { transform: scale(4.2); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .radar span { animation: none; opacity: 0.25; } }

.peers { position: absolute; inset: 0; }
.peer {
  position: absolute; left: 50%; top: 50%;
  width: 120px;
  transform: translate(calc(-50% + var(--x, 0px)), calc(-50% + var(--y, 0px)));
  transition: transform 0.45s cubic-bezier(.2,.8,.2,1), opacity 0.25s;
  --progress: 0;
}
.peer.entering, .peer.leaving { opacity: 0; transform: translate(calc(-50% + var(--x, 0px)), calc(-50% + var(--y, 0px))) scale(0.6); }
.peers.grid {
  position: static; height: 100%; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  align-content: start; justify-items: center; gap: 16px; padding: 24px 16px 120px;
}
.peers.grid .peer { position: relative; left: auto; top: auto; transform: none; }

.peer-main {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 4px; border: 0; background: none; color: inherit; font: inherit; cursor: pointer;
  border-radius: var(--radius);
  -webkit-touch-callout: none; user-select: none;
}
.peer-main:hover .avatar { transform: scale(1.06); }
.peer-main:active .avatar { transform: scale(0.96); }
.peer-name { font-weight: 650; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-sub { font-size: 0.75rem; color: var(--muted); margin-top: -4px; }
.peer-more { position: absolute; top: 2px; right: 4px; color: var(--muted); opacity: 0.8; }
.peer-badge {
  position: absolute; top: 56px; left: calc(50% + 18px);
  width: 24px; height: 24px; border-radius: 50%; display: none; place-items: center;
  background: var(--ok); color: #05261a; border: 2px solid var(--bg);
}
.peer-badge .ic { width: 14px; height: 14px; stroke-width: 2.4; }
.peer.trusted .peer-badge { display: grid; }
.peer.drop .avatar { box-shadow: 0 0 0 4px var(--accent), 0 0 40px color-mix(in srgb, var(--accent) 60%, transparent); transform: scale(1.1); }

.avatar {
  --hue: 220;
  position: relative; display: grid; place-items: center;
  width: 76px; height: 76px; border-radius: 50%;
  background: linear-gradient(140deg, hsl(var(--hue) 75% 60%), hsl(calc(var(--hue) + 40) 70% 48%));
  color: #fff; box-shadow: 0 8px 24px hsl(var(--hue) 70% 30% / 0.45);
  transition: transform 0.2s, box-shadow 0.2s;
}
.avatar .ic { width: 32px; height: 32px; }
.avatar.small { width: 44px; height: 44px; box-shadow: none; flex: none; }
.avatar.small .ic { width: 22px; height: 22px; }
.ring { position: absolute; inset: -7px; width: calc(100% + 14px); height: calc(100% + 14px); transform: rotate(-90deg); opacity: 0; transition: opacity 0.2s; }
.ring circle { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-dasharray: calc(var(--progress) * 1) 100; transition: stroke-dasharray 0.3s; }
.peer.busy .ring { opacity: 1; }

.empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(360px, 86vw); text-align: center; padding-top: 170px;
}
.empty p { margin: 6px 0; color: var(--muted); }
body.has-peers .empty { display: none; }

/* ------------------------------------------------------------ me */
.me { padding: 8px 12px calc(12px + var(--safe-b)); display: flex; justify-content: center; z-index: 4; }
.me-card {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px 8px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border: 1px solid var(--border); color: inherit; font: inherit; cursor: pointer;
  backdrop-filter: blur(10px); max-width: 100%;
}
.me-card:hover { border-color: var(--accent); }
.me-text { display: flex; flex-direction: column; text-align: left; min-width: 0; }
.me-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-sub { font-size: 0.78rem; color: var(--muted); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); flex: none; }
.status-dot[data-state="open"] { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.status-dot[data-state="closed"] { background: var(--err); }

/* ------------------------------------------------------------ drawer */
.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-height: 62vh; display: flex; flex-direction: column;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  transform: translateY(105%); transition: transform 0.25s ease;
  padding-bottom: var(--safe-b);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 8px 18px; gap: 8px; }
.transfer-list { overflow-y: auto; padding: 4px 12px 16px; display: flex; flex-direction: column; gap: 10px; }
#transfer-empty { padding: 8px 16px 24px; }
@media (min-width: 900px) {
  .drawer {
    left: auto; top: 64px; right: 12px; bottom: 12px; width: 400px; max-height: none;
    border-radius: 20px; border: 1px solid var(--border);
    transform: translateX(110%);
  }
}

.tcard { background: var(--surface-2); border-radius: 14px; padding: 12px; border: 1px solid var(--border); }
.tcard-head { display: flex; align-items: center; gap: 8px; }
.tdir { color: var(--accent); }
.tdir .ic { width: 18px; height: 18px; }
.tcard.in .tdir { color: var(--ok); }
.ttitle { flex: 1; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface); color: var(--muted); white-space: nowrap; }
.chip[data-status="done"] { color: var(--ok); }
.chip[data-status="active"] { color: var(--accent); }
.chip[data-status="failed"], .chip[data-status="declined"], .chip[data-status="cancelled"] { color: var(--err); }
.chip[data-status="partial"] { color: var(--warn); }
.ttext { margin-top: 8px; white-space: pre-wrap; word-break: break-word; max-height: 160px; overflow: auto; }
.frows { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.fline { display: flex; justify-content: space-between; gap: 8px; }
.fname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; border-radius: 3px; background: var(--surface); overflow: hidden; margin: 6px 0 4px; }
.bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.25s; }
.bar[data-status="done"] span { background: var(--ok); }
.bar[data-status="failed"] span, .bar[data-status="cancelled"] span { background: var(--err); }
.bar[data-status="skipped"] span { background: var(--muted); }
.facts { display: flex; gap: 6px; flex-wrap: wrap; }
.facts:not(:empty) { margin-top: 6px; }
.terror { color: var(--err); margin: 8px 0 0; }
.terror:empty { display: none; }

/* ------------------------------------------------------------ toasts */
.toasts {
  position: fixed; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-8px); transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: none; }
.toast-msg { flex: 1; }
.toast-success { border-left: 4px solid var(--ok); }
.toast-error { border-left: 4px solid var(--err); }
.toast-info { border-left: 4px solid var(--accent); }

/* ------------------------------------------------------------ dialogs */
.modal {
  border: 1px solid var(--border); border-radius: 20px; padding: 0;
  width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: pop 0.18s ease;
}
.modal:not([open]) { display: none; }
.modal.wide { width: min(560px, calc(100vw - 24px)); }
.modal.closing { opacity: 0; transform: scale(0.97); transition: opacity 0.15s, transform 0.15s; }
.modal::backdrop { background: rgb(0 0 0 / 0.55); backdrop-filter: blur(3px); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 12px 4px 20px; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 20px 18px; border-top: 1px solid var(--border); }
.modal.incoming .modal-actions { flex-direction: column; align-items: stretch; }
@media (max-width: 520px) {
  .modal { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: 20px 20px 0 0; padding-bottom: var(--safe-b); }
  .modal-actions { flex-direction: column-reverse; align-items: stretch; }
  .modal.incoming .modal-actions { flex-direction: column; }
}

.sender { display: flex; align-items: center; gap: 12px; }
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.file-list li .fname { flex: 1; }
.file-list .ic { width: 18px; height: 18px; color: var(--muted); }
.note { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 0.88rem; }
.note.warn { color: var(--warn); }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.message-text { white-space: pre-wrap; word-break: break-word; padding: 12px; border-radius: 12px; background: var(--surface-2); max-height: 50vh; overflow: auto; user-select: text; }

.action-list { display: flex; flex-direction: column; gap: 4px; }
.action-list p { margin: 0 0 8px; }
.action {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px;
  border: 0; border-radius: 12px; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.action:hover { background: var(--surface-2); }
.action .ic { color: var(--accent); }

.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit;
}
.input:focus { outline: none; border-color: var(--accent); }
textarea.input { resize: vertical; }
.select { width: auto; max-width: 100%; }

.fp-box { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fp-box > div { padding: 10px; border-radius: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 4px; }

/* pairing */
.pair-section { padding: 14px; border-radius: 14px; background: var(--surface-2); display: flex; flex-direction: column; gap: 10px; }
.pair-show:empty { display: none; }
.pair-show { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qr { width: 180px; height: 180px; background: #fff; border-radius: 12px; padding: 6px; }
.qr svg { width: 100%; height: 100%; display: block; }
.code-big { font: 700 2.2rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.08em; }
.code-input { font: 600 1.4rem ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 0.3em; text-align: center; }
.code-small { font-size: 1.05rem; letter-spacing: 0.08em; }
.pair-active { display: flex; flex-direction: column; gap: 6px; }

/* settings */
.settings { display: flex; flex-direction: column; gap: 18px; }
.set-section { display: flex; flex-direction: column; gap: 10px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.set-section:last-of-type { border-bottom: 0; }
.switch-row, .select-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.slider { position: absolute; inset: 0; border-radius: 14px; background: var(--border); transition: background 0.15s; pointer-events: none; }
.slider::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.trusted-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.about { margin: 0; }
