:root {
  color-scheme: light;
  font-family:
    "SF Pro Display", "PingFang SC", "Noto Sans SC", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background: #f3f5f7;
  color: #16202b;
  --panel: #ffffff;
  --panel-soft: #f6f8fb;
  --panel-muted: #eef2f6;
  --line: #d7e0e8;
  --line-strong: #bcc8d5;
  --text-muted: #637487;
  --text-soft: #7e8ea0;
  --primary: #0f6a82;
  --primary-dark: #0b5266;
  --bubble-own: linear-gradient(180deg, #18708f 0%, #0f5d76 100%);
  --bubble-peer: #ffffff;
  --accent: #2f8f69;
  --warm: #b87818;
  --shadow: 0 18px 44px rgb(20 32 44 / 9%);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgb(15 106 130 / 8%), transparent 28%),
    linear-gradient(180deg, #edf2f5 0, #f8f9fb 260px, #f4f6f8 100%);
}

button,
input,
textarea {
  font: inherit;
}

button,
.file-picker span {
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 750;
  padding: 10px 14px;
}

button:hover,
.file-picker span:hover {
  background: var(--primary-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  width: min(1220px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px 0 18px;
}

.topbar,
.workspace {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgb(255 255 255 / 92%);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
}

.message-meta,
.transfer-meta,
.peer-meta,
.empty-state {
  color: var(--text-muted);
  font-size: 13px;
}

.topbar-name-input,
.composer textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fbfcfd;
  color: #17202a;
  outline: none;
}

.topbar-name-input:focus,
.composer textarea:focus {
  border-color: #5b9ab0;
  box-shadow: 0 0 0 3px rgb(31 95 117 / 12%);
}

.topbar-name-input {
  max-width: 240px;
  padding: 10px 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 276px;
  gap: 0;
  height: calc(100vh - 120px);
  min-height: 580px;
  margin-top: 12px;
  overflow: hidden;
}

.chat-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  background: var(--panel);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  overflow: auto;
  padding: 18px 18px 24px;
  overscroll-behavior: contain;
  scroll-padding-bottom: 24px;
  background: linear-gradient(180deg, #f7fafc 0%, #f4f7f9 100%);
}

.message {
  max-width: min(72%, 760px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bubble-peer);
  padding: 10px 14px 11px;
  box-shadow: 0 10px 22px rgb(20 32 44 / 5%);
}

.message.peer {
  align-self: flex-start;
}

.message.own {
  align-self: flex-end;
  border-color: transparent;
  background: var(--bubble-own);
  color: #f7fbff;
}

.message.system {
  align-self: center;
  max-width: 100%;
  border-color: transparent;
  border-radius: 999px;
  background: rgb(22 32 43 / 6%);
  color: #556476;
  font-size: 12px;
  padding: 5px 10px;
  box-shadow: none;
}

.message.group-mid,
.message.group-end {
  margin-top: 2px;
}

.message.peer.group-mid,
.message.peer.group-end {
  border-top-left-radius: 8px;
}

.message.own.group-mid,
.message.own.group-end {
  border-top-right-radius: 8px;
}

.message.peer.group-start,
.message.own.group-start {
  margin-top: 12px;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
}

.message.own .message-meta {
  color: rgb(240 248 255 / 78%);
  justify-content: flex-end;
}

.message-body {
  line-height: 1.58;
  overflow-wrap: anywhere;
}

.message-body h1,
.message-body h2,
.message-body h3 {
  margin: 12px 0 8px;
  font-size: 17px;
}

.message-body p,
.message-body ul,
.message-body blockquote,
.message-body .code-block {
  margin: 8px 0 0;
}

.message-body ul {
  padding-left: 22px;
}

.message-body blockquote {
  border-left: 3px solid #8da0ae;
  color: #445360;
  padding-left: 10px;
}

.message-body code {
  border-radius: 5px;
  background: #e9eef2;
  color: #16364a;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
  padding: 2px 5px;
}

.message.own .message-body code {
  background: rgb(255 255 255 / 14%);
  color: #f1f7fb;
}

.code-block {
  overflow: hidden;
  border: 1px solid #22384b;
  border-radius: 12px;
  background: #102030;
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgb(255 255 255 / 10%);
  background: #152b3e;
  color: #b9c8d6;
  font-size: 12px;
  padding: 7px 8px 7px 12px;
}

.code-toolbar button {
  min-height: 28px;
  border: 1px solid rgb(255 255 255 / 16%);
  background: #203b52;
  color: #f1f6fb;
  font-size: 12px;
  padding: 5px 9px;
}

.code-toolbar button:hover {
  background: #2a4a64;
}

.message-body pre {
  overflow-x: auto;
  margin: 0;
  color: #eef6ff;
  padding: 12px;
}

.message-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.message-body a {
  color: #0c638e;
  font-weight: 750;
}

.message.own .message-body a {
  color: #d6f2ff;
}

.file-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}

.file-preview-button {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.file-preview-button:hover {
  background: transparent;
}

.file-preview {
  width: 100%;
  max-height: 300px;
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 14px;
  background: #ecf0f3;
  object-fit: contain;
}

.file-card-main {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.file-card-action {
  display: flex;
  justify-content: flex-start;
}

.file-card button {
  background: var(--accent);
  white-space: nowrap;
}

.file-card button:hover {
  background: #247655;
}

.composer {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  padding: 12px 16px 14px;
}

.composer textarea {
  min-height: 92px;
  max-height: 156px;
  resize: none;
  overflow-y: auto;
  padding: 12px;
  line-height: 1.5;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.file-picker input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker span {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #17202a;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 16px;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, #f8fafb 0%, #f3f6f8 100%);
  padding: 14px;
  overflow: auto;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title h2 {
  font-size: 15px;
}

.section-title span {
  min-width: 30px;
  border-radius: 999px;
  background: #f5ead8;
  color: var(--warm);
  font-weight: 850;
  padding: 4px 9px;
  text-align: center;
}

.peer-list,
.transfer-list {
  display: grid;
  gap: 8px;
}

.peer-group {
  display: grid;
  gap: 8px;
}

.peer-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.peer-group-header h3 {
  margin: 0;
  color: #334356;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.peer-group-list {
  display: grid;
  gap: 8px;
}

.peer-empty-hint {
  color: var(--text-soft);
  font-size: 12px;
  padding: 4px 2px 0;
}

.peer-row,
.transfer-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px 11px;
}

.peer-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.peer-name,
.transfer-name {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.peer-meta,
.transfer-meta {
  margin-top: 4px;
}

.peer-meta {
  display: flex;
  align-items: center;
  min-height: 14px;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  animation: status-breathe 1.8s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgb(0 0 0 / 0.1);
}

.status-dot-online {
  background: #2f9d5a;
  box-shadow: 0 0 0 0 rgb(47 157 90 / 0.32);
}

.status-dot-connecting {
  background: #d6a422;
  box-shadow: 0 0 0 0 rgb(214 164 34 / 0.32);
}

@keyframes status-breathe {
  0%,
  100% {
    transform: scale(0.92);
    opacity: 0.88;
    box-shadow: 0 0 0 0 rgb(47 157 90 / 0.05);
  }

  50% {
    transform: scale(1.08);
    opacity: 1;
    box-shadow: 0 0 0 7px rgb(47 157 90 / 0);
  }
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8ee;
  margin-top: 9px;
}

.progress span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 150ms ease;
}

.drop-over .chat-panel {
  box-shadow: inset 0 0 0 3px rgb(47 143 105 / 22%);
}

.qr-section {
  margin-top: auto;
}

.qr-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 14px 12px 12px;
}

.qr-status,
.qr-hint {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

.qr-image {
  width: min(100%, 184px);
  height: auto;
  aspect-ratio: 1;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
}

.qr-image-shell {
  position: relative;
  width: min(100%, 184px);
}

.qr-mask {
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgb(255 255 255 / 40%);
  backdrop-filter: blur(14px);
  color: #385066;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.qr-section[data-masked='true'] .qr-image {
  filter: blur(10px);
}

.qr-section[data-masked='true'] .qr-mask {
  opacity: 1;
}

.qr-section[data-state='loading'] .qr-image,
.qr-section[data-state='error'] .qr-image {
  display: none;
}

.toggle-qr-button {
  min-height: 28px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #385066;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
}

.toggle-qr-button:hover {
  background: #f5f8fb;
}

.empty-state {
  padding: 18px 0;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace {
    height: auto;
    min-height: calc(100vh - 180px);
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar-name-input {
    max-width: none;
    flex: 1 1 240px;
  }

  .side-panel {
    border-top: 1px solid var(--line);
    border-left: 0;
    max-height: 280px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 18px, 1220px);
    padding: 10px 0;
  }

  .topbar,
  .side-panel {
    padding: 12px;
  }

  .composer-actions,
  .file-card {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    display: grid;
  }

  .message {
    max-width: 88%;
  }

  .file-card-action {
    justify-content: stretch;
  }

  .topbar button,
  .composer-actions button,
  .file-picker span,
  .file-card button {
    justify-content: center;
    width: 100%;
  }

  .topbar-name-input {
    flex-basis: 100%;
  }
}
