:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-muted: #f1f3f5;
  --ink: #17191c;
  --muted: #68717d;
  --line: #dde2e7;
  --line-strong: #cbd2d9;
  --control: #202328;
  --accent: #c9473d;
  --accent-soft: #f9ecea;
  --danger: #ad352e;
  --success: #287a55;
  --success-soft: #eaf5ef;
  --info: #3867a8;
  --info-soft: #edf3fb;
  --shadow-dialog: 0 24px 60px rgba(23, 25, 28, 0.18);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI Variable", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(201, 71, 61, 0.52);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* 后台整体采用固定导航和独立数据工作区，避免页面级滚动。 */
.admin-app {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
}

.admin-sidebar {
  position: relative;
  z-index: 2;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 18px 14px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.admin-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 8px 10px;
}

.admin-brand-mark {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--control);
  color: #fff;
  font-size: 14px;
  font-weight: 750;
}

.admin-brand-copy {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.admin-brand-copy strong {
  font-size: 15px;
  font-weight: 730;
}

.admin-brand-copy small {
  color: var(--muted);
  font-size: 10px;
}

.admin-sidebar nav {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 3px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.admin-sidebar nav button {
  position: relative;
  width: 100%;
  height: 39px;
  padding: 0 12px 0 15px;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #525b66;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 560;
}

.admin-sidebar nav button:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.admin-sidebar nav button.is-active {
  background: #eef0f2;
  color: var(--ink);
  font-weight: 680;
}

.admin-sidebar nav button.is-active::before {
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 0;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  content: "";
}

.admin-sidebar footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 13px 7px 2px;
  border-top: 1px solid var(--line);
}

.admin-sidebar footer a,
.admin-sidebar footer button {
  padding: 5px 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
}

.admin-sidebar footer a:hover,
.admin-sidebar footer button:hover {
  color: var(--ink);
}

.admin-main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 76px minmax(0, 1fr);
}

.admin-topbar {
  position: relative;
  z-index: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

.admin-topbar h1,
.admin-topbar p {
  margin: 0;
}

.admin-topbar h1 {
  font-size: 19px;
  font-weight: 730;
}

.admin-topbar p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.admin-filters {
  min-width: 0;
  display: flex;
  gap: 7px;
}

.admin-filters input,
.admin-filters button,
.table-action,
.admin-form button {
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 11px;
}

.admin-filters input {
  width: 224px;
  padding: 0 11px;
}

.admin-filters input::placeholder {
  color: #9299a2;
}

.admin-filters button,
.table-action,
.admin-form button {
  padding: 0 11px;
}

.admin-filters button:hover,
.table-action:hover {
  border-color: #aeb6bf;
  background: var(--surface-muted);
}

.admin-content {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 22px 26px 30px;
  scrollbar-color: #c7cdd3 transparent;
  scrollbar-width: thin;
}

/* 概览使用连续数据带，不堆叠独立卡片。 */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.metric-strip div {
  min-width: 0;
  min-height: 104px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 17px 19px;
}

.metric-strip div:not(:nth-child(3n + 1)) {
  border-left: 1px solid var(--line);
}

.metric-strip div:nth-child(n + 4) {
  border-top: 1px solid var(--line);
}

.metric-strip span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 620;
}

.metric-strip strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  font-weight: 670;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 表格滚动限制在数据工具内部，表头在纵向浏览时保持可见。 */
.admin-table-wrap {
  width: 100%;
  max-height: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  scrollbar-color: #c7cdd3 transparent;
  scrollbar-width: thin;
}

.admin-table {
  width: 100%;
  min-width: 820px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11px;
}

.admin-table th,
.admin-table td {
  max-width: 260px;
  height: 44px;
  padding: 9px 13px;
  overflow: hidden;
  border-bottom: 1px solid #e8ebee;
  color: #30353b;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-table th {
  position: sticky;
  z-index: 1;
  top: 0;
  height: 40px;
  background: #f4f5f7;
  color: #606975;
  font-size: 10px;
  font-weight: 680;
}

.admin-table tbody tr:hover td {
  background: #fafbfc;
}

.admin-table tr:last-child td {
  border-bottom: 0;
}

.admin-table input,
.admin-table select {
  max-width: 132px;
  height: 30px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-size: 11px;
}

.admin-table input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.table-code,
.table-number {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.table-code {
  color: #555e68;
  font-size: 10px;
}

.table-number {
  color: var(--ink);
}

.table-number.is-positive {
  color: var(--success);
}

.table-number.is-negative {
  color: var(--danger);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: #555e68;
  font-size: 10px;
  font-weight: 650;
}

.status-badge.is-success {
  background: var(--success-soft);
  color: var(--success);
}

.status-badge.is-danger {
  background: var(--accent-soft);
  color: var(--danger);
}

.status-badge.is-info {
  background: var(--info-soft);
  color: var(--info);
}

.table-actions {
  display: flex;
  gap: 5px;
}

.table-action {
  flex: 0 0 auto;
  height: 30px;
}

.table-action.is-primary {
  border-color: var(--control);
  background: var(--control);
  color: #fff;
}

.table-action.is-primary:hover {
  border-color: #30343a;
  background: #30343a;
}

.table-action.is-danger {
  border-color: #edcbc8;
  background: #fffafa;
  color: var(--danger);
}

/* 用户代理权限用紧凑轨道开关表达，避免继续加宽操作按钮组。 */
.table-switch {
  min-width: 68px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
}

.table-switch span {
  width: 22px;
  height: 12px;
  position: relative;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #c9cdd2;
}

.table-switch span::after {
  width: 8px;
  height: 8px;
  position: absolute;
  top: 2px;
  left: 2px;
  border-radius: 50%;
  background: #fff;
  content: "";
  transition: transform 150ms ease;
}

.table-switch.is-on {
  border-color: #b9d8ca;
  color: var(--success);
}

.table-switch.is-on span {
  background: var(--success);
}

.table-switch.is-on span::after {
  transform: translateX(10px);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  margin-top: 12px;
}

.pagination-summary {
  margin-right: 5px;
  color: var(--muted);
  font-size: 10px;
}

.table-empty {
  height: 110px !important;
  color: var(--muted) !important;
  text-align: center !important;
}

/* 设置与充值表单保持紧凑，固定控件高度避免内容变化造成跳动。 */
.admin-form {
  width: min(680px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.admin-form label {
  min-width: 0;
  display: grid;
  gap: 7px;
  color: #5c6570;
  font-size: 10px;
  font-weight: 620;
}

.admin-form label.is-wide {
  grid-column: 1 / -1;
}

.admin-form input,
.admin-form select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.admin-form input:focus,
.admin-form select:focus {
  border-color: #bd837e;
}

/* 模型配置使用分段工具栏和单层列表，避免计费字段挤入横向宽表。 */
.pricing-toolbar {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.pricing-segments {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-muted);
}

.pricing-segments button,
.pricing-add {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
}

.pricing-segments button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(23, 25, 28, 0.1);
}

.pricing-add {
  background: var(--control);
  color: #fff;
}

.pricing-list {
  width: 100%;
  display: grid;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.pricing-item {
  min-width: 0;
  min-height: 70px;
  display: grid;
  grid-template-columns: minmax(220px, 1.35fr) minmax(190px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.pricing-item:last-child {
  border-bottom: 0;
}

.pricing-item-main,
.pricing-item-meta {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.pricing-item-main strong {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pricing-item-main strong i {
  margin-left: 7px;
  color: var(--danger);
  font-size: 9px;
  font-style: normal;
}

.pricing-item-main span,
.pricing-item-meta > span:first-child,
.model-test-note,
.pricing-empty {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pricing-item-meta {
  justify-items: start;
}

.pricing-item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
}

.pricing-empty {
  padding: 36px 14px;
  text-align: center;
}

.model-config-form {
  width: 100%;
  border: 0;
  padding: 4px 0;
}

.model-form-checks {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.admin-form label.admin-check {
  min-height: 34px;
  display: flex;
  grid-column: auto;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.admin-form label.admin-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.model-test-note {
  grid-column: 1 / -1;
  white-space: normal;
}

.admin-form button[type="submit"] {
  width: max-content;
  min-width: 92px;
  border-color: var(--control);
  background: var(--control);
  color: #fff;
  font-weight: 650;
}

.admin-form button[type="submit"]:hover {
  background: #30343a;
}

.manual-recharge-form {
  width: 100%;
  padding: 0;
  border: 0;
}

/* 改密弹窗采用一行管理员校验、两列新密码，控制在单屏高度内。 */
.user-password-form {
  width: 100%;
  padding: 0;
  border: 0;
}

.user-password-note,
.user-password-error {
  grid-column: 1 / -1;
  min-height: 16px;
  margin: -4px 0 0;
  font-size: 10px;
}

.user-password-note {
  color: var(--muted);
}

.user-password-error {
  color: var(--danger);
}

.user-password-form button:disabled {
  cursor: wait;
  opacity: 0.62;
}

/* 登录页沿用后台工作台语言，不使用营销式装饰。 */
.admin-login {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg);
}

.admin-login-form {
  width: min(370px, 100%);
  display: grid;
  gap: 15px;
  padding: 28px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(23, 25, 28, 0.08);
}

.admin-login-form > strong {
  margin-bottom: 2px;
  font-size: 18px;
  font-weight: 730;
}

.admin-login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 620;
}

.admin-login-form input {
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.admin-login-form button {
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--control);
  color: #fff;
  font-weight: 650;
}

.admin-login-form p {
  min-height: 15px;
  margin: -2px 0 0;
  color: var(--danger);
  font-size: 10px;
}

.admin-dialog {
  width: min(760px, calc(100% - 32px));
  max-height: min(82vh, 760px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-dialog);
}

.admin-dialog::backdrop {
  background: rgba(23, 25, 28, 0.42);
  backdrop-filter: blur(2px);
}

.admin-dialog header {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 17px;
  border-bottom: 1px solid var(--line);
}

.admin-dialog header strong {
  font-size: 13px;
}

.admin-dialog header button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 19px;
}

.admin-dialog header button:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.dialog-body {
  max-height: calc(82vh - 54px);
  overflow: auto;
  padding: 18px;
  font-size: 11px;
  line-height: 1.65;
  scrollbar-width: thin;
}

.dialog-message {
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dialog-message:first-child {
  padding-top: 0;
}

.dialog-message:last-child {
  border-bottom: 0;
}

.admin-notice {
  position: fixed;
  z-index: 20;
  right: 20px;
  /* 提示固定在右上角，避免被系统输入法和底部操作区遮挡。 */
  top: 18px;
  max-width: min(360px, calc(100% - 32px));
  padding: 10px 13px;
  border-radius: 6px;
  background: var(--control);
  color: #fff;
  box-shadow: 0 10px 26px rgba(23, 25, 28, 0.18);
  font-size: 11px;
}

@media (max-width: 700px) {
  .admin-notice {
    top: 12px;
    right: 12px;
  }
}

@media (max-width: 900px) {
  .admin-app {
    grid-template-columns: 196px minmax(0, 1fr);
  }

  .admin-content,
  .admin-topbar {
    padding-inline: 18px;
  }
}

/* 移动端将侧栏变成完整文字的横向导航，避免栏目只剩首字。 */
@media (max-width: 700px) {
  .admin-app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .admin-sidebar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 48px 42px;
    padding: 6px 12px 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .admin-brand {
    height: 48px;
    padding: 0;
  }

  .admin-brand-mark {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
  }

  .admin-sidebar nav {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 3px 0 6px;
    border-top: 0;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
  }

  /* 为最后一个标签保留收尾空间，滑到末端时不会紧贴屏幕边缘。 */
  .admin-sidebar nav::after {
    width: 8px;
    flex: 0 0 8px;
    content: "";
  }

  .admin-sidebar nav::-webkit-scrollbar {
    display: none;
  }

  .admin-sidebar nav button {
    width: auto;
    height: 32px;
    flex: 0 0 auto;
    padding: 0 10px;
    font-size: 11px;
  }

  .admin-sidebar nav button.is-active::before {
    top: auto;
    right: 10px;
    bottom: 0;
    left: 10px;
    width: auto;
    height: 2px;
    border-radius: 2px 2px 0 0;
  }

  .admin-sidebar footer {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    gap: 2px;
    padding: 0;
    border-top: 0;
  }

  /* 移动端在顶部同时保留聊天入口和退出操作，保证触控区域清晰且不挤占导航。 */
  .admin-sidebar footer a,
  .admin-sidebar footer button {
    height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0 8px;
    border-radius: 6px;
  }

  .admin-sidebar footer a:hover,
  .admin-sidebar footer button:hover {
    background: var(--surface-muted);
  }

  .admin-main {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .admin-topbar {
    min-height: 70px;
    flex-wrap: wrap;
    padding: 10px 14px;
  }

  .admin-filters {
    width: 100%;
  }

  .admin-filters input {
    width: auto;
    min-width: 0;
    flex: 1;
  }

  .admin-content {
    padding: 14px;
  }

  .metric-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-strip div {
    min-height: 88px;
    padding: 14px;
  }

  .metric-strip div:not(:nth-child(3n + 1)) {
    border-left: 0;
  }

  .metric-strip div:nth-child(odd) {
    border-left: 0;
  }

  .metric-strip div:nth-child(even) {
    border-left: 1px solid var(--line);
  }

  .metric-strip div:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

  .metric-strip strong {
    font-size: 19px;
  }

  .admin-form {
    grid-template-columns: minmax(0, 1fr);
    padding: 16px;
  }

  .admin-form label.is-wide {
    grid-column: auto;
  }

  .pricing-item {
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
  }

  .pricing-item-actions {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .pricing-toolbar {
    align-items: stretch;
  }

  .pricing-add {
    flex: 0 0 auto;
  }

  .model-form-checks {
    grid-template-columns: minmax(0, 1fr);
  }

  .model-config-form {
    padding: 0;
  }

  .manual-recharge-form {
    padding: 0;
  }

  .admin-table {
    min-width: 760px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
