:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef1f4;
  --line: #d7dde5;
  --line-strong: #c5ccd8;
  --muted: #626b7a;
  --text: #172033;
  --heading: #070b14;
  --brand: #111827;
  --brand-2: #b8892f;
  --accent: #0f766e;
  --danger: #b42318;
  --warning: #a15c07;
  --ok: #067647;
  --shadow: 0 18px 48px rgba(17, 24, 39, 0.09);
  --shadow-soft: 0 8px 22px rgba(17, 24, 39, 0.06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #fafbfc 0%, var(--bg) 280px),
    var(--bg);
  color: var(--text);
  min-width: 320px;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

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

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

.admin-shell {
  grid-template-columns: 260px minmax(0, 1fr);
}

.admin-main {
  padding: 30px;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(17, 24, 39, 0.10);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(22px);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.brand h1,
.brand span {
  letter-spacing: 0;
}

.mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(145deg, #111827 0%, #252b36 58%, #b8892f 160%);
  color: white;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(17, 24, 39, 0.18);
}

.brand h1 {
  font-size: 16px;
  margin: 0;
  letter-spacing: 0;
}

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

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

.nav button,
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  color: #3b4350;
  background: transparent;
  text-align: left;
  font-weight: 650;
}

.nav .active,
.nav button:hover,
.nav a:hover {
  color: var(--brand);
  background: #f1f3f6;
  box-shadow: inset 3px 0 0 var(--brand-2);
}

.account {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.account .ghost {
  justify-content: center;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.title h2 {
  margin: 0;
  color: var(--heading);
  font-size: 26px;
  font-weight: 760;
  letter-spacing: 0;
}

.title p {
  margin: 6px 0 0;
  color: var(--muted);
}

.button,
.ghost,
.danger,
.icon-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  font-weight: 680;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.button {
  background: linear-gradient(180deg, #1f2937 0%, #0b1220 100%);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 12px 26px rgba(17, 24, 39, 0.18);
}

.button:hover {
  background: linear-gradient(180deg, #273241 0%, #101827 100%);
  transform: translateY(-1px);
}

.ghost {
  background: white;
  color: #2f3745;
  border: 1px solid var(--line);
}

.ghost:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

.danger {
  background: #fff5f4;
  color: var(--danger);
  border: 1px solid #f4c7c3;
}

.icon-button {
  width: 38px;
  padding: 0;
  background: white;
  border: 1px solid var(--line);
}

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

.agent-grid {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.agent-card,
.panel,
.stat,
.message,
.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.agent-card {
  min-height: 210px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  overflow: hidden;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.agent-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-2) 100%);
}

.agent-card:hover {
  border-color: var(--line-strong);
  box-shadow: 0 22px 54px rgba(17, 24, 39, 0.12);
  transform: translateY(-1px);
}

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

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

.agent-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f1f3f6;
  color: #303846;
  font-size: 12px;
  font-weight: 680;
}

.status-active {
  background: #ecfdf3;
  color: var(--ok);
}

.status-draft {
  background: #fffaeb;
  color: var(--warning);
}

.status-disabled {
  background: #f2f4f7;
  color: #475467;
}

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

.stat {
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.stat::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 16px;
  width: 28px;
  height: 2px;
  background: var(--brand-2);
}

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

.stat strong {
  display: block;
  margin-top: 8px;
  color: var(--heading);
  font-size: 30px;
  font-weight: 780;
}

.panel {
  padding: 18px;
  box-shadow: var(--shadow-soft);
}

.admin-main .panel,
.admin-main .stat {
  border-color: #dce2ea;
}

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

.panel-head h3 {
  margin: 0;
  font-size: 18px;
}

.panel-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.switch-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: #2f3745;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

.switch-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  padding: 2px;
  background: #d4dae3;
  transition: background 0.18s ease;
}

.switch-thumb {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: white;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.18);
  transition: transform 0.18s ease;
}

.switch-control input:checked + .switch-track {
  background: var(--brand);
}

.switch-control input:checked + .switch-track .switch-thumb {
  transform: translateX(16px);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

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

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

th {
  background: #f5f6f8;
  color: #4b5565;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

td {
  color: #303846;
}

tbody tr:hover td {
  background: #fbfcfd;
}

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

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

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

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

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

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

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

.input:focus,
.textarea:focus,
.select:focus {
  border-color: #111827;
  background: white;
  box-shadow: 0 0 0 4px rgba(184, 137, 47, 0.14);
}

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

.conversation-list {
  overflow: auto;
  display: grid;
  gap: 8px;
}

.conversation-item {
  width: 100%;
  min-height: 52px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfcfd;
  text-align: left;
  color: #344054;
}

.conversation-item.active {
  border-color: var(--brand-2);
  background: #fffaf0;
  color: var(--brand);
}

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

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

.chat-header {
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfd 100%);
  border-radius: 8px 8px 0 0;
}

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

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

.messages {
  overflow: auto;
  padding: 18px;
  display: grid;
  gap: 12px;
  align-content: start;
  background:
    linear-gradient(180deg, #f8fafb 0%, #f3f5f7 100%);
}

.message {
  padding: 14px;
  max-width: 78%;
  box-shadow: none;
}

.message.user {
  margin-left: auto;
  background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
  color: white;
  border-color: #111827;
}

.message.assistant {
  margin-right: auto;
  border-color: #dfe4ea;
}

.message-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 12px;
  opacity: 0.75;
}

.message pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  line-height: 1.7;
}

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

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

.notice {
  border-radius: 8px;
  border: 1px solid #e4c98d;
  background: #fffaf0;
  color: #7a4a09;
  padding: 10px 12px;
  line-height: 1.5;
}

.empty {
  border: 1px dashed #cbd3df;
  border-radius: 8px;
  padding: 28px;
  color: var(--muted);
  background: #f8fafb;
  text-align: center;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
}

.login-copy {
  background:
    linear-gradient(135deg, rgba(7, 11, 20, 0.86), rgba(17, 24, 39, 0.66)),
    url("https://images.unsplash.com/photo-1552664730-d307ca884978?auto=format&fit=crop&w=1400&q=80") center/cover;
  color: white;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 100vh;
}

.login-copy h1 {
  max-width: 760px;
  font-size: 48px;
  line-height: 1.08;
  margin: 0;
  letter-spacing: 0;
}

.login-copy p {
  max-width: 640px;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.7;
  margin: 18px 0 0;
}

.login-side {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, #ffffff 0%, #f6f7f9 100%);
}

.login-panel {
  width: min(420px, 100%);
  padding: 26px;
  border-color: #dfe4ea;
  box-shadow: 0 26px 70px rgba(17, 24, 39, 0.10);
}

.login-panel h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.login-panel p {
  margin: 0 0 18px;
  color: var(--muted);
}

.entry-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  background: white;
}

.entry-hero {
  background:
    linear-gradient(135deg, rgba(7, 11, 20, 0.86), rgba(17, 24, 39, 0.66)),
    url("https://images.unsplash.com/photo-1552664730-d307ca884978?auto=format&fit=crop&w=1400&q=80") center/cover;
  color: white;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.entry-hero h1 {
  max-width: 760px;
  font-size: 46px;
  line-height: 1.08;
  margin: 0;
  letter-spacing: 0;
}

.entry-hero p {
  max-width: 640px;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.7;
  margin: 18px 0 0;
}

.entry-actions {
  padding: 32px;
  display: grid;
  align-content: center;
  gap: 16px;
  background: #f3f5f7;
}

.entry-card {
  width: 100%;
  min-height: 164px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 22px;
  text-align: left;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow);
  color: var(--text);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.entry-card:hover {
  border-color: var(--line-strong);
  box-shadow: 0 22px 54px rgba(17, 24, 39, 0.12);
  transform: translateY(-1px);
}

.entry-card strong {
  color: var(--heading);
  font-size: 22px;
}

.entry-card em {
  color: var(--muted);
  font-style: normal;
  line-height: 1.6;
}

.entry-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f1f3f6;
  color: var(--brand);
}

.entry-card.admin .entry-icon {
  background: #fffaf0;
  color: #8a5b12;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  background: #101828;
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.hidden {
  display: none !important;
}

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

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

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

  .main {
    padding: 16px;
  }

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

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

  .chat-panel {
    min-height: 72vh;
  }

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

  .entry-screen {
    grid-template-columns: 1fr;
  }

  .login-copy {
    min-height: 360px;
    padding: 32px;
  }

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

  .entry-hero {
    min-height: 360px;
    padding: 32px;
  }
}

@media (max-width: 640px) {
  .topbar,
  .panel-head,
  .composer-row {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .switch-control,
  .form-actions {
    width: 100%;
  }

  .form-actions {
    flex-direction: column-reverse;
  }

  .nav {
    grid-template-columns: 1fr 1fr;
  }

  .stats,
  .form.two {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }
}
