:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafd;
  --text: #172033;
  --muted: #687386;
  --line: #e2e8f0;
  --blue: #1f6feb;
  --blue-strong: #1557c0;
  --green: #0f9f6e;
  --red: #d92d20;
  --amber: #b7791f;
  --shadow: 0 18px 45px rgba(21, 32, 51, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select {
  font: inherit;
}
button {
  border: 0;
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
  opacity: .55;
}
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, .12);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) 460px;
  background: #fff;
}
.login-visual {
  position: relative;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(15, 23, 42, .84), rgba(15, 23, 42, .35)),
    url("https://images.unsplash.com/photo-1516321318423-f06f85e504b3?auto=format&fit=crop&w=1600&q=80") center/cover;
}
.login-visual-overlay {
  height: 100%;
  padding: 56px;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 24px;
  max-width: 760px;
}
.login-visual h1 {
  font-size: 48px;
  line-height: 1.08;
  margin: 0;
  font-weight: 760;
  letter-spacing: 0;
}
.login-visual p {
  max-width: 580px;
  color: rgba(255,255,255,.82);
  font-size: 18px;
  line-height: 1.7;
  margin: 0;
}
.hero-brand { position: absolute; top: 42px; left: 56px; color: #fff; }
.metric-strip {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.metric-strip span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 8px;
  background: rgba(255,255,255,.1);
  backdrop-filter: blur(12px);
}
.login-panel {
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
}
.login-panel h2 {
  margin: 0 0 8px;
  font-size: 32px;
}
.login-entry-list {
  display: grid;
  gap: 14px;
}
.login-entry-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  grid-template-areas:
    "icon title"
    "icon desc";
  gap: 4px 12px;
  align-items: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .04);
}
.login-entry-card:hover {
  border-color: rgba(31,111,235,.42);
  box-shadow: var(--shadow);
}
.login-entry-card strong {
  grid-area: title;
  font-size: 18px;
}
.login-entry-card small {
  grid-area: desc;
  color: var(--muted);
  line-height: 1.6;
}
.entry-icon {
  grid-area: icon;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eaf2ff;
  color: var(--blue);
  font-weight: 800;
}
.login-entry-card.admin .entry-icon {
  background: #e8fbf7;
  color: #0f9f6e;
}
.back-link {
  width: fit-content;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}
.back-link:hover,
.login-switch a {
  color: var(--blue);
}
.login-switch {
  text-align: center;
  line-height: 1.6;
}
label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
  color: #334155;
}
.demo-accounts {
  display: flex;
  gap: 10px;
}
.demo-accounts button {
  flex: 1;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--muted);
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}
.sidebar {
  background: #0f172a;
  color: #dce5f7;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2f80ed, #00b3a4);
  color: white;
  font-weight: 800;
}
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: #91a0ba; margin-top: 2px; }
.nav {
  display: grid;
  gap: 6px;
}
.nav a {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #aebbd1;
}
.nav a.active, .nav a:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.nav-icon {
  width: 18px;
  text-align: center;
  color: #7dd3fc;
}
.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 12px;
}
.user-chip {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
}
.user-chip strong {
  display: block;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-chip small { color: #91a0ba; }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #20304f;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
}
.main {
  min-width: 0;
  background: var(--bg);
}
.page {
  padding: 32px;
}
.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
}
.page-heading h1, .chat-header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}
.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}
.muted {
  color: var(--muted);
  margin: 0;
}
.toolbar { display: flex; gap: 10px; }
.primary, .secondary, .ghost, .danger {
  min-height: 38px;
  padding: 9px 14px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  border: 1px solid transparent;
}
.primary {
  background: var(--blue);
  color: #fff;
}
.primary:hover { background: var(--blue-strong); }
.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}
.ghost {
  background: transparent;
  color: #dce5f7;
  border-color: rgba(255,255,255,.16);
}
.danger {
  background: #fff1f0;
  color: var(--red);
  border-color: #ffccc7;
}
.large { min-height: 46px; font-size: 15px; }
.full { width: 100%; }
.mini {
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 6px;
  background: #eef4ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
  margin-right: 6px;
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.agent-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .04);
}
.agent-card:hover {
  border-color: rgba(31,111,235,.35);
  box-shadow: var(--shadow);
}
.agent-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.agent-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eaf2ff;
  color: var(--blue);
  font-weight: 800;
}
.agent-icon.large {
  width: 56px;
  height: 56px;
  margin: auto;
}
.agent-card h2 {
  margin: 0;
  font-size: 18px;
}
.agent-card p {
  min-height: 72px;
  color: var(--muted);
  line-height: 1.65;
  margin: 0;
}
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  background: #eef2f7;
  color: #475569;
}
.status.active, .status.success { background: #e7f8f0; color: var(--green); }
.status.error, .status.disabled { background: #fff1f0; color: var(--red); }
.status.draft { background: #fff7e6; color: var(--amber); }

.chat-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 284px minmax(0, 1fr);
}
.conversation-panel {
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}
.conversation-list {
  overflow: auto;
  display: grid;
  gap: 8px;
}
.conversation-item {
  text-align: left;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: #fff;
  display: grid;
  gap: 4px;
}
.conversation-item:hover, .conversation-item.active {
  background: #f3f7ff;
  border-color: #d6e5ff;
}
.conversation-item strong {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.conversation-item small { color: var(--muted); }
.chat-main {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: 24px 28px;
  gap: 14px;
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.chat-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.guide-box {
  background: #eef6ff;
  border: 1px solid #d8eaff;
  border-radius: 8px;
  padding: 12px 14px;
  color: #22436f;
  display: flex;
  gap: 10px;
  line-height: 1.6;
}
.guide-box strong { white-space: nowrap; }
.messages {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 6px;
}
.message {
  max-width: min(820px, 92%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
  box-shadow: 0 4px 18px rgba(15, 23, 42, .04);
}
.message.user {
  align-self: flex-end;
  background: #1f6feb;
  color: #fff;
  border-color: #1f6feb;
}
.message.assistant { align-self: flex-start; }
.message-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}
.message.user .message-meta { color: rgba(255,255,255,.72); }
.message pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
  font-family: inherit;
}
.empty-chat {
  margin: auto;
  text-align: center;
  max-width: 460px;
  color: var(--muted);
}
.empty-chat h2 { margin-bottom: 8px; color: var(--text); }
.composer {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.composer textarea {
  border: 0;
  box-shadow: none;
  padding: 4px;
  min-height: 84px;
}
.composer-actions {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.tabs a {
  padding: 12px 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-weight: 700;
}
.tabs a.active {
  color: var(--blue);
  border-color: var(--blue);
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.stat, .panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .04);
}
.stat {
  padding: 16px;
  display: grid;
  gap: 6px;
}
.stat span, .stat small { color: var(--muted); }
.stat strong { font-size: 28px; }
.panel {
  padding: 18px;
  min-width: 0;
}
.panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}
.two-col, .admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, .7fr);
  gap: 16px;
}
.row-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  margin: 0;
}
.table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}
.tr {
  display: grid;
  grid-template-columns: 1.4fr .7fr .5fr 1fr;
  gap: 12px;
  align-items: center;
  min-width: 720px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.tr:last-child { border-bottom: 0; }
.tr.head {
  background: var(--surface-soft);
  color: #475569;
  font-weight: 800;
  font-size: 12px;
}
.tr small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}
.model-table .tr {
  grid-template-columns: 1fr 1fr 1.35fr 1.2fr .5fr 1fr;
  min-width: 1060px;
}
.usage-table .tr {
  grid-template-columns: 1fr .6fr .7fr .7fr 2fr;
  min-width: 860px;
}
.stack-form {
  display: grid;
  gap: 14px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
summary {
  cursor: pointer;
  font-weight: 750;
}
details .form-row { margin-top: 12px; }
.switch {
  display: inline-flex;
}
.switch input { display: none; }
.switch i {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
}
.switch i::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: #fff;
  transition: transform .16s ease;
}
.switch input:checked + i { background: var(--blue); }
.switch input:checked + i::after { transform: translateX(16px); }
.inline-check {
  display: inline-flex;
  grid-template-columns: auto;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
  font-weight: 600;
}
.inline-check input { width: auto; }
.empty-line {
  color: var(--muted);
  margin: 0;
  padding: 12px;
}
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  background: #0f172a;
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition: all .18s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.error { background: var(--red); }

@media (max-width: 980px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-visual { min-height: 360px; }
  .login-panel { padding: 32px; }
  .login-visual-overlay { padding: 32px; }
  .login-visual h1 { font-size: 34px; }
  .hero-brand { top: 28px; left: 32px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    flex-direction: row;
    align-items: center;
    padding: 12px;
  }
  .nav { display: flex; }
  .sidebar-footer { margin-left: auto; margin-top: 0; grid-template-columns: 1fr auto; align-items: center; }
  .user-chip small { display: none; }
  .chat-shell { height: auto; min-height: calc(100vh - 70px); grid-template-columns: 1fr; }
  .conversation-panel { border-right: 0; border-bottom: 1px solid var(--line); max-height: 210px; }
  .chat-main { min-height: 760px; padding: 18px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col, .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .page { padding: 18px; }
  .page-heading, .chat-header, .composer-actions { flex-direction: column; align-items: stretch; }
  .sidebar {
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: hidden;
  }
  .brand {
    flex: 0 0 auto;
  }
  .brand > span:not(.brand-mark), .brand small, .user-chip { display: none; }
  .brand-mark {
    width: 32px;
    height: 32px;
  }
  .nav {
    flex: 1 0 auto;
  }
  .nav a {
    min-height: 34px;
    padding: 8px 9px;
    white-space: nowrap;
  }
  .sidebar-footer {
    display: block;
    margin-left: 0;
  }
  .sidebar-footer .ghost {
    width: auto;
    min-height: 34px;
    padding: 8px 10px;
    white-space: nowrap;
  }
  .stat-grid, .form-row { grid-template-columns: 1fr; }
  .message { max-width: 100%; }
}
