/* iPhone 上以 PWA 全屏运行，所以处处要考虑安全区（刘海/home indicator）。 */

:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --text-dim: #6c6c70;
  --line: rgba(60, 60, 67, 0.14);
  --accent: #0a84ff;
  --danger: #ff3b30;
  --ok: #34c759;
  --warn: #ff9f0a;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --text-dim: #98989f;
    --line: rgba(84, 84, 88, 0.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

.view { display: none; padding: 16px 16px 40px; max-width: 640px; margin: 0 auto; }
.view.active { display: block; }
.hidden { display: none !important; }

/* ---------- 头部 ---------- */

.hero { text-align: center; padding: 32px 8px 20px; }
.hero-icon { font-size: 46px; line-height: 1; }
.hero h1 { font-size: 26px; font-weight: 700; margin: 14px 0 8px; letter-spacing: -0.02em; }
.hero-sub { color: var(--text-dim); font-size: 14px; margin: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0 12px;
}
.topbar h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }

/* ---------- 卡片 / 表单 ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-dim); margin-bottom: 6px;
}

input, select {
  width: 100%;
  padding: 12px 14px;
  font-size: 17px;                 /* iOS 下小于 16px 会触发聚焦缩放 */
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  appearance: none;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  display: block; width: 100%;
  padding: 14px; margin-top: 4px;
  font-size: 17px; font-weight: 600; font-family: inherit;
  border: none; border-radius: 12px;
  background: var(--bg); color: var(--text);
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { width: auto; padding: 7px 14px; font-size: 15px; margin: 0; }
.btn:active { opacity: 0.65; }
.btn:disabled { opacity: 0.4; }

/* 用文本框 + 遮罩代替 type="password"，避开 iOS 的密码自动填充 */
input.masked { -webkit-text-security: disc; text-security: disc; letter-spacing: 3px; }
input.masked.reveal { -webkit-text-security: none; text-security: none; letter-spacing: 1px; }

.checkline {
  display: flex; align-items: center; gap: 8px;
  margin: -4px 0 14px; font-size: 14px; color: var(--text-dim);
}
.checkline input { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--accent); }

.hint { font-size: 13px; color: var(--text-dim); margin: 14px 0 0; }
.hint code {
  font: 500 12px ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--bg); padding: 1px 5px; border-radius: 4px;
}
.warn { font-size: 13px; color: var(--warn); margin: 0 0 12px; }

/* ---------- 标签页 ---------- */

.tabs {
  display: flex; gap: 4px; padding: 3px;
  background: var(--card); border-radius: 10px; margin-bottom: 16px;
}
.tab {
  flex: 1; padding: 8px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-dim);
  font: 600 14px inherit; font-family: inherit; cursor: pointer;
}
.tab.active { background: var(--bg); color: var(--text); }

.tabpane { display: none; }
.tabpane.active { display: block; }

/* ---------- 时长快选 ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 15px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--text);
  font: 500 15px inherit; font-family: inherit; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 生成结果 ---------- */

.result-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.codes { list-style: none; padding: 0; margin: 0; }
.codes li {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.codes li:last-child { border-bottom: none; }
.codes code {
  font: 600 15px ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.04em; word-break: break-all;
}

/* ---------- 列表 ---------- */

/* 统计格同时是筛选按钮 */
.stats {
  display: flex; gap: 8px; margin-bottom: 12px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px;
}
.stat {
  flex: 1 0 auto; min-width: 68px; padding: 10px 12px;
  background: var(--card); border: 1px solid transparent; border-radius: 10px;
  text-align: center; font-family: inherit; color: var(--text); cursor: pointer;
}
.stat.on { border-color: var(--accent); background: rgba(10, 132, 255, 0.12); }
.stat:active { opacity: 0.7; }
.stat b { display: block; font-size: 20px; font-weight: 700; }
.stat span { font-size: 12px; color: var(--text-dim); }

.filters { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters input { flex: 1; }

/* 批量操作栏 */
.bulkbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 10px;
}
.bulkbar-actions { display: flex; gap: 8px; }
.checkline.compact { margin: 0; font-size: 15px; color: var(--text); }

.list { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius);
  padding: 13px 15px; cursor: pointer;
}
.row:active { opacity: 0.7; }
.row-main { flex: 1; min-width: 0; }
.rowcheck { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--accent); pointer-events: none; }
.row.selectable { border: 1px solid var(--line); }

/* 数量 + 单位 */
.duo { display: flex; gap: 8px; }
.duo input { flex: 2; }
.duo select { flex: 1; }
.row-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-code { font: 600 14px ui-monospace, "SF Mono", Menlo, monospace; }
.row-meta { font-size: 13px; color: var(--text-dim); margin-top: 4px; }

.badge {
  flex: 0 0 auto; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge.unused  { background: rgba(10, 132, 255, 0.16); color: var(--accent); }
.badge.active  { background: rgba(52, 199, 89, 0.16);  color: var(--ok); }
.badge.expired { background: rgba(142, 142, 147, 0.2); color: var(--text-dim); }
.badge.revoked { background: rgba(255, 59, 48, 0.16);  color: var(--danger); }

.audit-row { background: var(--card); border-radius: 10px; padding: 11px 14px; }
.audit-row .ev { font-size: 14px; font-weight: 600; }
.audit-row .dt { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.empty { text-align: center; color: var(--text-dim); padding: 40px 0; font-size: 14px; }

/* ---------- 详情抽屉 ---------- */

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88vh; overflow-y: auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(28px + env(safe-area-inset-bottom));
  animation: rise 0.24s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes rise { from { transform: translateY(100%); } }
.sheet-handle {
  width: 36px; height: 5px; border-radius: 3px;
  background: var(--line); margin: 6px auto 16px;
}

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv span { color: var(--text-dim); flex: 0 0 auto; }
.kv b { font-weight: 500; text-align: right; word-break: break-all; }

.sheet h3 { font-size: 15px; margin: 20px 0 6px; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }

/* ---------- 提示卡片 ---------- */

.notice { border: 1px solid var(--warn); }
.notice h2 { font-size: 16px; margin: 0 0 10px; color: var(--warn); }
.notice p { font-size: 14px; margin: 0 0 8px; }
.notice p:last-child { margin-bottom: 0; }

/* ---------- 非安全上下文提示 ---------- */

.insecure { margin-top: 40px; }
.insecure h2 { font-size: 19px; margin: 0 0 12px; color: var(--danger); }
.insecure p { font-size: 15px; margin: 0 0 12px; }
.insecure code {
  font: 500 13px ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--bg); padding: 2px 6px; border-radius: 5px; word-break: break-all;
}

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

.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(28px + env(safe-area-inset-bottom));
  background: rgba(28, 28, 30, 0.95); color: #fff;
  padding: 12px 20px; border-radius: 12px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  z-index: 100; max-width: 84vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: rgba(255, 59, 48, 0.95); }
