/* =========================================================================
   Cloudflare 集中控制台 —— 设计系统
   ========================================================================= */

:root {
  --bg: #f5f6f8;
  --bg-elevated: #ffffff;
  --panel: #ffffff;
  --panel-soft: #fafbfc;
  --border: #e4e7ec;
  --border-strong: #d3d8e0;
  --text: #101828;
  --text-soft: #344054;
  --muted: #667085;
  --accent: #f6821f;
  --accent-strong: #dd6b10;
  --accent-soft: #fff4e8;
  --blue: #2563eb;
  --green: #12805c;
  --green-soft: #e7f6f0;
  --red: #d92d20;
  --red-soft: #fef3f2;
  --amber: #b54708;
  --amber-soft: #fffaeb;
  --sidebar: #0f1729;
  --sidebar-soft: #1a2438;
  --sidebar-text: #a7b3c9;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, 0.24);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

html[data-theme='dark'] {
  --bg: #0b1220;
  --bg-elevated: #111a2b;
  --panel: #111a2b;
  --panel-soft: #0e1726;
  --border: #1f2c44;
  --border-strong: #2b3a56;
  --text: #e7ecf5;
  --text-soft: #c2cddf;
  --muted: #8b9bb4;
  --accent-soft: #2a1c0d;
  --green-soft: #0e2a22;
  --red-soft: #2b1414;
  --amber-soft: #2a2010;
  --sidebar: #080e19;
  --sidebar-soft: #131d2f;
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

/* alert 为 flex 容器：单个内容块占满宽度，避免与列表并排挤压 */
.alert > div {
  flex: 1;
  min-width: 0;
}

/* 向导页权限清单：紧凑徽章式排列 */
.perm-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.perm-chips li {
  padding: 3px 10px;
  border: 1px solid rgba(146, 64, 14, 0.25);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.65);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  color: inherit;
}

/* hidden 属性优先于任何 display 规则（否则 alert/flex 元素会以空壳显示） */
[hidden] {
  display: none !important;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--blue);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ------------------------------------------------------------- 启动/加载 */

.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
}
.boot-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--muted);
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner.lg {
  width: 28px;
  height: 28px;
  border-width: 3px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------------------------------------------ 登录 */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: var(--bg);
}
.auth-aside {
  background: linear-gradient(150deg, #0f1729 0%, #16233c 55%, #1e2f4d 100%);
  color: #e6edf8;
  padding: 56px 52px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 650;
  font-size: 16px;
  letter-spacing: 0.2px;
}
.auth-brand .logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(246, 130, 31, 0.35);
}
.auth-aside h2 {
  font-size: 30px;
  line-height: 1.35;
  margin: 0 0 18px;
  font-weight: 620;
  letter-spacing: -0.4px;
}
.auth-aside p {
  color: #93a3bd;
  margin: 0 0 26px;
  max-width: 420px;
  line-height: 1.8;
}
.auth-features {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.auth-features li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  color: #c3d0e4;
  font-size: 13.5px;
}
.auth-features b {
  color: #fff;
  font-weight: 600;
}
.tick {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: rgba(246, 130, 31, 0.16);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 12px;
  margin-top: 1px;
}
.auth-foot {
  color: #6f8099;
  font-size: 12px;
}
.auth-main {
  display: grid;
  place-items: center;
  padding: 32px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
}
.auth-card h1 {
  font-size: 24px;
  margin: 0 0 8px;
  letter-spacing: -0.3px;
}
.auth-card .sub {
  color: var(--muted);
  margin: 0 0 26px;
  font-size: 13.5px;
}
.auth-card .field {
  margin-bottom: 16px;
}
.auth-card .btn {
  width: 100%;
  justify-content: center;
  height: 42px;
}
.auth-note {
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* ------------------------------------------------------------------ 布局 */

.shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
  width: 100%;
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 640;
  font-size: 14.5px;
  padding: 4px 8px 18px;
}
.sidebar .brand .logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  display: grid;
  place-items: center;
  flex: none;
}
.nav-group {
  margin-top: 14px;
}
.nav-label {
  font-size: 11px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #5b6b85;
  padding: 0 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  cursor: pointer;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover {
  background: var(--sidebar-soft);
  color: #fff;
  text-decoration: none;
}
.nav-item.active {
  background: rgba(246, 130, 31, 0.14);
  color: #ffb066;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-item .ico {
  width: 16px;
  text-align: center;
  opacity: 0.9;
}
.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  padding-top: 12px;
  font-size: 12px;
  color: #64748b;
}
.sidebar-foot .who {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #cbd5e1;
  font-size: 13px;
  margin-bottom: 4px;
}
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f6821f, #d97706);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex: none;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.04);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.crumbs b {
  color: var(--text);
  font-weight: 600;
}
.crumbs .sep {
  color: var(--border-strong);
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.content {
  padding: 26px 32px 40px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* ------------------------------------------------------------- 组件：卡片 */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 21px;
  margin: 0 0 4px;
  letter-spacing: -0.3px;
}
.page-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 620;
}
.card-head .hint {
  color: var(--muted);
  font-size: 12.5px;
}
.card-body {
  padding: 18px;
}
.card-body.tight {
  padding: 0;
}

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

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat .label {
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat .value {
  font-size: 25px;
  font-weight: 650;
  letter-spacing: -0.6px;
  margin-top: 6px;
  line-height: 1.2;
}
.stat .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

/* ------------------------------------------------------------- 组件：表格 */

.table-wrap {
  overflow-x: auto;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.2px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-soft);
  white-space: nowrap;
}
table.data td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-soft);
}
table.data tr:last-child td {
  border-bottom: 0;
}
table.data tbody tr:hover {
  background: var(--panel-soft);
}
table.data .name {
  color: var(--text);
  font-weight: 550;
}
.mono {
  font-family: var(--mono);
  font-size: 12.5px;
}
.truncate {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: bottom;
}
.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* --------------------------------------------------------------- 组件：小件 */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.7;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.green {
  background: var(--green-soft);
  color: var(--green);
  border-color: rgba(18, 128, 92, 0.18);
}
.badge.amber {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: rgba(181, 71, 8, 0.18);
}
.badge.red {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(217, 45, 32, 0.18);
}
.badge.gray {
  background: var(--panel-soft);
  color: var(--muted);
  border-color: var(--border);
}
.badge.blue {
  background: rgba(37, 99, 235, 0.1);
  color: var(--blue);
  border-color: rgba(37, 99, 235, 0.18);
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* 开关（D1 控制台只读模式） */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  position: relative;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .track {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  flex: none;
  transition: background 0.18s ease;
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.25);
  transition: transform 0.18s ease;
}
.switch input:checked + .track {
  background: var(--green);
}
.switch input:checked + .track::after {
  transform: translateX(16px);
}
.switch input:not(:checked) + .track {
  background: var(--red);
}
.switch input:focus-visible + .track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.switch input:disabled + .track {
  opacity: 0.6;
}
.switch:has(input:checked) #d1-mode-text {
  color: var(--green);
}
.switch:has(input:not(:checked)) #d1-mode-text {
  color: var(--red);
}

/* 快捷操作面板 */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.quick-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
  min-height: 58px;
}
.quick-item .lbl {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.quick-item .sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.5;
}
.quick-item .select {
  max-width: 140px;
}
.quick-item code {
  font-family: var(--mono);
  font-size: 11px;
  word-break: break-all;
}

/* 子页签（规则页内） */
.sub-tabs {
  margin-bottom: 14px;
  border-bottom: none;
  gap: 6px;
}
.sub-tabs .tab {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12.5px;
}
.sub-tabs .tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

/* 写操作确认框里的 SQL 摘录 */.sql-quote {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  max-height: 160px;
  overflow: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.14s;
  font-family: inherit;
}
.btn:hover {
  border-color: var(--muted);
  color: var(--text);
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(246, 130, 31, 0.3);
}
.btn.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}
.btn.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn.ghost:hover {
  background: var(--panel-soft);
  color: var(--text);
}
.btn.sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12.5px;
}
.btn.link {
  border: 0;
  background: none;
  color: var(--blue);
  padding: 0;
  height: auto;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-family: inherit;
}
.icon-btn:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.input,
.select,
textarea {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 11px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg-elevated);
  font-family: inherit;
  outline: none;
  transition: border-color 0.14s, box-shadow 0.14s;
}
textarea {
  height: auto;
  min-height: 120px;
  padding: 10px 11px;
  line-height: 1.6;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12.5px;
}
.input:focus,
.select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(246, 130, 31, 0.14);
}
.select {
  cursor: pointer;
  height: 34px;
  max-width: 220px;
}
.field {
  margin-bottom: 15px;
}
.field > label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 6px;
}
.field .help {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.6;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--text-soft);
  cursor: pointer;
}
.checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar .search {
  max-width: 280px;
}
.toolbar .spacer {
  flex: 1;
}

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
}
.tab {
  padding: 9px 14px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  border: 0;
  background: none;
  border-bottom: 2px solid transparent;
  font-family: inherit;
  font-weight: 550;
  white-space: nowrap;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--accent-strong);
  border-bottom-color: var(--accent);
}

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}
.empty .big {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--accent-soft), var(--panel-soft));
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 22px;
  opacity: 1;
  color: var(--accent-strong);
}
.empty p {
  margin: 0 0 14px;
}

/* 页面级大空态：无卡片框 + 三步引导 */
.empty-hero {
  padding: 60px 24px 44px;
  text-align: center;
  max-width: 780px;
  margin: 0 auto;
}
.empty-hero .hero-ico {
  width: 74px;
  height: 74px;
  margin: 0 auto 18px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--accent-soft), var(--panel-soft));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: grid;
  place-items: center;
  font-size: 32px;
  color: var(--accent-strong);
}
.empty-hero h2 {
  margin: 0 0 10px;
  font-size: 20px;
  font-weight: 650;
  color: var(--text);
}
.empty-hero > p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
  margin: 0 auto 20px;
  max-width: 560px;
}
.empty-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 30px;
  text-align: left;
}
.empty-steps .step {
  display: flex;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.empty-steps .step .no {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  flex: none;
}
.empty-steps .step b {
  display: block;
  font-size: 13.5px;
  margin-bottom: 3px;
  color: var(--text);
}
.empty-steps .step span {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.55;
}

.alert {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  border: 1px solid;
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  line-height: 1.65;
}
.alert.error {
  background: var(--red-soft);
  border-color: rgba(217, 45, 32, 0.25);
  color: var(--red);
}
.alert.warn {
  background: var(--amber-soft);
  border-color: rgba(181, 71, 8, 0.25);
  color: var(--amber);
}
.alert.info {
  background: rgba(37, 99, 235, 0.06);
  border-color: rgba(37, 99, 235, 0.2);
  color: var(--text-soft);
}
.alert code {
  font-family: var(--mono);
  font-size: 12px;
  background: rgba(0, 0, 0, 0.05);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ 图表 */

.chart {
  width: 100%;
  height: 180px;
  display: block;
}
.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.chart-legend i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 5px;
}

/* ------------------------------------------------------------------ 弹层 */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
  animation: fade 0.15s ease;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.modal {
  background: var(--panel);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: pop 0.16s ease;
}
.modal.wide {
  max-width: 760px;
}
@keyframes pop {
  from {
    transform: translateY(8px) scale(0.99);
    opacity: 0;
  }
}
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 620;
}
.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--panel-soft);
  border-radius: 0 0 14px 14px;
}
.modal-error {
  background: var(--red-soft);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 12.5px;
  margin-top: 10px;
}

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: #101828;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slide 0.18s ease;
  max-width: 380px;
  line-height: 1.6;
}
.toast.error {
  background: #b42318;
}
.toast.ok {
  background: #0b6b4f;
}
.toast.warn {
  background: #93540a;
}
@keyframes slide {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}

/* ------------------------------------------------------------ 工具类/杂项 */

.muted {
  color: var(--muted);
}
.small {
  font-size: 12.5px;
}
.mt-0 {
  margin-top: 0;
}
.mt-16 {
  margin-top: 16px;
}
.mt-4 {
  margin-top: 4px;
}
.txt-red {
  color: var(--red);
}
.mb-16 {
  margin-bottom: 16px;
}
.flex {
  display: flex;
  gap: 8px;
  align-items: center;
}
.flex.between {
  justify-content: space-between;
}
.flex.wrap {
  flex-wrap: wrap;
}
.right {
  text-align: right;
}
.nowrap {
  white-space: nowrap;
}
.kv-list {
  display: grid;
  grid-template-columns: 180px 1fr;
  font-size: 13px;
}
.kv-list > div {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.kv-list > div:nth-child(odd) {
  color: var(--muted);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child {
  border-bottom: 0;
}
.settings-row .meta {
  min-width: 0;
}
.settings-row .meta b {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
}
.settings-row .meta span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.settings-row .control {
  flex: none;
  min-width: 150px;
  text-align: right;
}
.settings-row .select,
.settings-row .input {
  max-width: 190px;
}
pre.code {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  margin: 0;
  max-height: 340px;
  color: var(--text-soft);
}

/* 移动端导航：汉堡按钮 + 左侧抽屉（桌面端隐藏相关元素） */
.nav-toggle,
.drawer-close {
  display: none;
}
.nav-backdrop {
  display: none;
}

@media (max-width: 1080px) {
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid.cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 880px) {
  .auth-wrap {
    grid-template-columns: 1fr;
  }
  .auth-aside {
    display: none;
  }
  .auth-main {
    padding: 20px;
  }
  .empty-steps {
    grid-template-columns: 1fr;
  }
  .shell {
    grid-template-columns: 1fr;
  }
  .content {
    padding: 16px;
  }
  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4 {
    grid-template-columns: 1fr;
  }
  .field-row {
    grid-template-columns: 1fr;
  }

  /* 侧边栏改为左侧抽屉：默认移出屏幕，body.nav-open 时滑入 */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(82vw, 296px);
    height: 100dvh;
    z-index: 70;
    flex-direction: column;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(-102%);
    visibility: hidden;
    box-shadow: var(--shadow-lg);
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
  }
  body.nav-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform 0.22s ease;
  }
  body.nav-open {
    overflow: hidden;
  }
  .sidebar .brand {
    justify-content: flex-start;
    padding: 2px 6px 16px;
  }
  .drawer-close {
    display: grid;
    margin-left: auto;
  }
  .side-nav {
    display: flex;
    flex-direction: column;
  }
  .nav-item {
    min-height: 46px;
    padding: 11px 12px;
    font-size: 14.5px;
  }
  .nav-item .txt {
    display: inline;
  }
  .nav-label {
    padding-top: 8px;
  }
  .sidebar-foot {
    display: block;
  }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(15, 23, 42, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
  }
  body.nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .nav-toggle {
    display: grid;
    flex: none;
  }
  .topbar {
    padding: 0 14px;
  }
}

/* ------------------------------- 手机（≤640px）：单手触控与阅读优化 ------ */
@media (max-width: 640px) {
  .content {
    padding: 12px 12px calc(28px + env(safe-area-inset-bottom));
  }
  /* 统计卡片（概览/区域概览）改为两列，避免整屏只看四张卡 */
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .stat {
    padding: 12px 14px;
  }
  .stat .value {
    font-size: 20px;
    margin-top: 4px;
  }
  .stat .sub {
    font-size: 11.5px;
    overflow-wrap: anywhere;
  }
  .topbar {
    height: 56px;
    padding: 0 10px;
    gap: 6px;
  }
  /* 窄屏隐藏面包屑：页面标题（.page-head h1）已表达当前位置，给操作区腾空间 */
  .crumbs {
    display: none;
  }
  .top-actions {
    flex: 1;
    justify-content: flex-end;
    gap: 2px;
  }
  #account-switch {
    max-width: 156px;
  }
  .page-head {
    gap: 10px;
    margin-bottom: 14px;
  }
  .page-head h1 {
    font-size: 19px;
  }
  .page-head p {
    font-size: 12.5px;
  }
  .page-actions {
    width: 100%;
  }
  .page-actions .btn {
    flex: 1;
    justify-content: center;
  }

  /* 触控目标 ≥42px；输入框 16px 以避免 iOS Safari 聚焦自动放大 */
  .btn {
    height: 42px;
    padding: 0 14px;
  }
  .btn.sm {
    height: 40px;
    padding: 0 11px;
  }
  .btn.primary {
    box-shadow: none;
  }
  .icon-btn {
    width: 42px;
    height: 42px;
    font-size: 16px;
  }
  .input,
  .select {
    height: 44px;
    font-size: 16px;
  }
  textarea {
    font-size: 16px;
  }
  /* 代码类编辑区保持等宽小字号（否则一行只放得下十来个字符） */
  textarea.code-edit,
  #sql-input {
    font-size: 13px;
  }
  .select {
    max-width: none;
  }
  .toolbar {
    gap: 8px;
  }
  .toolbar .search,
  .toolbar > .input {
    max-width: none !important;
    flex: 1 1 100%;
  }
  .toolbar .spacer {
    display: none;
  }
  .tabs,
  .sub-tabs {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar,
  .sub-tabs::-webkit-scrollbar {
    display: none;
  }
  .pager {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
  }
  .toasts {
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .toast {
    max-width: none;
    width: 100%;
  }

  /* 设置类长表单：标签在上、控件占满整行，避免被 150px 控制区挤扁 */
  .kv-list {
    grid-template-columns: 104px minmax(0, 1fr);
  }
  .settings-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .settings-row .control {
    min-width: 0;
    text-align: left;
  }
  .settings-row .select,
  .settings-row .input {
    max-width: none;
    width: 100%;
  }
  .truncate {
    max-width: 100%;
  }

  /* 弹窗：不再被 max-content 撑破视口，底部按钮平分宽度 */
  .modal-mask {
    padding: 12px;
  }
  .modal,
  .modal.wide {
    max-width: calc(100vw - 24px);
    max-height: 90dvh;
    border-radius: 12px;
  }
  .modal-head,
  .modal-body {
    padding-left: 14px;
    padding-right: 14px;
  }
  .modal-foot {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
  }
  .modal-foot .btn {
    flex: 1;
    justify-content: center;
  }
  .totp-codes {
    grid-template-columns: repeat(3, 1fr);
  }
  .acc-pick-list {
    max-height: 46dvh;
  }
  .empty-hero {
    padding: 32px 8px 24px;
  }

  /* 数据表格转「卡片 + 字段名」：删掉横向滚动的探路成本 */
  .table-wrap {
    overflow: visible;
  }
  table.data {
    display: block;
    font-size: 13px;
  }
  table.data thead {
    display: none;
  }
  table.data tbody {
    display: block;
  }
  table.data tbody tr {
    display: block;
    margin: 0 0 10px;
    padding: 2px 12px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
  }
  table.data tbody tr:last-child {
    margin-bottom: 0;
  }
  table.data tbody tr:hover {
    background: var(--panel-soft);
  }
  table.data td {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    min-height: 40px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
    overflow-wrap: anywhere;
  }
  table.data td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
  }
  table.data td:last-child {
    border-bottom: 0;
  }
  table.data td[data-label=''] {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    grid-template-columns: none;
    padding-top: 4px;
  }
  table.data td[data-label='']::before {
    content: none;
  }
  table.data .truncate {
    display: inline;
    max-width: 100%;
    white-space: normal;
    word-break: break-all;
  }
  table.data .row-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  table.data .mono {
    font-size: 12px;
    word-break: break-all;
  }
  /* 卡片里的文本链接（域名名、详情）也要有可点高度 */
  table.data td a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
  }
  .card-head a.small {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    margin: -10px 0;
    padding: 0 2px;
  }
}

@media (max-width: 380px) {
  #account-switch {
    max-width: 128px;
  }
  .nav-item {
    font-size: 14px;
  }
}

/* ===== 令牌权限诊断 ===== */
.diag-group { margin-bottom: 12px; }
.diag-group-title {
  font-weight: 600;
  font-size: 13px;
  margin: 8px 0 4px;
  color: var(--text, #333);
}
.diag-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px;
  border-radius: 6px;
}
.diag-row:nth-child(odd) { background: rgba(127, 127, 127, 0.08); }
.diag-missing { color: #d92d20; font-weight: 600; }

/* ===== Worker 脚本编辑 ===== */
.code-edit {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
  min-height: 320px;
  resize: vertical;
}
.code-pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
  overflow: auto;
  max-height: 260px;
  margin: 6px 0 0;
  padding: 10px;
  background: rgba(127, 127, 127, 0.1);
  border-radius: 6px;
}
.module-view summary { cursor: pointer; font-size: 12.5px; color: var(--text-soft, #555); }
#bind-tbody td { vertical-align: middle; }

/* 邮件路由：转发目标多选 chips */
.chips-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  min-height: 38px;
  background: var(--panel-soft);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .small.muted { align-self: center; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text-soft);
  font-size: 12.5px;
}
.chip-x {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
  padding: 0 3px;
  border-radius: 50%;
}
.chip-x:hover { color: var(--red); }

/* 输入框内嵌后缀（如邮件路由收件地址自动补齐 @域名） */
.input-affix {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}
.input-affix:focus-within { border-color: var(--accent); }
.input-affix .input {
  border: none;
  flex: 1;
  border-radius: 0;
  box-shadow: none;
  min-width: 0;
}
.input-affix .input:focus { outline: none; }
.input-affix .affix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  border-left: 1px solid var(--border);
  white-space: nowrap;
}

/* 分页器 */
/* Pages 直传部署进度条 */
.pu-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-muted, rgba(127, 127, 127, 0.15));
  overflow: hidden;
  margin-top: 8px;
}
.pu-bar-fill {
  height: 100%;
  width: 2%;
  border-radius: 999px;
  background: var(--primary, #f6821f);
  transition: width 0.25s ease;
}

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
  padding: 10px 4px 2px;
}

/* 两步验证 */
.totp-qr-wrap {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}
.totp-qr-wrap canvas {
  border-radius: 8px;
}
.totp-codes {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.totp-codes code {
  font-family: var(--mono, monospace);
  font-size: 13px;
  text-align: center;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg, transparent);
}

/* 添加账号 · 勾选列表 */
.acc-pick-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.acc-pick-list {
  max-height: 320px;
  overflow-y: auto;
  margin: 0 -4px;
}
.acc-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.acc-pick:hover {
  background: var(--bg-soft, rgba(0, 0, 0, 0.03));
}
.acc-pick input[type='checkbox'] {
  flex: none;
  width: 15px;
  height: 15px;
}
.acc-pick-name {
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.acc-pick.is-taken {
  opacity: 0.55;
  cursor: not-allowed;
}
