/* =========================================================
   BYOFERTA INVENTARIO — Estilos globales
   Modo claro / oscuro con transición suave
   ========================================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── MODO CLARO (por defecto) ── */
:root {
  --bg:          #f5f5f3;
  --surface:     #ffffff;
  --surface2:    #fafaf8;
  --border:      #e4e4df;
  --text:        #181816;
  --text2:       #444440;
  --muted:       #888780;

  --green-bg:    #eaf3de; --green-txt:  #2a5a0c;
  --yellow-bg:   #fef3dc; --yellow-txt: #7a4700;
  --red-bg:      #fce8e8; --red-txt:    #8b1f1f;
  --blue-bg:     #e4f0fb; --blue-txt:   #0c447c;
  --gray-bg:     #f0ede6; --gray-txt:   #4a4a46;
  --orange-bg:   #fff0e6;

  --primary:        #1A56A4;
  --primary-light:  #e4f0fb;
  --primary-hover:  #FF6B2C;

  --sidebar-w:   220px;
  --topbar-h:    52px;
  --radius:      8px;
  --radius-lg:   12px;
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.06);
  --shadow-md:   0 4px 16px rgba(0,0,0,0.10);
}

/* ── MODO OSCURO ── */
html.dark {
  --bg:          #111110;
  --surface:     #1c1c1a;
  --surface2:    #242422;
  --border:      #2e2e2a;
  --text:        #e8e8e4;
  --text2:       #b0b0aa;
  --muted:       #636360;

  --green-bg:    #162608; --green-txt:  #82cc52;
  --yellow-bg:   #261a04; --yellow-txt: #f5b840;
  --red-bg:      #260808; --red-txt:    #f07070;
  --blue-bg:     #0a1a2e; --blue-txt:   #60b0f0;
  --gray-bg:     #1e1e1c; --gray-txt:   #a0a09a;
  --orange-bg:   #261006;

  --primary:        #4a8ed8;
  --primary-light:  #0a1a2e;
  --primary-hover:  #ff7a3a;

  --shadow-sm:   0 1px 4px rgba(0,0,0,0.35);
  --shadow-md:   0 4px 20px rgba(0,0,0,0.50);
}

/* ── BASE ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

/* =========================================================
   LOGIN
   ========================================================= */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background: var(--bg);
  transition: background 0.25s;
}

.login-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 340px;
  max-width: 100%;
  box-shadow: var(--shadow-md);
  transition: background 0.25s, border-color 0.25s;
}

/* Logo en login: contenedor con aspect ratio fijo */
.login-logo-wrap {
  width: 100%;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.login-logo-wrap img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.login-subtitle {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  margin-bottom: 1.5rem;
}

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%;
  padding: 9px 12px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, background 0.25s, color 0.25s;
}
.field input:focus { border-color: var(--primary); }

.btn-login {
  width: 100%;
  padding: 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 0.25rem;
  transition: background 0.15s;
}
.btn-login:hover { background: var(--primary-hover); }
.login-err { color: var(--red-txt); font-size: 13px; margin-top: 8px; display: none; }

/* =========================================================
   APP SHELL
   ========================================================= */
#app { display: none; min-height: 100vh; }

/* ── TOPBAR ── */
.topbar {
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  transition: background 0.25s, border-color 0.25s;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.menu-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}

/* Logo en topbar */
.topbar-logo-wrap {
  height: 40px;
  display: flex;
  align-items: center;
  overflow: hidden;
}
.topbar-logo-wrap img {
  height: 40px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  display: block;
}

.topbar-right { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
#topbar-user { font-size: 13px; color: var(--text2); font-weight: 500; }

/* Botón tema */
.btn-theme {
  background: var(--surface2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s, border-color 0.25s;
  color: var(--text);
}
.btn-theme:hover { background: var(--bg); }

.btn-exit {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-exit:hover { background: var(--primary-hover); }

/* ── SIDEBAR ── */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 0.5px solid var(--border);
  z-index: 90;
  transition: transform 0.2s, background 0.25s, border-color 0.25s;
  overflow-y: auto;
}
.sidebar.hidden { transform: translateX(-100%); }

.sidebar-section { padding: 1rem 0 0.5rem; border-bottom: 0.5px solid var(--border); }
.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 0 1rem 0.5rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 1rem;
  cursor: pointer;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
}
.nav-icon { font-size: 15px; width: 20px; text-align: center; }

/* ── CONTENT ── */
.content {
  margin-top: var(--topbar-h);
  margin-left: var(--sidebar-w);
  padding: 1.25rem;
  min-height: calc(100vh - var(--topbar-h));
  transition: margin-left 0.2s;
  background: var(--bg);
}
.content.full { margin-left: 0; }
.page { display: none; }
.page.active { display: block; }
.page-title { font-size: 18px; font-weight: 600; margin-bottom: 1.25rem; color: var(--text); }

/* ── MÉTRICAS ── */
.metrics { margin-bottom: 1.25rem; }
.metrics-row1 { display: grid; grid-template-columns: repeat(6,1fr); gap: 10px; margin-bottom: 8px; }
.metrics-row2 { display: grid; grid-template-columns: repeat(6,1fr); gap: 10px; }
.metrics-row2 .mc:nth-child(1) { grid-column: 3; }
.metrics-row2 .mc:nth-child(2) { grid-column: 4; }
.metrics-row2 .mc:nth-child(3) { grid-column: 5; }
.metrics-row2 .mc:nth-child(4) { grid-column: 6; }

.mc {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.25s;
}
.mc:hover { border-color: var(--primary); }
.mc.active-filter { border-color: var(--primary); background: var(--primary-light); }
.mc-label { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.mc-val { font-size: 22px; font-weight: 600; }
.mc-val.g { color: var(--green-txt); }
.mc-val.y { color: var(--yellow-txt); }
.mc-val.r { color: var(--red-txt); }
.mc-val.b { color: var(--blue-txt); }
.mc-val.o { color: var(--primary-hover); }

/* ── CONTROLES / FILTROS ── */
.controls { display: flex; flex-direction: column; gap: 8px; margin-bottom: 1rem; }
.controls-row { display: flex; gap: 8px; align-items: center; width: 100%; }
.controls-row input,
.controls-row select {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, background 0.25s, color 0.25s;
}
.controls-row input:focus,
.controls-row select:focus { border-color: var(--primary); }

/* ── BOTONES ── */
.btn {
  font-size: 12px;
  padding: 7px 12px;
  border-radius: var(--radius);
  border: 0.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-success { background: #2a5a0c; color: #fff; border-color: #2a5a0c; }
.btn-success:hover { background: #3b7010; }
.btn-warn { background: #7a4700; color: #fff; border-color: #7a4700; }
.btn-warn:hover { background: #9c5c00; }
.btn-danger { color: var(--red-txt); border-color: var(--border); }
.btn-danger:hover { background: var(--red-bg); }

/* ── TABLA ── */
.tbl-wrap {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  transition: background 0.25s, border-color 0.25s;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 700px; }
th {
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 0.5px solid var(--border);
  background: var(--surface2);
  white-space: nowrap;
}
td {
  padding: 9px 12px;
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
  color: var(--text);
  transition: background 0.1s;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }
.sku { font-family: monospace; font-size: 11px; color: var(--muted); }
.prod-name { font-weight: 500; font-size: 13px; white-space: normal; color: var(--text); }
.prod-note { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: normal; }

/* ── BADGES ── */
.badge { display: inline-block; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 20px; white-space: nowrap; }
.b-green  { background: var(--green-bg);  color: var(--green-txt); }
.b-yellow { background: var(--yellow-bg); color: var(--yellow-txt); }
.b-red    { background: var(--red-bg);    color: var(--red-txt); }
.b-blue   { background: var(--blue-bg);   color: var(--blue-txt); }
.b-gray   { background: var(--gray-bg);   color: var(--gray-txt); }
.b-orange { background: var(--orange-bg); color: var(--primary-hover); }
.pill { font-size: 10px; padding: 1px 6px; border-radius: 20px; border: 0.5px solid var(--border); color: var(--muted); display: inline-block; }
.zona-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }

/* ── MISC ── */
.stock-warn { color: var(--yellow-txt); font-weight: 500; }
.empty { text-align: center; padding: 3rem; color: var(--muted); }

/* ── MODALES ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  width: 500px;
  max-width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  transition: background 0.25s, border-color 0.25s;
}
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 1.25rem; color: var(--text); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row { margin-bottom: 0.75rem; }
.form-row label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 7px 10px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, background 0.25s, color 0.25s;
}
.form-row input:focus,
.form-row select:focus { border-color: var(--primary); }
.form-row textarea { resize: vertical; min-height: 60px; }
.checkrow { display: flex; gap: 16px; margin-top: 4px; }
.checkrow label { display: flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; color: var(--text); }
.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 1rem 1.5rem;
  border-top: 0.5px solid var(--border);
  background: var(--surface2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  flex-shrink: 0;
}
.form-section {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 1rem 0 0.5rem;
  padding-top: 0.75rem;
  border-top: 0.5px solid var(--border);
}

/* ── OPERACIONES (scanner) ── */
.scan-box {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
  transition: background 0.25s, border-color 0.25s;
}
.scan-box h3 { font-size: 15px; font-weight: 600; margin-bottom: 1rem; color: var(--text); }
.scan-input-row { display: flex; gap: 8px; align-items: center; }
.scan-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  font-size: 15px;
  outline: none;
  background: var(--bg);
  color: var(--text);
  transition: background 0.25s, color 0.25s;
}
.scan-result {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 0.5px solid var(--border);
  display: none;
  background: var(--surface2);
}
.scan-result.show { display: block; }
.scan-product-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; color: var(--text); }
.scan-product-info { font-size: 12px; color: var(--muted); }
.qty-row { display: flex; align-items: center; gap: 10px; margin-top: 1rem; flex-wrap: wrap; }
.qty-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius);
  border: 0.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.qty-btn:hover { background: var(--bg); }
.qty-val { font-size: 20px; font-weight: 600; min-width: 40px; text-align: center; color: var(--text); }
.scan-log-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.log-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 13px;
}
.log-item:last-child { border-bottom: none; }
.log-sku { font-family: monospace; font-size: 11px; color: var(--muted); }
.log-qty-pos { color: var(--green-txt); font-weight: 600; }
.log-qty-neg { color: var(--red-txt); font-weight: 600; }

/* ── COSTOS ── */
.cost-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 10px; margin-bottom: 1rem; }
.cost-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  transition: background 0.25s, border-color 0.25s;
}
.cost-card-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.cost-card-val { font-size: 20px; font-weight: 600; color: var(--text); }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; }

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

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .content { margin-left: 0; }
  .metrics-row1 { grid-template-columns: repeat(2,1fr); }
  .metrics-row2 { grid-template-columns: repeat(3,1fr); }
  .metrics-row2 .mc:nth-child(1) { grid-column: 1; }
  .metrics-row2 .mc:nth-child(2) { grid-column: 2; }
  .metrics-row2 .mc:nth-child(3) { grid-column: 3; }
  .metrics-row2 .mc:nth-child(4) { grid-column: auto; }
  .controls-row { flex-direction: column; }
  .controls-row input,
  .controls-row select { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar-logo-wrap img { max-width: 140px; }
}

/* ── PAGE HEADER ── */
.page-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:1.25rem; }
.page-actions { display:flex; gap:8px; }

/* ── TABS ── */
.tabs-row { display:flex; gap:4px; margin-bottom:1rem; border-bottom:1px solid var(--border); padding-bottom:0; }
.tab-btn { background:none; border:none; padding:8px 16px; font-size:13px; font-weight:500; color:var(--muted); cursor:pointer; border-bottom:2px solid transparent; margin-bottom:-1px; }
.tab-btn:hover { color:var(--text); }
.tab-btn.active { color:var(--primary); border-bottom-color:var(--primary); }

/* ── CURVA ABC ── */
.curva-cards { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; }
.curva-card { background:var(--surface); border:0.5px solid var(--border); border-radius:var(--radius-lg); padding:1rem; }
.curva-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:.75rem; }
.curva-count { font-size:12px; color:var(--muted); }
.curva-item { display:flex; justify-content:space-between; align-items:center; padding:5px 0; border-bottom:0.5px solid var(--border); font-size:12px; }
.curva-item:last-child { border:none; }

/* ── DROP ZONE ── */
.drop-zone { border:2px dashed var(--border); border-radius:var(--radius-lg); padding:2.5rem; text-align:center; cursor:pointer; transition:border-color .15s; }
.drop-zone:hover { border-color:var(--primary); }
.drop-icon { font-size:2.5rem; margin-bottom:.5rem; }
.drop-sub { font-size:12px; color:var(--muted); margin-top:.25rem; }

/* ── ALERTAS DECISIONES ── */
.alerta-item { display:flex; align-items:center; gap:12px; padding:12px; background:var(--surface); border:0.5px solid var(--border); border-radius:var(--radius); margin-bottom:8px; }
.alerta-tipo { font-weight:500; font-size:13px; flex:1; text-transform:capitalize; }

/* ── SEARCH RESULT ── */
.search-result-item { padding:6px 10px; cursor:pointer; font-size:13px; background:var(--surface); border:0.5px solid var(--border); border-top:none; }
.search-result-item:hover { background:var(--bg); }

@media(max-width:768px){
  .curva-cards { grid-template-columns:1fr 1fr; }
  .page-header { flex-direction:column; align-items:flex-start; gap:8px; }
}
