@import url('https://fonts.loli.net/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ============================================================
   TPZ Admin — Refined Design System
   ============================================================ */

:root {
  --bg: #f8f7f4;
  --bg-accent: #faf9f7;
  --card: #ffffff;
  --card-hover: #faf9fe;
  --text: #1b1929;
  --text-heading: #100f1c;
  --muted: #6f6b80;
  --line: #e6e3ef;
  --line-soft: #f0edf6;
  --primary: #4f46e5;
  --primary-deep: #4338ca;
  --primary-light: #6366f1;
  --primary-soft: #eef2ff;
  --primary-glow: rgba(79, 70, 229, 0.10);
  --primary-glow-strong: rgba(79, 70, 229, 0.18);
  --accent: #e11d48;
  --accent-soft: #fff1f2;
  --success: #059669;
  --success-soft: #ecfdf5;
  --success-glow: rgba(5, 150, 105, 0.10);
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --info: #2563eb;
  --info-soft: #eff6ff;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.03);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.05), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.07), 0 2px 8px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 48px rgba(0,0,0,0.09);

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --radius-full: 999px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', Consolas, 'Source Code Pro', monospace;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0b0a14;
  --bg-accent: #0f0e19;
  --card: #14131f;
  --card-hover: #1a1928;
  --text: #e4e2ed;
  --text-heading: #f0eff8;
  --muted: #908da0;
  --line: #252338;
  --line-soft: #1e1c2e;
  --primary: #818cf8;
  --primary-deep: #6366f1;
  --primary-light: #a5b4fc;
  --primary-soft: #1e1b4b;
  --primary-glow: rgba(129, 140, 248, 0.10);
  --primary-glow-strong: rgba(129, 140, 248, 0.18);
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.25);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 2px 6px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.35);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.4);
  --shadow-xl: 0 20px 48px rgba(0,0,0,0.45);
}

/* ---- Base ---- */
* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--primary-deep); }
button, input, textarea, select { font: inherit; }

/* ---- Admin Shell ---- */
.admin-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

/* ============================================================
   Hero Section
   ============================================================ */

.admin-hero {
  position: relative;
  background: linear-gradient(135deg, #1e1b2e 0%, #312e81 30%, #4f46e5 70%, #6366f1 100%);
  color: #fff;
  border-radius: var(--radius-xl);
  padding: 36px 36px 32px;
  margin-bottom: 28px;
  box-shadow: 0 8px 32px rgba(79, 70, 229, 0.2), var(--shadow-lg);
  overflow: hidden;
}

.admin-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 600px 300px at 80% 0%, rgba(129, 140, 248, 0.2), transparent),
    radial-gradient(ellipse 400px 200px at 20% 100%, rgba(99, 102, 241, 0.15), transparent);
  pointer-events: none;
}

.admin-hero::after {
  content: "";
  position: absolute;
  top: -60px;
  right: -40px;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.06);
  pointer-events: none;
}

.admin-hero .hero-content {
  position: relative;
  z-index: 1;
}

.admin-hero h1 {
  margin: 0 0 8px;
  font-size: 32px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
}

.admin-hero p {
  margin: 0;
  max-width: 900px;
  color: rgba(255,255,255,0.82);
  line-height: 1.65;
  font-size: 15px;
}

.admin-hero .hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.admin-hero .hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 13px;
  font-weight: 500;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background var(--transition-fast);
}
.admin-hero .hero-badge:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* ---- Admin Header ---- */
.admin-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 24px;
}
.admin-header h1 { margin: 0; font-size: 28px; font-weight: 700; color: var(--text-heading); letter-spacing: -0.02em; }
.admin-header p { margin: 8px 0 0; }

/* ---- Admin Grid ---- */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

/* ============================================================
   Cards
   ============================================================ */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
}
.card:hover {
  box-shadow: var(--shadow);
  border-color: var(--primary-soft);
}
.card.full { grid-column: 1 / -1; }
.card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.015em;
}
.card h3 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-heading);
  letter-spacing: -0.01em;
}
.card p { margin: 0; line-height: 1.65; }
.card + .card { margin-top: 0; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  margin-bottom: 10px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}

/* ============================================================
   Form Elements
   ============================================================ */

.form-grid, .install-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.field-card:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.field-card.full { grid-column: 1 / -1; }
.field-card.compact { padding: 12px 16px; }
.field-card.check-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  display: block;
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--text-heading);
  font-size: 14px;
}
.input-hint, .helper-text, .muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}
.input-hint { margin: 0 0 8px; }
.helper-text { margin-top: 8px; }

input[type=text],
input[type=password],
input[type=url],
input[type=search],
textarea,
select {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
  line-height: 1.5;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.7; }

/* ---- Actions ---- */
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.005em;
  box-shadow: 0 2px 8px var(--primary-glow);
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.btn:hover {
  background: var(--primary-deep);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--primary-glow-strong);
}
.btn:active { transform: scale(0.97); }

.btn.secondary {
  background: #1e1b2e;
  box-shadow: var(--shadow-sm);
}
.btn.secondary:hover {
  background: #2d2a3d;
  box-shadow: var(--shadow);
}

.btn.ghost {
  background: transparent;
  color: var(--primary);
  box-shadow: none;
  border: 1px solid transparent;
}
.btn.ghost:hover {
  background: var(--primary-soft);
  color: var(--primary-deep);
  border-color: var(--primary-soft);
  transform: translateY(-1px);
  box-shadow: none;
}

.btn.danger {
  background: var(--danger);
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.15);
}
.btn.danger:hover {
  background: #b91c1c;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.25);
}

[data-theme="dark"] .btn.secondary { background: #2d2a40; }
[data-theme="dark"] .btn.secondary:hover { background: #3d3a55; }
[data-theme="dark"] .btn.ghost:hover { background: #1e1b4b; }

/* ---- Flash Messages ---- */
.flash {
  margin-bottom: 20px;
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.5;
}
.flash.success { background: var(--success-soft); color: #065f46; border-color: #a7f3d0; }
.flash.error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.flash.info { background: var(--primary-soft); color: var(--primary-deep); border-color: #c7d2fe; }

/* ---- KBD ---- */
.kbd {
  font-family: var(--font-mono);
  background: #1e1b2e;
  color: #fff;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

/* ============================================================
   Stat Cards — Refined
   ============================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  border-radius: 3px 0 0 3px;
}
.stat-card:nth-child(1)::after { background: var(--primary); }
.stat-card:nth-child(2)::after { background: #f59e0b; }
.stat-card:nth-child(3)::after { background: var(--success); }
.stat-card:nth-child(4)::after { background: #7c3aed; }

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: transparent;
}

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-card:nth-child(1) .stat-icon { background: var(--primary-soft); color: var(--primary); }
.stat-card:nth-child(2) .stat-icon { background: #fef3c7; color: #d97706; }
.stat-card:nth-child(3) .stat-icon { background: #d1fae5; color: #059669; }
.stat-card:nth-child(4) .stat-icon { background: #ede9fe; color: #7c3aed; }

.stat-card .stat-content strong {
  display: block;
  font-size: 26px;
  font-weight: 800;
  color: var(--text-heading);
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.stat-card .stat-content span {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
  display: block;
  font-weight: 500;
}

/* ---- Category Stats ---- */
.category-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.category-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 16px;
  background: var(--card-hover);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  transition: all var(--transition-fast);
}
.category-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-xs);
  background: var(--primary-soft);
}
.category-name { font-weight: 600; color: var(--text); font-size: 14px; }
.category-count { color: var(--muted); font-size: 13px; font-weight: 500; }

/* ============================================================
   Table
   ============================================================ */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}
.table th {
  background: var(--primary-soft);
  font-size: 12px;
  color: var(--primary-deep);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 700;
}
.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:nth-child(even) { background: var(--card-hover); }
.table tbody tr:hover { background: var(--primary-soft); }
.table td .btn.ghost { padding: 4px 10px; font-size: 13px; }

/* ============================================================
   Login
   ============================================================ */

.login-wrap { max-width: 480px; margin: 80px auto; }
.login-wrap .card { padding: 32px; }

/* ---- Utilities ---- */
.stack-16 > * + * { margin-top: 16px; }
.stack-20 > * + * { margin-top: 20px; }

/* ============================================================
   Admin Layout — Sidebar Refined
   ============================================================ */

.admin-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
  gap: 0;
}

.admin-sidebar {
  background: linear-gradient(180deg, #14121f 0%, #1e1b2e 50%, #1a182a 100%);
  color: #e2e8f0;
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.05);
}

.admin-sidebar .brand {
  padding: 28px 24px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 0;
}
.admin-sidebar .brand h1 {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  margin: 0;
  letter-spacing: -0.02em;
}
.admin-sidebar .brand p {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  margin-top: 4px;
  font-weight: 500;
}

.admin-sidebar nav {
  padding: 12px 0;
  display: flex;
  flex-direction: column;
}

.admin-sidebar nav a,
.admin-sidebar nav button[type="submit"] {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: rgba(255,255,255,0.55);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition-fast);
  border-left: 3px solid transparent;
  text-decoration: none;
  background: none;
  border-top: none;
  border-right: none;
  border-bottom: none;
  width: 100%;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: -0.005em;
}

.admin-sidebar nav a:hover,
.admin-sidebar nav button[type="submit"]:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
  border-left-color: rgba(255,255,255,0.3);
}

.admin-sidebar nav a.active {
  background: rgba(99, 102, 241, 0.15);
  color: #fff;
  border-left-color: var(--primary-light);
  font-weight: 600;
}

.admin-sidebar .sidebar-section {
  padding: 20px 24px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,0.3);
  font-weight: 700;
}

.admin-main {
  background: var(--bg);
  min-height: 100vh;
}
.admin-main .admin-shell {
  max-width: 1200px;
  margin: 0 auto;
}

/* ---- Mobile Menu ---- */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 110;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-fast);
  align-items: center;
  justify-content: center;
}
.mobile-menu-toggle:hover { background: var(--primary-deep); transform: scale(1.05); }

/* ============================================================
   Preview / Badge Styles
   ============================================================ */

.preview {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg);
}
.preview h3 { margin-bottom: 12px; font-size: 16px; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 6px;
  min-width: 20px;
  height: 20px;
}
.admin-sidebar a .badge-count { background: rgba(255, 255, 255, 0.2); }

/* ============================================================
   Settings Tabs
   ============================================================ */

.settings-tab-btn {
  border-bottom: 2px solid transparent !important;
  margin-bottom: -2px !important;
  border-radius: 0 !important;
  font-size: 14px !important;
  padding: 10px 18px !important;
}

/* ============================================================
/* ============================================================
   Preview Modal
   ============================================================ */

.preview-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10000;
  overflow-y: auto;
  padding: 24px;
}
.preview-modal.active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.preview-modal-container {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 900px;
  width: 100%;
  margin: 40px auto;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
}
.preview-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 32px;
  border-bottom: 1px solid var(--line);
}
.preview-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-heading);
}
.preview-modal-close {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all var(--transition-fast);
}
.preview-modal-close:hover {
  background: var(--line-soft);
  color: var(--text);
}
.preview-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  background: var(--bg);
}
.preview-modal-body .admin-article-preview {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-xs);
}
.preview-modal-body .article-body {
  line-height: 1.85;
  font-size: 16px;
}
.preview-modal-body .article-body h2 {
  margin-top: 32px;
  margin-bottom: 16px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-heading);
  border-bottom: 2px solid var(--line-soft);
  padding-bottom: 10px;
}
.preview-modal-body .article-body h3 {
  margin-top: 24px;
  margin-bottom: 12px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-heading);
}
.preview-modal-body .article-body p { margin-bottom: 16px; }
.preview-modal-body .article-body ul,
.preview-modal-body .article-body ol { margin-bottom: 16px; padding-left: 24px; }
.preview-modal-body .article-body li { margin-bottom: 8px; }
.preview-modal-body .article-body img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 18px auto;
  box-shadow: var(--shadow-md);
}
.preview-modal-body .article-body pre {
  background: #1e1b2e;
  color: #e2e8f0;
  padding: 0;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 16px 0;
  box-shadow: var(--shadow-sm);
  line-height: 1.65;
}
.preview-modal-body .article-body pre > code {
  display: block;
  padding: 18px 22px;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  color: #e2e8f0;
}
.preview-modal-body .article-body :not(pre) > code {
  background: var(--primary-soft);
  color: var(--primary-deep);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.9em;
  font-family: var(--font-mono);
}
.preview-modal-body .article-body blockquote {
  border-left: 4px solid var(--primary);
  padding: 14px 18px;
  margin: 16px 0;
  color: var(--muted);
  font-style: italic;
  background: var(--primary-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.preview-modal-footer {
  display: flex;
  gap: 10px;
  padding: 22px 32px;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}
body.modal-open { overflow: hidden; }

/* ============================================================
   Button Loading State
   ============================================================ */

.btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.loading::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  top: 50%;
  left: 50%;
  margin-left: -9px;
  margin-top: -9px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: btnSpin 0.6s linear infinite;
}
.btn.ghost.loading::after {
  border-color: rgba(79, 70, 229, 0.3);
  border-top-color: var(--primary);
}
@keyframes btnSpin { to { transform: rotate(360deg); } }

/* ============================================================
   Pager
   ============================================================ */

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 24px;
}
.pager a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: var(--line-soft);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition-fast);
}
.pager a:hover { background: var(--line); color: var(--text); text-decoration: none; }
.pager a.active {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 8px var(--primary-glow);
}
.pager a.active:hover { background: var(--primary-deep); }

/* ============================================================
   Animations
   ============================================================ */

.admin-main .admin-shell {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.is-ready .admin-main .admin-shell {
  animation: adminFadeUp 0.4s ease both;
}
@keyframes adminFadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes cardSlideIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Staggered card entrance */
.stats-grid .stat-card:nth-child(1) { animation: cardSlideIn 0.4s ease both; }
.stats-grid .stat-card:nth-child(2) { animation: cardSlideIn 0.4s 0.05s ease both; }
.stats-grid .stat-card:nth-child(3) { animation: cardSlideIn 0.4s 0.1s ease both; }
.stats-grid .stat-card:nth-child(4) { animation: cardSlideIn 0.4s 0.15s ease both; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 960px) {
  .mobile-menu-toggle { display: flex; }
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    position: fixed;
    left: -260px;
    transition: left var(--transition-slow);
    z-index: 100;
    box-shadow: var(--shadow-xl);
  }
  .admin-sidebar.open { left: 0; }
  .admin-grid, .form-grid, .install-grid, .stats, .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .admin-main .admin-shell { padding: 18px 14px 36px; }
  .admin-header { flex-direction: column; align-items: stretch; }
  .admin-hero { padding: 28px 24px; border-radius: var(--radius-lg); }
  .admin-hero h1 { font-size: 26px; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .admin-main { padding: 12px; }
  .admin-hero { padding: 24px 18px; }
  .admin-hero h1 { font-size: 22px; }
  .card { padding: 18px; }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid, .install-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .preview-modal { padding: 0; }
  .preview-modal-container { margin: 0; border-radius: 0; max-height: 100vh; }
  .preview-modal-body { padding: 24px 16px; }
  .preview-modal-footer { flex-wrap: wrap; }
  .preview-modal-footer .btn { flex: 1; min-width: 120px; }
  .table th, .table td { padding: 10px 12px; font-size: 13px; }
}
