:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #eef3f8;
  --line: #dbe4ee;
  --line-strong: #c5d2df;
  --text: #152033;
  --muted: #617089;
  --muted-2: #8290a3;
  --primary: #1368e8;
  --primary-strong: #0b55c4;
  --primary-soft: #e8f1ff;
  --teal: #0f9f8f;
  --teal-soft: #e6f7f4;
  --amber: #b97912;
  --amber-soft: #fff6df;
  --red: #d64545;
  --red-soft: #fff0f0;
  --green: #178a58;
  --green-soft: #e9f7ef;
  --shadow: 0 18px 45px rgba(26, 43, 71, 0.08);
  --radius: 8px;
  --sidebar: 248px;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(246, 248, 251, 0.2), rgba(246, 248, 251, 1)),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

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

button {
  border: 0;
}

a {
  color: inherit;
}

.boot-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  color: var(--muted);
}

.login-page {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  background: #f6f8fb;
}

.login-visual {
  position: relative;
  display: flex;
  min-height: 100%;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: 56px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(11, 85, 196, 0.88), rgba(15, 159, 143, 0.76)),
    url("/brand-texture.svg") center/cover;
}

.login-visual::after {
  position: absolute;
  inset: auto 0 0;
  height: 34%;
  background: linear-gradient(180deg, transparent, rgba(4, 20, 42, 0.24));
  content: "";
}

.login-brand,
.login-copy,
.login-metrics {
  position: relative;
  z-index: 1;
}

.logo-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: #101b2d;
  color: #fff;
  font-weight: 800;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 17px;
  font-weight: 700;
}

.login-copy {
  max-width: 520px;
}

.login-copy h1 {
  margin: 0 0 16px;
  font-size: 44px;
  line-height: 1.08;
  font-weight: 760;
}

.login-copy p {
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 16px;
  line-height: 1.8;
}

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

.metric-tile {
  min-height: 92px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(18px);
}

.metric-tile strong {
  display: block;
  margin-bottom: 8px;
  font-size: 24px;
}

.metric-tile span {
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
}

.login-form-wrap {
  display: grid;
  place-items: center;
  padding: 40px;
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card-header,
.panel-header,
.section-header {
  padding: 24px 24px 16px;
}

.login-card h2,
.page-title h1,
.panel-header h2,
.section-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: 0;
}

.login-card p,
.page-title p,
.panel-header p,
.section-header p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.form,
.login-form {
  display: grid;
  gap: 16px;
  padding: 8px 24px 24px;
}

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

.field label {
  color: #344057;
  font-size: 13px;
  font-weight: 650;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  background: #fff;
  color: var(--text);
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.input,
.select {
  padding: 0 12px;
}

.textarea {
  min-height: 96px;
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.65;
}

.textarea.code {
  min-height: 178px;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", "Microsoft YaHei Mono", monospace;
  font-size: 12px;
}

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

.hint {
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.5;
}

.error-box,
.success-box {
  display: none;
  padding: 11px 12px;
  border-radius: var(--radius);
  line-height: 1.55;
}

.error-box.show {
  display: block;
  border: 1px solid #f0b9b9;
  background: var(--red-soft);
  color: #a53232;
}

.success-box.show {
  display: block;
  border: 1px solid #bce1cd;
  background: var(--green-soft);
  color: #0f6b43;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(22px);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid var(--line);
}

.sidebar-brand strong {
  display: block;
  font-size: 15px;
}

.sidebar-brand span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav-group {
  display: grid;
  gap: 4px;
  padding: 14px 12px;
}

.nav-label {
  padding: 10px 10px 6px;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.nav-item,
.icon-button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition:
    background 0.18s ease,
    color 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease;
}

.nav-item {
  justify-content: flex-start;
  padding: 0 10px;
  color: #3c485f;
}

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

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.user-mini {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.avatar {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--primary-strong);
  font-weight: 760;
}

.user-mini strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

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

.main {
  min-width: 0;
}

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

.page-title h1 {
  font-size: 20px;
}

.page-title p {
  margin-top: 3px;
  font-size: 13px;
}

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

.content {
  padding: 28px;
}

.button {
  min-width: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  background: #fff;
  color: #27344b;
  font-weight: 650;
}

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

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

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

.button.secondary {
  border-color: var(--line);
}

.button.ghost {
  background: transparent;
}

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

.button[disabled] {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  stroke-width: 2;
}

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

.stat-card,
.panel,
.agent-card,
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(26, 43, 71, 0.05);
}

.stat-card {
  min-height: 112px;
  padding: 18px;
}

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

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.stat-card small {
  display: block;
  margin-top: 10px;
  color: var(--muted-2);
}

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

.agent-card {
  display: flex;
  min-height: 220px;
  flex-direction: column;
  padding: 18px;
}

.agent-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.agent-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.agent-card h2 {
  margin: 16px 0 8px;
  font-size: 18px;
}

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

.agent-card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  padding-top: 18px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

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

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

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

.pill.blue {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

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

.conversation-rail,
.chat-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(26, 43, 71, 0.05);
}

.conversation-rail {
  display: flex;
  flex-direction: column;
}

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

.conversation-list {
  display: grid;
  gap: 6px;
  overflow: auto;
  padding: 10px;
}

.conversation-item {
  display: grid;
  gap: 4px;
  padding: 11px 10px;
  border-radius: var(--radius);
  cursor: pointer;
}

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

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

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

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

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

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

.chat-agent-header p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.message-list {
  overflow: auto;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(248, 250, 252, 0.6), rgba(255, 255, 255, 0.7)),
    #fff;
}

.empty-chat {
  display: grid;
  min-height: 100%;
  place-items: center;
}

.empty-chat-inner {
  width: min(680px, 100%);
  text-align: center;
}

.empty-chat-inner .agent-icon {
  margin: 0 auto 18px;
}

.empty-chat h2 {
  margin: 0 0 10px;
  font-size: 26px;
}

.empty-chat p {
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}

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

.message-row.user {
  grid-template-columns: minmax(0, 760px) 36px;
  justify-content: end;
}

.message-avatar {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 750;
}

.message-row.user .message-avatar {
  grid-column: 2;
  background: var(--primary);
  color: #fff;
}

.message-bubble {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px 14px 12px;
  line-height: 1.72;
}

.message-content {
  white-space: pre-wrap;
}

.message-row.user .message-bubble {
  grid-column: 1;
  grid-row: 1;
  border-color: rgba(19, 104, 232, 0.22);
  background: var(--primary-soft);
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

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

.composer-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface-soft);
}

.composer textarea {
  min-height: 58px;
  max-height: 180px;
  border: 0;
  outline: none;
  resize: vertical;
  background: transparent;
  line-height: 1.65;
}

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

.panel {
  overflow: hidden;
}

.panel-body {
  padding: 0 18px 18px;
}

.table-wrap {
  overflow: auto;
}

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

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

.table th {
  background: var(--surface-soft);
  color: #46536a;
  font-size: 12px;
  font-weight: 760;
}

.table td {
  color: #2b374d;
  line-height: 1.55;
}

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

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

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

details.advanced {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

details.advanced summary {
  cursor: pointer;
  padding: 11px 12px;
  color: #344057;
  font-weight: 700;
}

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

.loading-line {
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

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

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

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

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

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

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

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-group {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }

  .nav-label,
  .sidebar-footer {
    display: none;
  }

  .topbar {
    padding: 0 16px;
  }

  .content {
    padding: 16px;
  }

  .agent-grid,
  .stats-grid,
  .chat-layout,
  .two-col,
  .advanced-grid {
    grid-template-columns: 1fr;
  }

  .conversation-rail {
    max-height: 260px;
  }
}

@media (max-width: 560px) {
  .login-form-wrap {
    padding: 18px;
  }

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

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

  .message-avatar {
    display: none;
  }

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