:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3348;
  --text: #e8eaf0;
  --text-muted: #8b90a5;
  --primary: #6c8cff;
  --primary-hover: #5a7af5;
  --success: #3dd68c;
  --warning: #f5a623;
  --danger: #f56565;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 40px 20px;
}

.container-wide {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ── 顶部导航 ── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.site-nav {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.nav-link {
  display: inline-block;
  padding: 14px 18px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.2s;
}

.nav-link:hover {
  color: var(--text);
  text-decoration: none;
}

.downloads-body {
  min-height: 100vh;
}

.downloads-container {
  padding-bottom: 24px;
}

.downloads-header {
  margin-bottom: 16px;
}

.downloads-header h1 {
  font-size: 24px;
  margin-bottom: 6px;
}

.downloads-header p {
  color: var(--text-muted);
  font-size: 14px;
}

.alist-frame-wrap {
  width: 100%;
  height: calc(100vh - 200px);
  min-height: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.alist-frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

.downloads-empty,
.downloads-external {
  text-align: center;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.downloads-external {
  margin-top: 16px;
}

.nav-link.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── 教程文章页 ── */

.article-page {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  margin-top: 24px;
}

.article-page h1 {
  font-size: 24px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.article-content {
  line-height: 1.8;
  font-size: 15px;
}

.article-content h2 {
  font-size: 18px;
  margin: 24px 0 12px;
}

.article-content h3 {
  font-size: 16px;
  margin: 20px 0 10px;
}

.article-content p {
  margin-bottom: 12px;
  color: var(--text);
}

.article-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 16px 0;
  border: 1px solid var(--border);
}

.article-content ul, .article-content ol {
  margin: 12px 0 12px 24px;
}

.article-content li {
  margin-bottom: 8px;
}

/* ── 后台图文编辑器 ── */

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}

.editor-area {
  min-height: 280px;
  padding: 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  outline: none;
  line-height: 1.7;
  font-size: 15px;
}

.editor-area:focus {
  border-color: var(--primary);
}

.editor-area img {
  max-width: 100%;
  border-radius: 6px;
  margin: 8px 0;
}

.tutorial-editor {
  margin-bottom: 28px;
}

.tutorial-editor h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

/* ── 用户取卡页 ── */

.hero {
  text-align: center;
  margin-bottom: 36px;
}

.hero-logo {
  font-size: 48px;
  margin-bottom: 12px;
  line-height: 1;
}

.hero-logo-img {
  max-width: 120px;
  max-height: 80px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.hero h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.hero p {
  color: var(--text-muted);
  font-size: 15px;
}

.card-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"],
input[type="password"],
input[type="datetime-local"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

textarea {
  resize: vertical;
  min-height: 120px;
  font-family: monospace;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-success { background: var(--success); color: #0f1117; }
.btn-warning { background: var(--warning); color: #0f1117; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

.result-box {
  margin-top: 24px;
  padding: 20px;
  border-radius: 8px;
  display: none;
}

.result-box.show { display: block; }

.result-success {
  background: rgba(61, 214, 140, 0.1);
  border: 1px solid rgba(61, 214, 140, 0.3);
}

.result-error {
  background: rgba(245, 101, 101, 0.1);
  border: 1px solid rgba(245, 101, 101, 0.3);
}

.result-warning {
  background: rgba(245, 166, 35, 0.1);
  border: 1px solid rgba(245, 166, 35, 0.3);
}

.result-title {
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 16px;
}

.card-content {
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: monospace;
  font-size: 16px;
  word-break: break-all;
  margin: 12px 0;
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  font-size: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.stock-section {
  margin-top: 28px;
}

.stock-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.stock-section-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.stock-updated {
  font-size: 12px;
  color: var(--text-muted);
}

.stock-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stock-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stock-item-name {
  font-size: 14px;
  font-weight: 600;
}

.stock-item-count {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stock-num {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stock-num.in { color: var(--success); }
.stock-num.low { color: var(--warning); }
.stock-num.out { color: var(--danger); }

.stock-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stock-dot.in { background: var(--success); box-shadow: 0 0 6px var(--success); }
.stock-dot.low { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.stock-dot.out { background: var(--danger); }

.stock-label {
  font-size: 12px;
  color: var(--text-muted);
}

.order-preview {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  display: none;
}

.order-preview.show { display: block; }

.order-preview-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

.order-preview-row span:first-child { color: var(--text-muted); }

.footer-note {
  text-align: center;
  margin-top: 32px;
  color: var(--text-muted);
  font-size: 13px;
}

.footer-note a { color: var(--text-muted); }

/* ── 管理后台 ── */

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-header h1 { font-size: 22px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.weekly-stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
}

.weekly-stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.weekly-stats-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.weekly-stats-range {
  font-size: 13px;
  color: var(--text-muted);
}

.weekly-stats-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
}

.weekly-day-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
}

.weekly-day-card.today {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(108, 140, 255, 0.25);
}

.weekly-day-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.weekly-day-count {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.weekly-day-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px 0 8px;
  overflow: hidden;
}

.weekly-day-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.weekly-day-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  padding: 10px 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-header h2 { font-size: 18px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tr:hover td { background: var(--surface2); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-active { background: rgba(61, 214, 140, 0.15); color: var(--success); }
.badge-expired { background: rgba(245, 166, 35, 0.15); color: var(--warning); }
.badge-terminated { background: rgba(245, 101, 101, 0.15); color: var(--danger); }
.badge-available { background: rgba(108, 140, 255, 0.15); color: var(--primary); }
.badge-claimed { background: rgba(139, 144, 165, 0.15); color: var(--text-muted); }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow);
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-box h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 22px;
}

.login-box p {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 14px;
}

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  animation: slideIn 0.3s ease;
}

.toast-success { background: var(--success); color: #0f1117; }
.toast-error { background: var(--danger); color: #fff; }

@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.settings-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.settings-card h3 {
  font-size: 16px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.logo-preview {
  width: 120px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  font-size: 40px;
  margin-bottom: 16px;
  overflow: hidden;
}

.logo-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

@media (max-width: 768px) {
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .container { padding: 24px 16px; }
  .card-box { padding: 24px 20px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .weekly-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
