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

:root {
  --bg:       #f1f5f9;
  --surface:  #ffffff;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --muted:    #64748b;
  --accent:   #2563eb;
  --green:    #16a34a;
  --red:      #dc2626;
  --orange:   #ea580c;
  --radius:   10px;
  --shadow:   0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── ICONS ── */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.icon svg {
  width: 100%;
  height: 100%;
}

/* ── LAYOUT ── */
.shell {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
}

.menu-toggle { display: none; }
.menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 110;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.35);
  z-index: 90;
}

/* ── SIDEBAR ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-logo {
  padding: 0 18px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.sidebar-logo img {
  max-width: 140px;
  max-height: 40px;
  object-fit: contain;
  display: block;
  margin-bottom: 4px;
}

.sidebar-logo small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.nav-section {
  padding: 0 12px;
  margin-bottom: 6px;
}

.nav-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 0 10px;
  margin-bottom: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: #eff6ff; color: var(--accent); }

/* ── MAIN ── */
.main {
  padding: 28px 32px;
  overflow-y: auto;
  min-width: 0;
}

.page-header {
  margin-bottom: 22px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.page-header p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}

/* ── STATS GRID ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-card .value {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.stat-card .label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
}

/* ── CARD ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.card-body { padding: 18px; }

/* ── FORMS ── */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

.form-field { margin-bottom: 14px; }
.form-field label,
.filter-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 5px;
}

.form-field input,
.form-field select,
.form-field textarea,
.filter-field input,
.filter-field select {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus,
.filter-field input:focus,
.filter-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px #2563eb18;
}

.form-field textarea { min-height: 72px; resize: vertical; }

/* ── FILTER BAR ── */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  align-items: end;
}

.filter-field { display: flex; flex-direction: column; gap: 4px; }

.filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s, transform .1s, background .15s;
  white-space: nowrap;
}

.btn:hover { opacity: .9; transform: translateY(-1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-outline {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

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

table { width: 100%; border-collapse: collapse; }

thead th {
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: #f8fafc;
}

tbody td { padding: 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafc; }

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}

.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }

/* ── ALERT ── */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
}

.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

/* ── PRODUCT CELLS ── */
.product-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.product-name:hover { text-decoration: underline; }

.product-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.product-tags {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 5px;
}

.price-main {
  font-size: 16px;
  font-weight: 800;
  color: var(--green);
  white-space: nowrap;
}
.price-old {
  font-size: 11px;
  color: var(--muted);
  text-decoration: line-through;
}

.score-cell {
  text-align: center;
  min-width: 100px;
}
.score-number {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin-top: 2px;
}
.score-reason {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.3;
  max-width: 130px;
  margin: 4px auto 0;
}

/* ── HISTORY PILLS ── */
.price-history {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  flex-wrap: wrap;
}

.price-pill {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  background: #f1f5f9;
  color: var(--muted);
}

.price-pill.current {
  background: #dcfce7;
  color: var(--green);
  font-weight: 600;
}

/* ── PAGINATION ── */
.pagination {
  margin-top: 18px;
  padding: 0 16px 16px;
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

/* ── MOBILE CARDS ── */
.mobile-card {
  display: none;
}

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }

  .menu-btn { display: inline-flex; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 250px;
    transform: translateX(-110%);
    transition: transform .2s ease;
    box-shadow: 4px 0 16px rgba(15,23,42,.12);
  }

  .menu-toggle:checked ~ .sidebar { transform: translateX(0); }
  .menu-toggle:checked ~ .overlay { display: block; }

  .main { padding: 64px 16px 24px; }

  .page-header { flex-direction: column; align-items: flex-start; }

  .filter-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }

  .page-header h1 { font-size: 18px; }

  /* Convertir tabla de candidatos/productos en cards apiladas */
  .data-table thead { display: none; }
  .data-table tbody,
  .data-table tr,
  .data-table td { display: block; width: 100%; }
  .data-table tr {
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
  }
  .data-table td {
    border: none;
    padding: 6px 12px;
  }
  .data-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    margin-bottom: 2px;
  }
  .data-table .score-cell { text-align: left; }
  .data-table .score-number,
  .data-table .score-reason { display: inline-block; margin-right: 8px; }
}
