:root {
  color-scheme: dark;
  --bg: #212121;
  --panel: #171717;
  --panel-hover: #2f2f2f;
  --surface: #2a2a2a;
  --surface-soft: #303030;
  --ink: #f4f4f4;
  --muted: #b4b4b4;
  --subtle: #8f8f8f;
  --line: #3d3d3d;
  --accent: #19a58c;
  --accent-strong: #0f766e;
  --amber: #f6b849;
  --red: #ff6b5f;
  --green: #4ade80;
  --blue: #7ab7ff;
  --sidebar-width: 260px;
  --shadow: 0 22px 52px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 15, 15, 0.84);
  backdrop-filter: blur(12px);
}

.auth-screen[hidden] {
  display: none;
}

.auth-card {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: #242424;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
}

.auth-card input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  padding: 0 12px;
  color: var(--ink);
  background: #1f1f1f;
}

.auth-card input:focus {
  border-color: rgba(122, 183, 255, 0.62);
}

.auth-card button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  color: #071815;
  background: #f4f4f4;
  font-weight: 700;
}

.auth-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  height: 100vh;
  position: sticky;
  top: 0;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 8px;
  padding: 12px;
  background: #0f0f0f;
  border-right: 1px solid #242424;
}

.sidebar-header,
.sidebar-action,
.history-item,
.sidebar-footer,
.chat-header,
.message,
.candidate-top,
.report-heading,
.trace-panel-head,
.trace-panel-title,
.trace-task-row,
.composer-inner {
  display: flex;
  align-items: center;
}

.sidebar-header {
  justify-content: space-between;
  min-height: 34px;
  margin-bottom: 4px;
}

.sidebar-brand {
  font-size: 18px;
  font-weight: 760;
  letter-spacing: 0;
}

.sidebar-icon,
.mobile-menu,
.composer-tool,
.send-button,
.copy-report {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
}

.sidebar-icon,
.mobile-menu {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}

.sidebar-icon:hover,
.mobile-menu:hover {
  background: var(--panel-hover);
  color: var(--ink);
}

.sidebar-action {
  min-height: 38px;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.sidebar-action:hover,
.sidebar-action.active {
  background: var(--panel-hover);
}

.history-section {
  min-height: 0;
  margin-top: 12px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.section-label {
  padding: 0 8px 8px;
  color: var(--subtle);
  font-size: 12px;
}

.history-list {
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.history-empty {
  color: var(--subtle);
  font-size: 13px;
  padding: 8px;
}

.history-item {
  width: 100%;
  min-height: 36px;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  padding: 8px 9px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.history-item:hover,
.history-item.active {
  color: var(--ink);
  background: var(--panel-hover);
}

.history-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-time {
  flex: 0 0 auto;
  color: var(--subtle);
  font-size: 11px;
}

.sidebar-footer {
  gap: 10px;
  min-height: 48px;
  padding: 8px;
  border-radius: 8px;
  color: var(--ink);
}

.sidebar-footer:hover {
  background: var(--panel-hover);
}

.sidebar-footer strong,
.sidebar-footer span {
  display: block;
}

.sidebar-footer strong {
  font-size: 13px;
}

.sidebar-footer span {
  color: var(--subtle);
  font-size: 12px;
}

.user-dot,
.avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #071815;
  font-weight: 800;
}

.chat-main {
  min-width: 0;
  min-height: 100vh;
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 10;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 18px;
  background: rgba(33, 33, 33, 0.88);
  backdrop-filter: blur(12px);
}

.mobile-menu {
  display: none;
}

.chat-title {
  font-weight: 650;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.llm-counter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 110px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.llm-counter-label {
  color: var(--subtle);
  font-size: 11px;
  letter-spacing: 0.06em;
}

.llm-counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.llm-counter strong {
  font-size: 18px;
  line-height: 1;
}

.llm-counter button {
  min-height: 24px;
  border: 0;
  border-radius: 999px;
  padding: 0 10px;
  color: var(--ink);
  background: var(--surface);
}

.llm-counter button:hover {
  background: var(--panel-hover);
}

.service-state,
.status-pill {
  min-height: 31px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
  white-space: nowrap;
}

.service-state.online,
.status-pill.completed {
  border-color: rgba(74, 222, 128, 0.34);
  color: var(--green);
  background: rgba(74, 222, 128, 0.12);
}

.status-pill.waiting_approval {
  border-color: rgba(246, 184, 73, 0.34);
  color: var(--amber);
  background: rgba(246, 184, 73, 0.12);
}

.service-state.error,
.status-pill.failed {
  border-color: rgba(255, 107, 95, 0.34);
  color: var(--red);
  background: rgba(255, 107, 95, 0.12);
}

.thread {
  width: min(920px, calc(100vw - var(--sidebar-width) - 48px));
  margin: 0 auto;
  padding: 26px 0 150px;
}

.empty-center {
  min-height: calc(100vh - 230px);
  display: grid;
  place-items: center;
  text-align: center;
}

.empty-center h2 {
  margin: 0 0 18px;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 720;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.prompt-chip {
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
}

.prompt-chip:hover {
  color: var(--ink);
  background: var(--surface);
}

.message {
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 24px;
}

.user-message {
  justify-content: flex-end;
}

.user-message .message-content {
  display: grid;
  justify-items: end;
}

.message-content {
  min-width: 0;
  max-width: min(820px, 100%);
}

.message-name {
  margin-bottom: 7px;
  color: var(--subtle);
  font-size: 13px;
  font-weight: 650;
}

.bubble {
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 15px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.18);
}

.assistant-message .bubble {
  border-top-left-radius: 3px;
}

.user-message .bubble {
  max-width: min(720px, calc(100vw - var(--sidebar-width) - 70px));
  color: var(--ink);
  background: #303030;
  border-top-right-radius: 3px;
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.62;
}

.agent-trace {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.trace-log {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 2px 2px 0;
}

.trace-log.compact {
  gap: 4px;
}

.trace-log-line {
  min-width: 0;
  overflow: hidden;
  color: var(--subtle);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  line-height: 1.35;
}

.trace-log-line::before {
  content: "›";
  margin-right: 8px;
  color: #666;
}

.trace-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #2b2b2b;
}

.trace-panel-head {
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 11px 14px;
  border-bottom: 1px solid #353535;
  color: var(--muted);
}

.trace-panel-title {
  min-width: 0;
  gap: 10px;
}

.trace-panel-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: var(--ink);
  font-size: 13px;
}

.trace-count {
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.35;
}

.trace-expand {
  color: var(--subtle);
  font-size: 16px;
}

.trace-list {
  display: grid;
  gap: 2px;
  padding: 9px 0 12px;
}

.trace-task-row {
  align-items: flex-start;
  min-width: 0;
  gap: 12px;
  padding: 7px 14px;
  color: var(--muted);
}

.trace-status {
  position: relative;
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-top: 5px;
  border: 1.5px solid #8a8a8a;
  border-radius: 50%;
}

.trace-task-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.trace-task-copy strong {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.38;
}

.trace-task-copy span {
  color: var(--subtle);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.trace-task-row.pending .trace-status {
  border-color: #777;
}

.trace-task-row.active .trace-status {
  border-color: rgba(244, 244, 244, 0.28);
  border-top-color: var(--ink);
  animation: trace-spin 0.8s linear infinite;
}

.trace-task-row.done .trace-status {
  border-color: var(--ink);
  background: var(--ink);
}

.trace-task-row.done .trace-status::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 5px;
  height: 8px;
  border: solid #242424;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.trace-task-row.failed .trace-status {
  border-color: var(--red);
  background: var(--red);
  animation: none;
}

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

.task-source,
.metric span,
.car-meta span,
.risk-flags {
  color: var(--subtle);
  font-size: 12px;
}

.task-source {
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.result-card {
  display: grid;
  gap: 14px;
}

.result-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.result-title h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.requirement-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.batch-summary {
  display: grid;
  gap: 10px;
}

.batch-stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.batch-stat-row > div,
.batch-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #242424;
}

.batch-stat-row > div {
  min-width: 0;
  padding: 11px 12px;
}

.batch-stat-row span {
  display: block;
  color: var(--subtle);
  font-size: 12px;
}

.batch-stat-row strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.batch-table-wrap {
  overflow: auto;
}

.batch-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

.batch-table th,
.batch-table td {
  padding: 9px 11px;
  border-bottom: 1px solid #303030;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.batch-table th {
  color: var(--subtle);
  font-weight: 650;
  background: #2b2b2b;
}

.batch-table td {
  color: var(--ink);
}

.batch-table tr:last-child td {
  border-bottom: 0;
}

.batch-more {
  color: var(--subtle);
  font-size: 12px;
}

.metric,
.candidate-card,
.report-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #242424;
}

.metric {
  min-width: 0;
  padding: 11px 12px;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.candidate-card {
  min-width: 0;
  padding: 14px;
}

.candidate-top {
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.candidate-card h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.decision {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  color: #8af7df;
  background: rgba(25, 165, 140, 0.16);
}

.decision.warn {
  color: var(--amber);
  background: rgba(246, 184, 73, 0.14);
}

.decision.risky {
  color: var(--red);
  background: rgba(255, 107, 95, 0.14);
}

.car-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 14px;
}

.car-meta strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
}

.risk-flags {
  margin-top: 12px;
  line-height: 1.45;
}

.detail-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin-top: 12px;
  border-radius: 8px;
  color: var(--blue);
  text-decoration: none;
  font-size: 13px;
  font-weight: 650;
}

.detail-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

.bubble p .detail-link {
  display: inline;
  min-height: auto;
  margin-top: 0;
}

.detail-link.unavailable {
  color: var(--subtle);
  cursor: default;
  font-weight: 500;
}

.detail-link.unavailable:hover {
  color: var(--subtle);
  text-decoration: none;
}

.empty-results {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--subtle);
  background: #242424;
}

.report-section {
  overflow: hidden;
}

.report-heading {
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #2b2b2b;
}

.report-heading h2 {
  margin: 0;
  font-size: 16px;
}

.copy-report {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}

.copy-report:hover {
  color: var(--ink);
  background: var(--panel-hover);
}

.report-table {
  padding: 14px;
  background: #242424;
}

.report-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.report-summary > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #202020;
}

.report-summary span,
.structured-table th {
  color: var(--muted);
  font-size: 12px;
}

.report-summary strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 14px;
}

.structured-block + .structured-block {
  margin-top: 16px;
}

.structured-block h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.structured-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.structured-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}

.structured-table th,
.structured-table td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.structured-table th {
  background: #202020;
  font-weight: 700;
}

.structured-table tr:last-child td {
  border-bottom: 0;
}

.candidate-table td:nth-child(2) {
  min-width: 240px;
  color: var(--ink);
  font-weight: 650;
}

.table-detail-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  min-height: 28px;
  border: 1px solid rgba(95, 168, 255, 0.45);
  border-radius: 7px;
  color: var(--blue);
  text-decoration: none;
  font-weight: 700;
}

.table-detail-link:hover {
  color: var(--ink);
  border-color: var(--blue);
  background: rgba(95, 168, 255, 0.12);
}

.table-detail-link.unavailable {
  border-color: var(--line);
  color: var(--subtle);
}

.table-note {
  margin-top: 10px;
  color: var(--subtle);
  font-size: 12px;
}

.stream-hidden {
  opacity: 0;
  transform: translateY(8px);
}

.stream-visible {
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}

.composer {
  position: fixed;
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 18px 14px 22px;
  background: linear-gradient(180deg, rgba(33, 33, 33, 0), var(--bg) 34%);
}

.attachment-strip {
  width: min(760px, 100%);
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-strip[hidden],
.file-input {
  display: none;
}

.attachment-pill,
.message-assets span {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #252525;
  font-size: 12px;
}

.attachment-pill {
  max-width: min(100%, 340px);
  min-height: 34px;
  padding: 6px 7px 6px 10px;
}

.attachment-pill span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-remove {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  color: var(--subtle);
  background: transparent;
}

.attachment-remove:hover {
  color: var(--ink);
  background: var(--panel-hover);
}

.composer-inner {
  width: min(760px, 100%);
  margin: 0 auto;
  gap: 10px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

textarea {
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 36px;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: none;
  color: var(--ink);
  background: transparent;
  padding: 8px 2px;
  line-height: 1.45;
}

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

.composer-tool,
.send-button {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.composer-tool {
  color: var(--muted);
  background: transparent;
  font-size: 23px;
}

.composer-tool:hover {
  color: var(--ink);
  background: var(--panel-hover);
}

.composer-tool:disabled {
  cursor: wait;
  opacity: 0.55;
}

.send-button {
  color: #071815;
  background: #f4f4f4;
  font-size: 20px;
  line-height: 1;
}

.send-button:hover {
  background: #ffffff;
}

.send-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.message-assets {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.message-assets span {
  max-width: 260px;
  padding: 5px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 110px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--ink);
  background: #303030;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 40;
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-flex;
  }

  .thread {
    width: min(920px, calc(100vw - 28px));
  }

  .composer {
    left: 0;
  }

  .user-message .bubble {
    max-width: min(720px, calc(100vw - 56px));
  }
}

@media (max-width: 720px) {
  .header-status {
    gap: 8px;
  }

  .llm-counter {
    min-width: 92px;
    padding: 7px 8px;
  }

  .llm-counter button {
    padding: 0 8px;
  }

  .service-state {
    display: none;
  }

  .thread {
    padding-top: 12px;
  }

  .empty-center h2 {
    font-size: 22px;
  }

  .requirement-strip,
  .batch-stat-row,
  .candidate-grid,
  .report-summary {
    grid-template-columns: 1fr;
  }

  .message {
    gap: 9px;
  }

  .avatar {
    width: 28px;
    height: 28px;
  }

  .composer {
    padding: 12px 10px 14px;
  }

  .composer-inner {
    border-radius: 8px;
  }
}
