:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f3f6;
  --line: #d9dee7;
  --line-strong: #b9c2cf;
  --text: #151922;
  --muted: #687386;
  --subtle: #8b96a8;
  --blue: #2563eb;
  --blue-ink: #153b91;
  --green: #0f8b6f;
  --amber: #b7791f;
  --red: #d64545;
  --shadow: 0 18px 45px rgba(20, 30, 50, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: 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;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

.app {
  min-height: 100vh;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 460px) minmax(420px, 1fr);
  background: #0f172a;
}

.login-panel {
  background: var(--surface);
  padding: 56px 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-visual {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(120deg, rgba(37, 99, 235, 0.92), rgba(15, 139, 111, 0.86)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='700' viewBox='0 0 900 700'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.34'%3E%3Cpath d='M90 110h340v80H90zM110 230h520v52H110zM110 310h470v52H110zM110 390h560v52H110zM110 510h210v54H110zM360 510h210v54H360zM610 510h160v54H610z'/%3E%3Cpath d='M665 92h125v125H665zM695 122h65v65h-65z'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
}

.login-visual-copy {
  position: absolute;
  left: 56px;
  right: 56px;
  bottom: 56px;
  color: #fff;
}

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

.mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: #111827;
  color: #fff;
  font-weight: 800;
}

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

.eyebrow {
  color: var(--blue);
  font-weight: 700;
  margin-bottom: 10px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.login-panel h1 {
  font-size: 34px;
  line-height: 1.12;
  margin-bottom: 12px;
}

.login-panel p,
.login-visual-copy p {
  color: var(--muted);
  line-height: 1.75;
}

.login-visual-copy p {
  color: rgba(255, 255, 255, 0.82);
  max-width: 640px;
}

.login-visual-copy h2 {
  font-size: 36px;
  line-height: 1.16;
  margin-bottom: 14px;
}

.form {
  margin-top: 28px;
  display: grid;
  gap: 14px;
}

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

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

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

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

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

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 9px 13px;
  border-radius: var(--radius);
  background: #e8edf5;
  color: var(--text);
  font-weight: 700;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.btn:hover {
  background: #dde5f0;
}

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

.btn.primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 12px 22px rgba(37, 99, 235, 0.22);
}

.btn.primary:hover {
  background: #1d4ed8;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.btn.danger {
  color: #fff;
  background: var(--red);
}

.btn.icon {
  width: 38px;
  padding: 0;
}

.hint {
  color: var(--subtle);
  font-size: 12px;
  line-height: 1.55;
}

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

.sidebar {
  background: #111827;
  color: #f8fafc;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sidebar .mark {
  background: #f8fafc;
  color: #111827;
}

.sidebar .brand-title {
  color: #fff;
}

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

.nav a {
  color: #cfd6e2;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
}

.nav a.active,
.nav a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.11);
}

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

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

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

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

.page-title-with-avatar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.owner-avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #111827, #2563eb);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.22);
}

.page-head h1 {
  font-size: 28px;
  margin-bottom: 8px;
}

.page-head p {
  color: var(--muted);
  line-height: 1.65;
}

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

.metric,
.agent-card,
.panel,
.message,
.conversation-item,
.admin-list-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric {
  padding: 16px;
}

.metric b {
  display: block;
  font-size: 24px;
  margin-top: 6px;
}

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

.agent-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  min-height: 214px;
  box-shadow: var(--shadow);
}

.agent-top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.agent-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: #e7f0ff;
  color: var(--blue-ink);
  display: grid;
  place-items: center;
  font-weight: 900;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e8f6f1;
  color: var(--green);
  font-size: 12px;
  font-weight: 750;
}

.badge.draft {
  background: #fff5df;
  color: var(--amber);
}

.badge.disabled {
  background: #f2f4f7;
  color: var(--muted);
}

.agent-card h3 {
  font-size: 18px;
  margin-bottom: 9px;
}

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

.add-agent-card {
  border-style: dashed;
  box-shadow: none;
  background: #fbfcfe;
}

.add-agent-card .agent-icon {
  background: #eef6f3;
  color: var(--green);
}

.chat-layout {
  height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
}

.chat-side {
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 18px;
  overflow: auto;
}

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

.chat-head {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 16px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.conversation-list {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.conversation-item {
  width: 100%;
  text-align: left;
  padding: 11px;
  background: #fff;
  color: var(--text);
}

.conversation-item.active,
.conversation-item:hover {
  border-color: var(--blue);
  background: #f3f7ff;
}

.messages {
  overflow: auto;
  padding: 24px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.empty-state {
  max-width: 720px;
  margin: 8vh auto 0;
  text-align: center;
}

.empty-state h2 {
  font-size: 28px;
  margin-bottom: 12px;
}

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

.message {
  width: min(760px, 92%);
  padding: 15px 16px;
  line-height: 1.75;
  white-space: pre-wrap;
  position: relative;
}

.message.user {
  margin-left: auto;
  background: #e9f1ff;
  border-color: #c8dbff;
}

.message.assistant {
  margin-right: auto;
}

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

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

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

.composer textarea {
  min-height: 52px;
  max-height: 160px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  outline: none;
  line-height: 1.6;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.admin-tabs a {
  text-decoration: none;
  color: var(--muted);
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
}

.admin-tabs a.active {
  color: #fff;
  background: #111827;
  border-color: #111827;
}

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

.panel {
  padding: 16px;
  min-width: 0;
}

.panel h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 {
  margin-bottom: 0;
}

.admin-list {
  display: grid;
  gap: 10px;
}

.admin-list-item {
  padding: 13px;
  display: grid;
  gap: 8px;
}

.admin-list-item header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: var(--radius);
}

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

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

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 240px;
  max-width: 420px;
  background: #111827;
  color: #fff;
  padding: 12px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
  z-index: 20;
}

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

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

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

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

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 4;
    flex-direction: row;
    align-items: center;
    overflow: auto;
  }

  .nav {
    display: flex;
  }

  .content {
    width: min(100% - 28px, 980px);
  }

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

  .chat-layout {
    height: auto;
  }

  .chat-side {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-main {
    min-height: calc(100vh - 180px);
  }
}

@media (max-width: 640px) {
  .login-panel {
    padding: 34px 22px;
  }

  .login-panel h1,
  .login-visual-copy h2 {
    font-size: 28px;
  }

  .page-head,
  .topbar,
  .chat-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-title-with-avatar {
    align-items: flex-start;
  }

  .topbar {
    height: auto;
    padding: 14px;
  }

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

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