/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #0f172a;
  color: #f1f5f9;
  min-height: 100vh;
}

/* ── Layout ──────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar desktop */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: #1e293b;
  border-right: 1px solid #334155;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid #334155;
  margin-bottom: 1rem;
}
.brand-icon { font-size: 1.4rem; }
.brand-name { font-size: 1.1rem; font-weight: 700; color: #8b5cf6; }

.nav-list { list-style: none; padding: 0 0.75rem; }
.nav-list li { margin-bottom: 0.25rem; }

.nav-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.875rem;
  background: none;
  border: none;
  border-radius: 8px;
  color: #94a3b8;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}
.nav-btn:hover { background: #334155; color: #f1f5f9; }
.nav-btn.tab-active { background: #8b5cf620; color: #8b5cf6; font-weight: 600; }
.nav-icon { font-size: 1.1rem; }

.main {
  margin-left: 220px;
  flex: 1;
  padding: 1.5rem;
  min-height: 100vh;
}

.tab-content { display: block; }
.tab-content.hidden { display: none; }

/* ── Error banner ────────────────────────────────────────── */
.error-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: #f87171;
  color: #fff;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 999;
  font-weight: 500;
}
.error-banner button {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
}

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #1e293b;
  border: 1px solid #334155;
  color: #f1f5f9;
  padding: 0.7rem 1.2rem;
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 998;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: opacity 0.3s;
}
.toast.ok  { border-left: 4px solid #4ade80; }
.toast.err { border-left: 4px solid #f87171; }

/* ── Cards de producto ───────────────────────────────────── */
.card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  transition: border-color 0.15s;
}
.card:hover { border-color: #8b5cf640; }

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.product-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}
.product-name { font-weight: 600; font-size: 0.95rem; color: #f1f5f9; }

/* Badge */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #8b5cf620;
  color: #8b5cf6;
}

/* Stock colors */
.stock-ok   { color: #4ade80; font-weight: 600; }
.stock-low  { color: #fbbf24; font-weight: 600; }
.stock-zero { color: #f87171; font-weight: 600; }

/* Margin color */
.margin-high { color: #4ade80; }
.margin-mid  { color: #fbbf24; }
.margin-low  { color: #f87171; }

.product-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.metric { font-size: 0.8rem; color: #94a3b8; }
.metric strong { display: block; color: #f1f5f9; font-size: 0.85rem; margin-top: 0.1rem; }

.product-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* Sparkline */
.sparkline { width: 100%; height: 40px; margin: 0.5rem 0; }

/* ── Botones ─────────────────────────────────────────────── */
.btn {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #334155;
  color: #f1f5f9;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #475569; border-color: #475569; }
.btn-primary { background: #8b5cf6; border-color: #8b5cf6; color: #fff; }
.btn-primary:hover { background: #7c3aed; border-color: #7c3aed; }
.btn-danger { background: #f87171; border-color: #f87171; color: #fff; }
.btn-danger:hover { background: #ef4444; border-color: #ef4444; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-icon { padding: 0.4rem 0.6rem; font-size: 1rem; background: none; border: none; color: #94a3b8; cursor: pointer; }
.btn-icon:hover { color: #f1f5f9; }

/* ── Toolbar (search + filters) ──────────────────────────── */
.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.search-input {
  flex: 1;
  min-width: 160px;
  padding: 0.5rem 0.875rem;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #f1f5f9;
  font-size: 0.875rem;
}
.search-input:focus { outline: none; border-color: #8b5cf6; }
select.filter-select {
  padding: 0.5rem 0.75rem;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #f1f5f9;
  font-size: 0.875rem;
  cursor: pointer;
}
select.filter-select:focus { outline: none; border-color: #8b5cf6; }

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.page-title { font-size: 1.3rem; font-weight: 700; }

/* ── Formulario ──────────────────────────────────────────── */
.form-container {
  background: #1e293b;
  border: 1px solid #8b5cf640;
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.form-title { font-weight: 600; margin-bottom: 1rem; color: #8b5cf6; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.875rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label { font-size: 0.8rem; color: #94a3b8; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
  padding: 0.5rem 0.75rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #f1f5f9;
  font-size: 0.875rem;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: #8b5cf6;
}
.form-group input.error, .form-group select.error { border-color: #f87171; }
.form-error { font-size: 0.75rem; color: #f87171; min-height: 1rem; }
.form-info  { font-size: 0.75rem; color: #94a3b8; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.form-full { grid-column: 1 / -1; }

/* ── Tablas ──────────────────────────────────────────────── */
.table-container {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  overflow: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
thead th {
  background: #0f172a;
  padding: 0.7rem 1rem;
  text-align: left;
  color: #94a3b8;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #334155;
}
tbody tr { border-bottom: 1px solid #334155; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #334155; }
tbody td { padding: 0.65rem 1rem; color: #f1f5f9; }
.total-row td { background: #0f172a; font-weight: 700; color: #8b5cf6; }

/* ── KPI Cards ───────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
}
.kpi-label { font-size: 0.78rem; color: #94a3b8; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.4rem; }
.kpi-value { font-size: 1.5rem; font-weight: 700; color: #f1f5f9; }
.kpi-sub   { font-size: 0.78rem; color: #94a3b8; margin-top: 0.2rem; }

/* ── Dashboard chart ─────────────────────────────────────── */
.chart-container {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.chart-title { font-weight: 600; margin-bottom: 1rem; }
#dash-chart { max-height: 280px; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 1.5rem;
  max-width: 380px;
  width: 90%;
}
.modal-box p { margin-bottom: 1.25rem; color: #f1f5f9; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* ── Loader ──────────────────────────────────────────────── */
.loader {
  text-align: center;
  padding: 3rem;
  color: #94a3b8;
  font-size: 0.9rem;
}

/* ── Period filter tabs ──────────────────────────────────── */
.period-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.period-btn {
  padding: 0.4rem 0.875rem;
  border-radius: 999px;
  border: 1px solid #334155;
  background: none;
  color: #94a3b8;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.period-btn.active, .period-btn:hover { background: #8b5cf6; border-color: #8b5cf6; color: #fff; }

/* ── Responsive mobile ───────────────────────────────────── */
@media (max-width: 767px) {
  .sidebar {
    width: 100%;
    min-height: unset;
    height: 60px;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    flex-direction: row;
    align-items: center;
    padding: 0;
    border-right: none;
    border-top: 1px solid #334155;
  }
  .brand { display: none; }
  .nav-list {
    display: flex;
    flex: 1;
    padding: 0;
    justify-content: space-around;
  }
  .nav-list li { margin: 0; flex: 1; }
  .nav-btn {
    flex-direction: column;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.5rem 0;
    font-size: 0.68rem;
    border-radius: 0;
    width: 100%;
  }
  .nav-label { font-size: 0.65rem; }
  .main {
    margin-left: 0;
    padding: 1rem;
    padding-bottom: 4.5rem;
  }
  .products-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Utility ─────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: #94a3b8; }
.text-success { color: #4ade80; }
.text-danger  { color: #f87171; }
.text-warning { color: #fbbf24; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.section-title { font-size: 1rem; font-weight: 600; margin: 1.25rem 0 0.75rem; }