/* =========================================================
   UICraft Design System
   Dark premium aesthetic — violet #7C5CFC / teal #00E5C7
   ========================================================= */

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

:root {
  --accent: #7C5CFC;
  --accent-2: #00E5C7;
  --accent-grad: linear-gradient(135deg, var(--accent), var(--accent-2));

  --bg: #0B0B12;
  --bg-elevated: #101018;
  --surface: #14141F;
  --surface-hover: #1A1A28;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  --text: #F2F2F7;
  --text-muted: #9A9AB0;
  --text-faint: #63637A;

  --success: #4ADE80;
  --warning: #FFB800;
  --danger: #FF5C7A;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-lg: 0 24px 60px -20px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 0 1px rgba(124,92,252,.25), 0 8px 30px -8px rgba(124,92,252,.35);

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --header-h: 72px;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #F7F7FB;
  --bg-elevated: #FFFFFF;
  --surface: #FFFFFF;
  --surface-hover: #F0F0F7;
  --border: rgba(20,20,31,0.08);
  --border-strong: rgba(20,20,31,0.14);
  --text: #14141F;
  --text-muted: #5C5C72;
  --text-faint: #8A8AA0;
  --shadow-lg: 0 24px 60px -24px rgba(20,20,31,0.18);
  color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
  min-height: 100vh;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; letter-spacing: -0.02em; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }
code, .mono { font-family: var(--font-mono); }
::selection { background: var(--accent); color: #0B0B12; }

.container { max-width: 1280px; margin: 0 auto; padding: 0 24px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, opacity .15s ease;
}
.btn-primary { background: var(--accent-grad); color: #08080D; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-glow); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-lg { padding: 16px 32px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-icon { padding: 10px; border-radius: var(--radius-sm); }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h); padding: 0 32px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  gap: 24px;
}
.header-left { display: flex; align-items: center; gap: 36px; flex: 1; min-width: 0; }
.logo { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 20px; flex-shrink: 0; }
.logo-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent-grad); display: flex; align-items: center; justify-content: center; font-size: 16px; color: #08080D; font-weight: 800; }
.logo-text { background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

.nav-categories { display: flex; align-items: center; gap: 4px; position: relative; }
.nav-categories .dropdown-trigger { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text-muted); }
.nav-categories .dropdown-trigger:hover { color: var(--text); background: var(--surface); }

.search-bar { flex: 1; max-width: 420px; position: relative; }
.search-bar input {
  width: 100%; padding: 10px 16px 10px 40px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-size: 14px; outline: none; transition: border-color .15s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); opacity: .5; }

.header-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.theme-toggle { width: 38px; height: 38px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; }
.theme-toggle:hover { background: var(--surface-hover); }

.avatar-btn { width: 38px; height: 38px; border-radius: 50%; overflow: hidden; background: var(--accent-grad); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; color: #08080D; }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* Category mega-dropdown */
.category-dropdown {
  position: absolute; top: calc(100% + 10px); left: 0;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: 12px; display: none;
  grid-template-columns: repeat(2, 1fr); gap: 4px; width: 420px; z-index: 200;
}
.category-dropdown.open { display: grid; }
.category-dropdown a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text-muted); }
.category-dropdown a:hover { background: var(--surface); color: var(--text); }

/* User dropdown */
.user-dropdown-wrap { position: relative; }
.user-dropdown { position: absolute; right: 0; top: calc(100% + 10px); background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); width: 220px; padding: 8px; display: none; z-index: 200; }
.user-dropdown.open { display: block; }
.user-dropdown a, .user-dropdown button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; text-align: left; }
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--surface); }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden; text-align: center;
  padding: 120px 24px 90px;
}
.hero::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(circle at 50% -10%, rgba(124,92,252,.28), transparent 55%),
              radial-gradient(circle at 85% 10%, rgba(0,229,199,.14), transparent 45%);
}
.hero .eyebrow { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; color: var(--accent-2); margin-bottom: 24px; }
.hero h1 { font-size: clamp(36px, 6vw, 64px); max-width: 820px; margin: 0 auto 22px; }
.hero h1 .highlight { background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--text-muted); font-size: 18px; max-width: 580px; margin: 0 auto 40px; }
.hero-cta { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hero-stats { display: flex; gap: 48px; justify-content: center; margin-top: 64px; flex-wrap: wrap; }
.hero-stats div { text-align: center; }
.hero-stats strong { display: block; font-family: var(--font-display); font-size: 28px; }
.hero-stats span { color: var(--text-faint); font-size: 13px; }

/* ---------- Section headers ---------- */
.section-head { display: flex; align-items: flex-end; justify-content: space-between; margin: 0 0 32px; flex-wrap: wrap; gap: 16px; }
.section-head h2 { font-size: 32px; }
.section-head p { color: var(--text-muted); margin-top: 6px; }

/* ---------- Category pills (landing showcase) ---------- */
.category-pills { display: flex; flex-wrap: wrap; gap: 12px; padding: 40px 0 80px; }
.category-pill { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 14px; transition: all .15s; }
.category-pill:hover { border-color: var(--accent); transform: translateY(-2px); }
.category-pill .count { color: var(--text-faint); font-size: 12px; }

/* ---------- Template Grid & Cards ---------- */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px; }
.template-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; transition: transform .2s, box-shadow .2s, border-color .2s; }
.template-card:hover { transform: translateY(-4px); border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.card-thumb { position: relative; aspect-ratio: 4/3; background: var(--bg-elevated); overflow: hidden; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.template-card:hover .card-thumb img { transform: scale(1.05); }
.card-badge { position: absolute; top: 12px; left: 12px; padding: 5px 11px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.badge-free { background: rgba(74,222,128,.15); color: var(--success); border: 1px solid rgba(74,222,128,.3); }
.badge-pro { background: rgba(124,92,252,.18); color: #B9A3FF; border: 1px solid rgba(124,92,252,.35); }
.card-fav { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 50%; background: rgba(11,11,18,.6); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; }
.card-fav.active svg { fill: var(--accent-2); stroke: var(--accent-2); }
.card-body { padding: 16px 18px 18px; }
.card-body h3 { font-size: 15px; margin-bottom: 4px; }
.card-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.card-cat { font-size: 12px; color: var(--text-faint); }
.card-stats { display: flex; gap: 10px; font-size: 12px; color: var(--text-faint); }
.card-skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-md); aspect-ratio: 4/3; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Filters ---------- */
.filters-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 24px 0; border-bottom: 1px solid var(--border); margin-bottom: 32px; }
.filter-chip { padding: 9px 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }
.filter-chip.active { background: var(--accent-grad); color: #08080D; border-color: transparent; font-weight: 600; }
.filter-select { padding: 9px 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 13px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 48px 0; }
.pagination button { width: 38px; height: 38px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); font-size: 14px; }
.pagination button.active { background: var(--accent-grad); color: #08080D; border-color: transparent; font-weight: 700; }
.pagination button:disabled { opacity: .4; }

/* ---------- Forms ---------- */
.auth-card { max-width: 420px; margin: 80px auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 40px; }
.auth-card h1 { font-size: 26px; margin-bottom: 8px; }
.auth-card > p { color: var(--text-muted); margin-bottom: 28px; font-size: 14px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; margin-bottom: 8px; color: var(--text-muted); }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  font-size: 14px; outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field-error { color: var(--danger); font-size: 12px; margin-top: 6px; }
.divider-text { display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 12px; margin: 20px 0; }
.divider-text::before, .divider-text::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.form-footer-link { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-muted); }
.form-footer-link a { color: var(--accent-2); font-weight: 600; }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 18px; }
.alert-error { background: rgba(255,92,122,.12); color: #FF8FA3; border: 1px solid rgba(255,92,122,.3); }
.alert-success { background: rgba(74,222,128,.12); color: var(--success); border: 1px solid rgba(74,222,128,.3); }

/* ---------- Dashboard layout ---------- */
.dash-layout { display: grid; grid-template-columns: 240px 1fr; gap: 32px; padding: 40px 24px; max-width: 1280px; margin: 0 auto; }
.dash-sidebar { position: sticky; top: calc(var(--header-h) + 24px); align-self: start; }
.dash-nav a { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text-muted); margin-bottom: 2px; }
.dash-nav a:hover { background: var(--surface); color: var(--text); }
.dash-nav a.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 28px; margin: 6px 0 2px; }
.stat-card .stat-label { color: var(--text-muted); font-size: 13px; }

/* ---------- Tables (admin) ---------- */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); }
.data-table th, .data-table td { padding: 14px 16px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text-faint); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-hover); }
.tag { display: inline-flex; padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 24px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); max-width: 560px; width: 100%; max-height: 85vh; overflow-y: auto; padding: 32px; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--bg-elevated); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 14px 18px; font-size: 14px; box-shadow: var(--shadow-lg); animation: toastIn .2s ease; min-width: 260px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding: 60px 24px 32px; margin-top: 80px; }
.footer-grid { max-width: 1280px; margin: 0 auto; display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 40px; }
.footer-grid h4 { font-size: 13px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 16px; }
.footer-grid a { display: block; color: var(--text-muted); font-size: 14px; margin-bottom: 10px; }
.footer-grid a:hover { color: var(--text); }
.footer-bottom { max-width: 1280px; margin: 40px auto 0; padding-top: 24px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; color: var(--text-faint); font-size: 13px; flex-wrap: wrap; gap: 12px; }

/* ---------- Utility ---------- */
.text-center { text-align: center; }
.mt-24 { margin-top: 24px; }
.hidden { display: none !important; }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.25); border-top-color: currentColor; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skip-link:focus { position: fixed; top: 8px; left: 8px; background: var(--accent); color: #08080D; padding: 10px 16px; border-radius: 8px; z-index: 9999; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .dash-layout { grid-template-columns: 1fr; }
  .dash-sidebar { position: static; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .nav-categories, .search-bar { display: none; }
  .site-header { padding: 0 16px; }
  .hero { padding: 90px 20px 60px; }
  .footer-grid { grid-template-columns: 1fr; }
}
