/* =====================================================================
   Anytime PDV — UI. Sidebar fijo + header, tarjetas, KPIs.
   Optimizado para PC (admin/supervisor) y responsive.
   El vendedor mantiene una columna estrecha tipo móvil.
   ===================================================================== */
:root {
  --primary: #2b5cff;
  --primary-d: #1e46d8;
  --azul: #2b5cff;
  --verde: #16b364;
  --verde-osc: #0e8a4a;
  --rojo: #f0436b;
  --rojo-osc: #d12e54;
  --naranja: #ff8a3d;
  --rosa: #f45b9c;
  --ambar: #f5a524;

  --bg: #f4f6fb;
  --card: #ffffff;
  --borde: #e7ecf3;
  --texto: #1f2b45;
  --texto-suave: #7a8699;
  --texto-tenue: #a3adbd;

  --radio: 14px;
  --radio-sm: 10px;
  --sombra: 0 2px 10px rgba(28, 50, 90, .06);
  --sombra-lg: 0 8px 28px rgba(28, 50, 90, .12);

  --sidebar-w: 260px;
  --header-h: 66px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--texto);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); }

/* =====================================================================
   Sidebar (fijo a la izquierda en escritorio; off-canvas en móvil)
   ===================================================================== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 45;
  width: var(--sidebar-w); background: #fff; border-right: 1px solid var(--borde);
  overflow-y: auto; transform: translateX(-100%); transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.sidebar-logo {
  display: flex; align-items: center; gap: .6rem;
  padding: 1.1rem 1.25rem; font-weight: 800; font-size: 1.15rem; color: var(--texto);
  text-decoration: none; letter-spacing: -.02em;
}
.sidebar-logo .logo-badge {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--primary), #6a8bff);
  color: #fff; display: grid; place-items: center; font-size: 1.05rem; box-shadow: var(--sombra);
}
.nav-group { padding: .35rem .75rem; }
.nav-group-title {
  padding: .7rem .6rem .35rem; font-size: .68rem; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; color: var(--texto-tenue);
}
.nav-link {
  display: flex; align-items: center; gap: .7rem; padding: .62rem .7rem; margin-bottom: 2px;
  border-radius: var(--radio-sm); color: var(--texto-suave); text-decoration: none;
  font-weight: 500; font-size: .92rem; transition: background .15s, color .15s;
}
.nav-link .icon { font-size: 1.1rem; width: 22px; text-align: center; flex: none; }
.nav-link .arrow { margin-left: auto; font-size: .8rem; color: var(--texto-tenue); }
.nav-link:hover { background: #f2f5fb; color: var(--texto); }
.nav-link.active { background: #eaf0ff; color: var(--primary); font-weight: 600; }
.nav-link.active .icon { color: var(--primary); }
.sidebar-foot { margin-top: auto; padding: 1rem 1.25rem; color: var(--texto-tenue); font-size: .75rem; }

/* =====================================================================
   Header superior (fijo, blanco)
   ===================================================================== */
.appheader {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); z-index: 35;
  background: #fff; border-bottom: 1px solid var(--borde);
  display: flex; align-items: center; gap: .8rem; padding: 0 1.1rem;
}
.menu-btn {
  background: transparent; border: 0; color: var(--texto); font-size: 1.5rem;
  cursor: pointer; padding: .1rem .3rem; line-height: 1;
}
.header-search {
  display: flex; align-items: center; gap: .5rem; background: var(--bg);
  border: 1px solid var(--borde); border-radius: 999px; padding: .5rem .95rem;
  color: var(--texto-suave); min-width: 180px; max-width: 340px; flex: 1 1 240px;
}
.header-search input { border: 0; background: transparent; outline: none; width: 100%; font-size: .9rem; color: var(--texto); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: .35rem; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--borde);
  background: #fff; color: var(--texto-suave); cursor: pointer; font-size: 1.1rem;
  display: grid; place-items: center; text-decoration: none; position: relative;
}
.icon-btn:hover { color: var(--primary); border-color: #cfd9ea; }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--rojo); border: 2px solid #fff; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--primary), #6a8bff); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: .95rem; text-decoration: none;
}
.header-user { display: flex; flex-direction: column; line-height: 1.1; margin-right: .2rem; }
.header-user .nombre { font-weight: 600; font-size: .85rem; color: var(--texto); }
.header-user .rol { font-size: .72rem; color: var(--texto-suave); }

.nav-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(20,30,50,.45);
  opacity: 0; pointer-events: none; transition: opacity .22s;
}
body.nav-open .sidebar { transform: translateX(0); }
body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

/* =====================================================================
   Contenido
   ===================================================================== */
.contenido { padding: calc(var(--header-h) + 1rem) 1rem 3rem; }
.pie { text-align: center; color: var(--texto-tenue); padding: 1rem 0 2rem; font-size: .8rem; }

h1 { font-size: 1.5rem; margin: .2rem 0 1rem; letter-spacing: -.02em; }
h2 { font-size: 1.08rem; margin: 1.3rem 0 .6rem; }
h3 { font-size: .98rem; margin: 1rem 0 .4rem; }

/* Encabezado de página */
.page-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; justify-content: space-between; margin-bottom: 1.3rem; }
.page-head .page-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.page-head .page-sub { color: var(--texto-suave); margin: .2rem 0 0; }
.page-metrics { display: flex; gap: 1.4rem; }
.page-metrics .m .n { font-size: 1.25rem; font-weight: 800; }
.page-metrics .m .l { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--texto-suave); }

/* Tarjetas */
.card {
  background: var(--card); border: 1px solid var(--borde);
  border-radius: var(--radio); padding: 1.15rem 1.2rem; margin-bottom: 1.1rem; box-shadow: var(--sombra);
}
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.card-title { font-size: .78rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--texto-suave); margin: 0 0 .9rem; }

/* KPIs simples (compat.) */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 1rem; }
.kpi { background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); padding: 1.1rem; box-shadow: var(--sombra); }
.kpi .valor { font-size: 1.9rem; font-weight: 800; color: var(--primary); }
.kpi .etiqueta { color: var(--texto-suave); font-size: .85rem; }

/* KPIs con degradado (dashboard) */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 1.1rem; margin-bottom: 1.1rem; }
.kpi-card { position: relative; overflow: hidden; border-radius: var(--radio); padding: 1.15rem 1.2rem 0; color: #fff; box-shadow: var(--sombra-lg); min-height: 168px; }
.kpi-card .kpi-top { display: flex; align-items: flex-start; justify-content: space-between; }
.kpi-card .kpi-label { text-transform: uppercase; letter-spacing: .06em; font-size: .74rem; opacity: .92; font-weight: 600; }
.kpi-card .kpi-num { font-size: 2.1rem; font-weight: 800; margin: .35rem 0 .1rem; letter-spacing: -.02em; }
.kpi-card .kpi-cmp { font-size: .82rem; opacity: .9; }
.kpi-card .kpi-ic { width: 40px; height: 40px; border-radius: 11px; background: rgba(255,255,255,.22); display: grid; place-items: center; font-size: 1.2rem; }
.kpi-card .kpi-spark { position: absolute; left: 0; right: 0; bottom: 0; height: 52px; }
.kpi-card .kpi-spark canvas { width: 100% !important; height: 100% !important; }
.kpi-blue   { background: linear-gradient(135deg, #2b5cff, #5b8bff); }
.kpi-red    { background: linear-gradient(135deg, #f0436b, #ff7aa0); }
.kpi-green  { background: linear-gradient(135deg, #16b364, #4bd88b); }
.kpi-orange { background: linear-gradient(135deg, #ff8a3d, #ffb072); }

/* Grillas de tarjetas del dashboard */
.grid-cards { display: grid; gap: 1.1rem; grid-template-columns: 1fr; margin-bottom: 1.1rem; }
.grid-2c { display: grid; gap: 1.1rem; grid-template-columns: 1fr; margin-bottom: 1.1rem; }

/* Contenedor de gráficos con altura fija (evita colapso de Chart.js) */
.chart-box { position: relative; height: 260px; }

/* Gauge */
.gauge-wrap { position: relative; width: 200px; height: 200px; max-width: 100%; margin: 1rem auto; }
.gauge-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.gauge-center .g-num { font-size: 1.9rem; font-weight: 800; color: var(--texto); }
.gauge-center .g-lbl { font-size: .72rem; color: var(--texto-suave); text-transform: uppercase; letter-spacing: .05em; }

/* Lista de actividad */
.act-list { display: flex; flex-direction: column; }
.act-item { display: flex; align-items: center; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--borde); }
.act-item:last-child { border-bottom: 0; }
.act-avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: .85rem; background: linear-gradient(135deg, #2b5cff, #6a8bff); }
.act-main { flex: 1; min-width: 0; }
.act-main .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act-main .s { color: var(--texto-suave); font-size: .82rem; }
.act-spark { width: 74px; height: 26px; flex: none; }

/* Formularios */
form .campo { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: .72rem .8rem; font-size: .95rem;
  border: 1px solid var(--borde); border-radius: var(--radio-sm); background: #fff; color: var(--texto);
}
textarea { min-height: 74px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(43,92,255,.35); border-color: var(--primary); }
.hint { color: var(--texto-suave); font-size: .82rem; margin-top: .25rem; }
.req { color: var(--rojo); }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .72rem 1.15rem; font-size: .92rem; font-weight: 600;
  border: 1px solid var(--borde); border-radius: var(--radio-sm); cursor: pointer;
  text-decoration: none; background: #fff; color: var(--texto); min-height: 44px; transition: filter .15s, background .15s;
}
.btn:hover { background: #f4f6fb; }
.btn-primario { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primario:hover { background: var(--primary-d); }
.btn-ok { background: var(--verde); color: #fff; border-color: var(--verde); }
.btn-ok:hover { background: var(--verde-osc); }
.btn-peligro { background: var(--rojo); color: #fff; border-color: var(--rojo); }
.btn-peligro:hover { background: var(--rojo-osc); }
.btn-bloque { width: 100%; }
.btn-sm { padding: .42rem .7rem; font-size: .82rem; min-height: 34px; }
.acciones { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }

/* Checkbox / radios agrupados */
.opciones { display: flex; flex-wrap: wrap; gap: .5rem; }
.opciones label {
  display: inline-flex; align-items: center; gap: .4rem; font-weight: 500;
  padding: .5rem .8rem; border: 1px solid var(--borde); border-radius: var(--radio-sm);
  background: #fff; cursor: pointer; margin: 0;
}
.opciones input { width: auto; }

/* Tablas */
.tabla-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tabla { width: 100%; border-collapse: collapse; background: #fff; }
table.tabla th, table.tabla td { padding: .7rem .7rem; border-bottom: 1px solid var(--borde); text-align: left; font-size: .9rem; }
table.tabla th { background: #fafbfe; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texto-suave); white-space: nowrap; }
table.tabla tbody tr:hover { background: #fafbff; }
table.tabla tr:last-child td { border-bottom: 0; }

/* Auditoría por producto */
.audit-prod { border: 1px solid var(--borde); border-radius: var(--radio-sm); padding: .85rem; margin-bottom: .8rem; background: #fff; }
.audit-prod .nombre-prod { font-weight: 700; margin-bottom: .5rem; }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }

/* Badges */
.badge { display: inline-block; padding: .18rem .6rem; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.badge-ok { background: #e4f7ee; color: var(--verde-osc); }
.badge-no { background: #fde7ed; color: var(--rojo-osc); }
.badge-pend { background: #fff2dd; color: #b9791a; }
.badge-info { background: #e9f0ff; color: var(--primary); }
.lock { color: var(--texto-suave); font-size: .85rem; }

/* Flash */
.flash { padding: .85rem 1rem; border-radius: var(--radio-sm); margin-bottom: 1rem; font-weight: 500; }
.flash-ok { background: #e4f7ee; color: var(--verde-osc); border: 1px solid #bce9d1; }
.flash-error { background: #fde7ed; color: var(--rojo-osc); border: 1px solid #f6c2d0; }
.flash-info { background: #e9f0ff; color: var(--primary); border: 1px solid #c6d7ff; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(135deg, #eef2fb, #f7f9fe); }
.login-card { background: #fff; border-radius: 18px; box-shadow: var(--sombra-lg); padding: 1.8rem; width: 100%; max-width: 390px; }
.login-card h1 { text-align: center; color: var(--primary); }

/* Firma / fotos */
.firma-box { border: 2px dashed var(--borde); border-radius: var(--radio-sm); background: #fff; touch-action: none; width: 100%; height: 180px; display: block; }
.foto-preview { max-width: 100%; border-radius: var(--radio-sm); margin-top: .5rem; border: 1px solid var(--borde); }
.foto-preview:not([src]), .foto-preview[src=""] { display: none; }

/* Utilidades */
.text-suave { color: var(--texto-suave); }
.text-right { text-align: right; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: .8rem; }
.chip-link { text-decoration: none; }
.filtros { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: .7rem; align-items: end; }
.rol-badge { display: none; }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */

/* Escritorio / laptop: sidebar fijo visible, contenido a pantalla completa */
@media (min-width: 992px) {
  .menu-btn { display: none; }
  .sidebar { transform: none; }
  .appheader { left: var(--sidebar-w); }
  .contenido { margin-left: var(--sidebar-w); padding-left: 1.6rem; padding-right: 1.6rem; }
  .pie { margin-left: var(--sidebar-w); }
  .nav-backdrop { display: none; }

  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-2c { grid-template-columns: 1.6fr 1fr; }

  /* Admin/Supervisor: aprovechar TODO el ancho para tablas completas */
  body.rol-admin .contenido,
  body.rol-supervisor .contenido { max-width: 1500px; }

  /* Vendedor: columna estrecha tipo móvil aunque esté en PC */
  body.rol-vendedor .contenido { max-width: 780px; margin-left: auto; margin-right: auto; padding-left: 1rem; padding-right: 1rem; }
  body.rol-vendedor .appheader { left: 0; }
  body.rol-vendedor .sidebar { transform: translateX(-100%); }
  body.rol-vendedor .menu-btn { display: inline-block; }
  body.rol-vendedor.nav-open .sidebar { transform: translateX(0); }
  body.rol-vendedor .pie { margin-left: 0; }
}

/* Móvil / tablet */
@media (max-width: 991px) {
  .header-user { display: none; }
  .header-search { min-width: 0; }
  .page-metrics { gap: 1rem; }
}
@media (max-width: 560px) {
  .header-search { display: none; }
  .fila-2 { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; }
}
