/* 密钥兑换 — 冷灰绿营业柜台式视觉 */
:root {
  --bg: #e9ede8;
  --surface: #f7f9f5;
  --surface-2: #eef2eb;
  --ink: #17241e;
  --ink-soft: #55635a;
  --line: #cfd8cd;
  --accent: #0f6b5c;
  --accent-deep: #0a4d42;
  --danger: #a8372a;
  --ok: #1c6b4b;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
}
.shell { max-width: 640px; margin: 0 auto; padding: 0 20px 40px; }
.shell-wide { max-width: 1600px; }
.shell-narrow { max-width: 460px; }

/* 双栏布局：前台与后台共用 */
.app-layout {
  display: grid; grid-template-columns: 220px 1fr;
  gap: 24px; margin: 0 auto; padding: 24px 20px 40px;
}
.sidebar {
  background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--ink);
  padding: 22px 18px; align-self: start; position: sticky; top: 24px;
}
.sidebar .brand { font-size: 17px; font-weight: 700; }
.sidebar-sub { color: var(--ink-soft); font-size: 13px; margin: 4px 0 22px; }
.side-nav { display: flex; flex-direction: column; gap: 6px; }
.side-nav button {
  font-family: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer;
  padding: 11px 12px; color: var(--ink-soft); background: transparent;
  border: 1px solid transparent; border-radius: 4px;
}
.side-nav button:hover { background: var(--surface-2); color: var(--ink); }
.side-nav button.active { background: #e3f0e9; color: var(--accent-deep); border-color: var(--accent); }
.nav-step { font-family: var(--mono); font-size: 12px; margin-right: 8px; opacity: .7; }
.sidebar-foot { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 12px; }
.main-area { min-width: 0; }
.work-panel { display: none; }
.work-panel.active { display: block; }
/* 卡片管理：仅列表滚动，筛选与批量栏固定 */
.card-scroll, .list-scroll { max-height: 450px; overflow-y: auto; overflow-x: auto; }
.card-scroll thead th, .list-scroll thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
#queryResult { max-height: 520px; overflow-y: auto; padding-right: 4px; }

/* 后台 */
.admin-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.tabs button {
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  padding: 10px 16px; color: var(--ink-soft); background: transparent;
  border: 0; border-bottom: 3px solid transparent; border-radius: 0;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--accent-deep); border-bottom-color: var(--accent); }
.grid-form { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.grid-form .field { flex: 1; min-width: 160px; margin: 0; }
.grid-form .btn-solid, .grid-form .btn-outline { width: auto; white-space: nowrap; }
.link-btn { font-size: 14px; font-weight: 600; color: var(--accent-deep); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
.link-btn:hover { color: var(--ink); }
.table-wrap { overflow-x: auto; margin-top: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--ink-soft); font-weight: 600; letter-spacing: .04em; }
td.mono { font-family: var(--mono); }
td.actions { white-space: nowrap; }
.mini-btn { font-family: inherit; font-size: 12px; font-weight: 600; padding: 4px 9px; margin-right: 5px; cursor: pointer; background: var(--surface-2); border: 1px solid var(--line); border-radius: 3px; color: var(--ink); }
.mini-btn:hover { background: #e3e9e0; }
.mini-btn.danger { color: var(--danger); }
.hint { color: var(--ink-soft); font-size: 13px; margin: 0 0 14px; }
.batch-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 14px 0; }
.batch-bar #selCount { margin-left: auto; font-weight: 600; color: var(--accent-deep); }
.test-mail { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 18px; }
.test-mail input { flex: 1; min-width: 200px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 4px; font-size: 14px; }
input[type=checkbox] { width: auto; }
.csv-area { width: 100%; font-family: var(--mono); font-size: 13px; padding: 12px; border: 1px solid var(--line); border-radius: 4px; margin-top: 12px; }

.masthead {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 30px 0 18px;
  border-bottom: 2px solid var(--ink);
}
.brand { font-size: 17px; font-weight: 700; letter-spacing: .01em; }
.brand-mark {
  font-family: var(--mono); font-size: 13px; font-weight: 700;
  color: var(--surface); background: var(--accent);
  padding: 3px 6px; border-radius: 3px; margin-right: 6px;
}
.masthead-note { font-size: 13px; color: var(--ink-soft); letter-spacing: .08em; }

.intro { padding: 28px 0 8px; }
.intro h1 { font-size: 27px; line-height: 1.25; margin: 0 0 8px; letter-spacing: -.01em; }
.intro p { margin: 0; color: var(--ink-soft); max-width: 46ch; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--ink);
  margin-top: 20px;
  padding: 22px 24px 24px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.hidden { display: none !important; }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.panel-head h2 { flex: 1; }
.refresh-btn {
  font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  padding: 5px 12px; color: var(--accent-deep); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 4px; white-space: nowrap;
}
.refresh-btn:hover { background: #e3e9e0; }
.refresh-btn:disabled { opacity: .6; cursor: default; }
.step {
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  color: var(--accent-deep); border: 1px solid var(--accent);
  padding: 2px 7px; border-radius: 2px;
}
.panel-head h2 { font-size: 18px; margin: 0; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 11px 12px;
  font-family: var(--sans); font-size: 15px;
  color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 4px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input.mono { font-family: var(--mono); letter-spacing: .03em; }
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,107,92,.12); }
.field input::placeholder { color: #9aa69c; }

button { font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer; border-radius: 4px; padding: 11px 18px; }
.btn-solid { width: 100%; color: #fff; background: var(--accent); border: 1px solid var(--accent); }
.btn-solid:hover { background: var(--accent-deep); }
.btn-outline { width: 100%; color: var(--accent-deep); background: transparent; border: 1px solid var(--accent); }
.btn-outline:hover { background: var(--surface-2); }
button:disabled { opacity: .6; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.notice { margin: 14px 0 0; font-size: 14px; color: var(--ink-soft); }
.notice.ok { color: var(--ok); font-weight: 600; }
.notice.err { color: var(--danger); font-weight: 600; }

/* 密钥票券：页面的记忆点 */
.ticket {
  margin-top: 18px; background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: 14px 16px;
}
.ticket + .ticket { margin-top: 10px; }
.ticket-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.ticket-name { font-weight: 700; font-size: 15px; }
.ticket-badge {
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft);
}
.ticket-badge.ready { background: #e3f0e9; color: var(--ok); }
.ticket-badge.pending { background: #f5ecd8; color: #8a6410; }
.ticket-badge.failed { background: #f6e3df; color: var(--danger); }
.ticket-key {
  display: flex; align-items: center; gap: 10px; margin-top: 12px;
  font-family: var(--mono); font-size: 14px; word-break: break-all; line-height: 1.5;
}
.ticket-key .val { flex: 1; }
.ticket-key.empty { color: var(--ink-soft); font-family: var(--sans); font-style: italic; }
.copy-btn {
  font-family: var(--sans); font-size: 12px; font-weight: 600;
  padding: 5px 10px; color: var(--accent-deep);
  background: var(--surface-2); border: 1px solid var(--line); flex-shrink: 0;
}
.copy-btn:hover { background: #e3e9e0; }
.ticket-meta { margin-top: 10px; font-size: 12px; color: var(--ink-soft); }

.result-empty { margin-top: 16px; padding: 16px; text-align: center; color: var(--ink-soft);
  background: var(--surface-2); border: 1px dashed var(--line); }

.foot {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
  margin-top: 26px; font-size: 12px; color: var(--ink-soft);
}

@media (max-width: 900px) {
  /* 前台双栏 → 单栏，侧栏变顶部横排导航 */
  .app-layout { grid-template-columns: 1fr; gap: 16px; padding: 16px 14px 32px; }
  .sidebar { position: static; padding: 16px; }
  .sidebar-sub, .sidebar-foot { display: none; }
  .side-nav { flex-direction: row; gap: 8px; margin-top: 12px; }
  .side-nav button { flex: 1; text-align: center; justify-content: center; }
  .nav-step { display: none; }

  /* 后台宽栏收窄、标签可横向滑动 */
  .shell-wide { padding: 0 14px 32px; }
  .masthead { padding: 18px 0 14px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .tabs button { white-space: nowrap; flex-shrink: 0; padding: 9px 13px; }

  /* 表单单列、按钮全宽易点 */
  .grid-form { flex-direction: column; align-items: stretch; }
  .grid-form .field { width: 100%; min-width: 0; }
  .grid-form .btn-solid, .grid-form .btn-outline { width: 100%; }

  /* 表格保持横向滚动，列表高度给触摸留空间 */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .card-scroll, .list-scroll { max-height: 60vh; }
  #queryResult { max-height: none; }

  /* 面板内边距收紧 */
  .panel { padding: 18px 16px 20px; }
  .batch-bar #selCount { margin-left: 0; width: 100%; }
}

@media (max-width: 480px) {
  .shell { padding: 0 14px 30px; }
  .intro h1 { font-size: 23px; }
  .panel { padding: 16px 14px 18px; }
  .brand { font-size: 16px; }
  .masthead-note { font-size: 12px; }
  .ticket-key { flex-wrap: wrap; }
  .test-mail input { min-width: 0; width: 100%; }
  .side-nav button { padding: 10px 6px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
