:root {
  --purple-700: #6d28d9;
  --purple-600: #7c3aed;
  --purple-100: #ede9fe;
  --purple-50: #f5f3ff;
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-200: #bbf7d0;
  --green-700: #15803d;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-900: #111827;
  --red-50: #fef2f2;
  --red-100: #fee2e2;
  --red-200: #fecaca;
  --red-700: #b91c1c;
  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --amber-200: #fde68a;
  --amber-700: #b45309;
  --radius: 0.75rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  -webkit-font-smoothing: antialiased;
}

/* ---------------- Topbar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 3.5rem;
  padding: 0 1.25rem;
  background: linear-gradient(90deg, var(--purple-700), var(--purple-600) 55%, #9333ea);
  color: white;
}

.topbar-left { display: flex; align-items: center; gap: 0.75rem; }

.logo {
  width: 2rem; height: 2rem;
  border-radius: 0.5rem;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem;
}

.topbar h1 { font-size: 1.02rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

.topbar-right { display: flex; align-items: center; gap: 0.75rem; font-size: 0.8rem; }

.sweep-indicator { color: rgba(255,255,255,0.85); font-size: 0.78rem; }

.icon-btn {
  background: none; border: none; color: white;
  font-size: 1.2rem; cursor: pointer; padding: 0.2rem;
}

.only-mobile { display: none; }

/* ---------------- Layout ---------------- */

.layout { display: flex; align-items: flex-start; }

.sidebar {
  position: sticky;
  top: 3.5rem;
  width: 14rem;
  flex-shrink: 0;
  height: calc(100vh - 3.5rem);
  background: white;
  border-right: 1px solid var(--gray-200);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.nav-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem; font-weight: 500;
  color: var(--gray-600); text-decoration: none;
  margin-bottom: 0.15rem;
}

.nav-item:hover { background: var(--gray-100); }
.nav-item.active { background: var(--purple-100); color: var(--purple-700); }
.nav-icon { font-size: 1rem; }

.sidebar-note { font-size: 0.72rem; color: var(--gray-400); padding: 0 0.75rem; margin: 0; }

.content {
  flex: 1;
  min-width: 0;
  max-width: 74rem;
  margin: 0 auto;
  padding: 1.5rem 2rem 4rem;
  display: flex; flex-direction: column; gap: 1.25rem;
}

.page-head { margin-bottom: 0.25rem; }
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.page-sub { color: var(--gray-500); font-size: 0.875rem; margin: 0.2rem 0 0; }

/* ---------------- Cards ---------------- */

.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.15rem 1.35rem;
}

.card h3 { font-size: 0.95rem; font-weight: 600; margin: 0 0 0.6rem; }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.card-header h3 { margin: 0; }
.card-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.help { font-size: 0.8rem; color: var(--gray-500); line-height: 1.5; margin: 0 0 0.75rem; }
.help code { background: var(--gray-100); padding: 0.05rem 0.3rem; border-radius: 0.25rem; }

/* ---------------- Stats ---------------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
}

.stat-card {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 1rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid;
}

.stat-icon { font-size: 1.35rem; }
.stat-label { font-size: 0.75rem; font-weight: 600; margin: 0; opacity: 0.85; }
.stat-value { font-size: 1.5rem; font-weight: 700; margin: 0.1rem 0 0; font-variant-numeric: tabular-nums; }

.stat-purple { background: var(--purple-50); border-color: #ddd6fe; color: var(--purple-700); }
.stat-green  { background: var(--green-50);  border-color: var(--green-200); color: var(--green-700); }
.stat-red    { background: var(--red-50);    border-color: var(--red-200);   color: var(--red-700); }
.stat-amber  { background: var(--amber-50);  border-color: var(--amber-200); color: var(--amber-700); }

/* ---------------- Sweep en vivo ---------------- */

.sweep-live { display: flex; align-items: center; gap: 1rem; }
.sweep-live-text { flex: 1; min-width: 0; }
.sweep-live-text p { margin: 0 0 0.4rem; font-size: 0.85rem; font-weight: 500; }

.spinner {
  width: 1.25rem; height: 1.25rem;
  border: 2px solid var(--purple-100);
  border-top-color: var(--purple-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

.progress { height: 0.4rem; background: var(--gray-100); border-radius: 999px; overflow: hidden; }
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--purple-600), #a855f7);
  transition: width 0.4s ease;
}

.muted-dark { color: var(--gray-500); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

/* ---------------- Banner de hallazgos ---------------- */

.found-banner {
  background: var(--green-50);
  border: 1px solid var(--green-200);
  color: var(--green-700);
  border-radius: var(--radius);
  padding: 0.9rem 1.15rem;
  font-size: 0.875rem;
}

.found-banner strong { font-weight: 700; }
.found-banner ul { margin: 0.5rem 0 0; padding-left: 1.1rem; }

.session-banner {
  background: var(--amber-50);
  border: 1px solid var(--amber-200);
  color: var(--amber-700);
  border-radius: var(--radius);
  padding: 0.9rem 1.15rem;
  font-size: 0.875rem;
}

.session-banner code {
  background: rgba(180, 83, 9, 0.1);
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
  font-size: 0.82rem;
}

/* ---------------- Tablas ---------------- */

.table-wrap { overflow-x: auto; }
.table-scroll { max-height: 22rem; overflow-y: auto; }
.table-scroll-lg { max-height: 34rem; overflow-y: auto; }

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

.table thead th {
  position: sticky; top: 0;
  background: white;
  text-align: left; font-weight: 500;
  color: var(--gray-400);
  border-bottom: 1px solid var(--gray-200);
  padding: 0.55rem 0.5rem;
  white-space: nowrap;
}

.table td {
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.table tbody tr:hover { background: var(--gray-50); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.empty { text-align: center; color: var(--gray-400); padding: 2rem 0; }

.cn { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 0.82rem; }
.prod-name { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- Badges ---------------- */

.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.7rem; font-weight: 600;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-neutral     { background: var(--gray-100);  color: var(--gray-600); }
.badge-available   { background: var(--green-100); color: var(--green-700); }
.badge-unavailable { background: var(--red-100);   color: var(--red-700); }
.badge-unknown     { background: var(--amber-100); color: var(--amber-700); }

/* ---------------- Formularios y botones ---------------- */

.input {
  border: 1px solid var(--gray-200);
  border-radius: 0.5rem;
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
  font-family: inherit;
  background: white;
  color: var(--gray-900);
}

.input:focus { outline: none; border-color: var(--purple-600); box-shadow: 0 0 0 3px var(--purple-100); }
.input-sm { font-size: 0.8rem; padding: 0.35rem 0.6rem; }

.btn {
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem 0.95rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary { background: var(--purple-600); color: white; }
.btn-primary:hover { background: var(--purple-700); }
.btn-primary:disabled { background: var(--gray-300); cursor: not-allowed; }

.btn-ghost { background: white; color: var(--gray-600); border: 1px solid var(--gray-200); }
.btn-ghost:hover { background: var(--gray-50); }

.btn-ghost-light {
  background: rgba(255,255,255,0.14); color: white;
  border: 1px solid rgba(255,255,255,0.3);
}
.btn-ghost-light:hover { background: rgba(255,255,255,0.24); }

.btn-danger-outline { background: white; color: var(--red-700); border: 1px solid var(--red-200); }
.btn-danger-outline:hover { background: var(--red-50); }

.btn-row-del {
  background: none; border: none; color: var(--gray-400);
  cursor: pointer; font-size: 0.95rem; padding: 0.2rem 0.4rem; border-radius: 0.35rem;
}
.btn-row-del:hover { color: var(--red-700); background: var(--red-50); }

.checkbox { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--gray-600); }

.add-one summary {
  cursor: pointer; font-size: 0.85rem; font-weight: 600; color: var(--gray-600);
}
.add-one[open] summary { margin-bottom: 0.75rem; }

.add-form { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.add-form #cn { width: 9rem; }
.add-form #name { flex: 1; min-width: 12rem; }
.add-form #targetQty { width: 6rem; }

/* ---------------- Importación ---------------- */

.drop-zone {
  position: relative;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 0.5rem;
  transition: border-color 0.15s, background 0.15s;
}

.drop-zone.dragover { border-color: var(--purple-600); background: var(--purple-50); }

.paste-area {
  width: 100%;
  min-height: 11rem;
  border: none;
  resize: vertical;
  padding: 0.6rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  background: transparent;
  color: var(--gray-900);
}

.paste-area:focus { outline: none; }

.drop-hint { text-align: center; font-size: 0.75rem; color: var(--gray-400); margin: 0 0 0.4rem; }

.import-actions { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.9rem; flex-wrap: wrap; }

.warn {
  background: var(--amber-50); border: 1px solid var(--amber-200); color: var(--amber-700);
  border-radius: 0.5rem; padding: 0.6rem 0.85rem; font-size: 0.8rem; margin-top: 0.75rem;
}

.result-ok {
  background: var(--green-50); border-color: var(--green-200); color: var(--green-700);
}

/* ---------------- Responsive ---------------- */

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 1.25rem 1rem 3rem; }
}

@media (max-width: 720px) {
  .only-mobile { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 3.5rem; bottom: 0;
    z-index: 45; height: auto;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar h1 { font-size: 0.92rem; }
}
