:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  --paper: #f4f0e7;
  --paper-deep: #e9e2d5;
  --paper-soft: rgba(255, 252, 244, 0.72);
  --ink: #20231f;
  --muted: #686d61;
  --line: rgba(82, 83, 72, 0.2);
  --line-strong: rgba(70, 77, 63, 0.34);
  --moss: #6c7666;
  --moss-deep: #3f4d3f;
  --clay: #8b7762;
  --ash: #d8d2c5;
  --charcoal: #2f302c;
  --danger: #8c3b32;
  --warning: #a27b3f;
  --shadow: 0 8px 18px rgba(38, 35, 28, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(76, 87, 69, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(76, 87, 69, 0.035) 1px, transparent 1px),
    linear-gradient(135deg, #f7f3eb 0%, #ece6d9 52%, #f3eee4 100%);
  background-size: 44px 44px, 44px 44px, 100% 100%;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    repeating-linear-gradient(11deg, rgba(72, 68, 58, 0.025) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(96deg, rgba(255, 255, 255, 0.18) 0 1px, transparent 1px 9px);
  opacity: 0.7;
}

button,
textarea {
  font: inherit;
}

button {
  transition: background-color 220ms ease, border-color 220ms ease, color 220ms ease, opacity 220ms ease;
}

button:hover,
button:focus-visible {
  border-color: var(--moss-deep);
  outline: none;
}

.paper-grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(61, 64, 55, 0.035) 0 1px, transparent 1px),
    radial-gradient(circle at 74% 28%, rgba(61, 64, 55, 0.028) 0 1px, transparent 1px),
    radial-gradient(circle at 42% 80%, rgba(61, 64, 55, 0.026) 0 1px, transparent 1px);
  background-size: 28px 31px, 39px 43px, 47px 53px;
  mix-blend-mode: multiply;
}

.top-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 74px;
  padding: 14px 28px;
  display: grid;
  grid-template-columns: minmax(230px, auto) 1fr minmax(210px, auto);
  align-items: center;
  gap: 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 241, 231, 0.9);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  gap: 13px;
  align-items: center;
  min-width: 0;
}

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid rgba(58, 63, 53, 0.18);
  filter: saturate(0.72) contrast(0.96);
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

.session-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
}

.nav {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.nav-item {
  min-width: 68px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 17px;
  color: var(--charcoal);
  background: transparent;
  text-align: center;
  cursor: pointer;
  font-weight: 600;
}

.nav-item.active {
  border-color: var(--line-strong);
  background: rgba(255, 252, 244, 0.58);
}

.nav-item:hover {
  background: rgba(255, 252, 244, 0.72);
}

.session-card {
  justify-self: end;
  min-width: 210px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 252, 244, 0.58);
}

.session-card strong {
  font-size: 15px;
  font-weight: 700;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--warning);
  flex: 0 0 auto;
  box-shadow: 0 0 0 4px rgba(162, 123, 63, 0.1);
}

.status-dot.ok {
  background: var(--moss);
  box-shadow: 0 0 0 4px rgba(108, 118, 102, 0.12);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(140, 59, 50, 0.12);
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1460px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.chat-card,
.panel {
  border: 1px solid var(--line);
  background: var(--paper-soft);
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 360px;
  gap: 16px;
  align-items: stretch;
}

.chat-card,
.panel {
  border-radius: 8px;
}

.chat-card {
  min-height: calc(100vh - 366px);
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  overflow: hidden;
}

.window-bar {
  min-height: 46px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(236, 230, 217, 0.64);
}

.window-bar span {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(139, 119, 98, 0.55);
  background: rgba(139, 119, 98, 0.16);
  transform: rotate(4deg);
}

.messages {
  padding: 22px;
  overflow: auto;
  scroll-behavior: smooth;
}

.message-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.message-row.user {
  grid-template-columns: minmax(0, 1fr) 38px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  background: rgba(255, 252, 244, 0.62);
  color: var(--moss-deep);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  border: 1px solid var(--line);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.7) contrast(0.95);
}

.bubble {
  width: min(100%, 820px);
  border-radius: 8px;
  padding: 15px 17px;
  background: rgba(255, 252, 244, 0.62);
  border: 1px solid rgba(82, 83, 72, 0.14);
  line-height: 1.78;
  white-space: pre-wrap;
  color: var(--ink);
}

.message-row.user .bubble {
  justify-self: end;
  background: rgba(232, 237, 225, 0.72);
  border-color: rgba(108, 118, 102, 0.24);
}

.message-row.user .avatar {
  grid-column: 2;
  grid-row: 1;
}

.message-row.user .bubble {
  grid-column: 1;
  grid-row: 1;
}

.progress-bubble {
  display: grid;
  gap: 6px;
  width: min(100%, 560px);
  background: rgba(245, 243, 236, 0.78);
}

.progress-title {
  display: block;
  color: var(--moss-deep);
  font-size: 15px;
  font-weight: 700;
}

.progress-detail {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-weight: 600;
  color: var(--moss-deep);
}

.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--moss);
  animation: pulse 1.3s infinite ease-in-out;
}

.typing i:nth-child(2) {
  animation-delay: 0.16s;
}

.typing i:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.table-card {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 252, 244, 0.76);
  overflow: hidden;
}

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  background: rgba(232, 226, 213, 0.58);
  border-bottom: 1px solid var(--line);
}

.table-head strong {
  font-size: 14px;
  font-weight: 700;
}

.table-head button {
  border: 1px solid var(--line-strong);
  background: rgba(255, 252, 244, 0.58);
  color: var(--moss-deep);
  border-radius: 3px;
  padding: 6px 11px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
}

.table-wrap {
  overflow: auto;
  max-height: 430px;
}

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

th,
td {
  border-bottom: 1px solid rgba(82, 83, 72, 0.14);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eee8dc;
  color: var(--charcoal);
  font-weight: 700;
}

tbody tr:nth-child(even) {
  background: rgba(237, 232, 221, 0.42);
}

.composer {
  margin: 0 22px 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: rgba(255, 252, 244, 0.68);
}

.composer:focus-within {
  border-color: var(--moss);
}

.composer textarea {
  width: 100%;
  min-height: 76px;
  max-height: 190px;
  border: 0;
  outline: 0;
  resize: vertical;
  color: var(--ink);
  background: transparent;
}

.composer textarea::placeholder {
  color: #75786e;
}

.composer-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.send-button {
  border: 1px solid var(--moss-deep);
  border-radius: 4px;
  min-width: 96px;
  height: 40px;
  padding: 0 16px;
  background: var(--moss-deep);
  color: #f7f3eb;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
}

.send-button:hover,
.send-button:focus-visible {
  background: #354236;
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.64;
}

.send-icon,
.send-text {
  white-space: nowrap;
}

.inspector {
  display: grid;
  align-content: start;
  gap: 14px;
  max-height: calc(100vh - 210px);
  overflow: auto;
}

.panel {
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.tool-list,
.trace-list {
  display: grid;
  gap: 9px;
}

.tool-item,
.trace-item {
  border: 1px solid rgba(82, 83, 72, 0.14);
  border-radius: 7px;
  padding: 11px;
  background: rgba(255, 252, 244, 0.52);
}

.tool-item {
  width: 100%;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.tool-item:hover,
.tool-item:focus-visible {
  background: rgba(249, 245, 235, 0.86);
  border-color: rgba(63, 77, 63, 0.36);
}

.tool-item.active {
  border-color: rgba(63, 77, 63, 0.54);
  background: rgba(232, 226, 213, 0.58);
}

.tool-item strong,
.trace-item strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
}

.tool-item span,
.trace-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  word-break: break-word;
  line-height: 1.5;
}

.tool-item small {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--moss-deep);
  background: rgba(225, 232, 218, 0.64);
  font-size: 11px;
  line-height: 1.4;
}

.phase-error strong {
  color: var(--danger);
}

@media (max-width: 1180px) {
  .top-nav {
    grid-template-columns: 1fr;
  }

  .session-card {
    justify-self: stretch;
  }

  .nav {
    justify-content: flex-start;
    overflow-x: auto;
  }

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

  .inspector {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .top-nav {
    padding: 12px;
    gap: 12px;
  }

  .shell {
    width: min(100% - 20px, 1460px);
    padding-top: 12px;
  }

  .chat-card {
    min-height: 620px;
  }

  .message-row,
  .message-row.user {
    grid-template-columns: 1fr;
  }

  .message-row .avatar,
  .message-row.user .avatar {
    display: none;
  }

  .message-row.user .bubble,
  .message-row.user .avatar {
    grid-column: auto;
    grid-row: auto;
  }
}
