/*
 * 瑶台管理后台 —— 全部样式（单文件、零依赖、无构建）
 * ============================================================================
 * 设计约束（都来自本轮硬要求，不是审美偏好）：
 *
 * 1. 🔴 **窄屏优先**：验收方式是"用安卓手机浏览器打开"，宽度区间 360~430px。
 *    所以每条布局都先写窄屏形态，再用 `@media (min-width: 900px)` 升到宽屏形态 ——
 *    反过来写（先桌面再补手机）在本项目已经翻车过一次：桌面好看、手机横向溢出。
 * 2. 🔴 **不允许内联 style 属性**：服务端对 /admin-web/* 下发
 *    `style-src 'self'`，`style="..."` 会被 CSP 直接拦掉（页面看起来"没生效"）。
 *    所以"动态样式"一律走 class 切换（`classList`）或 SVG 的几何属性
 *    （`x`/`y`/`width`/`height`/`stroke` 是**属性**，不受 style-src 管辖）。
 * 3. 没有 CSS 变量回退问题：目标浏览器（安卓 Chrome / 各家 WebView）都支持
 *    `var()`、`grid`、`flex`、`gap`、`position: sticky`，不做 IE 兼容。
 * 4. 深色主题：后台会在夜里被用来做应急下架，浅色在暗环境下刺眼；
 *    同时深色能明显区分"这是后台"和"这是 App"。
 */

/* ───────────────────────────────────────────────────────── 基础 / 复位 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f1218;
  --bg-elev: #161b24;
  --bg-elev-2: #1d2430;
  --border: #2a3342;
  --border-strong: #3a4657;
  --text: #e6eaf2;
  --text-dim: #a3adbe;
  --text-faint: #7b8598;
  --accent: #4c8dff;
  --accent-dim: #2f5fb0;
  --ok: #35c98a;
  --warn: #e0b341;
  --danger: #ff6b6b;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 10px;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  /* 16px 起步：手机上字号小了根本看不清，后台不是展示型页面 */
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-wrap: break-word;
}

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

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

input,
select,
textarea {
  font: inherit;
}

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

/* 键盘可达性：全局焦点环（手机上点按不会触发，但桌面/外接键盘需要） */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ───────────────────────────────────────────────────────── 通用零件 */

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.spacer {
  flex: 1 1 auto;
}

.mono {
  font-family: var(--mono);
  font-size: 0.88em;
  letter-spacing: 0.02em;
}

.dim {
  color: var(--text-dim);
}

.faint {
  color: var(--text-faint);
}

.num {
  /* 数字右对齐 + 等宽：表格里一列数字左对齐是很难对账的 */
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.right {
  text-align: right;
}

.nowrap {
  white-space: nowrap;
}

.small {
  font-size: 0.85rem;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  white-space: nowrap;
}

.badge-ok {
  color: var(--ok);
  border-color: rgba(53, 201, 138, 0.5);
  background: rgba(53, 201, 138, 0.1);
}

.badge-warn {
  color: var(--warn);
  border-color: rgba(224, 179, 65, 0.5);
  background: rgba(224, 179, 65, 0.1);
}

.badge-danger {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.5);
  background: rgba(255, 107, 107, 0.1);
}

.badge-accent {
  color: var(--accent);
  border-color: rgba(76, 141, 255, 0.5);
  background: rgba(76, 141, 255, 0.12);
}

/* ───────────────────────────────────────────────────────── 按钮 */

.btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  /* 最小 40px 高：手指点得中（Material 的最小触控目标是 48dp，这里再收一点也不低于 40） */
  min-height: 40px;
  padding: 8px 14px;
  font-size: 0.92rem;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: #253040;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent);
}

.btn-danger {
  border-color: rgba(255, 107, 107, 0.6);
  color: #ffb3b3;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(255, 107, 107, 0.18);
}

.btn-sm {
  min-height: 34px;
  padding: 5px 10px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
}

/* ───────────────────────────────────────────────────────── 表单 */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field-label {
  font-size: 0.86rem;
  color: var(--text-dim);
}

.input,
.select,
.textarea {
  background: #10151d;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  min-height: 42px;
  width: 100%;
}

.textarea {
  min-height: 84px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  outline: none;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 12px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.file-input {
  padding: 8px;
}

/* ───────────────────────────────────────────────────────── 登录页 */

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 18px;
}

.login-title {
  font-size: 1.3rem;
  font-weight: 700;
}

.login-sub {
  color: var(--text-dim);
  font-size: 0.88rem;
  margin-top: 6px;
}

.login-step {
  margin-top: 18px;
}

/* ───────────────────────────────────────────────────────── 顶栏 / 布局 */

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(15, 18, 24, 0.96);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}

.brand-sub {
  color: var(--text-faint);
  font-size: 0.78rem;
  white-space: nowrap;
}

.who {
  font-size: 0.84rem;
  color: var(--text-dim);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  /* 窄屏：导航（横向标签条）在上、内容在下 ⇒ 这一层是**列**方向 */
  flex-direction: column;
}

/*
 * 内容列：确认条 + 内容区。
 * `min-width: 0` 是必须的 —— flex 子项的默认 `min-width: auto` 会让内部的
 * 横向滚动容器（表格 / 图表）把整个页面撑宽，窄屏上表现为"整页可以左右拖"。
 */
.content-col {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

/*
 * 窄屏导航 = 顶部横向可滑动的标签条（这是本轮的硬要求）。
 * ⚠️ `overflow-x: auto` + `flex-wrap: nowrap` 是"横向滑动"的关键；
 * 少了 `-webkit-overflow-scrolling` 在老 WebView 上滑不顺。
 */
.nav {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.nav-item {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.9rem;
  white-space: nowrap;
}

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

.nav-item.is-active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 14px 12px 40px;
}

.page-head {
  margin-bottom: 12px;
}

.page-desc {
  color: var(--text-faint);
  font-size: 0.84rem;
  margin-top: 4px;
}

/* ───────────────────────────────────────────────────────── 统计卡 */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}

.stat-label {
  color: var(--text-faint);
  font-size: 0.8rem;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  color: var(--text-faint);
  font-size: 0.76rem;
  margin-top: 2px;
}

/* ───────────────────────────────────────────────────────── 图表 */

.chart-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

/*
 * 图表用固定像素尺寸 + `min-width`，而不是 `width: 100%; height: auto`：
 * 这里踩过一次 —— 在横向滚动容器（`overflow-x: auto`）里，百分比宽度会因为
 * "父容器宽度由内容决定"而塌成 0，表现是**图表整块消失**（页面其余部分正常，
 * 所以极容易误判成"数据没取到"）。固定像素尺寸在任何容器里都成立。
 * 720×260 ≈ 2.8:1，与 JS 里 SVG 的 viewBox 720×300 同量级，不会拉变形。
 */
.chart-svg {
  display: block;
  width: 720px;
  height: 260px;
  min-width: 620px;
}

.chart-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 14px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.swatch-bar {
  background: var(--accent);
}

.swatch-bar-peak {
  background: var(--warn);
}

.swatch-line {
  background: transparent;
  border-top: 2px dashed var(--danger);
  height: 0;
}

.chart-note {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-faint);
  line-height: 1.5;
}

/* ───────────────────────────────────────────────────────── 表格 */

/*
 * 窄屏表格一律横向滚动：把列压窄会让"用量/时间"这种关键数字截断，
 * 而截断的数字比需要滑动更危险（看错一位就是另一个量级）。
 */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
}

table.data {
  border-collapse: collapse;
  width: 100%;
  min-width: 620px;
  font-size: 0.88rem;
}

table.data th,
table.data td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data th {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.82rem;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}

table.data tbody tr:last-child td {
  border-bottom: none;
}

table.data tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cell-truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-clamp {
  max-width: 320px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}

/* 用量占比条（会员周期桶 / 用户用量） */
.usage {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}

.usage-track {
  height: 6px;
  border-radius: 999px;
  background: #0b0f15;
  border: 1px solid var(--border);
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.usage-fill.is-warn {
  background: var(--warn);
}

.usage-fill.is-danger {
  background: var(--danger);
}

/*
 * 进度条的宽度**只能**用下面这组预设类，不能用内联 `style="width: …%"`：
 * CSP 的 `style-src 'self'` 会拦掉内联 style 属性（`element.style.setProperty()`
 * 也属于内联样式，同样被拦）。10% 一跳是"够看"与"类表别太长"的折中；
 * 精确数字永远显示在条上方的文本里，条只承担"一眼看出是不是快满了"。
 */
.fill-0 { width: 0; }
.fill-10 { width: 10%; }
.fill-20 { width: 20%; }
.fill-30 { width: 30%; }
.fill-40 { width: 40%; }
.fill-50 { width: 50%; }
.fill-60 { width: 60%; }
.fill-70 { width: 70%; }
.fill-80 { width: 80%; }
.fill-90 { width: 90%; }
.fill-100 { width: 100%; }

/* ───────────────────────────────────────────────────────── 分页 / 工具条 */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.toolbar .field {
  margin-bottom: 0;
  min-width: 0;
}

.toolbar .field-grow {
  flex: 1 1 180px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.pager-info {
  color: var(--text-dim);
  font-size: 0.84rem;
}

/* ───────────────────────────────────────────────────────── 提示 / 错误 / 确认 */

.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  z-index: 90;
  pointer-events: none;
}

.progress.is-on::after {
  content: "";
  display: block;
  height: 100%;
  width: 40%;
  background: var(--accent);
  border-radius: 2px;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  0% {
    transform: translateX(-45%);
  }
  100% {
    transform: translateX(255%);
  }
}

.banner {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.88rem;
  border: 1px solid;
  margin-bottom: 12px;
  white-space: pre-wrap;
}

.banner-error {
  border-color: rgba(255, 107, 107, 0.55);
  background: rgba(255, 107, 107, 0.12);
  color: #ffd0d0;
}

.banner-ok {
  border-color: rgba(53, 201, 138, 0.55);
  background: rgba(53, 201, 138, 0.12);
  color: #c9f5e3;
}

.banner-warn {
  border-color: rgba(224, 179, 65, 0.55);
  background: rgba(224, 179, 65, 0.12);
  color: #f6e6bd;
}

.banner-info {
  border-color: var(--border-strong);
  background: var(--bg-elev-2);
  color: var(--text-dim);
}

.banner-dismiss {
  margin-top: 8px;
}

.confirm-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(224, 179, 65, 0.6);
  background: rgba(224, 179, 65, 0.14);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.confirm-text {
  flex: 1 1 220px;
  font-size: 0.9rem;
}

.empty {
  padding: 18px 12px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.88rem;
}

.muted-box {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.86rem;
  color: var(--text-dim);
}

/* ───────────────────────────────────────────────────────── 兑换码明文区 */

/*
 * 🔴 明文码**只出现这一次**（库里只有 hash + 前 4 位）。
 * 所以这块区域必须显眼到"不可能被忽略"：高对比边框 + 大号等宽字体 + 独立滚动。
 */
.plain-codes {
  border: 2px solid var(--warn);
  background: rgba(224, 179, 65, 0.1);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.plain-codes-title {
  font-weight: 700;
  color: #f6e6bd;
  font-size: 1rem;
}

.plain-codes-warn {
  color: #ffd9a0;
  font-size: 0.86rem;
  margin-top: 6px;
  line-height: 1.5;
}

.code-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
  margin-top: 10px;
  max-height: 300px;
  overflow-y: auto;
}

.code-item {
  font-family: var(--mono);
  font-size: 1rem;
  letter-spacing: 0.08em;
  background: #10151d;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 7px 9px;
  user-select: all;
  -webkit-user-select: all;
}

.code-fallback {
  width: 100%;
  min-height: 90px;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 0.86rem;
}

/* ───────────────────────────────────────────────────────── 图片预览 */

.thumb {
  width: 72px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0b0f15;
  display: block;
}

.thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 0.7rem;
}

/* ───────────────────────────────────────────────────────── 宽屏升级 */

@media (min-width: 900px) {
  .layout {
    flex-direction: row;
  }

  /* 宽屏：左侧竖向导航 */
  .nav {
    flex-direction: column;
    flex-wrap: nowrap;
    width: 190px;
    flex: 0 0 190px;
    overflow-x: hidden;
    overflow-y: auto;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 12px 10px;
    gap: 4px;
  }

  .nav-item {
    border-radius: 8px;
    justify-content: flex-start;
    width: 100%;
  }

  .content {
    padding: 20px 24px 60px;
  }

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

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

  .toolbar .field-grow {
    flex: 1 1 260px;
  }

  .who {
    max-width: 320px;
  }
}
