:root {
  --bg-base:      #0f1117;
  --bg-card:      #1a1d27;
  --bg-hover:     #222536;
  --accent:       #6c63ff;
  --accent-green: #22c55e;
  --accent-red:   #ef4444;
  --accent-amber: #f59e0b;
  --text-primary: #f1f5f9;
  --text-muted:   #94a3b8;
  --border:       #2d3148;
  --sidebar-w:    220px;
  --header-h:     60px;
  --radius:       10px;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --transition:   all 0.2s ease;
}

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Sidebar ─────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-logo {
  padding: 22px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.sidebar-logo span {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.3px;
}

.sidebar-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 18px 20px 6px;
}

.sidebar-nav { flex: 1; padding: 6px 10px 10px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
  margin-bottom: 2px;
  user-select: none;
}

.nav-link .nav-icon { font-size: 1rem; width: 18px; text-align: center; }
.nav-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-link.active {
  background: rgba(108, 99, 255, 0.15);
  color: var(--accent);
}
.nav-link.active .nav-icon { color: var(--accent); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Main layout ─────────────────────────────────────────────── */
#app-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  min-height: var(--header-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
}

.header-title {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-right { display: flex; align-items: center; gap: 12px; }

.scrape-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.scrape-badge .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── Content area ────────────────────────────────────────────── */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.view { animation: fadeIn 0.2s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Page title ──────────────────────────────────────────────── */
.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title .page-icon { font-size: 1.3rem; }

/* ── Metric cards ────────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: var(--transition);
}

.metric-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.metric-value {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1;
}

.metric-value.green  { color: var(--accent-green); }
.metric-value.red    { color: var(--accent-red); }
.metric-value.amber  { color: var(--accent-amber); }
.metric-value.violet { color: var(--accent); }

.metric-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Cards / panels ──────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-wrap {
  position: relative;
  width: 100%;
}

.chart-wrap.donut   { max-width: 360px; margin: 0 auto; }
.chart-wrap.bar-h   { height: 340px; }
.chart-wrap.bar-v   { height: 280px; }
.chart-wrap.line    { height: 320px; }
.chart-wrap.scatter { height: 320px; }

/* ── Tables ──────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead {
  position: sticky;
  top: 0;
  background: var(--bg-hover);
  z-index: 2;
}

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}

tbody tr {
  border-top: 1px solid var(--border);
  transition: background 0.12s;
}

tbody tr:nth-child(even) { background: rgba(255,255,255,0.015); }
tbody tr:hover           { background: var(--bg-hover); }

tbody td {
  padding: 9px 14px;
  color: var(--text-primary);
  white-space: nowrap;
}

tbody td a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s;
}

tbody td a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.td-muted { color: var(--text-muted); font-size: 0.78rem; }
.td-right { text-align: right; }
.td-center{ text-align: center; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge.green  { background: rgba(34,197,94,0.15);  color: var(--accent-green); }
.badge.red    { background: rgba(239,68,68,0.15);   color: var(--accent-red); }
.badge.amber  { background: rgba(245,158,11,0.15);  color: var(--accent-amber); }
.badge.violet { background: rgba(108,99,255,0.15);  color: var(--accent); }
.badge.gray   { background: rgba(148,163,184,0.15); color: var(--text-muted); }

/* ── Controls ────────────────────────────────────────────────── */
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.btn-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.btn-group button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.btn-group button:not(:last-child) { border-right: 1px solid var(--border); }
.btn-group button:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-group button.active { background: var(--accent); color: #fff; }

/* Pill filters */
.pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.pill {
  padding: 5px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: var(--transition);
  font-family: inherit;
}

.pill:hover  { border-color: var(--accent); color: var(--accent); }
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Sliders */
.slider-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-group label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.slider-group input[type=range] {
  -webkit-appearance: none;
  width: 180px;
  height: 4px;
  border-radius: 99px;
  background: var(--border);
  outline: none;
}

.slider-group input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(108,99,255,0.2);
}

.slider-val {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

/* ── Search ──────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
  margin-bottom: 20px;
  max-width: 480px;
}

.search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px 10px 38px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus { border-color: var(--accent); }

.search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 200;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.search-item {
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  font-size: 0.83rem;
}

.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--bg-hover); }
.search-item .item-name { font-weight: 500; }
.search-item .item-sub  { font-size: 0.72rem; color: var(--text-muted); }

/* ── Alert Feed ──────────────────────────────────────────────── */
.alert-feed { display: flex; flex-direction: column; gap: 10px; }

.alert-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  transition: var(--transition);
}

.alert-card:hover { background: var(--bg-hover); transform: translateX(2px); }
.alert-card.PRICE_DROP    { border-left-color: var(--accent-green); }
.alert-card.OUT_OF_STOCK  { border-left-color: var(--accent-red); }
.alert-card.BACK_IN_STOCK { border-left-color: var(--accent-green); }
.alert-card.LOW_STOCK     { border-left-color: var(--accent-amber); }
.alert-card.NEW_LIQUIDACION{ border-left-color: var(--accent-amber); }
.alert-card.NEW_PRODUCT   { border-left-color: var(--accent); }
.alert-card.HIGH_VELOCITY { border-left-color: #f97316; }

.alert-icon {
  font-size: 1.2rem;
  line-height: 1;
  width: 24px;
  text-align: center;
}

.alert-body { flex: 1; }

.alert-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.alert-product { font-weight: 600; font-size: 0.88rem; }
.alert-sku { font-size: 0.72rem; color: var(--text-muted); }
.alert-detail { font-size: 0.82rem; color: var(--text-muted); }
.alert-time { font-size: 0.72rem; color: var(--text-muted); margin-left: auto; white-space: nowrap; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; max-width: 300px; margin: 0 auto; }

/* ── Loading ─────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toggle ──────────────────────────────────────────────────── */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
}

.toggle {
  width: 36px; height: 20px;
  background: var(--border);
  border-radius: 99px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle.on { background: var(--accent); }

.toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.toggle.on::after { transform: translateX(16px); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  body { flex-direction: column; overflow: auto; }

  #sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0;
    overflow-x: auto;
  }

  .sidebar-logo { border-bottom: none; padding: 14px 16px; border-right: 1px solid var(--border); }
  .sidebar-label { display: none; }
  .sidebar-nav { display: flex; padding: 6px; flex-direction: row; }
  .nav-link { padding: 8px 12px; white-space: nowrap; }
  .sidebar-footer { display: none; }

  #app-shell { overflow: unset; }
  #content { overflow: unset; }

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

@media (max-width: 560px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
}
