:root {
  --verde: #2d6a2f; --verde-hover: #235422; --verde-light: #e8f2e8;
  --verde-border: #b8d9b8; --bg: #f5f5f3; --surface: #ffffff;
  --surface-2: #f9f9f7; --border: #e0deda; --border-dark: #ccc;
  --text: #1e1e1b; --muted: #6b6b68; --faint: #b0afaa;
  --danger: #c0392b; --danger-light: #fdecea; --danger-border: #f5c6c6;
  --success: #2d8a3e; --success-light: #f0f9f0;
  --radius: .5rem; --radius-lg: .75rem; --radius-xl: 1rem;
  --shadow: 0 1px 4px rgba(0,0,0,.08); --shadow-md: 0 4px 16px rgba(0,0,0,.1);
  --topbar: 62px; --font: 'Segoe UI', 'Helvetica Neue', sans-serif;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.6; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

/* ── TOPBAR ─────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 100; height: var(--topbar);
  background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow); display: flex; align-items: center;
  padding: 0 2rem; gap: 1.5rem;
}
.topbar-logo img { height: 36px; object-fit: contain; }
.topbar-title { font-weight: 700; font-size: 1.05rem; color: var(--verde); }
.topbar-nav { display: flex; gap: .25rem; flex: 1; }
.topbar-nav a {
  padding: .4rem .85rem; border-radius: var(--radius); font-size: .875rem;
  color: var(--muted); transition: background .15s, color .15s;
}
.topbar-nav a:hover, .topbar-nav a.active { background: var(--verde-light); color: var(--verde); font-weight: 600; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: .75rem; font-size: .85rem; color: var(--muted); }
.role-badge {
  background: var(--verde-light); color: var(--verde); font-size: .72rem;
  font-weight: 700; padding: 2px 8px; border-radius: 20px; text-transform: uppercase;
}
.btn-logout {
  padding: .35rem .9rem; border-radius: var(--radius); font-size: .85rem;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted); cursor: pointer;
  transition: background .15s;
}
.btn-logout:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger-border); }

/* ── BOTONES ────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1.1rem; border-radius: var(--radius); font-size: .875rem;
  font-weight: 600; border: 1.5px solid transparent; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s; white-space: nowrap;
}
.btn-primary { background: var(--verde); color: #fff; }
.btn-primary:hover { background: var(--verde-hover); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); border-color: var(--verde); color: var(--verde); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-xs { padding: .18rem .5rem; font-size: .75rem; font-weight: 600; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── ALERTAS ────────────────────────────────────── */
.alert { padding: .7rem 1rem; border-radius: var(--radius); font-size: .875rem; margin-bottom: 1rem; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid var(--verde-border); }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid var(--danger-border); }
.alert-info { background: #eef6ff; color: #1a56a0; border: 1px solid #b3d4f5; }

/* ── FORMULARIOS ────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; }
.form-group label { font-size: .825rem; font-weight: 600; color: var(--muted); }
.form-group input, .form-group select, .form-group textarea {
  padding: .55rem .85rem; border: 1.5px solid var(--border-dark);
  border-radius: var(--radius); background: var(--surface); font-size: .9rem;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group select:focus {
  border-color: var(--verde); box-shadow: 0 0 0 3px var(--verde-border); outline: none;
}
.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }

/* ── LOGIN ──────────────────────────────────────── */
body.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; max-width: 420px; padding: 1.5rem; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
  padding: 2.5rem 2rem; box-shadow: var(--shadow-md);
}
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo img { max-width: 200px; margin: 0 auto; }
.login-title { font-size: 1.2rem; font-weight: 700; text-align: center; margin-bottom: 1.5rem; color: var(--text); }
.login-footer { text-align: center; font-size: .78rem; color: var(--faint); margin-top: 1.5rem; }

/* ── MAIN LAYOUT ────────────────────────────────── */
.page-main { max-width: 1400px; margin: 0 auto; padding: 1.5rem 2rem 4rem; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; }

/* ── CARD ───────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.5rem; margin-bottom: 1.25rem;
}
.card h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; color: var(--text); }

/* ── FILTROS ────────────────────────────────────── */
.filters-bar { background: var(--surface); border-bottom: 1px solid var(--border); padding: .9rem 2rem; }
.filters-form { max-width: 1400px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.filter-group { display: flex; flex-direction: column; gap: .2rem; min-width: 150px; flex: 1; }
.filter-group label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.filter-group input, .filter-group select {
  padding: .45rem .75rem; border: 1.5px solid var(--border-dark); border-radius: var(--radius);
  background: var(--surface); font-size: .875rem;
}
.filter-group input:focus, .filter-group select:focus { border-color: var(--verde); outline: none; }
.filter-actions { display: flex; gap: .5rem; align-items: flex-end; }

/* ── TOOLBAR RESULTADOS ─────────────────────────── */
.results-bar {
  max-width: 1400px; margin: .75rem auto .25rem; padding: 0 2rem;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem;
}
.results-count { font-size: .9rem; color: var(--muted); }
.results-count strong { color: var(--text); font-size: 1rem; }
.results-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── PRODUCT GRID ───────────────────────────────── */
.products-wrap { max-width: 1400px; margin: 0 auto; padding: .75rem 2rem 3rem; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.product-card {
  display: flex; align-items: stretch; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow);
  transition: box-shadow .2s, transform .2s;
}
.product-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.product-img {
  width: 130px; min-width: 130px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.product-img img { width: 130px; height: 130px; object-fit: contain; padding: .5rem; }
.product-body { flex: 1; padding: 1rem; display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.product-brand { font-size: .72rem; font-weight: 800; color: var(--verde); text-transform: uppercase; letter-spacing: .07em; }
.product-name { font-size: .9rem; font-weight: 700; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.product-ref { font-size: .75rem; color: var(--faint); }
.product-price { margin-top: auto; font-size: 1rem; font-weight: 800; color: var(--verde); }
.product-stock { font-size: .72rem; }
.product-stock.in-stock { color: var(--success); }
.product-stock.out-stock { color: var(--danger); }

/* ── EMPTY STATE ────────────────────────────────── */
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--muted); }
.empty-state h3 { font-size: 1.1rem; color: var(--text); margin: 1rem 0 .5rem; }

/* ── PAGINACIÓN ─────────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 2rem 0; }
.pagination-info { font-size: .875rem; color: var(--muted); }

/* ── TABLA ADMIN ────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .875rem; }
thead th {
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); padding: .6rem .85rem;
  text-align: left; border-bottom: 2px solid var(--border); white-space: nowrap;
  background: var(--surface-2);
}
tbody td { padding: .75rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.td-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
code { font-family: monospace; font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 3px; }

/* ── BADGES ─────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .72rem; font-weight: 700; }
.badge-admin { background: var(--verde-light); color: var(--verde); }
.badge-consultor { background: #eef2ff; color: #3730a3; }
.badge-active { background: var(--success-light); color: var(--success); }
.badge-inactive { background: var(--danger-light); color: var(--danger); }

/* ── KPIs ───────────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; }
.kpi-val { font-size: 1.75rem; font-weight: 800; color: var(--verde); line-height: 1; }
.kpi-label { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* ── MODAL ──────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-box {
  background: var(--surface); border-radius: var(--radius-xl);
  padding: 2rem; width: 100%; max-width: 480px; position: relative;
  box-shadow: 0 12px 48px rgba(0,0,0,.2);
}
.modal-box h3 { font-size: 1.15rem; margin-bottom: 1rem; }
.modal-close { position: absolute; top: 1rem; right: 1rem; font-size: 1.1rem; color: var(--muted); cursor: pointer; background: none; border: none; }
.modal-close:hover { color: var(--text); }

/* ── QR / SHARE ─────────────────────────────────── */
.qr-wrap { display: flex; justify-content: center; margin: 1rem 0; }
.qr-wrap img { border: 4px solid var(--border); border-radius: var(--radius); }
.share-url { display: flex; gap: .5rem; margin-bottom: .75rem; }
.share-url input { flex: 1; font-size: .825rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .45rem .75rem; }
.share-note { font-size: .78rem; color: var(--muted); line-height: 1.5; }

/* ── SPINNER ────────────────────────────────────── */
.spinner { display: inline-block; width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--verde); border-radius: 50%; animation: spin .65s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { text-align: center; padding: 2rem; color: var(--muted); font-size: .9rem; }
.loading-msg .spinner { display: block; margin: 0 auto .75rem; width: 30px; height: 30px; }

/* ── HISTORIAL ──────────────────────────────────── */
.hist-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .85rem; }
.hist-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.hist-card .hist-meta { font-size: .78rem; color: var(--faint); }
.hist-card .hist-filters { font-size: .8rem; color: var(--muted); }
.hist-card .hist-count { font-weight: 700; color: var(--verde); font-size: .875rem; }
.hist-card .hist-actions { display: flex; gap: .4rem; margin-top: .25rem; }

/* ── RESPONSIVE ─────────────────────────────────── */
@media (max-width: 680px) {
  .topbar { padding: 0 1rem; }
  .topbar-nav { display: none; }
  .filters-bar { padding: .75rem 1rem; }
  .filters-form { flex-direction: column; }
  .filter-group { min-width: 100%; }
  .products-wrap, .page-main, .results-bar { padding-left: 1rem; padding-right: 1rem; }
  .product-grid { grid-template-columns: 1fr; }
  .results-bar { flex-direction: column; align-items: flex-start; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 1.5rem 1.25rem; }
}
@media print {
  .topbar, .filters-bar, .results-bar .results-actions, .pagination, nav { display: none !important; }
  .product-card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
  body { background: #fff; }
}
