:root {
  --bg: #f4f9fc;
  --panel: #ffffff;
  --panel-soft: #f8fbfd;
  --border: #e4edf3;
  --text: #162033;
  --muted: #7b8da0;
  --blue: #5a9cf8;
  --blue-strong: #3b82f6;
  --shadow: 0 18px 45px rgba(22, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background:
    radial-gradient(circle at 18% 8%, rgba(90, 156, 248, 0.12), transparent 30%),
    linear-gradient(180deg, #fbfdff 0%, var(--bg) 48%, #eef6fb 100%);
  color: var(--text);
}

.app {
  height: 100vh;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100vh;
  min-width: 0;
}

.topbar {
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(12px);
  box-shadow: 0 6px 24px rgba(48, 66, 91, 0.04);
}

.topbar-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.app-label {
  color: #6b7f93;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-title {
  color: var(--text);
  font-size: 17px;
  font-weight: 760;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-button {
  border: 1px solid #9fdec2;
  background: linear-gradient(135deg, #dcfce7, #bbf7d0);
  border-radius: 999px;
  color: #166534;
  padding: 9px 16px;
  cursor: pointer;
  font: inherit;
  font-weight: 760;
  box-shadow: 0 10px 24px rgba(34, 197, 94, 0.18);
  transition: all 0.18s ease;
}

.topbar-button:hover {
  border-color: #74c69d;
  background: linear-gradient(135deg, #d1fae5, #86efac);
  box-shadow: 0 14px 30px rgba(34, 197, 94, 0.28);
  transform: translateY(-1px);
}

.status {
  border: 1px solid #d9efe5;
  border-radius: 999px;
  background: #f2fbf7;
  color: #3f8465;
  font-size: 12px;
  font-weight: 650;
  padding: 7px 11px;
}

.chat {
  padding: 32px 24px 24px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.msg {
  max-width: min(860px, 88vw);
  padding: 16px 18px;
  border-radius: 22px;
  line-height: 1.65;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(22, 32, 51, 0.05);
}

.msg.user {
  white-space: pre-wrap;
}

.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #e9f2ff, #f5f9ff);
  border-color: #d7e7fb;
}

.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.94);
}

.md-body {
  white-space: normal;
  word-break: break-word;
}

.md-body > :first-child {
  margin-top: 0;
}

.md-body > :last-child {
  margin-bottom: 0;
}

.md-body h1,
.md-body h2,
.md-body h3 {
  margin: 0.9em 0 0.45em;
  line-height: 1.3;
}

.md-body p,
.md-body ul,
.md-body ol {
  margin: 0.5em 0;
}

.md-body ul,
.md-body ol {
  padding-left: 1.35em;
}

.md-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #eef4f8;
  padding: 0.1em 0.35em;
  border-radius: 8px;
}

.md-body pre {
  overflow: auto;
  background: #111827;
  color: #f9fafb;
  padding: 12px 14px;
  border-radius: 18px;
}

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

.md-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

.stream-slide-content.md-body {
  font-size: 14px;
  color: var(--text);
}

.slides {
  display: flex;
  gap: 12px;
  overflow: auto;
  margin-top: 10px;
}

.slides img {
  width: 160px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: white;
  box-shadow: 0 12px 28px rgba(22, 32, 51, 0.08);
}

.progress-panel {
  max-width: min(860px, 88vw);
  width: 100%;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.progress-panel.failed {
  border-color: #fecaca;
  background: #fff7f7;
}

.progress-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.progress-detail,
.progress-meta {
  color: var(--muted);
  font-size: 13px;
}

.progress-bar {
  height: 8px;
  margin: 12px 0 8px;
  border-radius: 999px;
  background: #e5eef5;
  overflow: hidden;
}

.progress-value {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), #7bc9f5);
  transition: width 0.25s ease;
}

.stream-panel {
  max-width: min(860px, 88vw);
  width: 100%;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.stream-title {
  font-weight: 700;
  margin-bottom: 12px;
}

.stream-slide {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.stream-slide-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.stream-slide-content {
  line-height: 1.65;
  white-space: pre-wrap;
}

.retry-panel {
  max-width: min(860px, 88vw);
  width: 100%;
  padding: 18px;
  border: 1px solid #fed7aa;
  border-radius: 24px;
  background: #fff7ed;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.retry-text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.retry-button {
  min-height: 40px;
  white-space: nowrap;
}

.retry-button:disabled {
  opacity: 0.7;
  cursor: wait;
}

.bottom-status {
  width: min(760px, calc(100% - 40px));
  margin: 0 auto 12px;
  padding: 12px 16px;
  border: 1px solid rgba(184, 215, 238, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 34px rgba(22, 32, 51, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  color: #37546f;
  font-size: 13px;
  backdrop-filter: blur(12px);
  animation: statusFloatIn 0.22s ease-out;
}

.bottom-status.failed {
  border-color: #fecaca;
  background: #fff7f7;
  color: #b91c1c;
}

.status-spinner {
  width: 18px;
  height: 18px;
  border: 3px solid #dcecff;
  border-top-color: var(--blue-strong);
  border-radius: 50%;
  flex: 0 0 auto;
  animation: spin 0.85s linear infinite;
}

.bottom-status.failed .status-spinner {
  display: none;
}

.bottom-status-title {
  font-weight: 750;
  white-space: nowrap;
}

.bottom-status-detail {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-status.failed .bottom-status-detail {
  color: inherit;
}

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

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

.composer {
  background: rgba(255, 255, 255, 0.9);
  border-top: 1px solid var(--border);
  padding: 14px 20px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  backdrop-filter: blur(12px);
}

.input {
  border: 1px solid var(--border);
  background: #fbfdff;
  border-radius: 18px;
  padding: 12px 14px;
  min-height: 46px;
  resize: vertical;
  font: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.input:focus {
  border-color: #b8d7ee;
  box-shadow: 0 0 0 4px rgba(90, 156, 248, 0.12);
}

.send {
  border: 0;
  background: linear-gradient(135deg, var(--blue), var(--blue-strong));
  color: white;
  border-radius: 18px;
  padding: 0 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 14px 26px rgba(59, 130, 246, 0.22);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.send:hover {
  box-shadow: 0 18px 34px rgba(59, 130, 246, 0.3);
  transform: translateY(-1px);
}

.upload {
  margin: auto;
  max-width: 780px;
  width: 100%;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(214, 229, 239, 0.9);
  border-radius: 32px;
  padding: 38px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow);
}

.upload h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.02em;
}

.upload .hint {
  line-height: 1.6;
}

.upload .input {
  min-height: 88px;
  line-height: 1.55;
}

.file-input {
  display: none;
}

.file-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
}

.file-button {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  border-radius: 18px;
  padding: 13px 16px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  font-weight: 650;
  color: var(--text);
  transition: all 0.18s ease;
}

.file-button:hover {
  border-color: #b8d7ee;
  box-shadow: 0 10px 24px rgba(90, 156, 248, 0.12);
}

.file-name {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-button {
  min-height: 50px;
}

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

.hidden {
  display: none;
}

a {
  color: var(--blue);
  text-decoration: none;
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
  }

  .topbar-actions,
  .file-row {
    width: 100%;
  }

  .bottom-status {
    width: calc(100% - 24px);
    border-radius: 20px;
    align-items: flex-start;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .send {
    min-height: 44px;
  }
}
