:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1b1d23;
  --ink-soft: #6b7280;
  --border: #e5e7eb;
  --accent: #b8862f;
  --accent-ink: #1b1d23;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 18, 24, 0.06), 0 8px 24px rgba(16, 18, 24, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: #14161c;
  color: #fff;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

#btnMenuToggle.menu-toggle { display: none; margin-left: auto; }
.btn-icon { display: inline-flex; }
.btn-label { display: none; }

.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 15;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #e0b567);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #14161c;
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: 0.04em; }
.brand p { font-size: 11px; margin: 0; color: #9aa0ab; }

.linea-filter {
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid #2a2d36;
  background: #1e2027;
  color: #fff;
  font-size: 13px;
}

.user-info { display: flex; align-items: center; gap: 6px; margin-left: 4px; }
.user-info span { font-size: 12px; color: #c8ccd4; white-space: nowrap; }

.search-wrap { flex: 1; max-width: 480px; margin-left: auto; }
.search-wrap input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid #2a2d36;
  background: #1e2027;
  color: #fff;
  font-size: 14px;
}
.search-wrap input::placeholder { color: #6b7280; }
.search-wrap input:focus { outline: 2px solid var(--accent); }

.icon-btn {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  width: 36px; height: 36px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); }
.icon-btn.danger { color: var(--danger); }

.import-status {
  max-width: 1200px;
  margin: 16px auto 0;
  padding: 12px 16px;
  border-radius: 10px;
  background: #fff8ec;
  border: 1px solid #f0dcae;
  color: #6b5116;
  font-size: 13.5px;
}
.import-status.error { background: #fdecea; border-color: #f3c1ba; color: #8a2c22; }
.import-status.ok { background: #eafaf0; border-color: #b9e6c8; color: #1e6b3d; }

main { padding: 24px; max-width: 1200px; margin: 0 auto; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease;
  display: flex;
  flex-direction: column;
}
.card:hover { transform: translateY(-2px); }

.card-img {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #eef0f3;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.card-img .placeholder { color: #b7bcc4; font-size: 12px; }

.card.agotado .card-img img { filter: grayscale(0.6) brightness(0.85); }

/* Foto de catálogo: relación de aspecto 4:5 (vertical) de la plantilla
   usada para subirla (ver referencia 1007), distinta del cuadrado 1:1 que
   usa la foto interna de bodega. */
.card-img-catalogo { aspect-ratio: 4 / 5; }

.badge-agotado {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--danger, #d33);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  padding: 4px 8px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.texto-agotado { color: var(--danger, #d33); font-weight: 700; }

.pedido-resultado-item.agotado {
  opacity: 0.55;
  cursor: not-allowed;
}
.pedido-resultado-item.agotado:hover { background: transparent; }
.pedido-resultado-item.agotado span { color: var(--danger, #d33); font-weight: 600; }

.card-body { padding: 12px 14px; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-ref { font-weight: 700; font-size: 13px; letter-spacing: 0.02em; }
.card-price {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.card-name { color: var(--ink-soft); font-size: 12.5px; margin-top: 4px; line-height: 1.3; }
.card-costo { font-size: 11px; color: #9a6b1e; font-weight: 600; margin-top: 3px; }
.card-precios-disenadora {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}
.card-precios-disenadora strong { color: var(--ink); }

.fab {
  position: fixed;
  right: 28px; bottom: 28px;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(184, 134, 47, 0.45);
}
.fab:hover { filter: brightness(1.05); }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--ink-soft);
}
.empty-state p { margin-bottom: 16px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.btn-primary.small { padding: 7px 14px; font-size: 13px; }
.btn-primary:hover { filter: brightness(1.05); }

dialog.sheet {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(560px, 92vw);
  max-height: 88vh;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
dialog.sheet.small { width: min(420px, 92vw); }

/* ---------- Pantallas completas (Métricas / Historial de pedidos) ---------- */
.screen {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 24px 40px;
}
.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.screen-header h2 { font-size: 18px; margin: 0; flex: 1; }
.screen-body { padding-bottom: 20px; }
.dark-on-light {
  border: 1px solid var(--border) !important;
  background: var(--surface) !important;
  color: var(--ink) !important;
}

.contenedores-list { display: flex; flex-direction: column; gap: 10px; }
.contenedor-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.contenedor-card:hover { transform: translateY(-2px); }
.contenedor-nombre { font-weight: 700; font-size: 15px; }
.contenedor-meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; }

.contenedor-detalle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.contenedor-detalle-conteo { font-size: 13px; color: var(--ink-soft); font-weight: 600; }

.pedidos-list { display: flex; flex-direction: column; gap: 10px; }
.pedido-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  border: 2px solid transparent;
  transition: border-color 0.2s ease;
}
.pedido-card.despachado {
  border-color: #2a9d3f;
  box-shadow: 0 0 0 3px rgba(42, 157, 63, 0.12), var(--shadow);
}
.pedido-card.rechazado {
  border-color: #9ca3af;
  opacity: 0.75;
}
.pedido-card-rechazado {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #f3f4f6;
  color: #4b5563;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
.pedido-card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.pedido-card-cliente { font-weight: 700; font-size: 14px; }
.pedido-card-fecha { font-size: 12px; color: var(--ink-soft); }
.pedido-card-meta { font-size: 12px; color: var(--ink-soft); margin-bottom: 8px; }
.pedido-card-items { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.pedido-card-item { display: flex; justify-content: space-between; font-size: 12.5px; }
.pedido-card-item span:first-child { color: var(--ink-soft); }
.pedido-card-total { display: flex; justify-content: flex-end; font-weight: 700; color: var(--accent); font-size: 14px; }
.pedido-card-observaciones { font-size: 12px; color: var(--ink-soft); margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); white-space: pre-wrap; }
.pedido-card-numero { font-weight: 700; font-size: 13px; color: var(--ink-soft); margin-right: auto; }
.pedido-card-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn-despacho {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: #d33;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-despacho:hover { background: #b82a2a; }
.btn-despacho.despachado { background: #2a9d3f; }
.btn-despacho.despachado:hover { background: #23842f; }
.btn-despacho:disabled { opacity: 0.85; cursor: not-allowed; }

.btn-rechazar {
  border: 1.5px solid #d33;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #d33;
  background: #fff;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn-rechazar:hover { background: #fdecea; }
.btn-rechazar:disabled { opacity: 0.6; cursor: not-allowed; }

.paginacion {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 20px;
  font-size: 13px;
}
.paginacion button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
}
.paginacion button:disabled { opacity: 0.4; cursor: default; }
dialog.sheet::backdrop { background: rgba(15, 17, 22, 0.55); }

.sheet-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 1;
}
.sheet-header h2 { font-size: 16px; margin: 0; flex: 1; }
.sheet-actions { margin-left: auto; display: flex; gap: 4px; }

.sheet-body { padding: 18px 20px 28px; overflow-y: auto; max-height: calc(88vh - 56px); }

.detail-img {
  position: relative;
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: 10px;
  overflow: hidden;
  background: #eef0f3;
  margin-bottom: 16px;
  display: flex; align-items: center; justify-content: center;
}
.detail-img img { width: 100%; height: 100%; object-fit: cover; }

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.detail-row span:first-child { color: var(--ink-soft); font-size: 13px; }
.detail-row span:last-child { font-weight: 600; text-align: right; }
.detail-row.price span:last-child { color: var(--accent); }
.detail-row.price.highlight { background: #fff8ec; margin: 0 -20px; padding: 10px 20px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
  min-width: 0;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; grid-column: span 1; min-width: 0; }
.field span { color: var(--ink-soft); font-weight: 600; }
.field.wide, .image-field, .fieldset-dims, .field.readonly.wide, .fieldset-precios { grid-column: 1 / -1; }
.field input, .field select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  width: 100%;
  min-width: 0;
}
.field.readonly output {
  padding: 9px 10px;
  background: #f6f7f9;
  border-radius: 8px;
  font-weight: 600;
  display: block;
  width: 100%;
  min-width: 0;
}
.fieldset-dims { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin: 0; }
.fieldset-dims legend { color: var(--ink-soft); font-size: 12px; padding: 0 4px; }
.dims-row { display: flex; gap: 8px; min-width: 0; }
.dims-row input { flex: 1; min-width: 0; }

.fieldset-precios { border: none; padding: 0; margin: 4px 0 0; }
.fieldset-precios legend {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  padding: 0 0 8px;
  width: 100%;
}
.precios-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.precio-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
  background: #fff8ec;
  border: 1px solid #f0dcae;
  border-radius: 12px;
  padding: 14px 10px;
}
.precio-nombre { color: var(--accent); font-weight: 800; font-size: 14px; letter-spacing: 0.02em; }
.precio-detalle { color: var(--ink-soft); font-size: 11px; margin-top: -4px; }
.precio-input-wrap { position: relative; width: 100%; }
.precio-input-wrap input {
  width: 100%;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
  padding: 8px 24px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.precio-suffix {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 13px;
  pointer-events: none;
}

.image-preview {
  width: 120px; height: 120px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 6px;
}

/* Vista previa de la foto de catálogo: misma relación de aspecto 4:5 de la
   plantilla (ver referencia 1007), distinta del cuadrado que usa la foto
   interna de bodega. */
.image-preview-catalogo {
  width: 120px; height: 150px;
}

.calc-preview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 6px;
}
.calc-preview div {
  background: #f6f7f9;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
}
.calc-preview b { display: block; font-size: 14px; margin-top: 2px; }

/* ---------- Login ---------- */
.login-screen {
  position: fixed;
  inset: 0;
  background: #14161c;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: min(360px, 90vw);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.login-mark { margin: 0 auto; font-size: 20px; }
.login-card h1 { margin: 0; font-size: 20px; letter-spacing: 0.04em; }
.login-card p { margin: 0; color: var(--ink-soft); font-size: 13px; }
.login-card .field { text-align: left; }
.login-error { color: var(--danger); font-size: 13px; margin: 0; }

/* ---------- Pedido ---------- */
.pedido-items { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.pedido-item-row {
  display: grid;
  grid-template-columns: 1fr 90px 30px;
  gap: 8px;
  align-items: start;
}
.pedido-item-row select,
.pedido-item-row input {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  width: 100%;
}
.pedido-buscador-wrap { position: relative; }
.pedido-resultados {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  z-index: 5;
}
.pedido-resultado-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
}
.pedido-resultado-item:last-child { border-bottom: none; }
.pedido-resultado-item:hover { background: #f6f7f9; }
.pedido-resultado-item b { display: block; font-size: 13px; }
.pedido-resultado-item span { color: var(--ink-soft); }
.pedido-resultado-vacio { padding: 10px 12px; font-size: 12.5px; color: var(--ink-soft); }
.pedido-buscador.seleccionado { border-color: var(--accent); background: #fff8ec; }
.pedido-item-row .remove-item {
  border: none;
  background: transparent;
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
}
.pedido-item-hint { font-size: 11.5px; color: var(--ink-soft); grid-column: 1 / -1; margin-top: -4px; }
.btn-secondary {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
#pedidoObservaciones {
  width: 100%;
  min-height: 60px;
  resize: vertical;
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input, #fff);
}
.pedido-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  margin-top: 14px;
  font-size: 15px;
}
.pedido-total b { color: var(--accent); font-size: 18px; }

.stock-tag { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.stock-tag.low { color: var(--danger); font-weight: 600; }

/* ---------- Métricas ---------- */
.metricas-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.kpi-card {
  background: #f6f7f9;
  border-radius: 10px;
  padding: 14px 16px;
}
.kpi-card span { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.kpi-card b { font-size: 20px; color: var(--accent); }

.metricas-section { margin-bottom: 28px; }
.metricas-section h3 { font-size: 14px; margin: 0 0 12px; }

.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 90px; align-items: center; gap: 10px; font-size: 12px; }
.bar-track { background: #eef0f3; border-radius: 999px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.bar-row .bar-label { color: var(--ink-soft); }
.bar-row .bar-value { text-align: right; font-weight: 600; }

.ranking-list { display: flex; flex-direction: column; gap: 8px; }
.ranking-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #f6f7f9;
  border-radius: 8px;
  gap: 10px;
}
.ranking-item .ranking-name { font-weight: 600; font-size: 13px; }
.ranking-item .ranking-sub { font-size: 11.5px; color: var(--ink-soft); }
.ranking-item .ranking-metric { font-weight: 700; color: var(--accent); white-space: nowrap; }
.ranking-item.alert .ranking-metric { color: var(--danger); }
.metricas-empty { color: var(--ink-soft); font-size: 13px; padding: 12px 0; }

/* ---------- Responsive (celular / tablet) ---------- */
@media (max-width: 860px) {
  #btnMenuToggle.menu-toggle { display: flex; }

  .topbar { padding: 10px 14px; gap: 10px; }
  .brand p { display: none; }
  .brand h1 { font-size: 14px; }
  .brand-mark { width: 32px; height: 32px; font-size: 13px; }

  .topbar-actions {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 20;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    background: #14161c;
    padding: 14px 16px 22px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.35);
  }
  .topbar-actions.open { display: flex; }

  .topbar-actions .search-wrap { max-width: none; margin-left: 0; }
  .topbar-actions .linea-filter { width: 100%; }

  .topbar-actions .icon-btn {
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
    border-radius: 10px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.06);
    font-size: 15px;
  }
  .topbar-actions .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
  .topbar-actions .btn-label { display: inline; }

  .topbar-actions .user-info {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin: 6px 0 0;
    padding-top: 10px;
    border-top: 1px solid #2a2d36;
  }
  .topbar-actions .user-info span { white-space: normal; font-size: 13px; }

  main { padding: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

  .screen { padding: 0 14px 32px; }
  .screen-header { flex-wrap: wrap; gap: 8px; padding: 14px 0; }
  .screen-header h2 { flex-basis: 100%; order: -1; }

  dialog.sheet { width: 100vw; max-height: 100vh; height: 100%; border-radius: 0; }
  .sheet-body { max-height: calc(100vh - 56px); }

  .form-grid { grid-template-columns: 1fr; }
  .field.wide, .image-field, .fieldset-dims, .field.readonly.wide, .fieldset-precios { grid-column: 1 / -1; }

  .calc-preview { grid-template-columns: 1fr; }

  .bar-row { grid-template-columns: 62px 1fr 72px; gap: 6px; font-size: 11px; }

  .pedido-card-top { flex-wrap: wrap; }
  .pedido-card-numero { margin-right: 0; flex-basis: 100%; }

  .fab { right: 18px; bottom: 18px; width: 52px; height: 52px; font-size: 24px; }
}

@media (max-width: 420px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
  .pedido-item-row { grid-template-columns: 1fr 70px 26px; gap: 6px; }
  .precios-row { grid-template-columns: 1fr; }
}
