:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-subtle: #f8f7f4;
  --surface-hover: #f0eee8;
  --border: #e5e2da;
  --border-strong: #d4d0c5;
  --text: #181a1c;
  --text-secondary: #5a6068;
  --text-muted: #848b94;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-soft: #e6f4f1;
  --accent-text: #ffffff;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --success: #15803d;
  --success-soft: #ecfdf3;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --shadow-sm: 0 1px 2px rgba(24, 26, 28, 0.04);
  --shadow-md: 0 8px 24px rgba(24, 26, 28, 0.06);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315;
    --surface: #191c1f;
    --surface-subtle: #202428;
    --surface-hover: #272c31;
    --border: #2a2f35;
    --border-strong: #394048;
    --text: #f1f3f5;
    --text-secondary: #adb5bd;
    --text-muted: #7c858f;
    --accent: #14b8a6;
    --accent-hover: #0d9488;
    --accent-soft: rgba(20, 184, 166, 0.14);
    --accent-text: #06211f;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, 0.12);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, 0.12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.45);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

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

.conn-pill.online .conn-dot {
  background: var(--success);
}

.conn-pill.online {
  color: var(--success);
  background: var(--success-soft);
  border-color: transparent;
}

.conn-pill.waiting .conn-dot {
  background: var(--warn);
}

.conn-pill.offline .conn-dot {
  background: var(--danger);
}

/* Main layout */
.shell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.panel-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.panel-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

/* QR Column */
.qr-panel {
  position: sticky;
  top: 76px;
}

.qr-stage {
  margin: 16px auto 14px;
  width: 220px;
  height: 220px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.qr-stage svg {
  width: 100%;
  height: 100%;
  display: block;
}

.room-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 13px;
}

.room-code {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.security-note {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.security-note.encrypted {
  background: var(--accent-soft);
  color: var(--accent);
}

.peer-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.peer-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.peer-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.peer-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
}

.peer-chip.is-self {
  opacity: 0.72;
}

.qr-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

/* Workspace Column */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Quick capture / upload */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.big-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.big-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.big-btn:active {
  transform: scale(0.985);
}

.big-btn.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.big-btn.primary:hover {
  background: var(--accent-hover);
}

.dropzone {
  margin-top: 12px;
  padding: 22px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone.drag-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-main {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.dropzone-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Text composer */
.text-composer {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.text-input {
  flex: 1;
  min-width: 0;
  resize: none;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 14px;
  line-height: 1.45;
  outline: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.text-input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* Feed */
.feed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.feed-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.switch-label input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.feed-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  padding: 36px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.empty-state strong {
  display: block;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 4px;
}

.feed-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feed-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.item-meta {
  min-width: 0;
  flex: 1;
}

.item-name {
  font-size: 14px;
  font-weight: 600;
  word-break: break-all;
}

.item-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.dir-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.dir-tag.in {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.12s linear;
  width: 0%;
}

.preview-img-wrap {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  max-height: 280px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
  align-self: flex-start;
}

.preview-img-wrap img {
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
  display: block;
}

.text-bubble {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Fullscreen Drop Overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 118, 110, 0.14);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.drop-overlay.show {
  display: flex;
}

.drop-overlay-box {
  background: var(--surface);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  padding: 36px 48px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(10, 12, 14, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}

.lightbox.show {
  display: flex;
}

.lightbox img {
  max-width: 94vw;
  max-height: 90vh;
  border-radius: 10px;
  object-fit: contain;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 80;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Mobile QR Toggle Button */
.mobile-qr-btn {
  display: none;
}

/* Mobile Layout */
@media (max-width: 820px) {
  .topbar-inner {
    padding: 10px 14px;
  }

  .brand-sub {
    display: none;
  }

  .shell {
    grid-template-columns: 1fr;
    padding: 14px 14px 40px;
    gap: 14px;
  }

  .qr-panel {
    position: static;
  }

  /* When phone scans a room URL, prioritize camera & upload controls above the QR card */
  body.is-joined-mobile .qr-panel {
    display: none;
  }

  body.is-joined-mobile.show-mobile-qr .qr-panel {
    display: block;
  }

  body.is-joined-mobile .mobile-qr-btn {
    display: inline-flex;
  }

  .action-grid {
    grid-template-columns: 1fr;
  }

  .big-btn {
    padding: 18px 16px;
    font-size: 16px;
  }

  .dropzone {
    display: none;
  }
}

/* Clipboard Copy States & Pending Auto-Copy Banner */
.btn.copied {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
}

.pending-copy-banner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--accent);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.pending-copy-banner:hover {
  background: rgba(15, 118, 110, 0.14);
}

.pending-copy-banner[hidden] {
  display: none;
}

/* Manual Join Room Box & Copy Room Code */
.room-code-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.room-code {
  cursor: pointer;
}

.room-copy-btn {
  padding: 3px 8px;
  font-size: 11px;
}

.join-room-box {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.join-room-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.join-room-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.join-room-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.join-room-input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

/* Transport Route Status Pill & Per-Card Channel Tags */
.route-note {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

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

.route-note.p2p {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.35);
  color: #047857;
}

.route-note.p2p .route-dot {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.route-note.probing {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.35);
  color: #b45309;
}

.route-note.probing .route-dot {
  background: #f59e0b;
}

.route-note.relay {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.28);
  color: #1d4ed8;
}

.route-note.relay .route-dot {
  background: #3b82f6;
}

.route-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
}

.route-tag.p2p {
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
}

.route-tag.relay {
  background: rgba(59, 130, 246, 0.1);
  color: #1d4ed8;
}

.route-tag.failover {
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
}

.route-note.clickable {
  cursor: pointer;
}

.route-note.clickable:hover {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(59, 130, 246, 0.45);
}

/* Windows Background Clipboard Bridge Status Bar */
.bridge-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 12px;
  color: var(--text-secondary);
}

.bridge-bar[hidden] {
  display: none;
}

.bridge-bar.connected {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.3);
  color: #047857;
}

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

.bridge-bar.connected .bridge-dot {
  background: #10b981;
}

.bridge-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.bridge-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bridge-retry-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.bridge-retry-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
