/* =====================================================================
 * 闪传 - 样式表
 * 风格：清爽现代，蓝绿主色，仿宜省闪传
 * ===================================================================== */

:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #dbeafe;
  --accent: #10b981;
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e5e9f0;
  --text: #1f2937;
  --text-light: #6b7280;
  --danger: #ef4444;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --radius: 14px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===================== 顶部导航 ===================== */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}
.brand i { font-size: 22px; }

.tabs {
  display: flex;
  gap: 4px;
}
.tab {
  background: transparent;
  border: none;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-light);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all .15s;
}
.tab:hover { background: var(--primary-light); color: var(--primary); }
.tab.active {
  background: var(--primary);
  color: #fff;
}

/* ===================== 主区域 ===================== */
.main { flex: 1; padding: 24px; }

/* 全局：移动端 page 切换逻辑（默认隐藏，active 才显示） */
.page { display: none; animation: fadeIn .2s ease; }
.page.active { display: block; }

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

/* ===================== 桌面端 3 栏布局（≥1024px） ===================== */
@media (min-width: 1024px) {
  .desktop-layout {
    display: grid;
    grid-template-columns: 340px 1fr 360px;
    gap: 20px;
    max-width: 1500px;
    margin: 0 auto;
    min-height: calc(100vh - 60px - 48px);
    min-height: calc(100dvh - 60px - 48px);
  }
  .col { display: flex; flex-direction: column; gap: 16px; }
  .col-left { min-width: 0; }
  .col-center { min-width: 0; }
  .col-right { min-width: 0; }

  /* 桌面端全部展示，无视 active */
  .page { display: block !important; }

  /* 桌面端隐藏 Tab 导航 */
  .tabs { display: none; }

  /* 桌面端聊天撑满中栏 */
  .col-center .chat-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    height: calc(100vh - 60px - 48px - 16px);
    height: calc(100dvh - 60px - 48px - 16px);
  }

  .connect-layout, .transfer-layout, .me-layout { display: contents; }
}

/* ===================== 移动端（<768px） ===================== */
@media (max-width: 767px) {
  .desktop-layout { display: block; }
  .col { display: contents; }
  .col-left,
  .col-center,
  .col-right {
    display: block;
  }
  .connect-layout { display: grid; grid-template-columns: 1fr; gap: 20px; max-width: 900px; margin: 0 auto; }
  .me-layout { display: grid; grid-template-columns: 1fr; gap: 20px; max-width: 1100px; margin: 0 auto; }
  .transfer-layout { max-width: 800px; margin: 0 auto; }
  .col-center .chat-layout {
    display: flex;
    flex-direction: column;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-height: 300px;
  }
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.panel-title {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.panel-title i { color: var(--primary); }
.panel-sub {
  color: var(--text-light);
  font-size: 13px;
  margin-top: 4px;
  margin-bottom: 16px;
}

/* ===================== 连接页 ===================== */
.connect-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
  max-width: 900px;
  margin: 0 auto;
}

.peers-list {
  margin: 16px 0;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.peer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all .15s;
  background: #fff;
}
.peer-item:hover { border-color: var(--primary); transform: translateY(-1px); }
.peer-item.connected { border-color: var(--accent); background: #ecfdf5; }
.peer-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.peer-info { flex: 1; }
.peer-name { font-weight: 600; font-size: 14px; }
.peer-desc { font-size: 12px; color: var(--text-light); }

.connect-actions { display: flex; gap: 10px; }

.qr-panel { text-align: center; }
.qr-box {
  width: 220px; height: 220px;
  margin: 16px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #fafbfc;
  padding: 6px;
  overflow: hidden;
  box-sizing: border-box;
}
.qr-box canvas, .qr-box img {
  display: block;
  width: 200px !important;
  height: 200px !important;
  border-radius: 8px;
}
.qr-placeholder { color: var(--text-light); text-align: center; }
.qr-placeholder i { font-size: 40px; margin-bottom: 8px; display: block; }
.qr-placeholder p { font-size: 12px; }

.room-code-display {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--primary-light);
  padding: 8px 16px;
  border-radius: 10px;
  margin: 8px 0;
}
.room-code-display .label { font-size: 12px; color: var(--text-light); }
.room-code-display .code {
  font-size: 22px; font-weight: 800; letter-spacing: 4px;
  color: var(--primary-dark); font-family: monospace;
}
.qr-tip { font-size: 12px; color: var(--text-light); margin-top: 8px; }

/* ===================== 按钮 ===================== */
.btn {
  flex: 1;
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all .15s;
  font-weight: 500;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-ghost { background: #f3f4f6; color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: #e5e7eb; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.file-pick { cursor: pointer; display: inline-flex; }

/* ===================== 空状态 ===================== */
.empty-hint {
  text-align: center;
  color: var(--text-light);
  padding: 40px 20px;
}
.empty-hint i { font-size: 40px; margin-bottom: 10px; display: block; opacity: .5; }
.empty-hint p { font-size: 13px; }

/* ===================== 聊天页 ===================== */
.chat-layout {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px - 48px);
  height: calc(100dvh - 60px - 48px);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.empty-hint.in-chat { margin: auto; }
.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}
.msg.self {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.other {
  align-self: flex-start;
  background: #f3f4f6;
  border-bottom-left-radius: 4px;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-light);
  font-size: 12px;
  max-width: 90%;
  text-align: center;
}
.chat-input-bar {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--border);
}
#chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
}
#chat-input:focus { border-color: var(--primary); }
.chat-input-bar .btn { flex: 0 0 auto; width: 44px; padding: 10px; }

/* ===================== 传输页 ===================== */
.transfer-layout { max-width: 800px; margin: 0 auto; }
.transfer-actions { display: flex; gap: 10px; margin-bottom: 16px; }
.transfer-list {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  min-height: 300px;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border-radius: 10px;
  transition: background .15s;
}
.file-item:hover { background: #f9fafb; }
.file-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.file-meta { flex: 1; min-width: 0; }
.file-name {
  font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-status { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.file-progress {
  height: 4px; background: #e5e7eb; border-radius: 2px;
  margin-top: 6px; overflow: hidden;
}
.file-progress-bar {
  height: 100%; background: var(--primary);
  width: 0; transition: width .15s;
}
.file-item.done .file-progress-bar { background: var(--accent); }
.file-direction { font-size: 12px; color: var(--text-light); flex-shrink: 0; }

/* ===================== 我的页 ===================== */
.me-layout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  max-width: 1100px;
  margin: 0 auto;
}
.video-wrap {
  background: #000;
  border-radius: 12px;
  aspect-ratio: 16/9;
  margin: 12px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.video-wrap video { width: 100%; height: 100%; object-fit: contain; }
.video-placeholder { color: #6b7280; text-align: center; }
.video-placeholder i { font-size: 36px; display: block; margin-bottom: 6px; }
.video-placeholder p { font-size: 12px; }
.media-actions { display: flex; gap: 10px; }

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.info-row span { color: var(--text-light); }
.info-row b { font-weight: 500; }
.state-on { color: var(--accent); }
.state-off { color: var(--text-light); }
.info-panel .btn { margin-top: 16px; width: 100%; }

/* ===================== Toast ===================== */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(31, 41, 55, .95);
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: all .25s;
  box-shadow: var(--shadow-lg);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===================== 弹窗 ===================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .4);
  display: none;
  align-items: center; justify-content: center;
  z-index: 50;
  animation: fadeIn .15s;
}
.modal:not([hidden]) {
  display: flex;
}
.modal-box {
  background: #fff;
  padding: 24px;
  border-radius: 16px;
  width: 320px;
  box-shadow: var(--shadow-lg);
}
.modal-wide { width: 420px; max-width: 90vw; }
.modal-box h3 { margin-bottom: 16px; text-align: center; }
.modal-box h3 i { margin-right: 6px; }
.modal-box input {
  width: 100%;
  text-align: center;
  font-size: 24px;
  letter-spacing: 6px;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
  outline: none;
  font-family: monospace;
}
.modal-box input:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; }

/* 文件预览列表项 */
.file-preview-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.file-preview-item i { color: var(--primary); width: 20px; text-align: center; }
.file-preview-item .fp-name { flex:1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-preview-item .fp-size { color: var(--text-light); flex-shrink: 0; }

/* 设备名编辑弹窗输入框 */
#name-input {
  text-align: left;
  font-size: 16px;
  letter-spacing: 0;
  font-family: inherit;
}

/* ===================== Drop Zone（拖拽上传） ===================== */
.drop-zone {
  position: fixed; inset: 0;
  background: rgba(59, 130, 246, .12);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
  pointer-events: none;
}
.drop-zone.active { display: flex; }
.drop-zone-inner {
  background: var(--card);
  border: 3px dashed var(--primary);
  border-radius: 24px;
  padding: 60px 80px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.drop-zone-inner i { font-size: 48px; color: var(--primary); display: block; margin-bottom: 12px; }
.drop-zone-inner p { font-size: 18px; color: var(--text); font-weight: 500; }

/* ===================== 传输项取消按钮 ===================== */
.file-item .btn-cancel {
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  flex-shrink: 0;
}
.file-item .btn-cancel:hover { background: #fee2e2; color: var(--danger); }

/* ===================== 我的页面设备名编辑 ===================== */
.device-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.device-name-row span { color: var(--text-light); }
.device-name-row b { font-weight: 500; }
.device-name-row .btn-edit-name {
  background: transparent; border: none; color: var(--primary);
  cursor: pointer; font-size: 13px; padding: 4px 8px; border-radius: 6px;
}
.device-name-row .btn-edit-name:hover { background: var(--primary-light); }

/* ===================== 深色模式 ===================== */
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --primary-light: #1e3a5f;
    --accent: #34d399;
    --bg: #0f172a;
    --card: #1e293b;
    --border: #334155;
    --text: #e2e8f0;
    --text-light: #94a3b8;
    --shadow: 0 2px 12px rgba(0,0,0,.3);
    --shadow-lg: 0 8px 30px rgba(0,0,0,.5);
  }
  .topbar, .panel, .chat-layout, .transfer-list { background: var(--card); }
  .peer-item { background: #1e293b; border-color: #334155; }
  .peer-item.connected { border-color: var(--accent); background: #064e3b; }
  .peer-avatar { background: #1e3a5f; }
  .btn-ghost { background: #334155; color: var(--text); }
  .btn-ghost:hover { background: #475569; }
  #chat-input, .modal-box input { background: #1e293b; border-color: #334155; color: #e2e8f0; }
  #chat-input:focus { border-color: var(--primary); }
  .msg.other { background: #334155; }
  .file-item:hover, .info-row { border-color: #334155; }
  .modal-box { background: var(--card); }
  .drop-zone { background: rgba(96, 165, 250, .15); }
  .drop-zone-inner { background: var(--card); }
  .file-preview-item { border-color: #334155; }
  .qr-box { background: #0f172a; }
  .room-code-display { background: #1e3a5f; }
  .file-progress { background: #334155; }
  .file-item .btn-cancel:hover { background: #450a0a; color: #fca5a5; }
}

/* ===================== 扫码器弹窗 ===================== */
.scanner-wrap {
  background: #000;
  border-radius: 12px;
  aspect-ratio: 1;
  margin: 12px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}
.scanner-wrap video { width: 100%; height: 100%; object-fit: cover; }
.scanner-placeholder { color: #6b7280; text-align: center; }
.scanner-placeholder i { font-size: 36px; display: block; margin-bottom: 6px; }
.scanner-placeholder p { font-size: 12px; }
.scanner-result {
  text-align: center;
  font-size: 14px;
  margin: 8px 0;
  color: var(--accent);
  word-break: break-all;
}

/* ===================== SEO 内容区（底部） ===================== */
.seo-content {
  max-width: 900px;
  margin: 40px auto 60px;
  padding: 0 20px;
  border-top: 1px solid var(--border);
  padding-top: 32px;
}
.seo-text {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}
@media (max-width: 640px) {
  .seo-text { grid-template-columns: 1fr; gap: 24px; }
}
.seo-text h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}
.seo-text p {
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-light);
  margin-bottom: 8px;
}
.seo-text .seo-en { border-left: 1px solid var(--border); padding-left: 24px; }
@media (max-width: 640px) {
  .seo-text .seo-en { border-left: none; padding-left: 0; border-top: 1px solid var(--border); padding-top: 16px; }
}

/* ===================== 响应式 ===================== */
@media (max-width: 768px) {
  .main { padding: 14px; }
  .connect-layout { grid-template-columns: 1fr; }
  .topbar { padding: 0 12px; }
  .tab span { display: none; }
  .tab { padding: 8px 12px; }
  .brand span { display: none; }
  .qr-box { width: 180px; height: 180px; }
  .qr-box canvas, .qr-box img { width: 164px !important; height: 164px !important; }
}
