:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #e5e8ef;
  --blue: #2563eb;
  --blue-2: #1d4ed8;
  --green: #12a150;
  --amber: #f59e0b;
  --red: #dc2626;
  --shadow: 0 18px 45px rgba(20, 32, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

#app {
  min-height: 100vh;
  display: flex;
}

.side {
  width: 264px;
  min-height: 100vh;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  background: #101828;
  color: #fff;
}

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

.brand.big {
  color: #fff;
}

.brandMark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #12a150);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #98a2b3;
  font-size: 13px;
  margin-top: 2px;
}

.side nav {
  display: grid;
  gap: 6px;
}

.side nav button,
.account .ghost {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  color: #cbd5e1;
  background: transparent;
  text-align: left;
}

.side nav button:hover,
.side nav button.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.account {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.account strong,
.account span {
  display: block;
  overflow-wrap: anywhere;
}

.account span {
  color: #98a2b3;
  font-size: 13px;
  margin: 4px 0 12px;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1,
.sectionBand h2,
.agentCard h3,
.loginPanel h1,
.agentIntro h2,
.panelHead h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.topActions,
.metricStrip,
.formActions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid #cdd7ff;
  border-radius: 999px;
  color: var(--blue);
  background: #eef4ff;
  font-size: 13px;
  white-space: nowrap;
}

.pill.ok {
  color: #067647;
  border-color: #b7ebc6;
  background: #ecfdf3;
}

.sectionBand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.sectionBand.slim {
  margin-top: 22px;
}

.metricStrip > div,
.stat {
  min-width: 132px;
  padding: 14px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.metricStrip strong,
.metricStrip span,
.stat span,
.stat strong {
  display: block;
}

.metricStrip strong,
.stat strong {
  font-size: 24px;
}

.metricStrip span,
.stat span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.agentGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.agentCard,
.tablePanel,
.editPanel,
.chatPane,
.historyPane,
.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.agentCard {
  min-height: 238px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.agentIcon,
.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef4ff;
  color: var(--blue);
  font-weight: 800;
}

.agentCard p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  flex: 1;
}

.primary,
.ghost {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 16px;
  border: 1px solid transparent;
}

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

.primary:hover {
  background: var(--blue-2);
}

.ghost {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.full {
  width: 100%;
}

.small {
  min-height: 30px;
  padding: 0 10px;
}

.loginPage {
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 26px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.95), rgba(16, 24, 40, 0.92)),
    radial-gradient(circle at 80% 20%, rgba(18, 161, 80, 0.45), transparent 32%);
}

.loginVisual {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1fr 420px;
  align-items: center;
  gap: 40px;
}

.loginVisual::before {
  content: "Text Agent Workbench";
  color: rgba(255, 255, 255, 0.16);
  font-size: 72px;
  font-weight: 800;
  line-height: 1.05;
}

.loginPanel {
  padding: 30px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.24);
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 14px;
  font-weight: 650;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.demoLine {
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.chatLayout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
  height: calc(100vh - 118px);
}

.historyPane,
.chatPane {
  min-height: 0;
}

.historyPane {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.historyList {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.historyList button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  text-align: left;
}

.historyList button.active {
  border-color: #9db7ff;
  background: #eef4ff;
}

.historyList strong,
.historyList span {
  display: block;
}

.historyList span,
.emptyText {
  color: var(--muted);
  font-size: 12px;
}

.chatPane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.agentIntro {
  padding: 18px 20px;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.agentIntro p {
  margin: 6px 0 0;
  color: var(--muted);
}

.messages {
  overflow: auto;
  padding: 22px;
}

.emptyState {
  max-width: 560px;
  margin: 80px auto;
  padding: 28px;
  border: 1px dashed #b7c7ea;
  border-radius: 8px;
  text-align: center;
  background: #f8fbff;
}

.emptyState p {
  color: var(--muted);
  line-height: 1.7;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

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

.message.user .bubble {
  background: #eef4ff;
}

.bubble {
  max-width: min(760px, 82%);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.bubble pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.7;
  font-family: inherit;
}

.copyBtn {
  margin-top: 10px;
  border: 0;
  color: var(--blue);
  background: transparent;
  padding: 0;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.statGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.adminGrid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 16px;
}

.tablePanel,
.editPanel {
  padding: 18px;
}

.tablePanel {
  max-width: 100%;
  overflow-x: auto;
}

.fullPanel,
.editPanel.wide {
  width: 100%;
}

.usageBlock {
  margin-bottom: 16px;
}

.panelHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panelHead span {
  color: var(--muted);
}

.listRows {
  display: grid;
  gap: 8px;
}

.rowButton {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fff;
  text-align: left;
}

.rowButton:hover {
  border-color: #9db7ff;
}

.rowButton strong,
.rowButton span {
  display: block;
}

.rowButton span {
  color: var(--muted);
  margin-top: 4px;
  font-size: 13px;
}

.fieldGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check input {
  width: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  color: #475467;
  background: #f8fafc;
}

.status {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #f2f4f7;
}

.status.success {
  color: #067647;
  background: #ecfdf3;
}

.status.error {
  color: #b42318;
  background: #fef3f2;
}

.status.warning {
  color: #b54708;
  background: #fffaeb;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #101828;
  box-shadow: var(--shadow);
}

.toast.error {
  background: var(--red);
}

.fatal {
  margin: auto;
  padding: 30px;
  text-align: center;
}

@media (max-width: 920px) {
  #app {
    display: block;
  }

  .side {
    width: 100%;
    min-height: auto;
  }

  .main {
    padding: 18px;
  }

  .sectionBand,
  .topbar,
  .agentIntro {
    align-items: stretch;
    flex-direction: column;
  }

  .metricStrip,
  .topActions {
    flex-wrap: wrap;
  }

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

  .loginVisual::before {
    font-size: 44px;
  }

  .chatLayout,
  .adminGrid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chatPane {
    min-height: 70vh;
  }

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

  .bubble {
    max-width: 88%;
  }
}
