/* =====================================================================
   Mercantil Villacarriedo — Panel administrativo
   Paleta tomada del logo: guinda #9C212E · negro #231F20 · blanco
   ===================================================================== */
:root {
  --mv-guinda: #9C212E;
  --mv-guinda-2: #A22E3A;
  --mv-guinda-osc: #7d1a25;
  --mv-negro: #231F20;
  --mv-gris: #C8C7C7;
  --mv-rosa: #F9F1F2;
  --mv-crema: #faf8f6;
  --topbar-h: 58px;
  --sidebar-w: 248px;

  --bs-primary: var(--mv-guinda);
  --bs-primary-rgb: 156, 33, 46;
  --bs-link-color: var(--mv-guinda);
  --bs-link-color-rgb: 156, 33, 46;
  --bs-link-hover-color: var(--mv-guinda-osc);
  --bs-body-color: var(--mv-negro);
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bs-border-radius: .5rem;
}

body.app { background: var(--mv-crema); min-height: 100vh; }
.font-serif, h1, h2, .h1, .h2 { font-family: "Playfair Display", Georgia, serif; }
h1, .h1 { font-size: 1.6rem; }

/* Botones con el color de marca */
.btn-primary {
  --bs-btn-bg: var(--mv-guinda); --bs-btn-border-color: var(--mv-guinda);
  --bs-btn-hover-bg: var(--mv-guinda-osc); --bs-btn-hover-border-color: var(--mv-guinda-osc);
  --bs-btn-active-bg: var(--mv-guinda-osc); --bs-btn-active-border-color: var(--mv-guinda-osc);
  --bs-btn-disabled-bg: var(--mv-guinda-2); --bs-btn-disabled-border-color: var(--mv-guinda-2);
}
.btn-outline-primary {
  --bs-btn-color: var(--mv-guinda); --bs-btn-border-color: var(--mv-guinda);
  --bs-btn-hover-bg: var(--mv-guinda); --bs-btn-hover-border-color: var(--mv-guinda);
  --bs-btn-active-bg: var(--mv-guinda-osc); --bs-btn-active-border-color: var(--mv-guinda-osc);
}
.text-primary { color: var(--mv-guinda) !important; }
.bg-primary { background-color: var(--mv-guinda) !important; }
.form-control:focus, .form-select:focus {
  border-color: var(--mv-guinda-2);
  box-shadow: 0 0 0 .2rem rgba(156, 33, 46, .18);
}
.form-check-input:checked { background-color: var(--mv-guinda); border-color: var(--mv-guinda); }
.page-link { color: var(--mv-guinda); }
.active > .page-link, .page-link.active { background-color: var(--mv-guinda); border-color: var(--mv-guinda); }
.nav-pills .nav-link.active { background: var(--mv-guinda); }

/* ---------------- Barra superior ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 1030;
  height: var(--topbar-h);
  display: flex; align-items: center;
  padding: 0 .75rem;
  background: var(--mv-guinda);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.topbar .brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; }
.topbar .brand img { width: 40px; height: 40px; border-radius: 50%; background: #fff; padding: 2px; }
.topbar .brand span { font-family: "Playfair Display", Georgia, serif; font-size: 1.15rem; letter-spacing: .02em; white-space: nowrap; }
@media (max-width: 380px) { .topbar .brand span { font-size: .95rem; } }

/* ---------------- Estructura ---------------- */
.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.content { flex: 1; min-width: 0; padding: 1.25rem; }
@media (max-width: 575.98px) { .content { padding: .85rem .65rem; } }

.sidebar { background: #fff; border-right: 1px solid #eee; }
@media (min-width: 992px) {
  .sidebar {
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    position: sticky; top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  }
}
.sidebar .offcanvas-body { padding: .75rem .5rem 2rem; display: flex; }
.sidebar .nav-group {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: #999; margin: 1rem .75rem .35rem;
}
.sidebar .nav-link {
  display: flex; align-items: center; gap: .65rem;
  color: var(--mv-negro); border-radius: .45rem;
  padding: .5rem .75rem; font-size: .93rem;
}
.sidebar .nav-link i { font-size: 1.05rem; color: #8a8586; }
.sidebar .nav-link:hover { background: var(--mv-rosa); }
.sidebar .nav-link.active { background: var(--mv-guinda); color: #fff; }
.sidebar .nav-link.active i { color: #fff; }

/* ---------------- Encabezado de página ---------------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .acciones { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem; }
@media (max-width: 575.98px) {
  .page-head .acciones { margin-left: 0; width: 100%; }
  .page-head .acciones > * { flex: 1 1 auto; }
}

/* ---------------- Tarjetas ---------------- */
.card { border: 0; box-shadow: 0 1px 3px rgba(35,31,32,.08); }
.card-header { background: #fff; font-weight: 600; }
.kpi { border-left: 4px solid var(--mv-guinda); }
.kpi .kpi-label { font-size: .8rem; color: #777; text-transform: uppercase; letter-spacing: .05em; }
.kpi .kpi-valor { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi.kpi-ok { border-left-color: #198754; }
.kpi.kpi-alerta { border-left-color: #e0a800; }
.kpi.kpi-gris { border-left-color: var(--mv-negro); }

.filtros { background: #fff; border-radius: .5rem; padding: .75rem; margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(35,31,32,.06); }

/* ---------------- Tablas ---------------- */
.table { --bs-table-hover-bg: var(--mv-rosa); }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: #666; background: #fbfafa; white-space: nowrap; }
.table td { vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fila-falt td { color: #999; text-decoration: line-through; }
.fila-falt td.no-tachar { text-decoration: none; }

/* Tablas que se vuelven tarjetas en teléfono */
@media (max-width: 767.98px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr {
    background: #fff; border: 1px solid #eee; border-radius: .5rem;
    margin-bottom: .6rem; padding: .35rem .6rem;
  }
  .table-stack td {
    display: flex; justify-content: space-between; gap: 1rem;
    border: 0; padding: .3rem 0; text-align: right;
  }
  .table-stack td::before {
    content: attr(data-label); font-weight: 600; color: #777;
    font-size: .8rem; text-align: left; flex: 0 0 40%;
  }
  .table-stack td[data-label=""]::before, .table-stack td:not([data-label])::before { display: none; }
  .table-stack td { align-items: center; }
  .table-stack td:not([data-label]) { justify-content: center; text-align: center; }
  .table-stack td[data-label=""]:empty { display: none; }
  .table-stack tfoot td[colspan] { display: none; }
  .table-stack tfoot tr { margin-bottom: .35rem; }
  .table-stack td.td-acciones { justify-content: flex-end; }
  .table-stack tfoot { display: block; }
  .table-stack tfoot tr { background: var(--mv-rosa); }
}

/* ---------------- Captura de venta / compra ---------------- */
.lineas .linea {
  background: #fff; border: 1px solid #eee; border-radius: .5rem;
  padding: .65rem; margin-bottom: .5rem; position: relative;
}
.lineas .linea.faltante { background: #f6f6f6; }
.lineas .linea.faltante .importe { text-decoration: line-through; color: #999; }
.lineas .linea label { font-size: .72rem; color: #777; margin-bottom: .1rem; text-transform: uppercase; letter-spacing: .03em; }
.lineas .linea .importe { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.lineas .linea .stock-info { font-size: .75rem; }
.totales-barra {
  position: sticky; bottom: 0; z-index: 10;
  background: var(--mv-negro); color: #fff;
  border-radius: .5rem; padding: .75rem 1rem;
  display: flex; flex-wrap: wrap; gap: .75rem 1.5rem; align-items: center;
}
.totales-barra .total { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Buscador con lista */
.buscador { position: relative; }
.buscador .resultados {
  position: absolute; z-index: 50; left: 0; right: 0; top: 100%;
  max-height: 260px; overflow-y: auto;
  background: #fff; border: 1px solid #ddd; border-radius: 0 0 .5rem .5rem;
  box-shadow: 0 6px 14px rgba(0,0,0,.1); display: none;
}
.buscador .resultados.show { display: block; }
.buscador .resultados button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: .45rem .75rem; font-size: .9rem;
}
.buscador .resultados button:hover, .buscador .resultados button.activo { background: var(--mv-rosa); }

/* ---------------- Login ---------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--mv-guinda) 0%, var(--mv-guinda-osc) 55%, var(--mv-negro) 100%);
  padding: 1rem;
}
.login-card { width: 100%; max-width: 380px; border-radius: 1rem; }
.login-card .logo { width: 120px; display: block; margin: 0 auto 1rem; }

/* ---------------- Recibo (nota de venta) ---------------- */
.recibo {
  background: #fff; max-width: 900px; margin: 0 auto;
  padding: 1.5rem; border: 1px solid #ddd; border-radius: .5rem;
  font-size: .92rem;
}
.recibo .rec-head { display: flex; gap: 1rem; align-items: flex-start; border-bottom: 2px solid var(--mv-guinda); padding-bottom: .75rem; }
.recibo .rec-head img { width: 86px; }
.recibo .rec-emp h2 { color: var(--mv-guinda); font-size: 1.35rem; margin: 0; }
.recibo .rec-folio { margin-left: auto; text-align: right; }
.recibo .rec-folio .no { font-size: 1.6rem; font-weight: 700; color: var(--mv-guinda); font-variant-numeric: tabular-nums; }
.recibo .rec-datos { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem 1.5rem; margin: .9rem 0; }
.recibo .rec-datos b { color: #555; font-weight: 600; margin-right: .35rem; }
.recibo table th { background: var(--mv-guinda) !important; color: #fff !important; }
.recibo .pagare { font-size: .72rem; color: #555; border: 1px solid #ccc; padding: .6rem; margin-top: 1rem; }
.recibo .firma { margin-top: 2.5rem; display: flex; justify-content: flex-end; }
.recibo .firma div { border-top: 1px solid #333; width: 260px; text-align: center; font-size: .8rem; padding-top: .25rem; }
@media (max-width: 575.98px) {
  .recibo { padding: .9rem; font-size: .85rem; }
  .recibo .rec-head { flex-wrap: wrap; }
  .recibo .rec-head img { width: 60px; }
  .recibo .rec-folio { margin-left: 0; text-align: left; width: 100%; }
  .recibo .rec-datos { grid-template-columns: 1fr; }
}

/* ---------------- Impresión ---------------- */
@media print {
  body.app { background: #fff; }
  .content { padding: 0; }
  .recibo { border: 0; padding: 0; max-width: none; }
  .recibo table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table-stack thead { display: table-header-group !important; }
  .table-stack, .table-stack tbody, .table-stack tr { display: revert !important; }
  .table-stack td { display: table-cell !important; }
  .table-stack td::before { display: none !important; }
  a[href]::after { content: none !important; }
}

/* Bodega (la letra de la nota: P = Paco) */
.badge-bodega { background: #fff; color: var(--mv-guinda); border: 1px solid var(--mv-guinda); font-weight: 700; letter-spacing: .03em; }
.recibo .badge-bodega { font-size: .7rem; }

/* Perfil en la barra superior */
.rol-chip { background: rgba(255,255,255,.18); font-weight: 500; }

/* Barra inferior en teléfono (vendedor, almacén, cobranza) */
.barra-movil {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035;
  display: flex; background: #fff; border-top: 1px solid #e5e5e5;
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
  padding-bottom: env(safe-area-inset-bottom);
}
.barra-movil a {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: .45rem 0 .4rem; color: #777; text-decoration: none; font-size: .72rem;
}
.barra-movil a i { font-size: 1.35rem; line-height: 1.1; }
.barra-movil a.activo { color: var(--mv-guinda); font-weight: 600; }
@media (max-width: 991.98px) {
  body.con-barra .content { padding-bottom: 5rem; }
  body.con-barra .totales-barra { bottom: calc(58px + env(safe-area-inset-bottom)); }
}

/* Accesos grandes de las pantallas de inicio por perfil */
.acceso {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem;
  background: #fff; border-radius: .75rem; padding: 1.1rem .5rem; text-align: center;
  color: var(--mv-negro); text-decoration: none; box-shadow: 0 1px 3px rgba(35,31,32,.08);
  height: 100%; font-weight: 600; font-size: .92rem;
}
.acceso i { font-size: 1.9rem; color: var(--mv-guinda); }
.acceso:hover { background: var(--mv-rosa); color: var(--mv-negro); }
.acceso.principal { background: var(--mv-guinda); color: #fff; }
.acceso.principal i { color: #fff; }
.acceso.principal:hover { background: var(--mv-guinda-osc); color: #fff; }
.acceso .badge { font-size: .75rem; }

.totales-barra .btn-guardar { font-weight: 600; padding: .5rem 1.25rem; }
@media (max-width: 575.98px) {
  .totales-barra { flex-wrap: nowrap; padding: .5rem .75rem; gap: .75rem; }
  .totales-barra .total { font-size: 1.15rem; }
  .totales-barra .small { font-size: .7rem; }
}

.page-head h1 .badge { font-size: .5em; vertical-align: middle; font-family: "Inter", sans-serif; }

/* Hoja de surtido: renglones grandes para tocar */
.surtir .list-group-item { padding: .85rem 1rem; cursor: pointer; }
.surtir .form-check-input { width: 1.6em; height: 1.6em; margin: 0; }
.surtir .list-group-item:has(input:checked) { background: #e9f6ee; }

/* Campos numéricos de los renglones: sin flechas para que quepa el valor */
.lineas input[type=number] { padding-left: .45rem; padding-right: .45rem; -moz-appearance: textfield; appearance: textfield; }
.lineas input[type=number]::-webkit-outer-spin-button,
.lineas input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }