/* ─────────────────────────────────────────────────────────────
   FFShare PWA — mobile-first, safe-area aware.
   Lock the viewport, scroll only the main content area, kill
   double-tap and pinch-to-zoom for an app-like feel.
   ───────────────────────────────────────────────────────────── */

:root {
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1b1f26;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e6e9ef;
  --text-muted: rgba(230, 233, 239, 0.6);
  --primary: #4f8cff;
  --primary-hover: #6aa0ff;
  --danger: #e6504f;
  --ok: #38c172;

  --radius: 12px;
  --radius-sm: 8px;
  --tap: 44px;            /* iOS HIG minimum tap target */
}

* {
  box-sizing: border-box;
  /* Disable callouts + magnifier glass on long-press, kill the
     blue tap flash. Keeps the app feeling like a native shell. */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* Re-enable text selection where it actually matters. */
input, textarea, .code-text, .sas-emojis, .peer-name {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  /* Lock the page — only .main scrolls. Disables pull-to-refresh,
     rubber-banding, and overscroll glow. */
  overflow: hidden;
  overscroll-behavior: none;
  /* manipulation = no double-tap zoom, no pinch zoom on this layer. */
  touch-action: manipulation;
}

html, body { height: 100%; }
body { height: 100svh; }   /* Account for iOS chrome shrink/grow. */

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  /* Safe-area: pad against notch + home indicator + landscape edges. */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ─── Top bar (fixed) ─────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.2px;
  flex-shrink: 0;
}

.device-name {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-dot.ok { background: var(--ok); }

/* ─── Tabs (fixed) ────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  min-height: var(--tap);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}
.tab.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

/* Hide LAN tab on phones — it's an info-only stub there. Desktop
   browsers keep it visible so users see the "install desktop app"
   panel and know LAN exists. */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  .tab[data-tab="lan"] { display: none; }
}

/* ─── Main: the only scrolling region ──────────────────────── */
.main {
  flex: 1;
  min-height: 0;          /* enable flex child to shrink */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tab-panel.hidden { display: none; }

.state {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.state.hidden { display: none; }

.hero {
  text-align: center;
  padding: 28px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.p2p-icon, .hero-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: rgba(79, 140, 255, 0.12);
  color: var(--primary);
}

.p2p-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 6px;
}
.p2p-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}
.p2p-label {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
  margin: 8px 0 0;
}

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

/* ─── Buttons ──────────────────────────────────────────────── */
.btn-primary,
.btn-ghost,
.btn-danger {
  min-height: var(--tap);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.05s ease, background-color 0.1s ease;
}
.btn-primary:active,
.btn-ghost:active,
.btn-danger:active { transform: scale(0.98); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger {
  background: transparent;
  border-color: rgba(230, 80, 79, 0.5);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(230, 80, 79, 0.1); }

.btn-block { width: 100%; }

.btn-small {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

.disconnect { margin-top: 8px; opacity: 0.85; }

/* ─── Code box ──────────────────────────────────────────────── */
.code-box {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  margin: 12px 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.code-text {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 6px;
}

.code-input-row {
  display: flex;
  justify-content: center;
  margin: 16px 0 8px;
}

.code-input {
  width: 100%;
  max-width: 280px;
  padding: 16px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  outline: none;
}
.code-input:focus { border-color: var(--primary); }

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  text-align: center;
}

/* ─── Scanning rings (idle/connecting) ─────────────────────── */
.scanning-icon {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto 12px;
}
.scanning-ring {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(79, 140, 255, 0.4);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1.2s linear infinite;
}
.scanning-dot {
  position: absolute;
  inset: 33%;
  border-radius: 50%;
  background: var(--primary);
}
@keyframes spin { to { transform: rotate(360deg); } }

.waiting-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.scanning-ring-small {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ─── Peer card ─────────────────────────────────────────────── */
.peer-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.peer-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.peer-meta { flex: 1; min-width: 0; text-align: left; }
.peer-name {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.dot.ok { background: var(--ok); }

/* ─── SAS block ─────────────────────────────────────────────── */
.sas-block {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sas-emojis {
  font-size: 36px;
  letter-spacing: 8px;
  word-break: keep-all;
  white-space: nowrap;
  overflow-x: auto;
}

/* ─── Transfer items ────────────────────────────────────────── */
.transfer-list,
.receive-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.transfer-item {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}

.transfer-name {
  font-weight: 500;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-bar {
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.2s ease;
}
.progress-fill.error { background: var(--danger); }
.progress-fill.complete { background: var(--ok); width: 100% !important; }

.transfer-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.download-link {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  background: var(--ok);
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
}

/* ─── Error banner ──────────────────────────────────────────── */
.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(230, 80, 79, 0.12);
  border: 1px solid rgba(230, 80, 79, 0.4);
  border-radius: var(--radius-sm);
  color: #ff8888;
  font-size: 13px;
}

.hidden { display: none !important; }

@media (min-width: 768px) {
  .hero { padding: 36px 24px; }
  .p2p-icon, .hero-icon { width: 96px; height: 96px; }
  .p2p-title { font-size: 24px; }
}
