* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #6c5ce7;
  --primary-dark: #5a4bd1;
  --bg: #f8f9fa;
  --white: #fff;
  --text: #2d3436;
  --muted: #636e72;
  --border: #e9ecef;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --white: #1a1d23; --text: #e0e0e0; --muted: #999; --border: #2a2d35; --shadow: 0 2px 12px rgba(0,0,0,.3);
  }
}
[data-theme="dark"] {
  --bg: #0f1115; --white: #1a1d23; --text: #e0e0e0; --muted: #999; --border: #2a2d35; --shadow: 0 2px 12px rgba(0,0,0,.3);
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
a { text-decoration: none; color: inherit; }
img { max-width: 100%; display: block; }
button, .btn { border: none; cursor: pointer; font-family: inherit; font-size: 14px; border-radius: 8px; padding: 10px 18px; font-weight: 600; transition: all .2s; }
input, select, textarea { font-family: inherit; font-size: 14px; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; width: 100%; background: var(--white); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,92,231,.1); }
small { color: var(--muted); font-size: 11px; }

/* Buttons */
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #e74c3c; color: #fff; }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-success { background: #00b894; color: #fff; }
.btn-icon { background: none; border: none; width: 34px; height: 34px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); transition: all .2s; padding: 0; }
.btn-icon:hover { background: var(--border); color: var(--primary); }
.btn-icon-danger:hover { background: #fde8e8; color: #e74c3c; }

/* Badge */
.badge { font-size: 11px; padding: 3px 8px; border-radius: 20px; font-weight: 600; }
.badge-success { background: #d4edda; color: #155724; }
.badge-muted { background: var(--border); color: var(--muted); }

/* Alert */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.alert-success { background: #d4edda; color: #155724; }

/* ==================== ADMIN LAYOUT ==================== */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar { width: 240px; background: #1a1d23; position: fixed; height: 100vh; display: flex; flex-direction: column; z-index: 100; transition: transform .3s; }
.admin-sidebar-brand { color: #fff; font-size: 16px; font-weight: 700; padding: 20px 24px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar-nav { flex: 1; padding: 12px 0; }
.sidebar-nav a, .sidebar-footer a { display: flex; align-items: center; gap: 12px; padding: 11px 24px; color: #8b95a5; font-size: 14px; transition: all .2s; border-radius: 0; }
.sidebar-nav a:hover, .sidebar-footer a:hover { color: #fff; background: rgba(108,92,231,.1); }
.sidebar-nav a.active { color: #fff; background: rgba(108,92,231,.15); border-left: 3px solid var(--primary); }
.sidebar-nav a i, .sidebar-footer a i { width: 18px; text-align: center; font-size: 14px; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.06); padding: 8px 0; }

.admin-main { flex: 1; margin-left: 240px; padding: 24px 32px; max-width: 100%; }
.admin-topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.admin-topbar h1 { font-size: 22px; font-weight: 700; flex: 1; }
.admin-welcome { font-size: 13px; color: var(--muted); }
.hamburger { display: none; background: none; border: none; font-size: 20px; color: var(--text); padding: 8px; cursor: pointer; }

/* ==================== STATS CARDS ==================== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 20px; display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ==================== CARDS ==================== */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden; margin-bottom: 20px; }
.card-header { padding: 16px 20px; font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); }
.card-header i { margin-right: 8px; }

/* ==================== PRODUCT ROWS ==================== */
.admin-search { padding: 12px 20px; border-bottom: 1px solid var(--border); }
.admin-search input { border-radius: 20px; padding: 10px 16px; font-size: 13px; }
.products-list { max-height: 600px; overflow-y: auto; }
.product-row { display: flex; align-items: center; gap: 14px; padding: 12px 20px; border-bottom: 1px solid var(--border); transition: background .15s; }
.product-row:hover { background: rgba(108,92,231,.03); }
.product-row:last-child { border-bottom: none; }
.product-row-img { width: 44px; height: 44px; border-radius: 8px; overflow: hidden; flex-shrink: 0; background: var(--border); }
.product-row-img img { width: 100%; height: 100%; object-fit: cover; }
.product-row-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 16px; }
.product-row-info { flex: 1; min-width: 0; }
.product-row-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-row-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.product-row-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }

/* ==================== TOP LIST ==================== */
.top-list { padding: 8px 0; }
.top-item { display: flex; align-items: center; gap: 12px; padding: 10px 20px; }
.top-rank { font-size: 12px; font-weight: 700; color: var(--primary); width: 28px; }
.top-name { flex: 1; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-clicks { font-size: 12px; font-weight: 600; color: var(--muted); }

/* ==================== METRICS ==================== */
.chart-container { padding: 20px; height: 250px; }
.clicks-bar-container { height: 6px; background: var(--border); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.clicks-bar { height: 100%; background: var(--primary); border-radius: 3px; transition: width .5s; }
.clicks-count { font-size: 14px; font-weight: 700; color: var(--primary); min-width: 50px; text-align: right; }
.table-responsive { overflow-x: auto; }
.metrics-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.metrics-table th { text-align: left; padding: 12px 16px; font-size: 11px; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--bg); font-weight: 600; }
.metrics-table td { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.metrics-table code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.metrics-table tr:hover { background: rgba(108,92,231,.03); }

/* ==================== META PREVIEW ==================== */
.meta-preview { display: flex; gap: 12px; align-items: center; background: var(--bg); border-radius: 8px; padding: 12px; margin-bottom: 14px; border: 1px solid var(--border); }
.meta-preview img { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.meta-text { flex: 1; min-width: 0; }
.meta-text div:first-child { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta-text div:last-child { font-size: 11px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==================== MODAL ==================== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.active { display: flex; }
.modal-content { background: var(--white); border-radius: var(--radius); width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; padding: 0; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 18px; font-weight: 700; }
.modal-content form { padding: 24px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }

/* ==================== LOGIN ==================== */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-box { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 40px; width: 100%; max-width: 380px; text-align: center; border: 1px solid var(--border); }
.login-box h1 { font-size: 20px; margin-bottom: 8px; }
.login-box p { font-size: 13px; color: var(--muted); margin-bottom: 24px; }
.login-error { background: #ffebee; color: #c62828; padding: 10px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }

/* ==================== PUBLIC CATALOG ==================== */
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.filters-nav { scrollbar-width: none; }
.filters-nav::-webkit-scrollbar { display: none; }
.filter-btn { background: var(--white); color: var(--muted); border: 1px solid var(--border); padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: 500; cursor: pointer; transition: all .2s; }
.filter-btn:hover, .filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; padding: 0 0 40px; }
.product-card { background: var(--white); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: transform .2s, box-shadow .2s; display: flex; flex-direction: column; border: 1px solid var(--border); }
.product-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.product-card-img { width: 100%; height: 180px; object-fit: cover; background: var(--border); }
.product-card-img-wrapper { position: relative; }
.product-card-body { padding: 16px; flex: 1; display: flex; flex-direction: column; }
.product-card-category { font-size: 11px; text-transform: uppercase; color: var(--primary); font-weight: 600; letter-spacing: .5px; margin-bottom: 6px; }
.product-card-name { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.product-card-desc { font-size: 13px; color: var(--muted); flex: 1; margin-bottom: 12px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.product-card-footer { display: flex; align-items: center; justify-content: space-between; }
.btn-comprar { background: var(--primary); color: #fff; padding: 10px 20px; border-radius: 8px; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; transition: background .2s; }
.btn-comprar:hover { background: var(--primary-dark); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state i { font-size: 48px; margin-bottom: 16px; display: block; opacity: .4; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
  .admin-sidebar { transform: translateX(-100%); position: fixed; }
  .admin-sidebar.open { transform: translateX(0); }
  .admin-main { margin-left: 0; padding: 16px; }
  .hamburger { display: block; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .products-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .product-card-img { height: 140px; }
  .product-row { flex-wrap: wrap; }
  .product-row-actions { width: 100%; justify-content: flex-end; margin-top: 8px; }
}

/* ==================== DARK MODE OVERRIDES ==================== */
[data-theme="dark"] .admin-sidebar { background: #12141a; }
[data-theme="dark"] .stat-card, [data-theme="dark"] .card { background: #1a1d23; border-color: #2a2d35; }
[data-theme="dark"] .product-row:hover, [data-theme="dark"] .metrics-table tr:hover { background: rgba(108,92,231,.05); }
[data-theme="dark"] .modal-content { background: #1a1d23; }
[data-theme="dark"] .login-box { background: #1a1d23; border-color: #2a2d35; }
[data-theme="dark"] .badge-success { background: #1a3a2a; color: #00b894; }
[data-theme="dark"] .btn-icon-danger:hover { background: #3a1a1a; }
[data-theme="dark"] .alert-success { background: #1a3a2a; color: #00b894; }
[data-theme="dark"] .meta-preview { background: #12141a; border-color: #2a2d35; }
[data-theme="dark"] .metrics-table th { background: #12141a; }
