:root {
  --wx-green: #07c160;
  --wx-green-dark: #06ad56;
  --wx-green-soft: #e8f8ef;
  --wx-green-soft-hover: #d4f2e0;
  --wx-green-border: #9edfb8;
  --bg: #ededed;
  --panel: #f7f7f7;
  --line: #d9d9d9;
  --text: #191919;
  --muted: #888;
  --bubble-other: #fff;
  --danger: #fa5151;
  --danger-soft: #fff0f0;
  --danger-soft-hover: #ffe3e3;
  --danger-border: #ffb4b4;
  --btn-disabled-bg: #f0f0f0;
  --btn-disabled-text: #b0b0b0;
  --btn-disabled-border: #e0e0e0;
  --btn-disabled-primary-bg: #059a4c;
  --shell-max: 720px;
  --control-h: 40px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[v-cloak] {
  display: none !important;
}

button,
input,
textarea {
  font: inherit;
}

.app-loading {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--panel);
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--wx-green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--wx-green);
}

.loading-sub {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: var(--shell-max);
  margin: 0 auto;
  background: var(--panel);
}

.app-shell button,
.app-shell a.icon-btn,
.app-shell label.icon-btn {
  opacity: 1;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 0;
  width: var(--control-h);
  height: var(--control-h);
  flex-shrink: 0;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn .bi {
  color: inherit;
  line-height: 1;
}

.icon-btn.accent,
.icon-btn.primary {
  border-color: var(--wx-green);
  background: var(--wx-green);
  color: #fff;
}

.icon-btn.accent:hover,
.icon-btn.primary:hover {
  background: var(--wx-green-dark);
  border-color: var(--wx-green-dark);
}

.icon-btn.accent .bi,
.icon-btn.primary .bi {
  color: #fff;
}

.icon-btn.danger {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-btn.danger:hover {
  background: var(--danger-soft-hover);
  border-color: var(--danger);
}

.icon-btn:disabled,
.welcome-btn:disabled,
.tab-btn:disabled,
.file-sub-btn:disabled {
  opacity: 1;
  cursor: not-allowed;
  background: var(--btn-disabled-bg);
  color: var(--btn-disabled-text);
  border-color: var(--btn-disabled-border);
}

.tab-btn.active:disabled,
.file-sub-btn.active:disabled {
  background: var(--btn-disabled-primary-bg);
  color: #fff;
  border-color: var(--btn-disabled-primary-bg);
}

.icon-btn.accent:disabled,
.icon-btn.primary:disabled,
.welcome-btn.primary:disabled {
  background: var(--btn-disabled-primary-bg);
  color: #fff;
  border-color: var(--btn-disabled-primary-bg);
}

.icon-btn.danger:disabled {
  background: var(--danger-soft);
  color: #f0a0a0;
  border-color: var(--danger-border);
}

.icon-btn.sm {
  width: 34px;
  height: 34px;
  font-size: 15px;
}

.icon-btn.lg {
  width: 48px;
  height: 48px;
  font-size: 20px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: #fff;
  flex-shrink: 0;
}

.tab-nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.tab-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  min-height: 40px;
}

.tab-btn .bi {
  color: inherit;
  font-size: 18px;
}

.tab-btn.active {
  color: #fff;
  background: var(--wx-green);
  border-color: var(--wx-green);
  font-weight: 600;
}

.tab-btn.active .bi {
  color: #fff;
}

.tab-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  font-weight: 600;
}

.space-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.space-label {
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}

.space-code {
  font-size: clamp(16px, 4vw, 18px);
  font-weight: 600;
  letter-spacing: 3px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.space-info .icon-btn {
  margin-left: auto;
}

.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.welcome-card {
  width: 100%;
  max-width: 400px;
  padding: clamp(24px, 5vw, 32px);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.welcome-title {
  margin: 0;
  font-size: clamp(24px, 6vw, 28px);
  text-align: center;
  color: var(--wx-green);
}

.welcome-desc {
  margin: 8px 0 28px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.welcome-actions.row-actions {
  flex-direction: row;
  justify-content: center;
}

.welcome-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 14px;
  font-size: 16px;
  min-height: 48px;
}

.welcome-btn.primary {
  border-color: var(--wx-green);
  background: var(--wx-green);
  color: #fff;
}

.welcome-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-label {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.panel-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.password-display {
  padding: 16px;
  border-radius: 8px;
  background: var(--panel);
  font-size: clamp(26px, 8vw, 32px);
  font-weight: 700;
  text-align: center;
  letter-spacing: clamp(4px, 2vw, 8px);
  color: var(--wx-green);
}

.password-display.muted {
  font-size: 18px;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: 500;
}

.password-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 20px;
  text-align: center;
  letter-spacing: 6px;
}

.password-input:focus {
  outline: none;
  border-color: var(--wx-green);
  box-shadow: 0 0 0 2px rgba(7, 193, 96, 0.15);
}

.welcome-back {
  margin-top: 4px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  min-height: var(--control-h);
}

.app-main {
  flex: 1;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  -webkit-overflow-scrolling: touch;
}

.message-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 14px;
}

.message-item.mine {
  align-items: flex-end;
}

.bubble {
  max-width: min(78%, 320px);
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bubble-other);
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-item.mine .bubble {
  background: #95ec69;
}

.bubble-image {
  padding: 4px;
  background: transparent !important;
}

.bubble-file-wrap {
  padding: 0;
  background: var(--bubble-other) !important;
}

.message-item.mine .bubble-file-wrap {
  background: #95ec69 !important;
}

.bubble-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-width: 160px;
  max-width: min(240px, 75vw);
  color: inherit;
  text-decoration: none;
}

.bubble-file .bi {
  font-size: 22px;
  flex-shrink: 0;
}

.bubble-file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.bubble-file-size {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.bubble-invalid {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.file-subnav {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.file-sub-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}

.file-sub-btn .bi {
  color: inherit;
}

.file-sub-btn.active {
  border-color: var(--wx-green);
  color: #fff;
  background: var(--wx-green);
}

.file-sub-btn.active .bi {
  color: #fff;
}

.file-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--panel);
  font-size: 12px;
  line-height: 18px;
}

.file-sub-btn.active .file-count {
  background: var(--wx-green-dark);
  color: #fff;
}

.file-thumb {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  cursor: zoom-in;
}

.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.message-image {
  display: block;
  max-width: min(200px, 60vw);
  max-height: min(200px, 40vh);
  border-radius: 6px;
  cursor: zoom-in;
}

.image-preview {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.88);
}

.image-preview-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

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

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #fff;
  flex-shrink: 0;
}

.composer-btn {
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: var(--control-h);
  max-height: 120px;
  line-height: 1.4;
}

.upload-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  flex-shrink: 0;
}

.upload-icon {
  width: var(--control-h);
  height: var(--control-h);
  font-size: 20px;
}

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

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

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

.file-name {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-name .bi {
  margin-right: 4px;
  color: var(--muted);
}

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

.file-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.empty-tip {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
}

.toast-stack {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(calc(100% - 24px), 360px);
  pointer-events: none;
}

.toast-item {
  padding: 10px 16px;
  border-radius: 8px;
  background: #333;
  color: #fff;
  font-size: 14px;
  text-align: center;
  box-shadow: 0 4px 12px #00000026;
  animation: toast-in 0.2s ease;
}

.toast-success {
  background: var(--wx-green);
}

.toast-error {
  background: var(--danger);
}

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

@media (min-width: 768px) {
  :root {
    --shell-max: 840px;
  }

  .app-shell {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.04);
  }

  .message-image {
    max-width: 280px;
    max-height: 280px;
  }

  .bubble {
    max-width: min(68%, 420px);
  }
}

@media (max-width: 480px) {
  .tab-label {
    display: none;
  }

  .tab-btn {
    padding: 8px 16px;
  }

  .bubble {
    max-width: 88%;
  }
}
