:root {
  --page: #dfe7ef;
  --panel: #ffffff;
  --soft: #f3f6f9;
  --line: #d9e1e9;
  --ink: #16202b;
  --muted: #677587;
  --accent: #0f766e;
  --accent-soft: #dcf5f0;
  --blue: #1d4ed8;
  --amber: #9a6700;
  --amber-soft: #fff4d6;
  --red: #b42318;
  --red-soft: #fdecea;
  --bubble-in: #ffffff;
  --bubble-out: #dcf8d3;
  --bubble-unknown: #eef2f6;
  --shadow: 0 14px 40px rgba(16, 33, 51, 0.16);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--ink);
}

body {
  -webkit-text-size-adjust: 100%;
}

button,
input {
  font: inherit;
}

.mobile-app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: #f1f5f8;
  box-shadow: var(--shadow);
}

.demo-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
  padding: 6px 14px;
  background: #ffe8a3;
  color: #5c4300;
  font-size: 11px;
  line-height: 1.35;
}

.demo-banner strong {
  font-size: 12px;
}

.mobile-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.header-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-copy h1 {
  margin: 0;
  font-size: 19px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.demo-chip {
  padding: 2px 7px;
  border-radius: 999px;
  background: #f4c430;
  color: #4d3800;
  font-size: 10px;
  font-weight: 800;
}

.text-button,
.back-button {
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.text-button:hover,
.back-button:hover {
  color: var(--ink);
}

.account-bar {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  padding: 10px 14px;
  overflow-x: auto;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}

.account-button {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 2px;
  min-width: 132px;
  max-width: 190px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.account-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.account-platform {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.account-label {
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-state {
  font-size: 10px;
  color: var(--muted);
}

.account-state.is-warning {
  color: var(--amber);
}

.account-state.is-error {
  color: var(--red);
}

.global-error {
  margin: 10px 14px;
  padding: 10px 12px;
  border: 1px solid #f0b9b3;
  border-radius: 12px;
  background: var(--red-soft);
  color: #7a1a12;
  font-size: 12px;
}

.global-error p {
  margin: 3px 0 8px;
  line-height: 1.5;
}

.error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.secondary-button,
.primary-button {
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.secondary-button {
  background: #fff;
  color: var(--accent);
}

.chat-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 12px 14px 14px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 8px;
}

.section-heading h2 {
  margin: 0;
  font-size: 16px;
}

.section-heading p {
  margin: 1px 0 0;
  font-size: 11px;
}

.muted {
  color: var(--muted);
}

.chat-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1px;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.chat-button {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.chat-button:last-child {
  border-bottom: 0;
}

.chat-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

.chat-main {
  min-width: 0;
}

.chat-title-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.chat-title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-type {
  flex: 0 0 auto;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--soft);
  color: var(--muted);
  font-size: 9px;
}

.chat-preview {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-time {
  align-self: flex-start;
  color: var(--muted);
  font-size: 9px;
  white-space: nowrap;
}

.message-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 10px 12px 12px;
}

.message-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding-bottom: 6px;
}

.back-button {
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
}

.message-heading h2 {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-heading p {
  margin: 1px 0 0;
  font-size: 10px;
}

.coverage-line {
  min-height: 16px;
  padding: 0 2px 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.chat-view .coverage-line.is-warning {
  color: var(--amber);
  font-weight: 700;
}

.message-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 6px 2px 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  gap: 2px;
}

.message.is-outgoing {
  align-self: flex-end;
  align-items: flex-end;
}

.message.is-incoming,
.message.is-unknown {
  align-self: flex-start;
  align-items: flex-start;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  align-items: center;
  padding: 0 3px;
  color: var(--muted);
  font-size: 9px;
}

.message-sender {
  max-width: 140px;
  overflow: hidden;
  color: #536172;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.direction-badge {
  padding: 1px 5px;
  border-radius: 999px;
  background: #e8edf2;
  color: #526173;
  font-size: 8px;
  font-weight: 800;
}

.message.is-outgoing .direction-badge {
  background: #cdecc3;
  color: #2f6b2b;
}

.message.is-unknown .direction-badge {
  background: #eef1f4;
  color: #697586;
}

.message-time {
  white-space: nowrap;
}

.bubble {
  max-width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bubble-in);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.message.is-outgoing .bubble {
  border-color: #c8e2bd;
  border-bottom-right-radius: 4px;
  background: var(--bubble-out);
}

.message.is-incoming .bubble {
  border-bottom-left-radius: 4px;
}

.message.is-unknown .bubble {
  border-style: dashed;
  background: var(--bubble-unknown);
}

.message-text {
  margin: 0;
  white-space: pre-wrap;
}

.message-text:empty {
  display: none;
}

.attachments {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 4px;
}

.attachment {
  width: min(240px, 64vw);
}

.media-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid #d8e1ea;
  border-radius: 10px;
  background: #eef3f8;
}

.media-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  padding: 10px;
  color: #6b7988;
  font-size: 10px;
  line-height: 1.4;
  text-align: center;
}

.media-placeholder strong {
  color: #4b5868;
  font-size: 11px;
}

.media-retry {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.attachment-problem {
  margin-top: 3px;
  color: var(--amber);
  font-size: 9px;
}

.attachment-unsupported {
  padding: 6px 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 10px;
}

.empty-state {
  padding: 22px 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  font-size: 11px;
}

.empty-state strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 13px;
}

.loading-line {
  padding: 8px 4px;
  color: var(--muted);
  font-size: 11px;
}

.inline-error {
  margin: 4px 0 8px;
  padding: 7px 9px;
  border: 1px solid #f0b9b3;
  border-radius: 9px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 11px;
}

.login-gate {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(360px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 10px 26px rgba(16, 33, 51, 0.08);
}

.login-card h1 {
  margin: 4px 0 6px;
  font-size: 22px;
}

.login-card .muted {
  margin: 0 0 14px;
  font-size: 11px;
  line-height: 1.5;
}

.field-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.login-input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}

.login-input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 118, 110, 0.15);
}

.login-card .primary-button {
  width: 100%;
  margin-top: 10px;
}

.login-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  text-align: center;
}

.login-links .text-button {
  color: var(--accent);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 30;
  max-width: 360px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(20, 31, 43, 0.88);
  color: #fff;
  font-size: 11px;
  transform: translateX(-50%);
}

.toast.is-error {
  background: rgba(150, 32, 22, 0.92);
}

@media (min-width: 720px) {
  .mobile-app {
    margin: 18px auto;
    height: calc(100dvh - 36px);
    border: 1px solid #cbd7e3;
    border-radius: 22px;
  }

  body {
    background:
      radial-gradient(circle at 20% 0%, #eef5fb, transparent 55%),
      linear-gradient(180deg, #dfe8f0, #cfdbe6);
  }
}

@media (max-width: 720px) {
  .mobile-app {
    max-width: none;
    box-shadow: none;
  }

  .message {
    max-width: 90%;
  }

  .attachment {
    width: min(230px, 66vw);
  }
}
