/* ═══════════════════════════════════════════════════════════════════
   Design System — "Architectural"
   Monochromatic, typography-forward, generous whitespace.
   Palette: Ink (#18181B), Paper (#FFF), Zinc grays.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Tokens ────────────────────────────────────────────────────── */
:root {
  --ink:       #18181B;
  --paper:     #FFFFFF;
  --warm-bg:   #FAFAFA;
  --zinc-500:  #71717A;
  --zinc-300:  #D4D4D8;
  --zinc-200:  #E4E4E7;
  --zinc-100:  #F4F4F5;
  --blue:      #2563EB;
  --blue-hover:#1D4ED8;
  --red:       #DC2626;
  --red-bg:    #FEF2F2;
  --green:     #16A34A;
  --green-bg:  #F0FDF4;
  --amber:     #D97706;
  --amber-bg:  #FFFBEB;

  --font:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;
  --space-3xl: 64px;
  --space-4xl: 96px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.1);

  --trans: 180ms ease;

  --sidebar-w: 232px;
  --topbar-h: 52px;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-weight: 400;
  line-height: 1.6;
  color: var(--ink);
  background: var(--warm-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg { display: block; max-width: 100%; }
a  { color: var(--blue); text-decoration: none; transition: color var(--trans); }
a:hover { color: var(--blue-hover); }
ul, ol { list-style: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ── Typography ────────────────────────────────────────────────── */
h1, h2, h3 { font-weight: 600; line-height: 1.25; color: var(--ink); }

.text-sm     { font-size: 0.8125rem; }
.text-xs     { font-size: 0.75rem; }
.text-muted  { color: var(--zinc-500); }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }

/* ── Layout ────────────────────────────────────────────────────── */
.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-center{ justify-content: center; }
.justify-between{ justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }
.hidden { display: none !important; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  border-radius: var(--radius-sm);
  transition: all var(--trans);
  min-height: 42px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.btn-primary {
  background: var(--ink);
  color: #fff;
}
.btn-primary:hover { background: #2A2A2E; }

.btn-secondary {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--zinc-300);
}
.btn-secondary:hover { background: var(--zinc-100); }

.btn-danger {
  background: var(--paper);
  color: var(--red);
  border: 1px solid var(--red);
}
.btn-danger:hover { background: var(--red-bg); }

.btn-lg { padding: 12px 28px; font-size: 0.9375rem; border-radius: var(--radius-md); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn .spinner {
  display: none;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.5s linear infinite;
}
.btn.is-loading .spinner { display: block; }
.btn.is-loading .btn-text { display: none; }
.btn-secondary .spinner { border-color: rgba(0,0,0,0.1); border-top-color: var(--ink); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ─────────────────────────────────────────────────────── */
.field { margin-bottom: var(--space-lg); }
.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--zinc-500);
  margin-bottom: 6px;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--zinc-300);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.9375rem;
  line-height: 1.5;
  min-height: 44px;
  transition: border-color var(--trans), box-shadow var(--trans);
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(24,24,27,0.08);
}
.field input::placeholder,
.field textarea::placeholder { color: var(--zinc-500); }
.field textarea { min-height: 100px; resize: vertical; }
.field .hint { font-size: 0.75rem; color: var(--zinc-500); margin-top: 4px; }

.field input[type="file"] { padding: 8px; font-size: 0.875rem; }
.field input[type="file"]::file-selector-button {
  padding: 6px 14px;
  border: 1px solid var(--zinc-300);
  border-radius: var(--radius-sm);
  background: var(--zinc-100);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  margin-right: 12px;
  transition: background var(--trans);
}
.field input[type="file"]::file-selector-button:hover { background: var(--zinc-200); }

.checkbox-label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 10px !important;
  cursor: pointer;
  font-size: 0.875rem !important;
  color: var(--ink) !important;
}
.checkbox-label input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--ink); min-height: unset; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
}
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

/* ── Messages ──────────────────────────────────────────────────── */
.msg {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: var(--space-lg);
  animation: slideDown 0.2s ease;
}
.msg svg { width: 18px; height: 18px; flex-shrink: 0; }
.msg-success { background: var(--green-bg); color: #166534; }
.msg-error   { background: var(--red-bg);   color: #991B1B; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--paper);
  border: 1px solid var(--zinc-200);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-xl);
}
.card-head svg { width: 20px; height: 20px; color: var(--zinc-500); }
.card-head h2 { font-size: 1rem; font-weight: 600; }
.card-head .count-badge { margin-left: auto; }
.card-head .range-tabs { margin-left: auto; display: flex; gap: 2px; }

.range-tab {
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--zinc-500);
  background: transparent;
  border-radius: var(--radius-sm);
  transition: all var(--trans);
  min-height: 28px;
}
.range-tab:hover { color: var(--ink); background: var(--zinc-100); }
.range-tab.active { color: var(--ink); background: var(--zinc-200); }

/* ── Pagination ─────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
  font-size: 0.8125rem;
}

.pagination button {
  padding: 6px 14px;
  border: 1px solid var(--zinc-200);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all var(--trans);
  min-height: 32px;
}
.pagination button:hover:not(:disabled) { background: var(--zinc-100); }
.pagination button:disabled { opacity: 0.35; cursor: not-allowed; }
.pagination button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.pagination .page-info { color: var(--zinc-500); padding: 0 var(--space-sm); }

/* ── Tables ────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

thead th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--zinc-500);
  border-bottom: 1px solid var(--zinc-200);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--zinc-100);
  color: var(--ink);
}
tbody tr:hover { background: var(--zinc-100); }
tbody tr:last-child td { border-bottom: none; }

/* ── Stats ─────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.stat-card {
  background: var(--paper);
  border: 1px solid var(--zinc-200);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
}
.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--zinc-500);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
}
.badge--danger  { background: var(--red-bg);   color: #991B1B; }
.badge--info    { background: #EFF6FF;          color: #1E40AF; }
.badge--success { background: var(--green-bg);  color: #166534; }
.badge--latest {
  background: #18181B;
  color: #fff;
  font-weight: 600;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  background: var(--ink);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
}

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-2xl) var(--space-md);
  color: var(--zinc-500);
  font-size: 0.875rem;
}
.empty-state a { font-weight: 500; }

/* ── Toast ─────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
  max-width: 360px;
}
.toast-success { background: #166534; color: #fff; }
.toast-error   { background: #991B1B; color: #fff; }

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

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}
.modal {
  background: var(--paper);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  max-width: 440px; width: 90%;
  box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 1rem; margin-bottom: var(--space-md); }
.modal p  { font-size: 0.875rem; color: var(--zinc-500); margin-bottom: var(--space-lg); }
.modal-actions { display: flex; gap: var(--space-sm); justify-content: flex-end; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ═══════════════════════════════════════════════════════════════════
   HOMEPAGE — Poster-like minimalism
   ═══════════════════════════════════════════════════════════════════ */

.home-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl) var(--space-lg);
  background: var(--paper);
}

.home-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2xl);
  max-width: 480px;
  width: 100%;
}

/* Logo */
.home-logo {
  width: 88px;
  height: 88px;
  border-radius: 18px;
  box-shadow: 0 2px 24px rgba(0,0,0,0.08);
  object-fit: cover;
  transition: transform 300ms ease;
}
.home-logo:hover { transform: scale(1.03); }

/* App name — poster headline */
.home-title {
  font-size: clamp(2rem, 4.5vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.1;
  color: var(--ink);
}

/* Version info row — pills */
.version-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
}

.version-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--zinc-500);
  background: var(--zinc-100);
  border-radius: 9999px;
}
.version-pill svg { width: 13px; height: 13px; opacity: 0.5; }

.version-pill--primary {
  color: var(--ink);
  background: #F0F0F0;
  font-weight: 600;
  font-size: 0.875rem;
}

/* Release notes */
.release-card {
  width: 100%;
  text-align: left;
  background: var(--warm-bg);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
}

.release-card-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--zinc-500);
  margin-bottom: var(--space-sm);
}

.release-card-text {
  font-size: 0.875rem;
  color: var(--zinc-500);
  line-height: 1.7;
  white-space: pre-wrap;
}

/* Download button */
.home-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
}

.home-dl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 360px;
  padding: 14px 32px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--ink);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all var(--trans);
  min-height: 52px;
}
.home-dl-btn:hover {
  background: #2A2A2E;
  color: #fff;
}
.home-dl-btn svg { width: 20px; height: 20px; }
.home-dl-btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.home-sub {
  font-size: 0.75rem;
  color: var(--zinc-500);
}

/* Footer */
.site-footer {
  padding: var(--space-lg);
  text-align: center;
  font-size: 0.75rem;
  color: var(--zinc-500);
}

/* Loading */
.loading-text {
  font-size: 0.875rem;
  color: var(--zinc-500);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.loading-text::before {
  content: '';
  width: 16px; height: 16px;
  border: 2px solid var(--zinc-300);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.5s linear infinite;
}

/* ── Homepage responsive ── */
@media (max-width: 640px) {
  .home-page { padding: var(--space-xl) var(--space-md); justify-content: flex-start; padding-top: 80px; }
  .home-main { gap: var(--space-xl); }
  .home-logo { width: 72px; height: 72px; border-radius: 14px; }
  .home-dl-btn { max-width: 100%; }
}

/* ═══════════════════════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════════════════════ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--warm-bg);
  padding: var(--space-lg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  box-shadow: var(--shadow-md);
}

.login-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 4px;
}

.login-sub {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--zinc-500);
  margin-bottom: var(--space-xl);
}

.login-card .btn { width: 100%; }
.login-card .field:last-of-type { margin-bottom: var(--space-xl); }

/* ═══════════════════════════════════════════════════════════════════
   ADMIN LAYOUT
   ═══════════════════════════════════════════════════════════════════ */

.admin-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.admin-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 250ms ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--space-lg);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand svg { width: 24px; height: 24px; opacity: 0.7; }

.sidebar-nav {
  flex: 1;
  padding: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255,255,255,0.55);
  border-radius: var(--radius-sm);
  transition: all var(--trans);
  text-decoration: none;
}
.sidebar-nav a:hover { color: #fff; background: rgba(255,255,255,0.06); }
.sidebar-nav a.active { color: #fff; background: rgba(255,255,255,0.1); }
.sidebar-nav a svg { width: 18px; height: 18px; opacity: 0.6; }
.sidebar-nav a.active svg { opacity: 1; }

.sidebar-footer {
  padding: var(--space-sm);
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255,255,255,0.55) !important;
  border-radius: var(--radius-sm);
  transition: all var(--trans);
  text-decoration: none;
}
.sidebar-logout:hover { color: #EF4444 !important; background: rgba(239,68,68,0.1); }
.sidebar-logout svg { width: 18px; height: 18px; opacity: 0.6; }

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
}
.sidebar-overlay.is-open { display: block; }

/* Top bar */
.admin-topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 var(--space-xl);
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--zinc-200);
}

.topbar-left { display: flex; align-items: center; gap: var(--space-md); }
.topbar-left h1 { font-size: 0.9375rem; font-weight: 600; }

.menu-toggle {
  display: none;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--ink);
}
.menu-toggle:hover { background: var(--zinc-100); }

/* Main content */
.admin-main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.admin-content { flex: 1; padding: var(--space-xl); }

/* ── Settings sections ──────────────────────────────────────────── */
.settings-section {
  background: var(--paper);
  border: 1px solid var(--zinc-200);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
}
.settings-section h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--zinc-100);
}

/* ── Row actions ───────────────────────────────────────────────── */
.row-actions { display: flex; gap: var(--space-sm); }
.row-actions button {
  padding: 4px 12px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  transition: all var(--trans);
  min-height: 30px;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Admin
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .admin-sidebar { transform: translateX(-100%); }
  .admin-sidebar.is-open { transform: translateX(0); }

  .admin-main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .admin-content { padding: var(--space-md); }
  .admin-topbar { padding: 0 var(--space-md); }

  .stats-row { grid-template-columns: 1fr 1fr; }

  /* Card-style table on mobile */
  .table-cards thead { display: none; }
  .table-cards tbody tr {
    display: block;
    padding: var(--space-md);
    border: 1px solid var(--zinc-200);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-sm);
    background: var(--paper);
  }
  .table-cards tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border: none;
    gap: var(--space-md);
  }
  .table-cards tbody td::before {
    content: attr(data-label);
    font-weight: 500;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--zinc-500);
    flex-shrink: 0;
  }
  .table-cards tbody td[data-label="操作"] {
    justify-content: flex-end;
    border-top: 1px solid var(--zinc-100);
    margin-top: 8px;
    padding-top: 10px;
  }

  .login-card { padding: var(--space-xl); }

  /* 下载趋势：卡片头部换行 */
  .card-head { flex-wrap: wrap; gap: 8px; }
  .card-head .range-tabs { margin-left: 0; width: 100%; justify-content: center; }

  /* latest 徽章：手机端缩小 */
  .badge--latest { font-size: 0.625rem; padding: 1px 8px; }
}

@media (min-width: 768px) and (max-width: 1023px) {
  :root { --sidebar-w: 200px; }
}

/* ── Reduced motion ────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
