/**
 * @file index.css
 * @description CF-WebRTC 高信噪比现代排版与深浅色模式样式系统
 */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --success: #10b981;
  --success-subtle: #ecfdf5;
  --danger: #ef4444;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.07), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
  --bg-page: #090d16;
  --bg-card: #131b2e;
  --bg-subtle: #1c2640;
  --border-color: #273553;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-subtle: rgba(59, 130, 246, 0.12);
  --success: #10b981;
  --success-subtle: rgba(16, 185, 129, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Header */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 20px;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.device-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.device-badge:hover {
  background: var(--border-color);
}

.theme-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

/* Grid & Layout */
.pairing-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 720px) {
  .pairing-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* QR Code */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #ffffff;
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  border: 1px solid var(--border-color);
}

.qr-canvas {
  width: 180px;
  height: 180px;
}

.room-pin-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-subtle);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.room-pin-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--primary);
}

.btn-copy {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  transition: all 0.15s ease;
}

.btn-copy:hover {
  color: var(--primary);
  background: var(--primary-subtle);
}

.btn-copy.is-copied,
.btn-copy.is-copied:hover {
  color: var(--success);
  background: var(--success-subtle);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

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

/* OTP Input */
.pin-input-group {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 24px;
}

.pin-input {
  width: 44px;
  height: 52px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  color: var(--text-main);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.15s;
}

.pin-input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
}

/* Connected View */
.peer-status-banner {
  background: var(--success-subtle);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.peer-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.peer-avatar {
  width: 40px;
  height: 40px;
  border-radius: 9999px;
  background: var(--success);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.peer-name {
  font-size: 15px;
  font-weight: 600;
}

.peer-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 36px 20px;
  text-align: center;
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 24px;
}

.dropzone.active,
.dropzone:hover {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.dropzone-icon {
  width: 52px;
  height: 52px;
  margin-bottom: 12px;
  color: var(--primary);
}

.dropzone-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
}

.dropzone-desc {
  font-size: 13px;
  color: var(--text-muted);
}

.action-buttons {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  justify-content: center;
}

/* Transfer Queue */
.queue-section {
  margin-top: 16px;
}

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

.task-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.task-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.task-name {
  font-size: 14px;
  font-weight: 600;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--bg-subtle);
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #38bdf8);
  transition: width 0.15s ease-out;
}

.task-footer {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

/* Quick Text Sync */
.text-sync-box {
  margin-top: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.text-sync-input-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.text-sync-input {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-main);
  outline: none;
}

.text-sync-input:focus {
  border-color: var(--primary);
}

.text-messages-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.text-message-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.text-message-item:hover {
  border-color: var(--border-color);
}

.text-message-content {
  flex: 1;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.5;
}

.text-message-sender {
  font-weight: 600;
  margin-right: 4px;
  color: var(--text-main);
}

.text-message-sender.is-self {
  color: var(--primary);
}

.text-message-text {
  color: var(--text-main);
}

.text-message-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: 4px;
}

.btn-copy-msg {
  padding: 4px;
  color: var(--text-muted);
  opacity: 0.75;
  transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.text-message-item:hover .btn-copy-msg,
.btn-copy-msg:focus-visible,
.btn-copy-msg.is-copied {
  opacity: 1;
}

@media (hover: none) {
  .btn-copy-msg {
    opacity: 0.85;
  }
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-main);
  color: var(--bg-page);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
