/* === Reset y base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════════════════
   APP LAYOUT — Sidebar + Main
   ═══════════════════════════════════════════════════════ */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

/* Sidebar header / logo */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  gap: 0.5rem;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sidebar-logo-icon {
  width: 28px;
  height: 28px;
  color: var(--color-primary);
}

/* Sidebar navigation */
.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
}

.nav-group {
  margin-bottom: 0.25rem;
}

.nav-group-label {
  display: block;
  padding: 0.75rem 1.25rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1.25rem;
  text-decoration: none;
  color: #94a3b8;
  border-radius: 0;
  transition: all 0.15s ease;
  position: relative;
  flex-wrap: wrap;
}

.sidebar-nav a .nav-hint {
  display: block;
  width: 100%;
  font-size: 0.7rem;
  color: #475569;
  margin-left: 2.25rem;
  margin-top: -0.2rem;
  line-height: 1.3;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,0.05);
  color: #e2e8f0;
}

.sidebar-nav a:hover .nav-hint {
  color: #64748b;
}

.sidebar-nav a.active {
  background: rgba(37, 99, 235, 0.15);
  color: #fff;
  border-right: 3px solid var(--color-primary);
}

.sidebar-nav a.active .nav-hint {
  color: rgba(147, 197, 253, 0.7);
}

.sidebar-nav a.active .nav-icon {
  color: var(--color-primary);
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-text {
  font-size: 0.875rem;
  font-weight: 500;
}

/* Sidebar footer / user */
.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 0.75rem;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem;
  border-radius: var(--radius);
  margin-bottom: 0.25rem;
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.7rem;
  color: #64748b;
  text-transform: capitalize;
}

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.5rem;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: #64748b;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
}

.sidebar-logout:hover {
  background: rgba(255,255,255,0.05);
  color: #f87171;
}

.sidebar-logout .nav-icon {
  width: 18px;
  height: 18px;
}

/* Sidebar collapse toggle button */
.sidebar-collapse-btn {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s;
}

.sidebar-collapse-btn:hover {
  background: rgba(255,255,255,0.07);
  color: #e2e8f0;
  border-color: rgba(255,255,255,0.2);
}

.sidebar-collapse-icon {
  width: 14px;
  height: 14px;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

/* ── Collapsed sidebar state ─────────────────────────── */
.sidebar--collapsed {
  width: var(--sidebar-collapsed-width);
}

.app-layout.sidebar--is-collapsed .app-main {
  margin-left: var(--sidebar-collapsed-width);
}

.sidebar--collapsed .sidebar-header {
  flex-direction: column;
  justify-content: center;
  padding: 1rem 0.5rem;
  gap: 0.65rem;
}

.sidebar--collapsed .sidebar-logo {
  justify-content: center;
}

.sidebar--collapsed .sidebar-logo-text {
  display: none;
}

.sidebar--collapsed .nav-group-label,
.sidebar--collapsed .nav-text,
.sidebar--collapsed .sidebar-nav a .nav-hint,
.sidebar--collapsed .sidebar-user-info,
.sidebar--collapsed .sidebar-logout-text {
  display: none;
}

.sidebar--collapsed .sidebar-nav a {
  justify-content: center;
  padding: 0.65rem 0;
  flex-wrap: nowrap;
  overflow: hidden;
}

.sidebar--collapsed .sidebar-user {
  justify-content: center;
}

.sidebar--collapsed .sidebar-footer {
  padding: 0.5rem;
}

.sidebar--collapsed .sidebar-logout {
  justify-content: center;
  padding: 0.5rem 0;
}

.sidebar--collapsed .sidebar-collapse-icon {
  transform: rotate(180deg);
}

/* Tooltip on collapsed nav items */
.sidebar--collapsed .sidebar-nav a {
  position: relative;
}

.sidebar--collapsed .sidebar-nav a::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 0.75rem);
  top: 50%;
  transform: translateY(-50%);
  background: #1e293b;
  color: #e2e8f0;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255,255,255,0.08);
  z-index: 200;
}

.sidebar--collapsed .sidebar-nav a:hover::after {
  opacity: 1;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  backdrop-filter: blur(2px);
}

/* ── Top bar (mobile only) ──────────────────────────── */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1rem;
  align-items: center;
  gap: 0.75rem;
  z-index: 50;
}

.topbar-menu {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  cursor: pointer;
  flex-shrink: 0;
}

.topbar-menu svg {
  width: 20px;
  height: 20px;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

/* ── Main content ───────────────────────────────────── */
.app-main {
  flex: 1;
  /* min-width: 0 — sin esto, el ancho mínimo intrínseco del contenido
     (filas con scroll horizontal, tablas) infla este flex item más allá
     del viewport en móvil; overflow-x:hidden del body solo lo recortaba. */
  min-width: 0;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content {
  flex: 1;
  padding: 1.75rem 2.5rem;
  width: 100%;
  min-width: 0;
}

/* ── Responsive: medium screens (show collapse button) ── */
@media (min-width: 768px) {
  .sidebar-collapse-btn {
    display: flex;
  }
}

/* ── Responsive: mobile (<768px) ────────────────────── */
@media (max-width: 767px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }

  .sidebar.sidebar--open {
    transform: translateX(0);
    box-shadow: 4px 0 25px rgba(0,0,0,0.3);
  }

  .sidebar-overlay.sidebar-overlay--visible {
    display: block;
  }

  .topbar {
    display: flex;
  }

  .app-main {
    margin-left: 0 !important;
  }

  .main-content {
    padding: 1rem 1.25rem;
  }
}

/* ═══════════════════════════════════════════════════════
   AUTH LAYOUT (no sidebar)
   ═══════════════════════════════════════════════════════ */

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ═══════════════════════════════════════════════════════
   FLASH MESSAGES
   ═══════════════════════════════════════════════════════ */

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.flash-notice { background: #ecfdf5; color: var(--color-success); border: 1px solid #bbf7d0; }
.flash-alert { background: #fef2f2; color: var(--color-danger); border: 1px solid #fecaca; }

/* ═══════════════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════════════ */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.875rem;
}

th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfe; }

/* ── Scrollable table wrapper ───────────────────────── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.table-scroll table {
  border-radius: 0;
  box-shadow: none;
}

/* ── Compact table variant ──────────────────────────── */
.table-compact th,
.table-compact td {
  padding: 0.5rem 0.75rem;
}

.table-compact th {
  position: sticky;
  top: 0;
  z-index: 1;
}

/* ── Column types ───────────────────────────────────── */
.col-product {
  min-width: 200px;
}

.col-category {
  white-space: nowrap;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-number {
  white-space: nowrap;
  text-align: right !important;
  min-width: 70px;
}

.col-center {
  text-align: center !important;
  white-space: nowrap;
}

.col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right !important;
}

/* ── Mobile: products list table → cards ──────────────────
   IMPORTANT: scoped to .products-main to avoid breaking other
   table-compact uses (e.g. WooCommerce table in product show)
   ────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .products-main .table-scroll {
    overflow-x: unset;
    border-radius: 0;
    box-shadow: none;
    background: none;
  }

  .products-main .table-compact,
  .products-main .table-compact tbody {
    display: block;
  }

  .products-main .table-compact thead {
    display: none;
  }

  /* Each row → card with flex-wrap for 2-col meta grid */
  .products-main .table-compact tr {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 4px rgba(0,0,0,0.07), 0 2px 8px rgba(0,0,0,0.05);
    border: 1px solid var(--color-border);
    margin-bottom: 0.75rem;
    padding: 0.875rem 1rem 0;
    position: relative;
    transition: box-shadow 0.15s, transform 0.15s;
  }

  .products-main .table-compact tr:active {
    transform: scale(0.99);
  }

  /* Reset all td defaults */
  .products-main .table-compact td {
    display: flex;
    border: none !important;
    background: none !important;
    text-align: left !important;
    white-space: normal;
    max-width: none;
    overflow: visible;
    padding: 0;
  }

  /* ── Product header: full width ─────── */
  .products-main .table-compact td.col-product {
    flex: 0 0 100%;
    display: block;
    padding: 0 5rem 0.75rem 0;
    margin-bottom: 0;
    border-bottom: 1px solid var(--color-border) !important;
  }

  .products-main .product-cell-name {
    font-size: 0.925rem !important;
    font-weight: 600 !important;
  }

  /* ── Status: absolute top-right ──────── */
  .products-main .table-compact td.col-status {
    position: absolute;
    top: 0.875rem;
    right: 1rem;
    flex: 0 0 auto;
    padding: 0;
    display: flex;
    align-items: flex-start;
  }

  /* ── Meta grid: 2 columns ────────────── */
  .products-main .table-compact td.col-category,
  .products-main .table-compact td.col-number:not(.col-price) {
    flex: 0 0 50%;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 0.15rem;
    padding: 0.6rem 0.5rem 0.6rem 0;
    border-bottom: 1px solid var(--color-border) !important;
    border-right: 1px solid var(--color-border) !important;
  }

  .products-main .table-compact td.col-price,
  .products-main .table-compact td.col-suppliers {
    flex: 0 0 50%;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-start;
    gap: 0.15rem;
    padding: 0.6rem 0 0.6rem 0.5rem;
    border-bottom: 1px solid var(--color-border) !important;
    text-align: right;
  }

  /* Label above value */
  .products-main .table-compact td[data-label]::before {
    content: attr(data-label);
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    display: block;
    flex-shrink: 0;
    line-height: 1;
    margin-bottom: 0.2rem;
  }

  /* ── Actions row: full width, bottom ──── */
  .products-main .table-compact td.col-actions {
    flex: 0 0 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0.5rem 0 0.625rem;
  }

  .products-main .table-compact td.col-actions::before {
    display: none;
  }

  /* Larger touch targets */
  .row-action {
    width: 38px;
    height: 38px;
  }

  .row-action svg {
    width: 18px;
    height: 18px;
  }

  .col-category {
    max-width: none;
    white-space: normal;
  }
}

/* ── Product cell (combined SKU + Name + Brand) ─────── */
.product-cell {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.product-cell-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-cell-name:hover {
  color: var(--color-primary);
}

.product-cell-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.product-sku {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

.product-brand {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

/* ── Category label ─────────────────────────────────── */
.category-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* ═══════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════ */

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  color: var(--color-text);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.55rem 0.85rem;
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea { min-height: 100px; resize: vertical; }

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-check input[type="checkbox"] { width: auto; }

.form-errors {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  color: var(--color-danger);
  font-size: 0.875rem;
}

.form-errors ul { margin-left: 1rem; }

/* ═══════════════════════════════════════════════════════
   UTILITY
   ═══════════════════════════════════════════════════════ */

.text-muted { color: var(--color-text-muted); font-size: 0.85rem; }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }

.filter-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-label-icon {
  width: 16px;
  height: 16px;
  opacity: 0.6;
}

.filter-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  transition: all 0.2s ease;
}

.filter-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-input::placeholder { color: var(--color-text-muted); }

/* ═══════════════════════════════════════════════════════
   IMPORT PROGRESS PANEL
   ═══════════════════════════════════════════════════════ */

.import-panel {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  z-index: 1000;
  transform: translateY(calc(100% + 2rem));
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

.import-panel--visible { transform: translateY(0); }

.import-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.85rem;
  background: var(--color-primary);
  color: #fff;
  gap: 0.5rem;
}

.import-panel__header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.import-panel__title {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.import-panel__close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}

.import-panel__close:hover { color: #fff; }

.import-panel__body { padding: 0.9rem 1rem; }

/* ── Fila de estado ─────────────────────────────────── */
.import-panel__status-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.import-panel__status-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text);
}

/* ── Chips de progreso ──────────────────────────────── */
.import-panel__progress {
  margin-top: 0.55rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.3rem;
  padding: 0.45rem 0.6rem;
  background: var(--color-bg);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  word-break: break-word;
}

.import-panel__chip {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  white-space: normal;
}

.import-panel__chip--time {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
  font-size: 0.72rem;
  flex-shrink: 0;
}

.import-panel__chip--count {
  color: var(--color-text);
  font-weight: 600;
}

.import-panel__chip--label {
  color: var(--color-text-muted);
}

.import-panel__sep {
  color: var(--color-border);
  flex-shrink: 0;
  font-size: 0.65rem;
  line-height: 1.8;
}

/* ── Stats (completado) ─────────────────────────────── */
.import-panel__stats {
  margin-top: 0.7rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.import-panel__stat-row { display: flex; justify-content: space-between; align-items: center; }
.import-panel__stat-row strong { color: var(--color-text); font-size: 0.85rem; }
.import-panel__error { color: var(--color-danger); font-size: 0.8rem; line-height: 1.4; }
.import-panel__actions { margin-top: 0.75rem; }

.import-spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: import-spin 0.75s linear infinite;
  flex-shrink: 0;
}

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

/* ═══════════════════════════════════════════════════════
   MOBILE — Product show & SupplierProduct show
   ═══════════════════════════════════════════════════════ */

/* ── Very small screens: tighter content padding ────────── */
@media (max-width: 480px) {
  .main-content {
    padding: 0.875rem 0.875rem;
  }
}
