:root {
  color-scheme: light;
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;

  /* 品牌三色 */
  --blue: #2B7FD8;
  --blue-deep: #205f9f;
  --yellow: #F4D758;
  --red: #E84A5F;

  /* 扩展中性色 */
  --green: #2d6a4f;
  --cream: #fefcf6;
  --cream-dark: #faf6eb;
  --ink: #1A1A2E;
  --ink-light: #4A4A5A;
  --ink-faint: #8a8a9a;
  --card: #fffdf7;
  --border: rgba(26, 26, 46, 0.08);
  --blue-soft: rgba(43, 127, 216, 0.10);
  --yellow-soft: rgba(244, 215, 88, 0.26);
  --red-soft: rgba(232, 74, 95, 0.12);
  --green-soft: rgba(45, 106, 79, 0.12);

  --nav-height: 64px;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--cream);
  background-image: radial-gradient(circle, rgba(43, 127, 216, 0.05) 1px, transparent 1.2px);
  background-size: 28px 28px;
}

::selection {
  background: var(--yellow);
  color: var(--ink);
}

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

button,
a,
input,
textarea,
select {
  -webkit-tap-highlight-color: transparent;
}

/* ===== 顶部品牌导航 ===== */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  padding: 0 clamp(20px, 4vw, 40px);
  background: var(--cream);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--yellow);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.35rem;
  box-shadow: inset 0 -3px 0 rgba(26, 26, 46, 0.08);
  flex: none;
}

.brand-text { min-width: 0; }

.nav-eyebrow {
  display: block;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-weight: 600;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--blue);
  white-space: nowrap;
}

.brand h1 {
  margin: 1px 0 0;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1.15;
  color: var(--ink);
}

.nav-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 7px 11px;
  border-radius: 999px;
  background: var(--cream-dark);
  color: var(--ink-light);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge.admin {
  color: #6f5a00;
  background: var(--yellow-soft);
  border-color: rgba(244, 215, 88, 0.55);
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 13px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.82rem;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease,
    color 0.15s ease;
}

.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:focus-visible { outline: 3px solid rgba(43, 127, 216, 0.28); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn.primary {
  background: var(--blue);
  color: #fffef9;
  box-shadow: 0 4px 14px rgba(43, 127, 216, 0.22);
}

.btn.primary:hover:not(:disabled) { background: var(--blue-deep); }
.btn.secondary { background: var(--cream-dark); color: var(--ink); }
.btn.secondary:hover:not(:disabled) { background: #f1e8d6; }
.btn.ghost { background: transparent; color: var(--ink-light); }
.btn.ghost:hover:not(:disabled) { background: var(--cream-dark); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.danger:hover:not(:disabled) { background: rgba(232, 74, 95, 0.18); }

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.hidden { display: none !important; }

/* ===== 管理员工具条 ===== */
.admin-panel {
  padding: 10px clamp(20px, 4vw, 40px);
  background: var(--cream-dark);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.admin-panel-title {
  color: var(--blue);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.admin-panel-title::before {
  content: "✦ ";
  color: var(--yellow);
}

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

/* ===== 全局通知 ===== */
.notice {
  position: fixed;
  top: calc(var(--nav-height) + 14px);
  right: clamp(16px, 4vw, 40px);
  z-index: 200;
  max-width: min(440px, calc(100vw - 32px));
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.8rem;
  line-height: 1.5;
  box-shadow: 0 12px 34px rgba(26, 26, 46, 0.16);
  background: var(--blue-soft);
  color: #1f5ea8;
  border: 1px solid rgba(43, 127, 216, 0.18);
}

.notice.error {
  background: var(--red-soft);
  color: #b53a4b;
  border-color: rgba(232, 74, 95, 0.20);
}

.notice.success {
  background: var(--green-soft);
  color: #265743;
  border-color: rgba(45, 106, 79, 0.18);
}

/* ===== 主布局：侧栏 + 聊天区 ===== */
.app-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: clamp(20px, 3vw, 32px);
  align-items: start;
  max-width: 1280px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 40px);
  min-height: calc(100vh - var(--nav-height));
}

.app-sidebar {
  position: sticky;
  top: calc(var(--nav-height) + clamp(20px, 4vw, 40px));
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: clamp(18px, 3vw, 24px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 14px 40px rgba(26, 26, 46, 0.06);
  max-height: calc(100vh - var(--nav-height) - clamp(20px, 4vw, 40px) * 2);
  overflow-y: auto;
}

.side-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.side-kicker,
.chat-kicker {
  display: block;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-weight: 600;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--blue);
}

.side-head h2,
.chat-header h2 {
  margin: 2px 0 0;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.3;
  color: var(--ink);
}

.p2p-tag {
  color: #265743;
  background: var(--green-soft);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.64rem;
  font-weight: 800;
  white-space: nowrap;
  flex: none;
}

.side-block {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.side-block--grow {
  flex: 1;
  min-height: 80px;
}

.side-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
}

.peer-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

select {
  width: 100%;
  border: 1px solid rgba(26, 26, 46, 0.14);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
  font-size: 0.82rem;
}

.peer-count {
  color: var(--ink-faint);
  font-size: 0.7rem;
  line-height: 1.4;
}

.side-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.side-controls .btn.primary { flex: 1 1 auto; }

.paste-zone {
  border: 2px dashed rgba(43, 127, 216, 0.40);
  border-radius: 12px;
  background: rgba(43, 127, 216, 0.03);
  padding: 12px 14px;
  cursor: pointer;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink-light);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.paste-icon {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.2rem;
  color: var(--blue);
  line-height: 1;
}

.paste-copy {
  font-size: 0.76rem;
  font-weight: 700;
}

.paste-zone:hover,
.paste-zone:focus,
.paste-zone.dragging,
.paste-zone.flash {
  border-color: var(--blue);
  background: rgba(43, 127, 216, 0.06);
}

.paste-zone.dragging { transform: scale(0.998); }

.selected-files {
  color: var(--ink-light);
  font-size: 0.72rem;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.file-queue {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
}

.file-queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--card);
}

.file-queue-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-queue-info strong {
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-queue-info span {
  color: var(--ink-faint);
  font-size: 0.64rem;
}

.file-remove {
  border: 0;
  background: var(--cream-dark);
  color: var(--ink-light);
  border-radius: 7px;
  padding: 5px 7px;
  font-size: 0.64rem;
  cursor: pointer;
  flex: none;
}

.file-remove:hover {
  background: #f1e8d6;
  color: var(--ink);
}

.file-remove:focus-visible {
  outline: 3px solid rgba(43, 127, 216, 0.28);
  outline-offset: 2px;
}

.transfer-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.transfer-item {
  border: 1px solid rgba(43, 127, 216, 0.18);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 10px;
}

.transfer-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.72rem;
}

.transfer-title {
  font-weight: 800;
  min-width: 0;
  overflow-wrap: anywhere;
}

.transfer-status {
  color: var(--ink-faint);
}

.transfer-progress {
  height: 4px;
  background: #eee7d8;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}

.transfer-progress i {
  display: block;
  height: 100%;
  width: 0;
  background: currentColor;
  color: var(--blue);
  transition: width 0.1s linear;
}

.transfer-actions {
  margin-top: 7px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.download-link {
  font-size: 0.72rem;
  font-weight: 800;
  color: #1f5ea8;
  text-decoration: none;
  padding: 5px 8px;
  background: var(--blue-soft);
  border-radius: 7px;
}

.download-link:hover { background: rgba(43, 127, 216, 0.18); }

.transfer-preview {
  max-width: 200px;
  max-height: 120px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.transfer-preview.video { width: 200px; }

.p2p-hint {
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--ink-faint);
  font-size: 0.68rem;
  line-height: 1.55;
}

/* ===== 聊天面板 ===== */
.chat-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: min(820px, calc(100vh - var(--nav-height) - clamp(20px, 4vw, 40px) * 2));
  min-height: 560px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 14px 40px rgba(26, 26, 46, 0.06);
  overflow: hidden;
}

.chat-header {
  padding: clamp(16px, 3vw, 22px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
}

.chat-rule {
  font-size: 0.72rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: clamp(18px, 3vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--cream-dark);
  scrollbar-width: thin;
  scrollbar-color: rgba(43, 127, 216, 0.35) transparent;
}

.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: rgba(43, 127, 216, 0.28);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}

.empty {
  margin: auto;
  color: var(--ink-faint);
  text-align: center;
  line-height: 1.9;
  font-size: 0.9rem;
  white-space: pre-line;
}

.empty::before {
  content: "✦";
  display: block;
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(2.4rem, 7vw, 3.8rem);
  line-height: 1;
  color: rgba(244, 215, 88, 0.72);
  margin-bottom: 8px;
}

.message {
  max-width: min(78%, 680px);
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-self: flex-start;
}

.message.admin { align-self: flex-end; }

.message-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  color: var(--ink-faint);
}

.message.admin .message-meta { justify-content: flex-end; }
.message-name { font-weight: 800; color: var(--ink); }

.role-tag {
  font-size: 0.64rem;
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--yellow-soft);
  color: #6f5a00;
  font-weight: 800;
}

.message-bubble {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 11px 13px;
  border-radius: 6px 16px 16px 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
  font-size: 0.9rem;
}

.message.admin .message-bubble {
  background: var(--ink);
  color: #f7f2e8;
  border-color: var(--ink);
  border-radius: 16px 6px 16px 16px;
}

.expire {
  font-size: 0.68rem;
  color: var(--ink-faint);
}

/* ===== 静默入口门 ===== */
.offline-panel {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(24px, 5vw, 44px);
  background: rgba(254, 252, 246, 0.98);
  text-align: center;
}

.gate-card {
  max-width: 560px;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: clamp(28px, 5vw, 46px);
  box-shadow: 0 20px 60px rgba(26, 26, 46, 0.12);
}

.gate-mark {
  display: inline-flex;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--yellow);
  color: var(--ink);
  align-items: center;
  justify-content: center;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.6rem;
  margin-bottom: 16px;
  box-shadow: inset 0 -3px 0 rgba(26, 26, 46, 0.08);
}

.gate-card h2 {
  margin: 0 0 10px;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--ink);
}

.gate-card p {
  margin: 0 0 20px;
  color: var(--ink-light);
  font-size: 0.86rem;
  line-height: 1.8;
}

/* ===== 输入区 ===== */
.composer {
  border-top: 1px solid var(--border);
  padding: clamp(12px, 2vw, 16px) clamp(16px, 3vw, 20px);
  background: var(--card);
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 9px;
}

.nickname-input { width: 190px; }

.char-count {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-family: "Fira Code", ui-monospace, monospace;
}

input,
textarea {
  width: 100%;
  border: 1px solid rgba(26, 26, 46, 0.14);
  border-radius: 11px;
  background: var(--card);
  padding: 10px 12px;
  color: var(--ink);
  outline: none;
  font-size: 0.88rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

textarea {
  resize: none;
  line-height: 1.6;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 10px;
}

.hint {
  color: var(--ink-faint);
  font-size: 0.68rem;
}

/* ===== 弹窗 ===== */
.dialog {
  border: 0;
  padding: 0;
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(26, 26, 46, 0.24);
  background: var(--card);
}

.dialog::backdrop {
  background: rgba(26, 26, 46, 0.42);
  backdrop-filter: blur(3px);
}

.dialog-card {
  width: min(390px, calc(100vw - 32px));
  padding: clamp(20px, 3vw, 24px);
}

.dialog-title {
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.1rem;
  font-weight: 900;
  margin-bottom: 6px;
  color: var(--ink);
}

.dialog-card p {
  color: var(--ink-light);
  font-size: 0.8rem;
  margin: 0 0 14px;
  line-height: 1.6;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* 移动端底部 Tab 切换：桌面端不显示，手机端作为聊天 / 文件视图切换。 */
.mobile-tab-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.mobile-tabs {
  display: none;
}

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .app-layout {
    display: flex;
    flex-direction: column;
  }

  .app-sidebar {
    position: static;
    max-height: none;
    order: 2;
  }

  .chat-panel {
    order: 1;
    height: calc(100vh - var(--nav-height) - 32px);
    height: calc(100dvh - var(--nav-height) - 32px);
    min-height: 0;
  }
}

@media (max-width: 600px) {
  :root { --nav-height: 60px; }

  .app-nav {
    padding: 0 14px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 1.2rem;
  }

  .brand h1 { font-size: 0.95rem; }
  .nav-eyebrow { display: none; }
  .nav-actions { gap: 7px; }

  .admin-panel {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 14px;
  }

  .app-layout {
    display: block;
    height: calc(100vh - var(--nav-height) - 56px - env(safe-area-inset-bottom, 0px));
    height: calc(100dvh - var(--nav-height) - 56px - env(safe-area-inset-bottom, 0px));
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }

  .mobile-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    display: flex;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--cream);
    border-top: 1px solid var(--border);
  }

  .mobile-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--ink-faint);
    cursor: pointer;
    user-select: none;
  }

  .mobile-tab::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: transparent;
  }

  #tab-chat:checked ~ .mobile-tabs .mobile-tab--chat,
  #tab-file:checked ~ .mobile-tabs .mobile-tab--file {
    color: var(--blue);
  }

  #tab-chat:checked ~ .mobile-tabs .mobile-tab--chat::before,
  #tab-file:checked ~ .mobile-tabs .mobile-tab--file::before {
    background: var(--yellow);
  }

  .app-sidebar {
    display: none;
    position: static;
    height: 100%;
    max-height: none;
    overflow-y: auto;
    padding: 16px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .chat-panel {
    display: none;
    position: relative;
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  #tab-chat:checked ~ .chat-panel { display: flex; }
  #tab-file:checked ~ .app-sidebar { display: flex; }

  .chat-rule { display: none; }
  .offline-panel { padding: 16px; overflow-y: auto; }
  .message { max-width: 88%; }
  .nickname-input { width: 145px; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
