:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #20222b;
  background: #f0f2f7;
  font-synthesis: none;
  --sidebar: #1a1a2e;
  --sidebar-muted: #77798e;
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --line: #e7e9f0;
  --muted: #808495;
  --surface: #ffffff;
  --canvas: #f0f2f7;
  --success: #16815b;
  --danger: #c33732;
  --warning: #a56b00;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-width: 320px; min-height: 100%; }
body { margin: 0; background: var(--canvas); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  color: #20222b;
  border: 1px solid #dfe2eb;
  border-radius: 6px;
  outline: none;
  background: #fff;
}
input::placeholder, textarea::placeholder { color: #a0a4b2; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .11);
}
label { display: grid; gap: 7px; color: #5c6070; font-size: 13px; font-weight: 600; }

.login-shell {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  background: var(--sidebar);
  place-items: center;
}
.login-panel {
  width: min(380px, 100%);
  padding: 34px 32px 30px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(4, 5, 18, .35);
}
.login-brand { display: flex; align-items: center; gap: 11px; }
.login-brand img { width: 42px; height: 42px; object-fit: contain; }
.login-brand div { display: grid; gap: 2px; }
.login-brand strong { font-size: 18px; }
.login-brand span { color: #8b8e9e; font-size: 9px; font-weight: 700; }
.login-panel h1 { margin: 28px 0 6px; font-size: 23px; }
.login-panel > p { margin: 0 0 24px; color: #818594; font-size: 13px; }
.login-panel label + input { margin-bottom: 15px; }
.login-panel > button {
  width: 100%;
  min-height: 42px;
  margin-top: 5px;
  color: #fff;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  font-weight: 700;
}
.login-panel > button:hover { background: var(--accent-dark); }
.error { display: block; min-height: 19px; margin-top: 11px; color: var(--danger); font-size: 12px; }

.admin-layout { min-height: 100vh; }
.sidebar {
  position: fixed;
  z-index: 100;
  inset: 0 auto 0 0;
  display: flex;
  width: 220px;
  color: #a9abb9;
  overflow-y: auto;
  background: var(--sidebar);
  flex-direction: column;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  min-height: 64px;
  padding: 10px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
  gap: 10px;
}
.sidebar-brand img { width: 36px; height: 36px; object-fit: contain; }
.sidebar-brand div { display: grid; min-width: 0; gap: 1px; }
.sidebar-brand strong { color: #fff; font-size: 17px; }
.sidebar-brand span { color: #65677b; font-size: 8px; font-weight: 700; white-space: nowrap; }
.sidebar-nav { padding: 7px 0 18px; }
.nav-group { margin: 0; padding: 9px 0 1px; }
.nav-group h2 {
  margin: 0;
  padding: 5px 20px 6px;
  color: #606277;
  font-size: 11px;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 0 18px 0 23px;
  color: #9a9cad;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  text-align: left;
  gap: 11px;
}
.nav-item img { width: 17px; height: 17px; filter: invert(65%); opacity: .9; }
.nav-item span { font-size: 13px; }
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, .04); }
.nav-item:hover img, .nav-item.active img { filter: brightness(0) invert(1); opacity: 1; }
.nav-item.active {
  color: #fff;
  border-left-color: #818cf8;
  background: rgba(99, 102, 241, .18);
  font-weight: 600;
}
.sidebar-footer {
  display: flex;
  align-items: center;
  min-height: 48px;
  margin-top: auto;
  padding: 0 21px;
  color: #74768a;
  border-top: 1px solid rgba(255, 255, 255, .06);
  font-size: 11px;
  gap: 8px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #30b980; box-shadow: 0 0 0 3px rgba(48, 185, 128, .12); }
.sidebar-overlay { display: none; }

.admin-main { min-width: 0; min-height: 100vh; margin-left: 220px; }
.topbar {
  position: sticky;
  z-index: 90;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 20px 0 22px;
  border-bottom: 1px solid #eceef3;
  background: #fff;
  box-shadow: 0 1px 4px rgba(25, 28, 45, .03);
}
.topbar-title, .topbar-actions, .admin-identity { display: flex; align-items: center; }
.breadcrumb { display: flex; align-items: center; color: #999cab; font-size: 13px; gap: 9px; }
.breadcrumb i { color: #c4c6cf; font-style: normal; }
.breadcrumb strong { color: #333641; font-weight: 650; }
.topbar-actions { gap: 8px; }
.topbar-divider { width: 1px; height: 22px; margin: 0 4px; background: #eceef3; }
.admin-identity { color: #666a78; font-size: 12px; gap: 8px; }
.avatar {
  display: grid;
  width: 30px;
  height: 30px;
  color: #fff;
  border-radius: 50%;
  background: #303247;
  font-size: 12px;
  font-weight: 800;
  place-items: center;
}
.icon-button {
  display: grid;
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  place-items: center;
}
.icon-button:hover { border-color: #e5e7ee; background: #f6f7fa; }
.icon-button img { width: 18px; height: 18px; opacity: .7; }
.logout-button:hover { background: #fff1f0; border-color: #f2d2cf; }
.logout-button:hover img { filter: invert(28%) sepia(47%) saturate(1641%) hue-rotate(322deg) brightness(87%); opacity: 1; }
.menu-button { display: none; }

.admin-content { position: relative; min-height: calc(100vh - 56px); padding: 20px; }
.view { display: none; }
.view.active { display: block; }
.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  min-height: 48px;
  margin-bottom: 16px;
  gap: 18px;
}
.section-heading h1 { margin: 0; color: #272a34; font-size: 20px; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.updated-at { color: #9699a7; font-size: 11px; }
.notice {
  position: fixed;
  z-index: 210;
  top: 70px;
  right: 22px;
  max-width: min(390px, calc(100vw - 32px));
  padding: 11px 15px;
  color: #fff;
  border-radius: 6px;
  background: #242735;
  box-shadow: 0 9px 28px rgba(21, 24, 37, .2);
  font-size: 13px;
}
.notice.error { background: #a9322d; }

.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 16px; gap: 12px; }
.stat {
  min-width: 0;
  min-height: 108px;
  padding: 17px;
  border: 1px solid #ebeef3;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(25, 28, 45, .035);
}
.stat span { display: block; color: #898d9c; font-size: 12px; }
.stat strong { display: block; margin-top: 15px; overflow: hidden; color: #242731; font-size: 24px; text-overflow: ellipsis; white-space: nowrap; }
.panel {
  padding: 18px;
  border: 1px solid #ebeef3;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(25, 28, 45, .035);
}
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; min-height: 28px; margin-bottom: 8px; }
.panel-heading h2, .form-section-title h2 { margin: 0; font-size: 14px; }
.text-link { padding: 4px; color: var(--accent); border: 0; background: transparent; font-size: 12px; }
.text-link:hover { color: var(--accent-dark); }
.compact-row { display: flex; align-items: center; justify-content: space-between; min-height: 56px; border-top: 1px solid #f0f1f5; gap: 14px; }
.compact-row:first-child { border-top: 0; }
.compact-row div { min-width: 0; }
.compact-row strong, .compact-row span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-row strong { color: #383b46; font-size: 13px; }
.compact-row span { margin-top: 3px; color: #9295a2; font-size: 11px; }
.compact-row b { color: #343743; font-size: 13px; }
.empty { padding: 28px 8px !important; color: #9a9daa; font-size: 12px; text-align: center; }

.data-panel { padding: 0; overflow: hidden; }
.filter-bar { display: flex; align-items: center; min-height: 62px; padding: 10px 14px; border-bottom: 1px solid #eef0f4; gap: 10px; }
.filter-bar select { width: 150px; }
.conversation-filter-bar { flex-wrap: wrap; }
.conversation-filter-bar select { width: min(220px, 100%); }
.privacy-note { margin: 0; padding: 10px 14px; color: #7c8090; border-bottom: 1px solid #eef0f4; background: #fffdf4; font-size: 11px; line-height: 1.6; }
.search { display: flex; width: min(450px, 100%); gap: 8px; }
.search button, .form-actions button, .dialog-actions button {
  min-height: 40px;
  padding: 0 16px;
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}
.search button:hover, .form-actions button:hover, .dialog-actions button:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { height: 42px; padding: 0 13px; color: #888c9b; text-align: left; border-bottom: 1px solid #eceef3; background: #fafbfc; font-size: 12px; font-weight: 600; white-space: nowrap; }
td { min-height: 54px; padding: 11px 13px; color: #424550; border-bottom: 1px solid #f0f1f4; vertical-align: middle; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfe; }
.primary-cell { min-width: 190px; }
.primary-cell strong, .primary-cell small { display: block; }
.primary-cell small { margin-top: 4px; color: #9094a1; }
.actions { display: flex; min-width: 178px; gap: 6px; }
.actions button {
  min-height: 30px;
  padding: 0 9px;
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--accent);
  font-size: 12px;
  white-space: nowrap;
}
.actions button:hover { background: var(--accent-dark); }
.actions button.secondary { color: #525664; border-color: #dde0e8; background: #fff; }
.actions button.danger { color: var(--danger); border-color: #efc9c6; background: #fff; }
.actions button.secondary:hover { background: #f6f7f9; }
.actions button.danger:hover { background: #fff3f2; }
.sort-actions { display: grid; grid-template-columns: 28px minmax(30px, auto) 28px; align-items: center; gap: 4px; }
.sort-actions span { color: #777b88; text-align: center; font-variant-numeric: tabular-nums; }
.sort-actions button { width: 28px; height: 28px; padding: 0; color: #525664; border: 1px solid #dde0e8; border-radius: 5px; background: #fff; font-size: 15px; line-height: 1; }
.sort-actions button:hover { color: var(--accent); border-color: var(--accent); background: #f7f5ff; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; color: #555965; border-radius: 4px; background: #eef0f4; font-size: 11px; white-space: nowrap; }
.badge.good { color: #116947; background: #e2f3ec; }
.badge.warn { color: #805300; background: #fff0c8; }
.badge.bad { color: #9f302b; background: #f9e3e1; }

.settings-form { display: grid; width: min(980px, 100%); gap: 18px; }
.compact-form { width: 100%; align-self: start; }
.form-section-title { padding-bottom: 11px; border-bottom: 1px solid #eef0f4; }
.form-section-title p { margin: 4px 0 0; color: #9295a2; font-size: 11px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.settings-form textarea { min-height: 92px; resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; }
.align-start { align-items: start; }
.catalog-panel { margin-top: 16px; }
.subpanel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 10px 14px;
  border-bottom: 1px solid #eef0f4;
  gap: 14px;
}
.subpanel-heading h2 { margin: 0; color: #343741; font-size: 14px; }
.subpanel-heading > span { color: #9396a3; font-size: 11px; }
.heading-action {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 13px;
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  gap: 6px;
}
.heading-action:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.heading-action img { width: 15px; height: 15px; filter: brightness(0) invert(1); }
.heading-action.small { min-height: 32px; padding: 0 10px; }
.toggle-label { display: inline-flex; align-items: center; color: #5d6170; font-size: 12px; font-weight: 500; gap: 7px; }
.toggle-label input, .check-grid input { width: 16px; min-height: 16px; margin: 0; accent-color: var(--accent); box-shadow: none; }
.filter-input { width: min(420px, 100%); }
.inline-form { display: flex; align-items: center; width: min(570px, 100%); gap: 8px; }
.inline-form input { min-width: 120px; }
.inline-form button, .key-reveal button {
  min-height: 38px;
  padding: 0 13px;
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}
.api-docs { display: grid; align-self: stretch; gap: 10px; }
.api-docs h2 { margin: 0 0 3px; font-size: 14px; }
.api-docs code { display: block; padding: 9px 11px; color: #35394a; border-radius: 5px; background: #f4f5f8; font-size: 12px; }
.api-docs p { margin: 4px 0 0; color: #858997; font-size: 11px; line-height: 1.7; }
.key-reveal { display: flex; align-items: center; justify-content: space-between; margin: 12px 14px; padding: 12px 14px; border: 1px solid #d9dcfa; border-radius: 6px; background: #f4f4ff; gap: 14px; }
.key-reveal div { display: grid; min-width: 0; gap: 5px; }
.key-reveal strong { color: #4b4f67; font-size: 12px; }
.key-reveal code { overflow: hidden; color: #30334a; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.config-dialog { width: min(650px, calc(100% - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; }
.config-fields { display: grid; gap: 15px; }
.config-fields textarea { min-height: 92px; resize: vertical; }
.config-fields textarea.suggestions-editor { min-height: 132px; line-height: 1.7; }
.config-fields textarea.prompt-editor { min-height: 190px; font-family: Menlo, Consolas, monospace; font-size: 12px; }
.config-fields select[multiple] { min-height: 145px; }
.config-fields .field-note { margin: -6px 0 0; color: #9699a6; font-size: 11px; line-height: 1.6; }
.hero-image-editor { display: grid; grid-template-columns: minmax(220px, 360px) 1fr; align-items: center; gap: 18px; }
.hero-image-editor img { width: 100%; aspect-ratio: 2.3 / 1; object-fit: cover; border: 1px solid #e1e3e9; border-radius: 7px; background: #f3f4f7; }
.hero-file-field { display: grid; align-content: center; min-height: 88px; padding: 14px; border: 1px dashed #cfd2dc; border-radius: 7px; color: #555a69; background: #fafbfc; gap: 10px; }
.hero-file-field input { padding: 8px; background: #fff; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.check-grid label { display: flex; align-items: center; padding: 8px 10px; border: 1px solid #e5e7ed; border-radius: 5px; background: #fafbfc; font-weight: 500; gap: 8px; }
.mono { font-family: Menlo, Consolas, monospace; font-size: 11px; }
.positive { color: #16815b; font-weight: 700; }
.negative { color: #c33732; font-weight: 700; }
.muted-cell { max-width: 280px; overflow: hidden; color: #8e919e; text-overflow: ellipsis; }

dialog { width: min(440px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 8px; box-shadow: 0 20px 60px rgba(4, 5, 18, .25); }
dialog::backdrop { background: rgba(8, 10, 18, .5); }
dialog form { display: grid; padding: 24px; gap: 16px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.dialog-heading h2 { margin: 0; font-size: 18px; }
.dialog-heading p { margin: 5px 0 0; color: #858997; font-size: 12px; }
.dialog-close { display: grid; width: 32px; min-width: 32px; height: 32px; padding: 0; border: 0; border-radius: 5px; background: transparent; place-items: center; }
.dialog-close:hover { background: #f2f3f6; }
.dialog-close img { width: 18px; height: 18px; opacity: .65; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 3px; gap: 8px; }
.dialog-actions button.secondary { color: #4f5360; border-color: #dfe2e9; background: #fff; }
.dialog-actions button.secondary:hover { background: #f6f7f9; }
.dialog-note { margin: -6px 0 0; color: #858997; font-size: 11px; line-height: 1.6; }
.membership-credit-toggle { justify-content: flex-start; }
.exclusive-prompt-editor { display: grid; padding-top: 15px; border-top: 1px solid #eef0f4; gap: 14px; }
.exclusive-prompt-editor textarea { min-height: 210px; resize: vertical; font-family: Menlo, Consolas, monospace; font-size: 12px; line-height: 1.65; }
.exclusive-agent-visibility { display: grid; min-width: 0; margin: 0; padding: 15px 0; border: 0; border-top: 1px solid #eef0f4; gap: 12px; }
.exclusive-agent-visibility legend { padding: 0; font-size: 13px; font-weight: 700; }
.exclusive-agent-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.exclusive-agent-check { display: flex; min-width: 0; align-items: center; padding: 9px 10px; border: 1px solid #e5e7ed; border-radius: 5px; gap: 8px; cursor: pointer; }
.exclusive-agent-check input { width: 16px; min-height: 16px; padding: 0; flex: 0 0 16px; margin: 0; accent-color: var(--accent); box-shadow: none; }
.exclusive-agent-check span { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-preview { display: block; max-width: 420px; overflow: hidden; color: #777b89; text-overflow: ellipsis; white-space: nowrap; }
.conversation-dialog { width: min(820px, calc(100% - 32px)); max-height: calc(100vh - 32px); overflow: hidden; }
.conversation-dialog-shell { display: grid; max-height: calc(100vh - 32px); padding: 24px; gap: 16px; grid-template-rows: auto minmax(0, 1fr) auto; }
.conversation-messages { display: grid; min-height: 180px; padding: 2px 6px 2px 2px; overflow-y: auto; gap: 12px; }
.conversation-message { display: grid; max-width: 88%; padding: 12px 14px; border: 1px solid #e5e7ed; border-radius: 7px; background: #f7f8fa; gap: 7px; }
.conversation-message.user { margin-left: auto; border-color: #d9dcfa; background: #f2f2ff; }
.conversation-message header { color: #737786; font-size: 11px; font-weight: 700; }
.conversation-message .conversation-content { color: #30333d; font-size: 13px; line-height: 1.75; overflow-wrap: anywhere; white-space: pre-wrap; }

@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 18px 0 55px rgba(4, 5, 18, .3); }
  .sidebar-overlay { position: fixed; z-index: 99; inset: 0; display: none; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(9, 10, 18, .42); }
  .sidebar-overlay.open { display: block; }
  .admin-main { margin-left: 0; }
  .menu-button { display: grid; }
  .split { grid-template-columns: 1fr; }
  .form-grid-three { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 620px) {
  .login-shell { padding: 16px; }
  .login-panel { padding: 28px 22px 24px; }
  .topbar { padding: 0 10px 0 8px; }
  .breadcrumb > span, .breadcrumb i, .admin-identity > span:last-child { display: none; }
  .topbar-actions { gap: 4px; }
  .topbar-divider { margin: 0 2px; }
  .admin-content { padding: 14px; }
  .section-heading { align-items: flex-start; margin-bottom: 13px; flex-direction: column; gap: 5px; }
  .section-heading h1 { font-size: 18px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .stat { min-height: 96px; padding: 14px; }
  .stat strong { margin-top: 12px; font-size: 21px; }
  .panel { padding: 14px; }
  .data-panel { padding: 0; }
  .filter-bar { align-items: stretch; }
  .search { width: 100%; }
  .form-grid, .form-grid-three { grid-template-columns: 1fr; }
  .subpanel-heading { align-items: stretch; flex-direction: column; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .conversation-filter-bar { align-items: stretch; flex-direction: column; }
  .conversation-filter-bar select { width: 100%; }
  .check-grid { grid-template-columns: 1fr; }
  .exclusive-agent-checks { grid-template-columns: 1fr; }
  .hero-image-editor { grid-template-columns: 1fr; }
  .key-reveal { align-items: stretch; flex-direction: column; }
  .notice { top: 66px; right: 14px; }
}
