/* ============================================================
   卡密管理后台（原型演示）— 全部样式
   按板块组织，公共颜色集中在 :root 变量，便于后续调色
   ============================================================ */

/* ---------- 公共颜色变量 ---------- */
:root {
  --bg-page: #F5F6F8;          /* 页面背景浅灰 */
  --bg-card: #FFFFFF;          /* 卡片白底 */
  --border-light: #E7E9EE;     /* 极淡边框 */
  --shadow-light: 0 1px 3px rgba(20, 24, 40, 0.05); /* 极轻阴影 */

  --text-main: #1F2430;        /* 主文字深色 */
  --text-gray: #6B7280;        /* 灰色文字 */
  --text-light: #9CA3AF;       /* 更浅灰 */

  --purple: #5B4BE0;           /* 紫色主按钮 */
  --purple-hover: #6D5CE7;
  --save: #4F46E5;             /* 保存按钮深蓝紫 */
  --save-hover: #4338CA;
  --green: #22C55E;            /* 绿色 */
  --green-hover: #16A34A;
  --orange: #F59E0B;           /* 橙色 */
  --orange-hover: #D97706;
  --red: #EF4444;              /* 红色 */
  --red-hover: #DC2626;
  --gray-btn: #6B7280;         /* 深灰按钮 */
  --gray-btn-hover: #4B5563;

  --radius-card: 8px;          /* 卡片圆角 */
  --radius-btn: 6px;           /* 按钮圆角 */

  /* 弹窗统一模板：调整以下变量可同步作用于全部弹窗 */
  --modal-width: 560px;
  --modal-radius: 8px;
  --modal-max-height: 80vh;
  --modal-titlebar-height: 45px;
  --modal-titlebar-bg: #F1F2F5;
  --modal-title-color: var(--text-main);
  --modal-title-size: 15px;
  --modal-body-padding: 22px 24px 26px;
  --modal-group-gap: 20px;
  --modal-field-gap: 6px;
  --modal-error-gap: 6px;
  --modal-footer-padding: 14px;
  --modal-btn-gap: 10px;
}

/* ---------- 全局重置 ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  background: var(--bg-page);
  font-family: 'Microsoft YaHei', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
  color: var(--text-main);
  font-size: 14px;
}

button {
  font-family: inherit;
}

/* ============================================================
   顶部提示条（原型演示声明）
   ============================================================ */
.notice-bar {
  max-width: 1600px;
  margin: 16px auto 0;
  padding: 10px 16px;
  background: #FFF7E6;
  border: 1px solid #FFE0B2;
  color: #8A6D3B;
  border-radius: var(--radius-card);
  font-size: 13px;
}

/* ============================================================
   板块一：标题条
   ============================================================ */
.topbar {
  max-width: 1600px;
  margin: 16px auto 0;
  height: 56px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-light);
  display: flex;
  align-items: center;
  padding: 0 20px;
}

/* 标题条内部：左标题、右按钮，同一水平线（改动一） */
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-gray);
  font-size: 16px;
  font-weight: 600;
}

.topbar-icon {
  font-size: 18px;
}

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

/* 退出：红色纯文字，无背景无边框 */
.logout-link {
  color: var(--red);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.logout-link:hover {
  text-decoration: underline;
}

/* ============================================================
   通用按钮
   白字、圆角、内边距适中、无边框、悬停略深，字号偏小（13px）
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-btn);
  padding: 7px 14px;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.btn-purple { background: var(--purple); }
.btn-purple:hover { background: var(--purple-hover); }

.btn-save { background: var(--save); }
.btn-save:hover { background: var(--save-hover); }

.btn-green { background: var(--green); }
.btn-green:hover { background: var(--green-hover); }

.btn-orange { background: var(--orange); }
.btn-orange:hover { background: var(--orange-hover); }

.btn-red { background: var(--red); }
.btn-red:hover { background: var(--red-hover); }

.btn-gray { background: var(--gray-btn); }
.btn-gray:hover { background: var(--gray-btn-hover); }

/* 小尺寸按钮（表格行内用） */
.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
  border-radius: 5px;
}

/* 「保存」有未保存改动时的状态：略变亮 + 右上角小红点 */
.btn-save.has-changes {
  background: var(--purple-hover);
  position: relative;
}
.btn-save.has-changes::after {
  content: '';
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red);
  border: 1px solid #fff;
}

/* ============================================================
   页面主容器：内容区最大宽度 1600px，居中，左右留白
   ============================================================ */
.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px 0 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 通用白色圆角卡片 */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-light);
  padding: 14px 20px;
}

/* 灰色小字标签（如「应用：」「生成：」「批量：」） */
.label-gray {
  color: var(--text-gray);
  font-size: 13px;
  flex-shrink: 0;
}

/* ============================================================
   板块二：应用卡说明
   应用卡不再有专属样式——它直接复制「生成卡密」卡片的
   stat-head / stat-mid 结构，排版节奏与其余卡片一致
   ============================================================ */

/* ============================================================
   板块三：六块统计卡（等宽）
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-light);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat-head {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-gray);
  font-size: 13px;
}

.stat-icon {
  display: inline-flex;
  align-items: center;
  font-size: 15px;
}

/* 内联 SVG 图标：统一线性风格、15px、灰色（继承标题文字色），不依赖系统 emoji 字体 */
.stat-icon svg {
  width: 15px;
  height: 15px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stat-mid {
  display: flex;
  align-items: center;
  /* 应用卡 .stat-mid 内并排放三个胶囊按钮：
     间距与生成卡按钮所在行保持同一层级节奏；空间不足时整体换行不溢出 */
  gap: 6px;
  flex-wrap: wrap;
}

/* 大数字 */
.stat-num {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
}
.stat-num-purple { color: var(--purple); }
.stat-num-orange { color: var(--orange); }

.stat-unit {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-gray);
}

/* 可点击的胶囊开关按钮
   改动四：固定高度 + 统一内边距/字号/行高，保证「已开启/已关闭」两种状态
   及两张开关卡片切换前后尺寸恒定，不发生高度跳动 */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
  border: none;
  border-radius: 999px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}
/* 关闭态：浅粉底红字 */
.pill-off {
  background: #FEE2E2;
  color: var(--red);
}
/* 开启态：浅绿底绿字 */
.pill-on {
  background: #DCFCE7;
  color: var(--green);
}
/* 中性态：浅灰底深灰字（应用卡「切换」按钮） */
.pill-gray {
  background: #F3F4F6;
  color: var(--text-gray);
}

/* ============================================================
   板块四：搜索行（改动五：左搜索框，右恢复默认排序，同一行分置两端）
   ============================================================ */
.search-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.search-row .search-box {
  width: 45%;
  min-width: 300px;
  max-width: 520px;
}

/* 搜索框：浅灰底、圆角、左侧放大镜 */
.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #F1F2F5;
  border-radius: var(--radius-btn);
  padding: 0 12px;
  width: 100%;
  max-width: 380px;
}

.search-icon {
  font-size: 13px;
  color: var(--text-light);
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  padding: 8px 0;
  font-size: 13px;
  width: 100%;
  color: var(--text-main);
  font-family: inherit;
}

/* ============================================================
   板块五：批量操作区
   ============================================================ */
.batch-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

/* 未勾选任何卡密时：批量按钮禁用视觉（降不透明度 + not-allowed） */
.batch-btn.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* 「恢复默认排序」：白底、浅灰边框、灰字（区别于实心按钮） */
.btn-reset-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #FFFFFF;
  border: 1px solid var(--border-light);
  color: var(--text-gray);
  border-radius: var(--radius-btn);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}
.btn-reset-sort:hover {
  background: #F5F6F8;
}
.filter-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ============================================================
   板块六：主表格
   ============================================================ */
.table-card {
  padding: 0;
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
}

.card-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 1500px; /* 15 列，保证窄屏横向滚动而不挤压 */
}

/* 表头：浅灰底、深灰字、13px */
.card-table thead th {
  background: #F7F8FA;
  color: var(--text-gray);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  padding: 12px 12px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

/* 表头排序：默认双箭头灰色，当前列仅当前方向为红色 */
.card-table thead th[data-sort-key] { cursor: pointer; user-select: none; }
.sort-arrows {
  display: inline-flex;
  flex-direction: column;
  margin-left: 4px;
  font-size: 11px;
  line-height: 1;
  vertical-align: middle;
}
.sort-arrows span { color: #C3C8D2; }
.sort-arrows .is-active { color: var(--red); font-weight: 700; }

/* 数据行：白底、极淡横线分隔、垂直居中 */
.card-table tbody td {
  padding: 12px 12px;
  border-bottom: 1px solid #F0F1F4;
  vertical-align: middle;
  color: var(--text-main);
}

.card-table tbody tr:hover {
  background: #FAFBFC;
}

/* 待删除行：整行置灰 */
.card-table tbody tr.row-deleted td {
  background: #F3F4F6;
  color: var(--text-light);
}

/* 各列宽度控制 */
.col-check  { width: 40px; }
.col-id     { width: 150px; }
.col-type   { width: 70px; }
.col-created{ width: 150px; }
.col-validity{ width: 210px; }   /* 有效期文案较长（如「已激活（剩余53天4小时4分钟）」），适当加宽 */
.col-cooldown{ width: 90px; }
.col-activated{ width: 160px; }
.col-device { width: 220px; }
.col-remain { width: 100px; }
.col-online { width: 90px; }
.col-devlimit{ width: 90px; }     /* 第三轮改动：可绑数量列（取代原绑定模式列） */
.col-status { width: 90px; }
.col-selfunbind{ width: 95px; }   /* 单个切换按钮 */
.col-note   { width: 110px; }
.col-actions{ min-width: 230px; } /* 操作列按钮较多，适当加宽 */

/* 追加要求（改动7）：状态 / 激活时间 / 有效期三列表头与内容居中 */
.card-table thead th.col-status,
.card-table thead th.col-activated,
.card-table thead th.col-validity {
  text-align: center;
}
/* 数据行内使用：单元格内容居中 */
.td-center { text-align: center; }

/* 卡密编号单元格 */
.cell-id {
  display: flex;
  align-items: center;
  gap: 6px;
}
/* 改动6：卡号文字本身可点击复制，悬停高亮给「可点」暗示 */
.card-code {
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: color 0.15s ease;
}
.card-code:hover {
  color: var(--purple);
  text-decoration: underline;
}

/* 待删除徽标 */
.deleted-badge {
  display: inline-block;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

/* 绑定设备：机器码自动换行，字号略小 */
.device-code {
  word-break: break-all;
  font-size: 12px;
  color: var(--text-gray);
  line-height: 1.5;
}

/* 状态颜色规则（改动7.1）：
   未激活/正常→绿，已过期/已禁用→红；居中、加粗、字号略大于正文（正文 13px） */
.status-green { color: var(--green); font-weight: 700; font-size: 14px; }
.status-red   { color: var(--red);   font-weight: 700; font-size: 14px; }

/* 有效期颜色 */
.validity-green { color: var(--green); }
.validity-red   { color: var(--red); }

/* 未激活 / 未绑定等灰色占位文字 */
.text-muted { color: var(--text-light); }

/* 第三轮改动前的自助解绑 / 绑定模式小标签（旧样式，保留备用）
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin-right: 6px;
}
.tag-green  { background: #DCFCE7; color: var(--green); }
.tag-orange { background: #FEF3C7; color: var(--orange-hover); }
*/

/* 切换按钮：单按钮既是状态显示，点击又可切换
   自助解绑：已开启=绿底浅色字 / 已关闭=灰底 */
.toggle-btn {
  display: inline-block;
  border: none;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.toggle-on {
  background: var(--green);
  color: #FFFFFF;
}
.toggle-on:hover {
  background: var(--green-hover);
}
.toggle-off {
  background: #E5E7EB;
  color: var(--text-gray);
}
.toggle-off:hover {
  background: #D1D5DB;
}

/* 数字小圆角框（可绑数量 / 解绑冷却共用同一视觉风格，点击打开编辑弹窗）
   取值范围：可绑数量 1-999；解绑冷却单位为小时 */
.dev-limit,
.num-chip {
  display: inline-block;
  min-width: 28px;
  text-align: center;
  background: #EDE9FE;
  color: var(--purple);
  font-weight: 600;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.dev-limit:hover,
.num-chip:hover {
  background: #DDD6FE;
}

/* 接口异常时的顶部红色提示条（默认隐藏，由 app.js 在取数失败时显示） */
.error-banner {
  max-width: 1600px;
  margin: 16px auto 0;
  padding: 10px 16px;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: #B91C1C;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}
.error-banner[hidden] {
  display: none;
}

/* 自助解绑「-」横杠居中 */
.dash {
  display: block;
  text-align: center;
  color: var(--text-light);
}

/* 备注为空时的「点击添加」浅灰占位 */
.note-placeholder {
  color: #C3C8D2;
  cursor: pointer;
  font-size: 12px;
}
.note-placeholder:hover {
  color: var(--text-gray);
}

/* 操作列按钮排布 */
.actions-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* 复选框尺寸 */
input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--purple);
}

/* ============================================================
   轻提示（toast）
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(31, 36, 48, 0.92);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 999;
  max-width: 80%;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   改动五：生成卡密模态窗
   遮罩：全屏半透明黑 + 背景模糊；点击遮罩不关闭（防误触），
   遮罩存在时底层页面不可点击（被遮罩拦截）。
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay[hidden] {
  display: none; /* 覆盖 display:flex，保证 hidden 属性生效 */
}

/* 弹窗本体：所有弹窗共用同一套尺寸变量 */
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--modal-radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  width: var(--modal-width);
  max-width: calc(100vw - 40px);
  max-height: var(--modal-max-height);
  overflow: auto;
}

/* 标题栏：浅灰底、标题居中，× 固定右上角 */
.modal-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--modal-titlebar-height);
  background: var(--modal-titlebar-bg);
  border-bottom: 1px solid var(--border-light);
  border-radius: var(--modal-radius) var(--modal-radius) 0 0;
  padding: 0 48px;
}
.modal-title {
  font-size: var(--modal-title-size);
  font-weight: 600;
  color: var(--modal-title-color);
}
.modal-close {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--text-gray);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.modal-close:hover {
  background: #E4E6EB;
  color: var(--text-main);
}

/* 内容区：普通弹窗按字段间距排布，分组表单按分组间距排布 */
.modal-body {
  padding: var(--modal-body-padding);
  display: flex;
  flex-direction: column;
  gap: var(--modal-field-gap);
}
.modal-body--grouped {
  gap: var(--modal-group-gap);
}
.modal-group {
  display: flex;
  flex-direction: column;
  gap: var(--modal-field-gap);
}
.modal-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}
.modal-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-main);
}
.modal-cooldown {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-gray);
}
.modal-cooldown .modal-input {
  width: 80px;
}
.modal-cooldown .modal-input:disabled {
  background: var(--bg-page);
  cursor: not-allowed;
}
.modal-desc {
  font-size: 13px;
  color: var(--text-gray);
  line-height: 1.6;
  margin: 0;
}
.modal-input-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--modal-error-gap);
}
.modal-input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text-main);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-btn);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea.modal-input {
  min-height: 5em;
  resize: vertical;
  line-height: 1.6;
}
.modal-input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}
.modal-input.has-error {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}
.modal-input-error {
  font-size: 12px;
  color: var(--red);
  line-height: 1.4;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--modal-btn-gap);
  margin-top: 4px;
  padding-top: var(--modal-footer-padding);
  border-top: 1px solid var(--border-light);
}
.modal > .modal-footer {
  padding: var(--modal-footer-padding) var(--modal-body-padding);
}
textarea.modal-input[readonly] {
  resize: none;
  background: var(--bg-card);
}

.gen-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* 切换应用弹窗：应用列表（每行一项，当前选中高亮 + ✓标记） */
.app-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.app-list .app-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-btn);
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.app-list .app-list-item:hover {
  background: #F5F6F8;
}
.app-list .app-list-item.is-current {
  background: #DCFCE7;
  border-color: #BBF7D0;
  color: var(--green);
  font-weight: 600;
}
.app-list .app-list-check {
  font-size: 12px;
}

/* ============================================================
   响应式（窄屏）
   ============================================================ */
@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .batch-bar {
    flex-direction: column;
    align-items: flex-start;
  }
  .search-row .search-box {
    width: 100%;
  }
}
