:root {
  color-scheme: light;
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-raised: #f8fafb;
  --surface-tint: #eff6f3;
  --ink: #17211d;
  --text: #26322e;
  --muted: #66736e;
  --subtle: #8a9691;
  --line: #dbe3df;
  --line-strong: #c3d0ca;
  --primary: #0d7462;
  --primary-strong: #095b4d;
  --primary-soft: #e2f2ee;
  --accent: #d9543f;
  --accent-soft: #fff0ec;
  --info: #255fc9;
  --info-soft: #e8efff;
  --warning: #a85d11;
  --warning-soft: #fff5e6;
  --danger: #be3830;
  --danger-soft: #fff0ee;
  --success: #0d7462;
  --success-soft: #e2f2ee;
  --shadow-sm: 0 8px 22px rgba(20, 32, 29, 0.07);
  --shadow-md: 0 18px 48px rgba(20, 32, 29, 0.12);
  --radius: 8px;
  --sidebar: 264px;
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(13, 116, 98, 0.08), rgba(13, 116, 98, 0) 360px),
    var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(13, 116, 98, 0.22);
  outline-offset: 2px;
}

a {
  color: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: #11201c;
  color: #f7fbf9;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.brand {
  padding: 8px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

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

.brand-mark,
.avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
}

.brand-mark {
  background: #ffffff;
  color: #11201c;
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
}

.brand-subtitle {
  margin-top: 2px;
  color: #b9c9c3;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 5px;
}

.nav a,
.logout-button {
  min-height: 40px;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #dce8e4;
  text-align: left;
  text-decoration: none;
  transition: background 150ms ease, color 150ms ease;
}

.nav a:hover,
.logout-button:hover,
.nav a.active {
  background: rgba(255, 255, 255, 0.11);
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.user-chip {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  color: #dce8e4;
  font-size: 12px;
}

.user-chip strong,
.user-chip span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip span {
  margin-top: 3px;
  color: #b9c9c3;
}

.main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 66px;
  padding: 0 28px;
  border-bottom: 1px solid rgba(195, 208, 202, 0.82);
  background: rgba(238, 242, 245, 0.9);
  backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  color: var(--ink);
  font-size: 20px;
  line-height: 1.3;
  letter-spacing: 0;
}

.topbar-meta {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.content {
  min-width: 0;
  padding: 24px 28px 34px;
}

.mobile-nav {
  display: none;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(380px, 0.92fr);
  background:
    linear-gradient(120deg, rgba(13, 116, 98, 0.16), rgba(37, 95, 201, 0.08) 48%, rgba(217, 84, 63, 0.08)),
    #f4f7f6;
}

.login-visual {
  min-width: 0;
  padding: 54px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
}

.login-copy h1 {
  max-width: 720px;
  margin: 26px 0 0;
  color: var(--ink);
  font-size: 52px;
  line-height: 1.08;
  letter-spacing: 0;
}

.login-copy p {
  max-width: 660px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.8;
}

.signal-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-width: 760px;
}

.signal {
  min-height: 126px;
  padding: 18px;
  border: 1px solid rgba(195, 208, 202, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow-sm);
}

.signal b {
  display: block;
  margin-bottom: 12px;
  color: var(--ink);
  font-size: 28px;
}

.signal span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 28px;
}

.auth-card {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.auth-card h2,
.section-head h2,
.chat-header h2,
.form-panel h3 {
  margin: 0;
  color: var(--ink);
  letter-spacing: 0;
}

.auth-card h2 {
  font-size: 25px;
}

.auth-card p,
.section-head p,
.chat-header p,
.muted {
  color: var(--muted);
  line-height: 1.65;
}

.auth-card p {
  margin: 7px 0 24px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.field span,
.field label {
  color: #394942;
  font-size: 13px;
  font-weight: 700;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.textarea {
  min-height: 108px;
  resize: vertical;
  line-height: 1.65;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 116, 98, 0.14);
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--primary);
  color: #ffffff;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 120ms ease, background 150ms ease, border 150ms ease, box-shadow 150ms ease;
}

.button:hover {
  background: var(--primary-strong);
  box-shadow: 0 8px 18px rgba(13, 116, 98, 0.18);
}

.button:active {
  transform: translateY(1px);
}

.button.secondary {
  border-color: var(--line-strong);
  background: #ffffff;
  color: var(--text);
}

.button.secondary:hover {
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--primary);
}

.button.ghost:hover {
  background: var(--primary-soft);
  box-shadow: none;
}

.button.danger {
  background: var(--danger);
}

.button.danger:hover {
  background: #9f2e28;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  box-shadow: none;
}

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

.section-head h2 {
  font-size: 25px;
}

.section-head p {
  margin: 6px 0 0;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

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

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.agent-card {
  min-height: 242px;
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 13px;
}

.agent-card-top,
.conversation-item-top,
.row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.agent-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 19px;
}

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

.agent-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: #56625e;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.badge.active,
.badge.enabled,
.badge.success {
  border-color: rgba(13, 116, 98, 0.24);
  background: var(--success-soft);
  color: var(--success);
}

.badge.draft,
.badge.warning {
  border-color: rgba(168, 93, 17, 0.25);
  background: var(--warning-soft);
  color: var(--warning);
}

.badge.disabled,
.badge.error {
  border-color: rgba(190, 56, 48, 0.2);
  background: var(--danger-soft);
  color: var(--danger);
}

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

.conversation-list {
  min-width: 0;
  padding: 14px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
}

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

.conversation-item:hover,
.conversation-item.active {
  border-color: var(--line);
  background: var(--surface-raised);
}

.conversation-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.conversation-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.chat-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

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

.chat-header h2 {
  font-size: 21px;
}

.chat-header p {
  margin: 5px 0 0;
}

.messages {
  min-width: 0;
  padding: 20px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 16px;
  background:
    linear-gradient(180deg, #ffffff, #f7faf8),
    var(--surface);
}

.message {
  min-width: 0;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
}

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

.message.user .avatar {
  grid-column: 2;
  background: #31443e;
}

.message.user > div:not(.avatar) {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
}

.message.assistant .avatar {
  background: var(--primary-soft);
  color: var(--primary);
}

.bubble {
  max-width: min(820px, 100%);
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: #31443e;
  border-color: #31443e;
  color: #ffffff;
}

.message-tools {
  margin-top: 8px;
}

.typing {
  display: inline-grid;
  grid-template-columns: repeat(3, 6px);
  gap: 4px;
  align-items: center;
  min-height: 22px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--primary);
  opacity: 0.35;
  animation: pulse 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 120ms;
}

.typing span:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

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

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.composer textarea {
  min-height: 74px;
  max-height: 190px;
}

.composer-hint {
  margin-top: 8px;
  color: var(--subtle);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-raised);
  color: #56625e;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

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

.form-panel {
  padding: 16px;
  position: sticky;
  top: 86px;
}

.form-panel h3 {
  margin-bottom: 14px;
}

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

.metric {
  padding: 16px;
}

.metric b {
  display: block;
  color: var(--ink);
  font-size: 27px;
  margin-bottom: 4px;
}

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

.empty {
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.empty-panel {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  max-width: min(440px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #11201c;
  color: #ffffff;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .agent-grid,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }
}

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

  .sidebar {
    display: none;
  }

  .mobile-nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .mobile-nav a {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 8px 10px;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    background: var(--surface-raised);
  }

  .mobile-nav a.active {
    background: var(--primary);
    color: #ffffff;
  }

  .topbar {
    position: static;
    min-height: 62px;
    padding: 0 16px;
  }

  .topbar-meta > span:first-child {
    display: none;
  }

  .content {
    padding: 18px 16px 26px;
  }

  .login-page {
    grid-template-columns: 1fr;
  }

  .login-visual {
    padding: 32px 22px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .login-copy h1 {
    font-size: 36px;
  }

  .signal-board,
  .agent-grid,
  .metric-grid,
  .grid.two {
    grid-template-columns: 1fr;
  }

  .chat-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .conversation-list {
    max-height: 236px;
  }

  .chat-panel {
    min-height: 630px;
  }

  .chat-header,
  .section-head {
    align-items: start;
    flex-direction: column;
  }

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

@media (max-width: 520px) {
  .auth-card,
  .login-panel {
    padding: 18px;
  }

  .signal {
    min-height: 0;
  }

  .agent-card-foot,
  .toolbar,
  .row-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .button {
    width: 100%;
  }

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

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

  .message.user > div:not(.avatar) {
    grid-column: 2;
    justify-self: stretch;
  }

  .avatar {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
  }
}
