/*
  全站视觉基底 —— htools 风格：纯白底、近黑文字、8px 圆角、无毛玻璃、无阴影。
  共用 token + 组件：app-shell 侧栏布局、按钮、auth-card、面板、徽标、表格、
  对话框、toast。四页（提交页 /admin /login /register）共用本文件，页面专属样式各自 css。
  严格 CSP：仅类名切换，无内联 style/script。

  深色模式：主题只经 token 层实现 —— :root 是浅色基线，下方
  :root[data-theme="dark"] 覆盖同名 token，属性由 /theme.js 在首绘前写到 <html>。
  **所以规则体里不许再出现颜色字面量**（#hex / rgb / rgba）：写死的颜色不会跟着
  token 翻转，深色下就在那一处破相。需要新颜色时先加 token，两个块都给值。
  tests/frontend-layout.test.js 有一条扫描把这条钉死。
*/

:root {
  color-scheme: light;
  --bg: #fff;
  --surface: #fff;
  --surface-2: #f4f4f5;
  /* 比 --surface-2 更淡的一层：表格 hover、登录页背景、平台卡片 hover 都用它。
     原先散在四个文件里写死 #fafafa，深色下会变成刺眼的近白块。 */
  --surface-subtle: #fafafa;
  --text: #09090b;
  --muted: #52525b;
  --faint: #71717a;
  --border: #e4e4e7;
  --border-soft: #ededed;
  --button: #09090b;
  --button-hover: #27272a;
  --button-text: #fff;
  --danger: #b4232f;
  --danger-soft: #fdf2f3;
  /* 语义色的描边：--*-soft 背景早已 token 化，描边却一直是字面量，
     两者迟早不同步。成对定义，改一个就会想起另一个。 */
  --danger-border: #f5c6cb;
  --danger-hover: #8f1d27;
  --danger-text: #fff;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;
  --info: #1d4ed8;
  --info-soft: #eff6ff;
  --toast-border: #3f3f46;
  --focus-ring: rgba(9, 9, 11, 0.35);
  /* 遮罩与焦点影：从 --text 派生。深色下近黑遮罩盖在深色界面上等于看不见，
     所以必须是 token 而不是字面量。 */
  --scrim: rgba(9, 9, 11, 0.35);
  --scrim-strong: rgba(9, 9, 11, 0.45);
  --focus-shadow: rgba(9, 9, 11, 0.12);
  --radius: 8px;
  --radius-sm: 6px;
  /* 全站唯一控件高度：按钮、输入框、下拉、状态开关都用它 */
  --control-height: 38px;
  --sidebar-width: 220px;
  --topbar-height: 64px;
  --shell-max: 1440px;
  --font:
    "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", Arial,
    sans-serif;
  /* admin.css 的 .config-url / .invite-code 引用它，但此前全仓库从未声明，
     一直静默回退到继承字体。 */
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
}

/* 深色主题：只覆盖颜色，尺寸与字体 token 沿用上面那份。
   属性由 /theme.js 写入（system / light / dark 三档，system 解析成实际的一档）。
   刻意不写 @media (prefers-color-scheme: dark)：theme.js 已经把系统偏好解析成属性，
   再写一份媒体查询等于同样的值维护两遍，且两份必然漂移。
   代价：JS 被禁时停在浅色 —— 与改动前的现状一致。 */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09090b;
  --surface: #131316;
  --surface-2: #1f1f23;
  --surface-subtle: #17171a;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #8b8b94;
  --border: #2e2e35;
  --border-soft: #26262c;
  /* 浅色下主按钮是近黑底白字；深色下反过来 —— 近白底深字仍是最高对比的那一档。 */
  --button: #f4f4f5;
  --button-hover: #d4d4d8;
  --button-text: #09090b;
  /* 语义色整体提亮：浅色那组是给白底调的，放到深底上对比度不够。 */
  --danger: #f87171;
  --danger-soft: #2a1416;
  --danger-border: #5b2226;
  --danger-hover: #fca5a5;
  --danger-text: #1a0c0d;
  --success: #4ade80;
  --success-soft: #10231a;
  --success-border: #1f5133;
  --warning: #fbbf24;
  --warning-soft: #241a08;
  --warning-border: #59431a;
  --info: #7dabff;
  --info-soft: #111a2b;
  --toast-border: #3f3f46;
  --focus-ring: rgba(244, 244, 245, 0.45);
  /* 遮罩仍是压暗而非提亮：深色界面上盖一层更黑的才有层次，加深不透明度补足。 */
  --scrim: rgba(0, 0, 0, 0.6);
  --scrim-strong: rgba(0, 0, 0, 0.7);
  --focus-shadow: rgba(244, 244, 245, 0.16);
}


* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.5;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--info);
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
  border-radius: var(--radius-sm);
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
}

/* ---------- 布局：侧栏 + 顶栏 + 内容（dashboard 外壳） ---------- */

.app-shell {
  min-height: 100vh;
  /* dvh 跟随手机地址栏收放；vh 留作旧浏览器回退。与 .auth-body 同一写法。 */
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  background: var(--bg);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px 16px;
}

.sidebar-head {
  padding: 0 10px 18px;
}

/* 品牌行：徽标 + 主标题/副标题两行文字。徽标高度对齐两行文字的总高，
   所以主副标题的行高写死，改字号时同步调整徽标尺寸即可。 */
.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  flex: none;
  border-radius: var(--radius-sm);
}

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

/* 侧栏品牌：鹅栏只有 220px，产品名必须一行放得下，所以字号压到 13px 且不换行。
   主标题 18px + 副标题 14px = 32px，徽标同高。 */
.sidebar-head .brand-row {
  gap: 8px;
}

.sidebar-head .brand-mark {
  width: 32px;
  height: 32px;
}

.sidebar-head .product-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 18px;
  white-space: nowrap;
  color: var(--text);
}

.sidebar-head .sidebar-sub {
  font-size: 11px;
  font-weight: 500;
  line-height: 14px;
  white-space: nowrap;
  color: var(--faint);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

/* 侧栏导航项也是按钮，高度并入全站唯一控件高度（原来靠 padding+行高凑出 37.7px） */
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--control-height);
  padding: 8px 10px;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: left;
  font-size: 14px;
}

.sidebar-nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-nav-item.is-active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

.sidebar-bottom {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
  margin-top: 8px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--muted);
}

.sidebar-user .user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.sidebar-user-name {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 退出等侧栏工具按钮与导航项同高 */
.sidebar-utility {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--control-height);
  padding: 8px 10px;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: left;
  font-size: 14px;
}

.sidebar-utility:hover {
  background: var(--surface-2);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--topbar-height);
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-content {
  width: 100%;
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 28px;
}

/* ---------- 按钮 ----------
   全站只有一种按钮尺寸：高 --control-height、左右 16px、字号 14px、宽度由文字自适应。
   颜色变体（danger / danger-outline）也列在这里，所以单独使用也有完整尺寸。
   .status-toggle 同样走这套——它是可点击的开关，不是只读徽标。 */

.primary-button,
.button,
.ghost-button,
.button-secondary,
.button-danger,
.status-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: auto;
  min-height: var(--control-height);
  padding: 0 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.primary-button:disabled,
.button:disabled,
.ghost-button:disabled,
.button-secondary:disabled,
.button-danger:disabled,
.status-toggle:disabled {
  cursor: default;
}

/* 主操作：实底近黑 */
.primary-button,
.button {
  background: var(--button);
  border: 1px solid var(--button);
  color: var(--button-text);
}

.primary-button:hover:not(:disabled),
.button:hover:not(:disabled) {
  background: var(--button-hover);
  border-color: var(--button-hover);
}

/* 次操作：白底灰边 */
.ghost-button,
.button-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.ghost-button:hover:not(:disabled),
.button-secondary:hover:not(:disabled) {
  background: var(--surface-2);
}

/* 危险操作：实底红。禁用时统一变浅（见全局 button:disabled 的 opacity），
   所以「深红 = 可点、浅红 = 不可点」在全站是同一套视觉规则。 */
.button-danger {
  background: var(--danger);
  border: 1px solid var(--danger);
  color: var(--danger-text);
}

.button-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

/* ---------- 表单 ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

/* 非 <label> 的字段标题（例如字段里放的是按钮而不是输入框） */
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

/* .field 是纵向 flex，默认把子元素拉满整列宽——放输入框时正确，放按钮时
   会把按钮抻成一整列。按钮宽度必须由文字决定，这里让它保持自适应。 */
.field > .status-toggle,
.field > .primary-button,
.field > .button,
.field > .ghost-button,
.field > .button-secondary,
.field > .button-danger {
  align-self: flex-start;
}

.field-input,
.field input,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="file"],
select,
textarea {
  min-height: var(--control-height);
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  /* 行高压到 1.2：body 的 1.55 会让单行输入框实际高出按钮约 2px */
  line-height: 1.2;
  color: var(--text);
  width: 100%;
}

/* 文件选择框：原生「选择文件」按钮由浏览器绘制，只能靠 ::file-selector-button
   对齐全站按钮外观，否则它会是一颗灰色小方块。 */
input[type="file"] {
  padding: 0;
  display: inline-flex;
  align-items: center;
  overflow: hidden;
}

input[type="file"]::file-selector-button {
  min-height: calc(var(--control-height) - 2px);
  margin-right: 12px;
  padding: 0 16px;
  background: var(--surface-2);
  border: 0;
  border-right: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: var(--border);
}

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

.field-input:focus,
.field input:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.field-input::placeholder,
input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

/* ---------- 登录 / 闸门卡片 ---------- */

.auth-body {
  background: var(--surface-subtle);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 登录/注册/后台闸门：品牌左对齐，与下方字段标签、输入框同一条左基线。
   徽标高度对齐两行文字（18+14=32px）。主标题大于副标题，层级不倒置。 */
.auth-card .brand-row {
  justify-content: flex-start;
  gap: 10px;
}

.auth-card .brand-text {
  align-items: flex-start;
  text-align: left;
}

.auth-card .brand-mark {
  width: 32px;
  height: 32px;
}

.auth-card .product-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 18px;
  white-space: nowrap;
  color: var(--text);
}

.auth-card .auth-title {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 14px;
  color: var(--faint);
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-card .field {
  gap: 8px;
}

.auth-card .auth-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.auth-card .auth-actions .primary-button {
  width: 100%;
}

.auth-hint {
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
}

.auth-alt {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 面板 / 卡片网格 ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

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

/* ---------- 徽标 ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-soft {
  background: var(--surface-2);
  color: var(--muted);
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-clickable {
  cursor: pointer;
  appearance: none;
  font: inherit;
}

.badge-clickable:hover {
  border-color: var(--border);
}

/* ---------- 表格 ---------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.account-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.account-table th,
.account-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

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

.account-table tbody tr:last-child td {
  border-bottom: 0;
}

.account-table tbody tr:hover {
  background: var(--surface-subtle);
}

/* 同类数据表统一等分列宽，让表头、内容和操作区保持同一网格节奏。 */
.table-accounts {
  table-layout: fixed;
}

.table-accounts col {
  width: 20%;
}

.table-users {
  table-layout: fixed;
}

/* 五列等分：用户名 / 注册时间 / 账号数 / 配额 / 状态。 */
.table-users col {
  width: 20%;
}

.table-rank {
  table-layout: fixed;
}

.table-rank col {
  width: 25%;
}

/* 覆盖平台：每个平台一个可点 chip，点了跳到站点账号那张卡 */
.platform-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.platform-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 2px 8px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.platform-chip:hover {
  border-color: var(--button);
  background: var(--surface);
}

.platform-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.platform-chip-count {
  color: var(--faint);
  flex: none;
}

.account-table .cell-user,
.account-table .cell-auth {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-user {
  font-weight: 600;
}

.cell-count {
  text-align: center !important;
  font-variant-numeric: tabular-nums;
}

.cell-owner p {
  margin: 0;
}

.cell-muted {
  margin: 0;
  padding-top: 2px;
  font-size: 12px;
  color: var(--faint);
}

.cell-pad {
  color: var(--faint);
  text-align: center !important;
}

/* 表格里的操作区：按钮已统一 38px 高，行高随之变高，单元格上下留白收窄一点 */
.cell-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: nowrap;
}

.cell-state {
  text-align: right;
}

.cell-action-heading {
  display: inline-flex;
  justify-content: flex-start;
  box-sizing: border-box;
  min-width: 62px;
  padding: 0 16px;
  border: 1px solid transparent;
  font-size: 14px;
}

.cell-action-heading[aria-hidden="true"] {
  visibility: hidden;
}

.account-table td:has(.cell-actions) {
  padding-top: 6px;
  padding-bottom: 6px;
}

/* 状态开关：尺寸与其他按钮一致（见「按钮」段的共用规则），只用颜色表达状态。 */
.status-toggle {
  background: var(--surface-2);
  border: 1px solid transparent;
  color: var(--muted);
}

.status-toggle.is-active {
  background: var(--success-soft);
  color: var(--success);
}

.status-toggle.is-disabled {
  background: var(--surface-2);
  color: var(--muted);
}

.status-toggle.is-warn {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-toggle:hover:not(:disabled) {
  border-color: currentColor;
}

.status-toggle:disabled {
  opacity: 0.6;
}

/* ---------- 对话框 ---------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--scrim);
}

.dialog {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.dialog-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.dialog-message {
  font-size: 14px;
  color: var(--muted);
}

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

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(90vw, 480px);
  padding: 10px 16px;
  background: var(--text);
  border: 1px solid var(--toast-border);
  border-radius: var(--radius);
  color: var(--button-text);
  font-size: 13px;
  font-weight: 600;
}

.toast.is-error {
  background: var(--danger);
}

/* 提交页顶部结果条复用 toast 的黑色基调，但可关闭 */
.toast .toast-close {
  margin-left: 10px;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
}

/* ---------- 空态 / 加载 / 错误 ---------- */

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--faint);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.load-error {
  padding: 10px 14px;
  margin-bottom: 16px;
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 13px;
}

.loading-block {
  padding: 24px;
  text-align: center;
  color: var(--faint);
}

/* ---------- 全站统一选择菜单 ---------- */

.choice-picker {
  position: relative;
  width: 100%;
}

.choice-trigger {
  width: 100%;
  min-height: var(--control-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  text-align: left;
}

.choice-trigger-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.choice-trigger:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.choice-chevron {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  margin: -3px 3px 0 auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  color: var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease, margin 0.15s ease;
}

.choice-picker.is-open .choice-chevron {
  margin-top: 3px;
  transform: rotate(225deg);
}

.choice-picker.is-disabled {
  opacity: 0.65;
}

.choice-combobox-field {
  position: relative;
}

.choice-anchor {
  position: relative;
  display: inline-flex;
}

.choice-menu,
.choice-floating {
  position: absolute;
  z-index: 40;
}

.choice-picker > .choice-menu,
.choice-combobox-menu {
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
}

.choice-combobox-menu.is-flipped {
  top: auto;
  bottom: calc(100% + 4px);
}

.choice-menu {
  min-width: 180px;
  max-height: 260px;
  overflow-y: auto;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.choice-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  text-align: left;
}

.choice-option:hover,
.choice-option:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.choice-option-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.choice-option-text strong {
  font-size: 14px;
  font-weight: 600;
}

.choice-option-text span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.choice-option.is-current .choice-option-text strong {
  font-weight: 700;
}

.choice-check {
  color: var(--success);
  font-weight: 700;
}

.choice-floating {
  top: calc(100% + 4px);
  left: 0;
}

.choice-floating.is-aligned-end {
  right: 0;
  left: auto;
}

.choice-floating .choice-menu {
  width: max-content;
  max-width: min(320px, calc(100vw - 28px));
}

.choice-floating .choice-menu {
  position: static;
}

/* ---------- 面板切换（提交页三个 tabpanel 共用） ---------- */

.result {
  border-radius: var(--radius);
  padding: 20px;
}

.result.is-success {
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  color: var(--success);
}

.result.is-error {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
}

/* ---------- 移动端抽屉 ---------- */

/* 汉堡按钮与抽屉关闭按钮：桌面端隐藏，窄屏才出现；尺寸走全站控件高度 */
.drawer-toggle,
.drawer-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  flex: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
}

.drawer-toggle:hover,
.drawer-close:hover {
  background: var(--surface-2);
}

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--scrim-strong);
  z-index: 40;
}

/* ---------- 响应式 ---------- */

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  /* 侧栏改抽屉：默认滑出屏幕外，点汉堡滑入 */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    /* dvh 才是手机上真正可见的高度：100vh 是地址栏收起后的大视口，地址栏显示时
       fixed 侧栏的底部会掉到可见区外面 —— 实测「退出」按钮被截断（用户 2026-08-23 报障）。
       vh 留在前面作旧浏览器回退，与 .auth-body / .auth-gate 同一写法。 */
    height: 100dvh;
    width: min(84vw, 300px);
    padding: 16px 12px;
    border-right: 1px solid var(--border);
    border-bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 50;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 0 4px 14px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 8px;
  }

  .drawer-close {
    display: inline-flex;
  }

  .drawer-toggle {
    display: inline-flex;
  }

  .drawer-backdrop.is-open {
    display: block;
  }

  /* 抽屉打开时锁住背景滚动 */
  body.is-drawer-open {
    overflow: hidden;
  }

  .topbar {
    gap: 10px;
    padding: 0 14px;
  }

  .topbar-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-content {
    padding: 16px 14px;
  }

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

  /* 窄屏表格：解除固定列宽，让内容自己撑开后横向滚动 */
  .table-accounts,
  .table-users,
  .table-rank {
    table-layout: auto;
    min-width: 560px;
  }

  .account-table th,
  .account-table td {
    padding: 8px 10px;
  }
}

@media (max-width: 520px) {
  .admin-tool-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    min-height: 56px;
    padding: 10px 14px;
  }

  .app-content {
    padding: 14px 12px;
  }

  .panel {
    padding: 16px 14px;
  }

  /* 站点卡片/面板头：标题与操作按钮改上下排，按钮不再被挤出屏幕 */
  .site-card-head,
  .panel-head,
  .section-heading {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .site-actions,
  .panel-head .ghost-button,
  .section-heading .button-secondary {
    width: 100%;
  }

  .site-actions .button {
    flex: 1;
  }

  .site-actions .choice-anchor {
    flex: 1;
  }

  .site-actions .choice-anchor .button {
    width: 100%;
  }

  /* .overview-tiles / .platform-grid 的窄屏规则在 cards.css 里，
     和卡片本体待在一起，不要在 base 里再叠一层。 */

  .invite-create {
    grid-template-columns: minmax(0, 1fr);
  }

  .mode-settings-grid,
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
