:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #151922;
  --muted: #626b7a;
  --subtle: #8a93a3;
  --line: #dde2ea;
  --line-strong: #c7ceda;
  --primary: #176bff;
  --primary-strong: #0c55d9;
  --primary-soft: #e9f1ff;
  --teal: #0f9f8f;
  --teal-soft: #e4f7f4;
  --amber: #b7791f;
  --amber-soft: #fff5df;
  --red: #d64545;
  --red-soft: #fff0f0;
  --shadow: 0 18px 50px rgba(20, 29, 43, 0.08);
  --radius: 8px;
  --sidebar: 264px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.page {
  min-height: 100vh;
}

.entry-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(420px, 1.1fr);
  gap: 28px;
  align-items: center;
  width: min(1180px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 48px 0;
}

.entry-hero h1 {
  margin: 24px 0 16px;
  font-size: 42px;
  line-height: 1.12;
}

.entry-hero p {
  margin: 0;
  max-width: 520px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.8;
}

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

.entry-card {
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.entry-card.admin {
  border-top: 4px solid var(--primary);
}

.entry-kicker {
  color: var(--muted);
  font-weight: 760;
}

.entry-card h2 {
  margin: 28px 0 10px;
  font-size: 24px;
}

.entry-card p {
  margin: 0 0 28px;
  color: var(--muted);
  line-height: 1.75;
}

.login-page {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 480px);
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(23, 107, 255, 0.08), rgba(15, 159, 143, 0.08)),
    var(--bg);
}

.login-brand {
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--line);
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-weight: 800;
}

.brand-copy {
  max-width: 640px;
}

.brand-copy h1 {
  margin: 0 0 18px;
  font-size: 46px;
  line-height: 1.08;
  letter-spacing: 0;
}

.brand-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.8;
}

.login-panel {
  display: flex;
  align-items: center;
  padding: 40px;
  background: var(--surface);
}

.login-box {
  width: 100%;
}

.login-box h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.login-box .hint {
  color: var(--muted);
  margin: 0 0 28px;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 56px 1fr;
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left,
.topbar-right,
.nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.product-name {
  font-weight: 760;
  margin-right: 8px;
}

.nav a,
.tab {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
}

.nav a.active,
.tab.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--line);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 760;
}

.content {
  width: min(1280px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-head h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.2;
}

.section-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

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

.agent-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-height: 188px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.agent-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

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

.agent-title h2 {
  margin: 0;
  font-size: 18px;
}

.agent-card p {
  color: var(--muted);
  line-height: 1.7;
  margin: 14px 0 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 12px;
  white-space: nowrap;
}

.badge.active {
  background: var(--teal-soft);
  color: #087468;
  border-color: #bbe7df;
}

.badge.draft {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: #f5dda6;
}

.badge.disabled,
.badge.error {
  background: var(--red-soft);
  color: var(--red);
  border-color: #ffd2d2;
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

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

.btn.primary:hover {
  border-color: var(--primary-strong);
  background: var(--primary-strong);
}

.btn.save-wide {
  width: 100%;
  min-height: 48px;
  font-size: 16px;
  font-weight: 760;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.btn.danger {
  border-color: #ffd2d2;
  color: var(--red);
  background: var(--red-soft);
}

.btn.icon {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

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

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

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 46px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
}

.password-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  line-height: 1.5;
}

.checkline input {
  width: 16px;
  height: 16px;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.6;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 255, 0.12);
}

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: #19427f;
  border: 1px solid #cfe0ff;
  line-height: 1.6;
}

.notice.compact {
  padding: 9px 11px;
  font-size: 12px;
}

.notice.error {
  background: var(--red-soft);
  color: var(--red);
  border-color: #ffd2d2;
}

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

.conversation-panel,
.chat-panel,
.admin-panel,
.table-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.conversation-panel {
  padding: 14px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 15px;
}

.conversation-list {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.conversation-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 10px;
  color: var(--muted);
}

.conversation-item.active {
  background: var(--primary-soft);
  color: var(--text);
  border-color: #cfe0ff;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 680px;
  overflow: hidden;
}

.chat-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chat-header h1 {
  margin: 0 0 4px;
  font-size: 18px;
}

.chat-header p {
  margin: 0;
  color: var(--muted);
}

.messages {
  padding: 22px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 14px;
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    linear-gradient(180deg, rgba(23, 107, 255, 0.04), rgba(15, 159, 143, 0.04)) border-box;
}

.empty-chat {
  align-self: center;
  justify-self: center;
  max-width: 640px;
  text-align: center;
  color: var(--muted);
  line-height: 1.7;
}

.empty-chat h2 {
  color: var(--text);
  margin: 0 0 10px;
}

.message {
  display: grid;
  gap: 7px;
  max-width: 820px;
}

.message.user {
  justify-self: end;
}

.message.assistant {
  justify-self: start;
}

.message-meta {
  color: var(--subtle);
  font-size: 12px;
}

.bubble {
  border-radius: 8px;
  padding: 13px 14px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--primary);
  color: #fff;
}

.message.assistant .bubble {
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.composer {
  border-top: 1px solid var(--line);
  padding: 14px;
  background: var(--surface);
}

.composer textarea {
  min-height: 78px;
  max-height: 220px;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 12px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 16px;
}

.admin-tabs {
  display: grid;
  align-content: start;
  gap: 8px;
}

.admin-panel {
  padding: 18px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
  gap: 16px;
}

.table-panel {
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.table-toolbar h2 {
  margin: 0 0 4px;
  font-size: 16px;
}

.table-toolbar p {
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  background: var(--surface-2);
}

td {
  line-height: 1.55;
}

tr.row-selected td {
  background: var(--primary-soft);
}

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

.truncate {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loading {
  min-height: 240px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

@media (max-width: 980px) {
  .login-page,
  .entry-page,
  .chat-layout,
  .admin-layout,
  .split {
    grid-template-columns: 1fr;
  }

  .entry-page {
    width: min(100vw - 24px, 1180px);
    align-items: start;
  }

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

  .login-brand {
    padding: 32px 24px;
    min-height: 320px;
  }

  .login-panel {
    padding: 24px;
  }

  .brand-copy h1 {
    font-size: 34px;
  }

  .agent-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .table-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .content {
    width: min(100vw - 24px, 1280px);
    padding-top: 18px;
  }

  .topbar {
    padding: 0 12px;
  }

  .product-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-right {
    gap: 4px;
  }

  .user-chip {
    font-size: 0;
    gap: 0;
  }

  .user-chip .avatar {
    font-size: 13px;
  }

  .topbar .btn {
    padding: 0 8px;
  }

  .nav {
    display: none;
  }
}
