/* =========================================================
   Apple-style design tokens
   ========================================================= */
:root {
  /* Apple iOS / macOS Sonoma 系统色 */
  --bg-page: #F2F2F7;
  --bg-card: rgba(255, 255, 255, 0.62);
  --bg-card-solid: #FFFFFF;
  --bg-input: rgba(120, 120, 128, 0.08);
  --bg-elev: rgba(120, 120, 128, 0.12);
  --bg-fill-3: rgba(118, 118, 128, 0.16);
  --border: rgba(60, 60, 67, 0.08);
  --border-strong: rgba(60, 60, 67, 0.16);
  --separator: rgba(60, 60, 67, 0.12);
  --text-primary: #1D1D1F;
  --text-secondary: rgba(60, 60, 67, 0.6);
  --text-tertiary: rgba(60, 60, 67, 0.3);
  --accent: #007AFF;
  --accent-hover: #0084FF;
  --accent-pressed: #0064D6;
  --success: #34C759;
  --warning: #FF9500;
  --danger: #FF3B30;
  --shadow-sm: 0 0.5px 1px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.10);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 28px;
  --radius-pill: 980px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-spring: cubic-bezier(0.5, 1.6, 0.3, 1);
  --transition: 0.35s var(--ease);
}

[data-theme="dark"] {
  --bg-page: #000000;
  --bg-card: rgba(28, 28, 30, 0.62);
  --bg-card-solid: #1C1C1E;
  --bg-input: rgba(118, 118, 128, 0.24);
  --bg-elev: rgba(118, 118, 128, 0.18);
  --bg-fill-3: rgba(118, 118, 128, 0.32);
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.14);
  --separator: rgba(84, 84, 88, 0.65);
  --text-primary: #F5F5F7;
  --text-secondary: rgba(235, 235, 245, 0.6);
  --text-tertiary: rgba(235, 235, 245, 0.3);
  --accent: #0A84FF;
  --accent-hover: #1F8FFF;
  --accent-pressed: #0066CC;
  --shadow-sm: 0 0.5px 1px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
}

/* =========================================================
   Reset & base
   ========================================================= */
* { box-sizing: border-box; }
*:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
/* 修复: HTML hidden 属性必须强制隐藏, 否则被 display:flex 等显式 display 覆盖 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
               "PingFang SC", "Helvetica Neue", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.012em;
  transition: background var(--transition), color var(--transition);
}

body { min-height: 100vh; overflow-x: hidden; }

a { color: var(--accent); text-decoration: none; transition: opacity var(--transition); }
a:hover { opacity: 0.7; }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.025em; line-height: 1.12; }
h1 { font-size: 34px; font-weight: 700; }
h2 { font-size: 22px; font-weight: 600; letter-spacing: -0.022em; }
h3 { font-size: 17px; font-weight: 600; }
.muted { color: var(--text-secondary); }
.small { font-size: 13px; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px;
       background: var(--bg-elev); padding: 2px 6px; border-radius: 6px;
       color: var(--text-primary); }

/* =========================================================
   Background gradient blobs
   ========================================================= */
.bg-decor {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden;
}
/* 苹果官方风: 单色低饱和极光, 极慢漂移 */
.blob {
  position: absolute; border-radius: 50%; filter: blur(120px);
  animation: float 32s ease-in-out infinite;
}
.blob-1 {
  width: 640px; height: 640px; top: -240px; left: -180px; opacity: 0.18;
  background: radial-gradient(circle, #007AFF 0%, transparent 65%);
}
.blob-2 {
  width: 540px; height: 540px; bottom: -200px; right: -140px; opacity: 0.14;
  background: radial-gradient(circle, #5E5CE6 0%, transparent 65%);
  animation-delay: -12s;
}
.blob-3 { display: none; }

[data-theme="dark"] .blob-1 { opacity: 0.32; }
[data-theme="dark"] .blob-2 { opacity: 0.24; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, -30px) scale(1.05); }
}

/* =========================================================
   Navbar (sticky frosted)
   ========================================================= */
.navbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg-card);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.nav-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  filter: drop-shadow(0 1px 2px rgba(0, 122, 255, 0.18));
  transition: transform 0.4s var(--ease-spring);
}
.brand-logo svg { width: 100%; height: 100%; display: block; }
.brand:hover .brand-logo { transform: rotate(45deg); }
.brand-text {
  font-weight: 600; font-size: 16px;
  letter-spacing: -0.022em; color: var(--text-primary);
}
.brand-tag {
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em;
  background: var(--bg-fill-3);
  color: var(--text-secondary);
  padding: 3px 8px; border-radius: 6px;
  text-transform: uppercase;
}
.nav-actions { display: flex; align-items: center; gap: 10px; }

.cdkey-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-elev);
  padding: 5px 6px 5px 12px; border-radius: var(--radius-pill);
  font-size: 13px; color: var(--text-primary);
}

/* 站长信息 */
.owner {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 2px 12px 2px 2px;
  background: var(--bg-elev);
  border-radius: var(--radius-pill);
  font-size: 13px;
  transition: background var(--transition);
}
.owner:hover { background: var(--bg-fill-3); }
.owner-avatar-wrap {
  position: relative;
  width: 28px; height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, #ffd1ff 0%, #fad0c4 50%, #ffe9d6 100%);
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.owner-avatar {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
  position: relative; z-index: 1;
}
.owner-avatar-fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; line-height: 1;
}
.owner-name {
  font-weight: 600; color: var(--text-primary);
  letter-spacing: -0.012em;
}
.cdkey-pill .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.2);
}
.cdkey-pill .balance {
  color: var(--text-secondary); padding-left: 8px;
  border-left: 1px solid var(--border);
}

.icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius-pill);
  border: none; background: var(--bg-elev);
  color: var(--text-primary); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; transition: background 0.2s var(--ease);
}
.icon-btn:hover { background: var(--bg-fill-3); }
.icon-btn:active { background: var(--separator); }

/* =========================================================
   Container & cards
   ========================================================= */
.container {
  max-width: 1100px; margin: 0 auto;
  padding: 40px 24px 96px;
  display: flex; flex-direction: column; gap: 24px;
}

.card {
  background: var(--bg-card);
  backdrop-filter: saturate(180%) blur(40px);
  -webkit-backdrop-filter: saturate(180%) blur(40px);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: background var(--transition);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px 16px; gap: 16px;
  border-bottom: 0.5px solid var(--separator);
  flex-wrap: wrap;
}
.card-head h2 { flex: 0 0 auto; }
.card-head-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Hero / 卡密激活 */
.hero { padding: 0; }
.hero-body { padding: 44px 36px; }
.hero-headline h1 { margin-bottom: 8px; }
.hero-headline p { margin: 0 0 24px; font-size: 15px; max-width: 540px; }
.cdkey-box {
  display: flex; gap: 10px; max-width: 560px;
}
.cdkey-box input {
  flex: 1; height: 44px; padding: 0 16px;
  border: 0.5px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-card-solid); color: var(--text-primary);
  font-size: 15px; font-family: inherit;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.cdkey-box input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.18);
}
.hint { margin-top: 14px; font-size: 13px; min-height: 18px; color: var(--text-secondary); }
.hint.error { color: var(--danger); }
.hint.ok { color: var(--success); }

/* 公告 - iOS Settings 分组列表风格 */
.notice details { padding: 0; }
.notice summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; font-weight: 600; font-size: 15px;
  letter-spacing: -0.012em;
}
.notice summary::-webkit-details-marker { display: none; }
.notice summary::after {
  content: ""; margin-left: auto;
  width: 7px; height: 7px;
  border-right: 1.5px solid var(--text-tertiary);
  border-bottom: 1.5px solid var(--text-tertiary);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform var(--transition);
}
.notice details[open] summary::after { transform: rotate(225deg) translate(-2px, -2px); }
.notice-icon {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.notice-icon svg { width: 100%; height: 100%; }
.notice-list {
  margin: 0; padding: 0 0 8px;
  list-style: none;
}
.notice-list li {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 12px 20px;
  border-top: 0.5px solid var(--separator);
}
.notice-row-icon {
  flex: 0 0 auto;
  width: 28px; height: 28px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-elev); color: var(--text-secondary);
  margin-top: 1px;
}
.notice-row-icon svg { width: 16px; height: 16px; }
.notice-row-icon.tone-blue   { background: rgba(0, 122, 255, 0.12); color: var(--accent); }
.notice-row-icon.tone-orange { background: rgba(255, 149, 0, 0.14); color: var(--warning); }
.notice-row-icon.tone-red    { background: rgba(255, 59, 48, 0.12);  color: var(--danger); }
.notice-row-icon.tone-green  { background: rgba(52, 199, 89, 0.14); color: var(--success); }
.notice-row-text {
  flex: 1; min-width: 0;
  font-size: 14px; color: var(--text-secondary); line-height: 1.5;
}
.notice-row-text b {
  display: block;
  color: var(--text-primary); font-weight: 600;
  font-size: 14.5px; margin-bottom: 2px; letter-spacing: -0.012em;
}

/* 统计 - 苹果 Health 仪表卡风格 */
.stats {
  display: grid; gap: 16px;
  grid-template-columns: repeat(4, 1fr);
}
.stat-card {
  background: var(--bg-card);
  backdrop-filter: saturate(180%) blur(40px);
  -webkit-backdrop-filter: saturate(180%) blur(40px);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition);
  position: relative;
}
.stat-card:hover { background: var(--bg-card-solid); }
.stat-label {
  font-size: 13px; color: var(--text-secondary); margin-bottom: 8px;
  font-weight: 500; letter-spacing: -0.005em;
  display: flex; align-items: center; gap: 6px;
}
.stat-label::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-tertiary);
}
.stat-value {
  font-size: 32px; font-weight: 700;
  letter-spacing: -0.035em; line-height: 1; color: var(--text-primary);
  font-feature-settings: "tnum";
}
.stat-card.tone-blue   .stat-label::before { background: var(--accent); }
.stat-card.tone-green  .stat-label::before { background: var(--success); }
.stat-card.tone-red    .stat-label::before { background: var(--danger); }
.accent-blue { color: var(--text-primary); }
.accent-green { color: var(--text-primary); }
.accent-red { color: var(--text-primary); }

.queue-bar {
  padding: 12px 20px; border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  font-size: 13px; color: var(--text-secondary);
  backdrop-filter: blur(20px);
}
.queue-bar b { color: var(--accent); font-weight: 600; font-feature-settings: "tnum"; }

/* 添加单号 */
.add-body { padding: 24px 28px 28px; }
.form-grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(2, 1fr);
}
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span {
  font-size: 13px; color: var(--text-secondary); font-weight: 500;
  letter-spacing: -0.005em;
}
.req {
  display: inline-block; margin-left: 3px;
  color: var(--danger); font-style: normal; font-weight: 600;
}
.field > span .req { font-size: 13px; line-height: 1; vertical-align: 0; }
input:required:invalid:not(:placeholder-shown) {
  border-color: rgba(255, 59, 48, 0.4);
  box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.08);
}
.field input, .field textarea, textarea {
  height: 42px; padding: 0 14px;
  border: 0.5px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-input); color: var(--text-primary);
  font-size: 14.5px; font-family: inherit;
  letter-spacing: -0.005em;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background var(--transition);
}
.field input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
textarea {
  width: 100%; height: auto; padding: 12px 14px; line-height: 1.6;
  resize: vertical; min-height: 120px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px;
}
.field input:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  background: var(--bg-card-solid);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.18);
}

.actions-row {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 12px; margin-top: 20px; flex-wrap: wrap;
}

/* 分段控制器 - iOS UISegmentedControl */
.seg {
  display: inline-flex; padding: 2px;
  background: var(--bg-input); border-radius: 9px;
}
.seg-btn {
  border: none; background: transparent; cursor: pointer;
  padding: 5px 14px; border-radius: 7px;
  font-size: 13px; font-weight: 500; color: var(--text-primary);
  font-family: inherit; letter-spacing: -0.005em;
  transition: background 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.seg-btn:hover:not(.active) { background: rgba(120, 120, 128, 0.08); }
.seg-btn.active {
  background: var(--bg-card-solid); color: var(--text-primary);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  font-weight: 600;
}
[data-theme="dark"] .seg-btn.active { background: rgba(120, 120, 128, 0.36); }
.seg-inline { align-self: flex-start; }

/* 按钮 - 苹果系统按钮 */
.btn {
  height: 40px; padding: 0 18px;
  border: none; border-radius: var(--radius-md);
  font-size: 14.5px; font-weight: 590;
  cursor: pointer; font-family: inherit;
  letter-spacing: -0.012em;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background 0.18s var(--ease), opacity 0.18s var(--ease);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-pressed); }
.btn-ghost {
  background: var(--bg-elev); color: var(--text-primary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-fill-3); }
.btn-ghost:active:not(:disabled) { background: var(--separator); }
.btn-danger {
  background: rgba(255, 59, 48, 0.12); color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: rgba(255, 59, 48, 0.2); }
.btn-sm { height: 28px; padding: 0 12px; font-size: 12.5px; border-radius: 8px; }

/* 任务表格 */
.list-section .table-wrap { overflow-x: auto; }
.task-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.task-table th {
  text-align: left; font-weight: 600; padding: 12px 20px;
  background: rgba(120, 120, 128, 0.05);
  color: var(--text-secondary);
  border-bottom: 0.5px solid var(--separator);
  position: sticky; top: 0;
  font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase;
}
.task-table td {
  padding: 14px 20px; border-bottom: 0.5px solid var(--separator);
  vertical-align: middle;
}
.task-table tbody tr:last-child td { border-bottom: none; }
.task-table tbody tr { transition: background 0.15s var(--ease); }
.task-table tbody tr:hover { background: rgba(120, 120, 128, 0.06); }
.task-table .empty-row td {
  text-align: center; color: var(--text-tertiary);
  padding: 80px 20px; border: none;
  font-size: 14px;
}

.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600;
}
.status-badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
}
.status-pending  { background: rgba(0, 113, 227, 0.12); color: var(--accent); }
.status-pending::before { background: var(--accent); animation: pulse 1.5s ease-in-out infinite; }
.status-running  { background: rgba(255, 159, 10, 0.12); color: var(--warning); }
.status-running::before { background: var(--warning); animation: pulse 1.2s ease-in-out infinite; }
.status-success  { background: rgba(52, 199, 89, 0.14); color: var(--success); }
.status-success::before { background: var(--success); }
.status-failed   { background: rgba(255, 59, 48, 0.12); color: var(--danger); }
.status-failed::before { background: var(--danger); }
.status-canceled { background: var(--bg-elev); color: var(--text-tertiary); }
.status-canceled::before { background: var(--text-tertiary); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

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

.cell-email { font-family: "SF Mono", Menlo, monospace; font-size: 13px; }
.cell-msg { color: var(--text-secondary); max-width: 320px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-time { color: var(--text-tertiary); font-size: 12px; white-space: nowrap; }

/* =========================================================
   Toast
   ========================================================= */
.toast-stack {
  position: fixed; top: 80px; right: 24px; z-index: 300;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 240px; max-width: 360px;
  padding: 12px 16px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px; line-height: 1.5;
  animation: toastIn 0.3s var(--ease);
  display: flex; align-items: flex-start; gap: 10px;
}
.toast.leaving { animation: toastOut 0.25s var(--ease) forwards; }
.toast .toast-icon { flex: 0 0 auto; font-size: 16px; line-height: 1.2; }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }
.toast.warning { border-left: 3px solid var(--warning); }

@keyframes toastIn  { from { opacity: 0; transform: translateX(20px); }
                      to   { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to   { opacity: 0; transform: translateX(20px); } }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 880px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .nav-inner { padding: 12px 16px; }
  .container { padding: 20px 16px 60px; }
  .hero-body { padding: 24px 20px; }
  .add-body { padding: 18px; }
  .card-head { padding: 16px 18px; }
  .task-table th, .task-table td { padding: 10px 14px; }
  .cell-msg { max-width: 180px; }
  .brand-text { font-size: 15px; }
  h1 { font-size: 22px; }
  .cdkey-pill .balance { display: none; }
  .owner-name { display: none; }
  .owner { padding: 3px; }
}
@media (max-width: 540px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 24px; }
  .nav-actions .icon-btn[id="docBtn"] { display: none; }
  .card-head-right { width: 100%; justify-content: flex-start; }
  .task-table { font-size: 13px; }
  .task-table th { font-size: 11px; }
}

/* 滚动条美化 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 10px;
  border: 2px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); background-clip: padding-box; }
