/* FTools Drop — brand FTRACK VIETNAM, primary #6AB745 (cùng bộ token với src/tools/shared/ui.css).
   Trang này còn được máy chủ drop phục vụ cho điện thoại, nên tự chứa, không dùng file ngoài thư mục. */
:root {
  --brand-50: #F3FAEE;
  --brand-100: #E6F5DC;
  --brand-200: #CDEAB9;
  --brand-400: #8ACC66;
  --brand-500: #6AB745;
  --brand-700: #428020;
  --brand-800: #2F6B1E;
  --brand-rgb: 106, 183, 69;

  --bg: #f8fafc;
  --fg: #0f172a;
  --accent: #428020;
  --accent-hover: #2F6B1E;
  --muted: #606B7B;
  --card: #ffffff;
  --card-border: #e2e8f0;
  --success: #16a34a;
  --error: #dc2626;
  --warn: #b45309;
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

.ft-sprite { display: none; }
.ico-inline { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.ico-brand { color: var(--brand-700); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 28px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: #ffffff;
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-logo { height: 26px; width: auto; }
.badge-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-50);
  color: var(--accent);
  border: 1px solid var(--brand-100);
}

.net-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.net-dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.net-status.is-online .net-dot { background: var(--success); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15); }
.net-status.is-connecting .net-dot { background: #f59e0b; animation: blink 1.2s infinite; }
.net-status.is-offline .net-dot { background: var(--error); }
.net-status.is-offline { color: var(--error); }
@keyframes blink { 50% { opacity: 0.3; } }

/* Nút */
.btn, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, color 0.16s;
  -webkit-tap-highlight-color: transparent;
}
.btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 9px;
}
.btn:hover:not(:disabled) { border-color: #cbd5e1; background: #f1f5f9; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-ghost {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--card-border);
  border-radius: 8px;
}
.btn-ghost:hover { color: var(--fg); border-color: #cbd5e1; background: #f1f5f9; }

.input {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 9px;
}
.input:focus { outline: none; border-color: var(--brand-400); box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.16); }
.textarea { resize: vertical; min-height: 120px; line-height: 1.45; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
}

/* Bố cục */
.page { max-width: 1080px; margin: 0 auto; padding: 22px 28px 48px; }

.me { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.me-avatar {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--brand-50);
  color: var(--brand-700);
  border: 1px solid var(--brand-100);
}
.me-avatar svg { width: 22px; height: 22px; }
.me-text small { display: block; font-size: 12px; color: var(--muted); }
.me-name {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 17px; font-weight: 700; color: var(--fg);
  background: none; border: none; padding: 2px 0; cursor: pointer;
}
.me-name svg { color: var(--muted); }
.me-name:hover svg { color: var(--brand-700); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }

.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 12px; }

/* Thiết bị */
.peers { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.peers:empty { display: none; }

.peer {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 18px 12px 14px;
  background: var(--card);
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.16s, box-shadow 0.16s, transform 0.16s;
  -webkit-tap-highlight-color: transparent;
}
.peer:hover, .peer:focus-visible { border-color: var(--brand-400); box-shadow: 0 6px 18px rgba(var(--brand-rgb), 0.14); outline: none; }
.peer.is-drag { border-color: var(--brand-500); background: var(--brand-50); transform: scale(1.02); }
.peer-ico {
  width: 54px; height: 54px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--brand-50);
  color: var(--brand-700);
}
.peer-ico svg { width: 26px; height: 26px; }
.peer-name { font-size: 14px; font-weight: 700; line-height: 1.3; word-break: break-word; }
.peer-sub { font-size: 12px; color: var(--muted); }
.peer-actions { display: flex; gap: 6px; margin-top: 4px; }
.peer-actions .btn { padding: 5px 9px; font-size: 12px; }
.peer-busy { position: absolute; inset: auto 12px 8px; height: 3px; border-radius: 2px; background: var(--brand-100); overflow: hidden; }
.peer-busy i { display: block; height: 100%; background: var(--brand-500); width: 0; transition: width 0.2s; }

.route { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; }
.route .ico-inline { width: 12px; height: 12px; vertical-align: 0; }
.route-lan { background: var(--brand-50); color: var(--brand-800); }
.route-internet { background: #fef3c7; color: #92400e; }

.hint { margin-top: 10px; font-size: 12.5px; color: var(--muted); }

/* Chưa thấy ai */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  padding: 36px 20px 30px;
  background: var(--card);
  border: 1.5px dashed var(--card-border);
  border-radius: var(--radius);
}
.empty b { font-size: 15px; }
.empty p { font-size: 13px; color: var(--muted); max-width: 380px; line-height: 1.5; }
.radar { position: relative; width: 96px; height: 96px; display: grid; place-items: center; margin-bottom: 10px; color: var(--brand-700); }
.radar svg { width: 30px; height: 30px; position: relative; }
.radar span {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid var(--brand-400);
  opacity: 0;
  animation: ping 3s ease-out infinite;
}
.radar span:nth-child(2) { animation-delay: 1s; }
.radar span:nth-child(3) { animation-delay: 2s; }
@keyframes ping { 0% { transform: scale(0.35); opacity: 0.9; } 100% { transform: scale(1); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .radar span { animation: none; opacity: 0.3; } }

/* Lượt gửi / nhận */
.transfers-wrap { margin-top: 28px; }
.transfers { display: flex; flex-direction: column; gap: 10px; }
.tr {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 14px;
}
.tr-head { display: flex; align-items: center; gap: 10px; }
.tr-ico {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: #f1f5f9; color: var(--muted);
}
.tr-ico svg { width: 18px; height: 18px; }
.tr.is-in .tr-ico { background: var(--brand-50); color: var(--brand-700); }
.tr-main { flex: 1; min-width: 0; }
.tr-title { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 2px; }
.tr-status.is-done { color: var(--success); font-weight: 600; }
.tr-status.is-error { color: var(--error); font-weight: 600; }
.tr-bar { height: 5px; margin-top: 10px; border-radius: 3px; background: #eef2f6; overflow: hidden; }
.tr-bar i { display: block; height: 100%; width: 0; background: var(--brand-500); transition: width 0.25s; }
.tr-files { list-style: none; margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.tr-files li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 6px 8px; background: #f8fafc; border-radius: 8px; }
.tr-files .fname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-files .fsize { color: var(--muted); flex: none; }

/* Cột ghép mã */
.pair-col { display: flex; flex-direction: column; gap: 14px; }
.pair-card h3 { font-size: 15px; margin-bottom: 6px; }
.pair-card p { font-size: 12.5px; line-height: 1.5; }
.qr { width: 184px; height: 184px; margin: 12px auto 4px; padding: 8px; background: #fff; border: 1px solid var(--card-border); border-radius: 12px; }
.qr svg { width: 100%; height: 100%; display: block; }
.my-code { display: flex; justify-content: space-between; align-items: baseline; margin: 12px 0; font-size: 12.5px; color: var(--muted); }
.my-code b { font-size: 22px; letter-spacing: 0.08em; color: var(--fg); font-variant-numeric: tabular-nums; }
.join-form { display: flex; gap: 8px; margin-bottom: 8px; }
.join-form .input { letter-spacing: 0.04em; }
.joined { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.joined:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  background: var(--brand-50); color: var(--brand-800);
  border: 1px solid var(--brand-100);
}
.chip button { display: grid; place-items: center; width: 20px; height: 20px; border: none; background: none; color: inherit; cursor: pointer; border-radius: 50%; }
.chip button:hover { background: var(--brand-100); }
.chip svg { width: 12px; height: 12px; }

.info-card { display: flex; flex-direction: column; gap: 10px; }
.info-card p { display: flex; gap: 8px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.info-card p .ico-inline { margin-top: 1px; vertical-align: 0; }
.info-card a { color: var(--brand-800); font-weight: 600; }

/* Hộp thoại */
.dlg {
  margin: auto;
  width: min(440px, calc(100vw - 32px));
  border: none;
  border-radius: 16px;
  padding: 20px;
  color: var(--fg);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}
.dlg::backdrop { background: rgba(15, 23, 42, 0.45); }
.dlg h3 { font-size: 16px; margin-bottom: 12px; line-height: 1.35; word-break: break-word; }
.dlg-head { display: flex; gap: 12px; align-items: flex-start; }
.dlg-head h3 { margin-bottom: 2px; }
.dlg-head p { font-size: 13px; }
.dlg-ico { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--brand-50); color: var(--brand-700); }
.dlg-ico svg { width: 20px; height: 20px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dlg-actions .btn { min-width: 92px; padding: 9px 16px; }
.file-list { list-style: none; margin-top: 14px; max-height: 220px; overflow: auto; border: 1px solid var(--card-border); border-radius: 10px; }
.file-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; font-size: 13px; border-top: 1px solid var(--card-border); }
.file-list li:first-child { border-top: none; }
.file-list .fname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .fsize { color: var(--muted); flex: none; }
.text-recv {
  max-height: 50vh; overflow: auto;
  padding: 12px; font-size: 14px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
  background: #f8fafc; border: 1px solid var(--card-border); border-radius: 10px;
  user-select: text;
}
.text-recv a { color: var(--brand-800); }

.replaced { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(248, 250, 252, 0.92); }
.replaced .card { max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #0f172a; color: #fff;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.3);
  z-index: 30;
}

/* Điện thoại / màn hẹp */
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
  .page { padding: 16px 16px 40px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .peers { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .peer { padding: 16px 8px 12px; }
  .is-mobile .qr-block { display: none; }
}
