/* ==========================================================================
   Componentes — sidebar, navbar, cards, botones, tablas, forms, badges,
   toasts, modales, skeletons. Ver docs/05-ui-ux.md
   ========================================================================== */

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5);
  min-height: var(--navbar-h);
  border-bottom: 1px solid var(--border-color);
}

.sidebar-brand .logo-mark {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--gradient-brand);
  flex: none;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: var(--shadow-1);
}

.sidebar-brand .logo-text { font-weight: 700; font-size: var(--fs-md); white-space: nowrap; }
.sidebar-brand .logo-text small { display: block; font-weight: 500; font-size: var(--fs-xs); color: var(--text-muted); }

.is-collapsed .sidebar-brand .logo-text,
.is-collapsed .nav-group-label,
.is-collapsed .nav-link span,
.is-collapsed .nav-link .badge { display: none; }

.sidebar-nav { padding: var(--sp-4) var(--sp-3); flex: 1; }

.nav-group-label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: 500;
  margin-bottom: 2px;
  position: relative;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-link.active { background: linear-gradient(90deg, rgba(22,184,105,.16), rgba(22,184,105,.03)); color: var(--accent-strong); }
.nav-link.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  background: var(--accent); border-radius: var(--radius-pill);
}

.nav-link .badge { margin-left: auto; }

/* ---------------- Navbar ---------------- */
.navbar {
  height: var(--navbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-6);
  background: color-mix(in srgb, var(--bg-app) 70%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 30;
}

.navbar .btn-icon { flex: none; }

.navbar-search {
  position: relative;
  flex: 1;
  max-width: 420px;
}

.navbar-search input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-size: var(--fs-sm);
}

.navbar-search svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-muted);
}

.navbar-spacer { flex: 1; }

.navbar-actions { display: flex; align-items: center; gap: var(--sp-2); }

.user-chip {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 6px 10px 6px 6px; border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  cursor: pointer;
}

.user-chip .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--gradient-brand);
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 13px;
}

.user-chip .meta { line-height: 1.2; }
.user-chip .meta strong { font-size: var(--fs-sm); display: block; }
.user-chip .meta span { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }

.btn-sm { padding: 7px 12px; font-size: var(--fs-xs); }
.btn-lg { padding: 13px 22px; font-size: var(--fs-base); }

.btn-primary { background: var(--gradient-brand); color: #fff; box-shadow: var(--shadow-1); }
.btn-primary:hover { box-shadow: 0 6px 18px rgba(15,157,88,.35); }

.btn-secondary { background: var(--bg-surface-2); color: var(--text-primary); border-color: var(--border-color); }
.btn-secondary:hover { background: var(--bg-hover); }

.btn-outline { background: transparent; color: var(--accent-strong); border-color: var(--border-color-strong); }
.btn-outline:hover { background: var(--bg-hover); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

.btn-icon { width: 38px; height: 38px; padding: 0; border-radius: var(--radius-md); background: var(--bg-surface-2); color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn-icon:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ---------------- Cards ---------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}

.card-header {
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  border-bottom: 1px solid var(--border-color);
}
.card-header h3 { font-size: var(--fs-base); }
.card-body { padding: var(--sp-5); }
.card-footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: var(--sp-3); }

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.stat-card::after {
  content: ""; position: absolute; inset: 0; background: var(--gradient-surface); pointer-events: none;
}
.stat-card .stat-label { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-card .stat-value { font-size: var(--fs-xl); font-weight: 700; margin-top: var(--sp-2); }
.stat-card .stat-delta { font-size: var(--fs-xs); font-weight: 600; margin-top: var(--sp-2); display: inline-flex; align-items: center; gap: 4px; }
.stat-card .stat-delta.up { color: var(--success); }
.stat-card .stat-delta.down { color: var(--danger); }
.stat-card .stat-icon {
  position: absolute; top: var(--sp-5); right: var(--sp-5);
  width: 42px; height: 42px; border-radius: var(--radius-md);
  display: grid; place-items: center;
  background: var(--info-bg); color: var(--accent-strong);
}

.grid-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
@media (max-width: 992px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-xs); font-weight: 600;
  padding: 3px 10px; border-radius: var(--radius-pill);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-info    { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--bg-surface-2); color: var(--text-secondary); }

/* ---------------- Alerts (mensajes flash de error/exito) ---------------- */
.alert { border-radius: var(--radius-md); padding: 12px 16px; font-size: var(--fs-sm); border: 1px solid transparent; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(240,68,56,.25); }
.alert-success { background: var(--success-bg); color: var(--success); border-color: rgba(23,178,106,.25); }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border-color); }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.table thead th {
  position: sticky; top: 0;
  text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 600;
  background: var(--bg-surface-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}
table.table tbody td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border-color); color: var(--text-primary); }
table.table tbody tr { background: var(--bg-surface); transition: background var(--dur-fast) var(--ease); }
table.table tbody tr:hover { background: var(--bg-hover); }
table.table tbody tr:last-child td { border-bottom: none; }

.table-empty { text-align: center; padding: var(--sp-10); color: var(--text-muted); }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4); font-size: var(--fs-sm); color: var(--text-muted); }
.pagination .pages { display: flex; gap: var(--sp-2); }
.pagination a, .pagination span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-color); color: var(--text-secondary);
}
.pagination a:hover { background: var(--bg-hover); }
.pagination .active { background: var(--accent); color: #fff; border-color: transparent; }

/* ---------------- Forms ---------------- */
.form-group { margin-bottom: var(--sp-4); }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-4); }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.field-floating { position: relative; }
.field-floating input, .field-floating select, .field-floating textarea {
  width: 100%;
  padding: 20px 14px 8px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  transition: border-color var(--dur-fast) var(--ease);
}
.field-floating textarea { padding-top: 24px; min-height: 92px; resize: vertical; }
.field-floating input:focus, .field-floating select:focus, .field-floating textarea:focus {
  outline: none; border-color: var(--accent);
}
.field-floating label {
  position: absolute; left: 14px; top: 14px;
  font-size: var(--fs-sm); color: var(--text-muted);
  transition: all var(--dur-fast) var(--ease);
  pointer-events: none;
}
.field-floating input:focus + label,
.field-floating input:not(:placeholder-shown) + label,
.field-floating select + label,
.field-floating textarea:focus + label,
.field-floating textarea:not(:placeholder-shown) + label {
  top: 6px; font-size: var(--fs-xs); color: var(--accent-strong);
}
.field-error { color: var(--danger); font-size: var(--fs-xs); margin-top: 4px; }

.input-icon-group { position: relative; }
.input-icon-group svg { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 11, 24, .6);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4); z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-base) var(--ease);
}
.modal-backdrop.is-open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 640px;
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-3);
  transform: translateY(12px) scale(.98);
  transition: transform var(--dur-base) var(--ease);
}
.modal-backdrop.is-open .modal { transform: translateY(0) scale(1); }
.modal.modal-lg { max-width: 860px; }

.modal-header { padding: var(--sp-5); border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: var(--fs-md); }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: var(--sp-3); }

/* ---------------- Producto: foto + precios por almacen ---------------- */
.producto-form-layout { display: grid; grid-template-columns: 160px 1fr; gap: var(--sp-5); }
@media (max-width: 640px) { .producto-form-layout { grid-template-columns: 1fr; } }

.foto-picker { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); }
.foto-picker .foto-preview {
  width: 140px; height: 140px; border-radius: var(--radius-lg);
  background: var(--bg-surface-2); border: 1px dashed var(--border-color-strong);
  object-fit: cover; display: block;
}
.foto-picker label.btn { width: 100%; text-align: center; cursor: pointer; }
.foto-picker input[type="file"] { display: none; }

.producto-thumb {
  width: 76px; height: 76px; border-radius: var(--radius-md);
  object-fit: cover; background: var(--bg-surface-2); border: 1px solid var(--border-color); flex: none;
}
.producto-thumb-placeholder {
  width: 76px; height: 76px; border-radius: var(--radius-md);
  background: var(--bg-surface-2); border: 1px solid var(--border-color);
  display: grid; place-items: center; color: var(--text-muted); flex: none; font-size: 1.4rem;
}

.almacenes-precio-table { width: 100%; border-collapse: collapse; margin-top: var(--sp-2); }
.almacenes-precio-table th {
  text-align: left; font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600;
  padding: 6px 8px; border-bottom: 1px solid var(--border-color);
}
.almacenes-precio-table td { padding: 6px 8px; border-bottom: 1px solid var(--border-color); }
.almacenes-precio-table input { width: 100%; padding: 7px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-color); background: var(--bg-surface-2); color: var(--text-primary); font-size: var(--fs-sm); }

.almacenes-precio-badges { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.almacenes-precio-badges .fila { font-size: var(--fs-xs); color: var(--text-secondary); display: flex; gap: 6px; }
.almacenes-precio-badges .fila strong { color: var(--text-primary); }

.check-toggle { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); cursor: pointer; margin-bottom: var(--sp-3); }
.check-toggle input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------------- Toasts ---------------- */
.toast-stack { position: fixed; top: var(--sp-5); right: var(--sp-5); z-index: 200; display: flex; flex-direction: column; gap: var(--sp-3); }
.toast {
  min-width: 280px; max-width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  padding: var(--sp-3) var(--sp-4);
  display: flex; gap: var(--sp-3); align-items: flex-start;
  animation: toast-in var(--dur-base) var(--ease);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast strong { display: block; font-size: var(--fs-sm); }
.toast p { font-size: var(--fs-xs); color: var(--text-secondary); margin-top: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

/* ---------------- Skeleton ---------------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-surface-2) 25%, var(--bg-hover) 37%, var(--bg-surface-2) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------------- Utilities ---------------- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.fw-600 { font-weight: 600; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.mt-3 { margin-top: var(--sp-3); }
.mb-0 { margin-bottom: 0; }
.w-100 { width: 100%; }
