:root {
  color-scheme: light;
  --bg: #eef2f6;
  --card: #ffffff;
  --line: #d7dee7;
  --text: #1f2937;
  --subtle: #6b7280;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --danger: #c62828;
  --danger-bg: #fde8e8;
  --info: #0f766e;
  --info-bg: #def7ec;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

body {
  overflow: hidden;
}

#app {
  height: 100%;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.screen {
  height: 100%;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.login-card {
  width: min(92vw, 380px);
  margin: 10vh auto 0;
  padding: 20px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.subtle {
  color: var(--subtle);
  font-size: 13px;
}

.field {
  display: block;
  margin-top: 14px;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.field input,
#text-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

.field input:focus,
#text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  font: inherit;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:active {
  background: var(--primary-2);
}

.btn.ghost,
.tool-btn {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 42px;
  border-radius: 12px;
  cursor: pointer;
  padding: 0 10px;
}

.banner {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
}

.banner.error {
  color: var(--danger);
  background: var(--danger-bg);
}

.banner.info {
  color: var(--info);
  background: var(--info-bg);
}

#chat-screen {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  position: relative;
}

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

.title {
  font-size: 18px;
  font-weight: 700;
}

#message-list {
  position: absolute;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 86px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px 140px;
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
}

.day-divider {
  width: fit-content;
  margin: 14px auto;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--subtle);
  font-size: 12px;
}

.msg {
  margin: 8px 0;
  display: flex;
}

.msg.self {
  justify-content: flex-end;
}

.bubble {
  max-width: min(78vw, 560px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

.msg.self .bubble {
  background: #eef5ff;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-image {
  display: block;
  max-width: min(72vw, 420px);
  max-height: 320px;
  border-radius: 14px;
  background: #f5f7fa;
}

.image-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.image-actions,
.media-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.image-actions a,
.media-actions a,
.media-actions button {
  font-size: 13px;
}

.media-actions button {
  border: 0;
  background: transparent;
  color: #2563eb;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.file-actions {
  justify-content: flex-start;
  margin-top: 2px;
}

.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.file-card .file-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e8eefc;
  color: #1d4ed8;
  font-weight: 700;
  flex: 0 0 auto;
}

.file-name {
  font-weight: 600;
  word-break: break-word;
}

.meta-row {
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  font-size: 12px;
  color: var(--subtle);
}

.status.ok {
  color: #15803d;
}

.status.fail {
  color: var(--danger);
}

.status.sending {
  color: var(--subtle);
}

#attachment-panel {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 78px;
  z-index: 20;
}

.attach-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.16);
}

.attach-preview-wrap {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: #f5f7fa;
  overflow: hidden;
}

#attach-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#attach-file-icon.file-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  font-size: 20px;
}

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

.attach-name {
  font-weight: 700;
  word-break: break-word;
}

.progress-wrap {
  margin-top: 10px;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2563eb, #06b6d4);
}

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

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
  touch-action: manipulation;
}

#text-input {
  min-height: 42px;
  max-height: 120px;
  resize: vertical;
}

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

  #text-input {
    grid-column: 1 / -1;
  }

  #send-text {
    grid-column: 2;
  }
}
