:root {
  color-scheme: light;
  --ccb-blue: #005bac;
  --ccb-blue-dark: #00427d;
  --ccb-blue-soft: #e8f2ff;
  --bg-soft: #edf4fb;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #dbe6f1;
  --line-strong: #bfd3e6;
  --surface: #ffffff;
  --surface-soft: #f6fafd;
  --success: #0f766e;
  --warning: #a16207;
  --danger: #b42318;
  --radius: 8px;
  --focus: 0 0 0 3px rgba(0, 91, 172, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 16px 24px;
  overflow: hidden;
  background:
    linear-gradient(180deg, #e6f1fb 0%, #f4f8fc 42%, #edf4fb 100%);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button,
textarea,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
  cursor: pointer;
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 32px);
  width: min(1152px, 100%);
  margin: 0;
  background: var(--surface);
  border: 1px solid rgba(191, 211, 230, 0.78);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.1);
}

/* ===== Header ===== */
.app-header {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(0, auto) minmax(180px, 1fr);
  align-items: center;
  gap: 16px;
  min-height: 68px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.header-left {
  display: flex;
  align-items: center;
  min-width: 0;
}

.logo-img {
  display: block;
  width: auto;
  height: 36px;
  max-width: 200px;
}

.header-title {
  margin: 0;
  min-width: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
  letter-spacing: 0;
  line-height: 1.35;
}

.clear-history-btn {
  width: 40px;
  height: 40px;
  justify-self: end;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.clear-history-btn:hover {
  border-color: var(--ccb-blue);
  color: var(--ccb-blue-dark);
  background: var(--ccb-blue-soft);
}

.clear-history-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* ===== Chat main ===== */
.chat-main {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(232, 242, 255, 0.46), rgba(255, 255, 255, 0) 240px),
    #ffffff;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 32px 32px 72px;
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: center;
  pointer-events: auto;
}

.empty-state.is-hidden {
  display: none;
}

.welcome-title {
  margin: 0;
  max-width: 760px;
  font-size: 28px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.35;
  text-wrap: balance;
}

.example-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  min-width: 0;
  max-width: 720px;
  pointer-events: auto;
}

.example-chip {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink-soft);
  padding: 12px 14px;
  text-align: left;
  line-height: 1.5;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-break: anywhere;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.example-chip:hover {
  border-color: var(--ccb-blue);
  background: var(--ccb-blue-soft);
  color: var(--ccb-blue-dark);
}

.example-chip:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* ===== Messages ===== */
.message-stack {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 100%;
}

.message-user {
  flex-direction: row-reverse;
}

.message-avatar {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ccb-blue-soft);
  color: var(--ccb-blue-dark);
}

.message-user .message-avatar {
  background: #ecfdf3;
  color: var(--success);
}

.message-avatar svg {
  width: 18px;
  height: 18px;
}

.message-body {
  min-width: 0;
  max-width: min(780px, 78%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(246, 250, 253, 0.96);
  padding: 15px 17px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
}

.message-user .message-body {
  border-color: rgba(0, 91, 172, 0.18);
  background: #eef6ff;
}

.message-label {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.message-status {
  margin: -2px 0 8px;
  color: #6b7c93;
  font-size: 12px;
  line-height: 1.45;
}

.message-status:empty {
  display: none;
}

.message-content {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.75;
}

/* Markdown rendering */
.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 14px 0 8px;
  line-height: 1.4;
  font-weight: 700;
}
.message-content h1 { font-size: 20px; }
.message-content h2 { font-size: 18px; }
.message-content h3 { font-size: 16px; }

.message-content p {
  margin: 8px 0;
}

.message-content ul,
.message-content ol {
  margin: 8px 0;
  padding-left: 22px;
}

.message-content li {
  margin: 4px 0;
}

.message-content code {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 14px;
  font-family: "Consolas", "Menlo", monospace;
}

.message-content pre {
  margin: 10px 0;
  padding: 12px 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
}

.message-content pre code {
  background: transparent;
  border: none;
  padding: 0;
}

.message-content blockquote {
  margin: 10px 0;
  padding: 6px 14px;
  border-left: 3px solid var(--ccb-blue);
  background: var(--ccb-blue-soft);
  color: var(--ink-soft);
}

.message-content a {
  color: var(--ccb-blue);
  text-decoration: underline;
}

.message-content strong {
  font-weight: 700;
}

.streaming-tail {
  white-space: pre-wrap;
}

/* Citation superscripts */
.message-content sup.citation {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 5px;
  margin: 0 1px;
  border-radius: 4px;
  vertical-align: super;
  position: relative;
  top: -2px;
}

.message-content sup.citation-web {
  background: var(--ccb-blue-soft);
  color: var(--ccb-blue-dark);
}

.message-content sup.citation-web a {
  color: inherit;
  text-decoration: none;
}

.message-content sup.citation-web a:hover {
  text-decoration: underline;
}

.message-content sup.citation-local {
  background: #f0fdf4;
  color: var(--success);
}

/* Sources — text-only list */
.message-sources {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.sources-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.sources-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

.sources-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.source-list-text {
  display: grid;
  gap: 8px;
}

.source-item-text {
  padding: 8px 0;
  border-top: 1px solid rgba(219, 230, 241, 0.72);
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-soft);
}

.source-item-text:first-child {
  border-top: none;
  padding-top: 0;
}

.source-title-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 6px;
  align-items: baseline;
}

.source-item-text .si-label {
  display: inline-block;
  min-width: 28px;
  color: var(--ccb-blue-dark);
  font-weight: 700;
}

.source-item-text a {
  color: var(--ccb-blue);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.source-item-text a:hover {
  text-decoration: underline;
}

.source-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 4px 0 0 34px;
}

.source-meta-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.source-meta-official,
.source-meta-regulatory {
  border-color: rgba(0, 91, 172, 0.24);
  background: var(--ccb-blue-soft);
  color: var(--ccb-blue-dark);
}

.source-meta-media,
.source-meta-public {
  border-color: rgba(15, 118, 110, 0.2);
  background: #f0fdf4;
  color: var(--success);
}

.source-meta-background,
.source-meta-local {
  background: #f8fafc;
  color: var(--ink-soft);
}

.source-meta-site,
.source-meta-date {
  background: transparent;
}

.source-provenance {
  margin: 2px 0 0 32px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.source-provenance-label {
  color: var(--muted);
}

.source-provenance a {
  margin-right: 0;
}

.source-toggle,
.source-provenance-toggle {
  margin-top: 8px;
  background: transparent;
  border: none;
  color: var(--ccb-blue);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
}

.source-provenance-toggle {
  margin: 0;
  font-size: 12px;
}

.source-toggle:hover,
.source-provenance-toggle:hover {
  text-decoration: underline;
}

/* ===== Footer ===== */
.chat-footer {
  flex: 0 0 auto;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(0, 91, 172, 0.08);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.input-wrap:focus-within {
  border-color: var(--ccb-blue);
  box-shadow: var(--focus);
}

textarea {
  flex: 1 1 auto;
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  padding: 12px 56px 12px 16px;
  line-height: 1.6;
}

textarea::placeholder {
  color: var(--muted);
}

.send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--radius);
  background: var(--ccb-blue);
  color: #fff;
  transition: background 160ms ease, opacity 160ms ease, transform 160ms ease;
}

.send-btn:hover {
  background: var(--ccb-blue-dark);
}

.send-btn:active {
  transform: translateY(1px);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 760px) {
  body {
    display: block;
    padding: 0;
    background: #ffffff;
  }

  .app-shell {
    width: 100%;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .app-header {
    grid-template-columns: 104px minmax(0, 1fr) 104px;
    gap: 7px;
    min-height: 62px;
    padding: 8px;
  }

  .header-title {
    font-size: 13px;
    line-height: 1.35;
    text-align: center;
  }

  .logo-img {
    width: 104px;
    height: auto;
    max-width: 100%;
  }

  .welcome-title {
    max-width: 320px;
    font-size: 22px;
    line-height: 1.35;
  }

  .empty-state {
    justify-content: flex-start;
    gap: 18px;
    padding: 118px 18px 96px;
  }

  .example-list {
    grid-template-columns: 1fr;
    max-width: 100%;
  }

  .example-chip {
    padding: 11px 13px;
  }

  .message-stack {
    padding: 18px 14px;
  }

  .chat-footer {
    padding: 10px 12px 14px;
  }

  .message-body {
    max-width: 86%;
  }

  .clear-history-btn {
    width: 36px;
    height: 36px;
  }

  .clear-history-btn svg {
    width: 18px;
    height: 18px;
  }

  textarea {
    padding-left: 14px;
  }
}

@media (max-height: 620px) {
  .empty-state {
    justify-content: flex-start;
    gap: 14px;
    padding-top: 28px;
    padding-bottom: 28px;
  }

  .welcome-title {
    font-size: 24px;
  }
}

@media (max-width: 760px) and (max-height: 700px) {
  .empty-state {
    padding-top: 72px;
    padding-bottom: 72px;
  }

  .welcome-title {
    font-size: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
