:root {
  --bg: #f1f5f9; --card: #fff; --text: #0f172a; --muted: #64748b; --border: #e2e8f0;
  --primary: #2563eb; --primary-h: #1d4ed8; --ok: #16a34a; --warn: #d97706; --err: #dc2626;
  --me: #2563eb; --them: #e2e8f0; --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --card: #111827; --text: #e5e7eb; --muted: #94a3b8; --border: #1f2937; --them: #1f2937; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45; min-height: 100%;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.fileswap-root {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.fileswap-root > .topbar,
.fileswap-root > .footer { flex: 0 0 auto; }
.fileswap-root > .container {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}
[hidden] { display: none !important; }
h2 { font-size: 1.1rem; margin: 0 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.2rem; }
.topbar a.brand { color: inherit; text-decoration: none; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600; border: 1px solid var(--border); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status-waiting .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.status-online .dot { background: var(--ok); }
.status-offline .dot { background: var(--err); }
.route { font-size: .8rem; color: var(--muted); }
@keyframes pulse { 50% { opacity: .3; } }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 18px; flex: 1; }
.lead { font-size: 1.05rem; margin: 6px 0 18px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card, .panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.note { color: var(--muted); font-size: .9rem; margin-top: 14px; }

.btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); padding: 9px 16px; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--err); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-small { padding: 5px 10px; font-size: .85rem; }
.btn-big { padding: 12px 22px; font-size: 1.05rem; margin-top: 8px; }

.join-form { display: flex; gap: 8px; margin-top: 8px; }
.code-input {
  flex: 1; min-width: 0; font: inherit; font-size: 1.3rem; letter-spacing: .15em; text-transform: uppercase;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
}

.alert { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }
.alert.info { background: #eff6ff; color: #1e3a8a; border-color: #bfdbfe; }
.alert-close { background: none; border: 0; font-size: 1.3rem; line-height: 1; cursor: pointer; color: inherit; }

.waiting-card { max-width: 760px; margin: 0 auto; }
.waiting-grid { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.qr-box { background: #fff; padding: 8px; border-radius: 12px; border: 1px solid var(--border); line-height: 0; }
.qr-box img { width: 220px; height: 220px; image-rendering: pixelated; }
.code-box { flex: 1; min-width: 240px; }
.code-label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; }
.code-display { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 2.6rem; font-weight: 700; letter-spacing: .12em; margin: 2px 0 12px; }
.link-row { display: flex; gap: 8px; }
.link-input { flex: 1; min-width: 0; font: inherit; font-size: .85rem; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.spinner-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: var(--muted); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.sas-bar { display: flex; gap: 18px; align-items: center; background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: var(--radius); padding: 10px 16px; margin-bottom: 14px; flex-wrap: wrap; }
.sas-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.sas-code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 1.7rem; font-weight: 700; letter-spacing: .1em; }
.sas-help { margin: 0; flex: 1; min-width: 220px; font-size: .9rem; color: var(--muted); }
.sas-bar.disconnected { border-left-color: var(--err); opacity: .75; }

.session-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .session-grid { grid-template-columns: 1fr; } }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

.dropzone { border: 2px dashed var(--border); border-radius: 12px; padding: 24px 14px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone:focus, .dropzone.over { border-color: var(--primary); background: rgba(37,99,235,.06); outline: none; }
.dropzone.disabled { opacity: .5; pointer-events: none; }
.dz-icon { font-size: 1.6rem; color: var(--primary); }
.linklike { color: var(--primary); text-decoration: underline; }
.save-note { margin: 8px 2px 0; }

.transfers { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 10px; }
.tr { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.tr-top { display: flex; gap: 10px; align-items: center; }
.tr-dir { font-size: 1.1rem; width: 1.4em; text-align: center; }
.tr-dir.in { color: var(--ok); } .tr-dir.out { color: var(--primary); }
.tr-info { flex: 1; min-width: 0; }
.tr-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-meta { font-size: .82rem; color: var(--muted); }
.tr-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tr-bar { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.tr-fill { height: 100%; width: 0; background: var(--primary); transition: width .3s; }
.tr.done .tr-fill { background: var(--ok); }
.tr.failed .tr-fill { background: var(--err); }
.tr-warn { font-size: .82rem; color: var(--warn); margin-top: 6px; }
.tr-status-ok { color: var(--ok); font-weight: 700; }
.tr-status-err { color: var(--err); font-weight: 600; }

.chat-panel { display: flex; flex-direction: column; height: min(70vh, 640px); min-height: 360px; }
.messages { list-style: none; padding: 4px; margin: 0; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; display: flex; flex-direction: column; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.them { align-self: flex-start; align-items: flex-start; }
.msg.sys { align-self: center; max-width: 95%; color: var(--muted); font-size: .82rem; text-align: center; }
.bubble { padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--me); color: #fff; border-bottom-right-radius: 4px; }
.msg.them .bubble { background: var(--them); border-bottom-left-radius: 4px; }
.msg-meta { display: flex; gap: 8px; align-items: center; font-size: .75rem; color: var(--muted); margin-top: 2px; }
.copy-btn { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; font-size: .75rem; padding: 0; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; }
.chat-form textarea { flex: 1; resize: none; font: inherit; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); max-height: 160px; }

.drop-overlay { position: fixed; inset: 0; background: rgba(37,99,235,.15); border: 4px dashed var(--primary); z-index: 50; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; font-weight: 700; color: var(--primary); pointer-events: none; }
.footer { text-align: center; padding: 14px; }

@media (max-width: 520px) {
  .container { padding: 12px; }
  .code-display { font-size: 2rem; }
  .route { display: none; }
  .msg { max-width: 92%; }
}

.footer-links { margin-top: 4px; }
.footer a,
.footer-textbtn {
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.footer a:hover,
.footer-textbtn:hover { color: var(--text); }

.site-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.site-card {
  width: 100%;
  max-width: 28rem;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
}
.site-card h2 { margin-bottom: .35rem; }
.site-card .lead-muted { color: var(--muted); font-size: .85rem; margin: 0 0 12px; }
.contact-text {
  width: 100%;
  resize: vertical;
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.share-card {
  padding: 24px;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}
.share-title { font-size: 1.6rem; }
.share-page {
  color: var(--muted);
  font-size: .85rem;
  margin: 0 0 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-qr {
  display: flex;
  justify-content: center;
  margin: 4px 0 14px;
}
.share-qr img {
  width: 176px;
  height: 176px;
  background: #fff;
  image-rendering: pixelated;
}
.share-qr-miss { color: var(--muted); font-size: .85rem; text-align: center; margin: 8px 0 14px; }
.share-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 12px;
}
.share-grid a,
.share-grid button {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  font: inherit;
  font-size: .85rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  text-decoration: none;
}
.share-grid a:hover,
.share-grid button:hover { color: var(--text); }
.share-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: var(--card);
  padding-top: 12px;
}
.share-status {
  margin-right: auto;
  color: var(--muted);
  font-size: .85rem;
  min-height: 1.2em;
}
