:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-soft: #f9fbff;
  --text: #172033;
  --muted: #667085;
  --subtle: #98a2b3;
  --line: #d9e1ec;
  --line-soft: #edf1f7;
  --primary: #2167f3;
  --primary-strong: #174fc4;
  --primary-soft: #eaf1ff;
  --green: #14a46c;
  --green-soft: #e8f7f0;
  --amber: #b76e00;
  --amber-soft: #fff4dc;
  --red: #d92d20;
  --red-soft: #ffebe9;
  --violet: #6f42c1;
  --cyan: #007c89;
  --shadow: 0 12px 30px rgba(16, 24, 40, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(234, 241, 255, 0.9), rgba(246, 248, 251, 0) 320px),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

html,
body {
  overflow-x: hidden;
}

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

button {
  border: 0;
}

button:not(:disabled) {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 22px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--cyan));
  font-weight: 800;
}

.admin-login .brand-mark,
.admin-sidebar .brand-mark {
  background: linear-gradient(135deg, var(--violet), var(--primary-strong));
}

.brand-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.brand-subtitle,
.meta {
  color: var(--muted);
  font-size: 12px;
}

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

.nav button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.nav button.active {
  color: var(--primary-strong);
  background: var(--primary-soft);
  font-weight: 700;
}

.nav .nav-admin {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 248, 251, 0.84);
  backdrop-filter: blur(16px);
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.content {
  width: 100%;
  max-width: 1380px;
  margin: 0 auto;
  padding: 28px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
}

.login-visual {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 56px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(16, 24, 40, 0.94), rgba(23, 79, 196, 0.78)),
    url("data:image/svg+xml,%3Csvg width='900' height='720' viewBox='0 0 900 720' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='rgba(255,255,255,.2)'%3E%3Cpath d='M80 118h740M80 248h740M80 378h740M80 508h740M180 40v620M360 40v620M540 40v620M720 40v620'/%3E%3C/g%3E%3Crect x='112' y='106' width='268' height='92' rx='12' fill='rgba(255,255,255,.14)'/%3E%3Crect x='428' y='238' width='326' height='128' rx='12' fill='rgba(255,255,255,.12)'/%3E%3Crect x='170' y='412' width='520' height='88' rx='12' fill='rgba(255,255,255,.1)'/%3E%3C/svg%3E");
  background-size: cover;
}

.login-visual h1 {
  width: 100%;
  max-width: 680px;
  margin: 0;
  font-size: 44px;
  line-height: 1.12;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.login-visual p {
  width: 100%;
  max-width: 620px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 16px;
  line-height: 1.8;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.login-panel {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--panel);
}

.login-card {
  width: 100%;
  max-width: 360px;
  min-width: 0;
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 26px;
}

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

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

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

.input,
.textarea,
.select {
  width: 100%;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  outline: none;
}

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

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(33, 103, 243, 0.12);
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  font-weight: 700;
}

.button:hover {
  background: var(--primary-strong);
}

.button.secondary {
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
}

.button.secondary:hover {
  background: var(--panel-soft);
}

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

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

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

.hero-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(247, 250, 255, 0.96)),
    linear-gradient(90deg, rgba(33, 103, 243, 0.14), rgba(0, 124, 137, 0.12));
  box-shadow: var(--shadow);
}

.hero-strip h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.hero-strip p {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.stat {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat strong {
  display: block;
  margin-bottom: 6px;
  font-size: 24px;
}

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

.agent-card {
  min-height: 218px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.04);
}

.agent-card:hover {
  border-color: rgba(33, 103, 243, 0.45);
  transform: translateY(-1px);
  transition: 0.16s ease;
}

.agent-card h3,
.panel h3 {
  margin: 0;
  font-size: 17px;
}

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

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--line-soft);
  font-size: 12px;
}

.tag.green {
  color: var(--green);
  background: var(--green-soft);
}

.tag.amber {
  color: var(--amber);
  background: var(--amber-soft);
}

.tag.red {
  color: var(--red);
  background: var(--red-soft);
}

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

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.04);
}

.panel-header {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.conversation-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  overflow: auto;
  max-height: calc(100% - 58px);
}

.conversation-item {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.conversation-item.active,
.conversation-item:hover {
  background: var(--primary-soft);
}

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

.guide {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.messages {
  overflow: auto;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(249, 251, 255, 0.98), rgba(255, 255, 255, 0.98));
}

.empty-state {
  max-width: 680px;
  margin: 64px auto;
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 10px;
}

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

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

.avatar.user {
  background: #344054;
}

.bubble {
  padding: 14px 15px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

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

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

.composer textarea {
  min-height: 54px;
  max-height: 180px;
}

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

.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  overflow-x: auto;
}

.tab {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  white-space: nowrap;
}

.tab.active {
  color: var(--primary-strong);
  border-color: rgba(33, 103, 243, 0.4);
  background: var(--primary-soft);
  font-weight: 700;
}

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

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

.table th {
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 12px;
  font-weight: 800;
}

.table td {
  font-size: 14px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

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

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .nav .nav-admin {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

  .login-visual {
    min-height: 360px;
  }

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

  .chat-layout {
    height: auto;
  }

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

@media (max-width: 680px) {
  .content,
  .topbar,
  .login-visual,
  .login-panel {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav,
  .grid,
  .stat-row,
  .hero-strip,
  .split-fields,
  .composer-box {
    grid-template-columns: 1fr;
  }

  .login-page {
    display: block;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
  }

  .login-visual,
  .login-panel {
    width: 100%;
    max-width: 100vw;
  }

  .login-visual h1 {
    max-width: min(calc(100vw - 36px), 320px);
    font-size: 28px;
    line-height: 1.18;
    word-break: break-all;
  }

  .login-visual p {
    max-width: min(calc(100vw - 36px), 320px);
  }

  .login-visual .tag-row {
    max-width: min(calc(100vw - 36px), 320px);
  }

  .login-card {
    max-width: min(100%, 320px);
  }

  .login-visual .tag {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
