:root {
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --text: #1D1D1F;
  --text2: #6E6E73;
  --text3: #3A3A3C;
  --line: #E5E5EA;
  --line2: #D2D2D7;
  --soft: #F2F2F7;
  --accent: #0071E3;
  --accent-text: #0058B0;
  --accent-soft: #EAF2FF;
  --green: #1D7A35;
  --green-soft: #E8F5EC;
  --switch: #34C759;
  --red: #C4001A;
  --red-soft: #FDECEC;
  --orange: #A04500;
  --orange-soft: #FFF4E5;
  --amber: #B25000;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 6px 20px rgba(0,0,0,0.05);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
.oculto { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Estructura ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; padding: 28px 16px 24px;
  background: #FBFBFD; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 32px;
  position: sticky; top: 0; height: 100vh;
}
.marca { display: flex; align-items: center; gap: 12px; padding: 0 10px; }
.marca-logo {
  width: 38px; height: 38px; border-radius: 11px; background: var(--text); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700;
}
.marca-nombre { font-size: 17px; font-weight: 700; letter-spacing: -0.015em; }
.marca-sub { font-size: 12px; color: var(--text2); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 12px;
  border: none; border-radius: 10px; background: transparent; text-align: left;
  font-size: 15px; font-weight: 500; color: var(--text); width: 100%;
}
.nav-item svg { flex-shrink: 0; }
.nav-item.activo { background: #E8E8ED; font-weight: 600; }
.nav-item.activo svg { color: var(--accent); }
.nav-item:disabled { color: #8E8E93; cursor: default; }
.nav-pronto { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--text2); background: var(--soft); padding: 2px 8px; border-radius: 8px; }
.usuario {
  margin-top: auto; display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: 14px; background: var(--card); border: 1px solid var(--line); position: relative;
}
.avatar {
  width: 36px; height: 36px; border-radius: 18px; background: #E8E8ED; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600;
}
.usuario-nombre { font-size: 14px; font-weight: 600; }
.usuario-rol { font-size: 12px; color: var(--text2); }
.usuario-mas { margin-left: auto; width: 32px; height: 32px; border: none; background: transparent; border-radius: 8px; color: var(--text2); }
.usuario-mas:hover { background: var(--soft); }

.main { flex-grow: 1; min-width: 0; padding: 36px 44px 60px; display: flex; flex-direction: column; gap: 24px; }
.cabecera { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.cabecera h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.022em; }
.cabecera p { margin: 4px 0 0; font-size: 15px; color: var(--text2); }
.acciones { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Controles ---------- */
.btn {
  height: 44px; padding: 0 20px; border-radius: 22px; border: 1px solid var(--line2);
  background: var(--card); color: var(--text); font-size: 15px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn:hover { background: #FAFAFA; }
.btn-primario { border: none; background: var(--accent); color: #fff; font-weight: 600; }
.btn-primario:hover { background: #0068D1; }
.btn-suave { border: none; background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.btn-peligro { border: none; background: var(--red-soft); color: var(--red); font-weight: 600; }
.btn-peq { height: 34px; padding: 0 14px; border-radius: 17px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.barra { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.buscador {
  display: flex; align-items: center; gap: 10px; width: 330px; max-width: 100%; height: 44px; padding: 0 14px;
  background: var(--card); border: 1px solid var(--line2); border-radius: 12px; color: var(--text2);
}
.buscador input { flex-grow: 1; min-width: 0; border: none; outline: none; background: transparent; font-size: 15px; color: var(--text); }
.segmentado { display: inline-flex; padding: 3px; background: #E8E8ED; border-radius: 12px; gap: 2px; }
.segmentado button {
  height: 38px; padding: 0 16px; border: none; border-radius: 9px; background: transparent;
  font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap;
}
.segmentado button.activo { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,0.12); font-weight: 600; }
.selector {
  height: 44px; padding: 0 14px; border: 1px solid var(--line2); border-radius: 12px; background: var(--card);
  font-size: 15px; max-width: 260px;
}
.desplegable { position: relative; }
.desplegable-boton {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px;
  border: 1px solid var(--line2); border-radius: 12px; background: var(--card); font-size: 15px;
}
.desplegable-boton .etq { color: var(--text2); }
.desplegable-boton .val { font-weight: 600; }
.menu {
  position: absolute; top: 52px; left: 0; z-index: 30; width: 320px; padding: 6px;
  background: var(--card); border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.16), 0 0 0 1px rgba(0,0,0,0.05);
  display: flex; flex-direction: column; gap: 2px; max-height: 70vh; overflow-y: auto;
}
.menu-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 4px 12px;
  border: none; border-radius: 10px; background: transparent; text-align: left; width: 100%;
}
.menu-item:hover { background: var(--soft); }
.menu-item.activo { background: var(--soft); }
.menu-item .t { font-size: 15px; font-weight: 500; }
.menu-item.activo .t { font-weight: 600; }
.menu-item .m { font-size: 12px; color: var(--text2); }
.menu-item .check { color: var(--accent); font-weight: 700; }
.menu-sep { height: 1px; margin: 4px 8px; background: var(--line); }
.menu-nuevo { color: var(--accent-text); font-weight: 600; font-size: 15px; justify-content: flex-start; gap: 10px; }

/* ---------- Tarjetas y métricas ---------- */
.metricas { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
.metrica { background: var(--card); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.metrica .etq { font-size: 13px; color: var(--text2); }
.metrica .num { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }

.rejilla { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; }
.producto {
  background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
}
.producto:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(0,0,0,0.05), 0 12px 28px rgba(0,0,0,0.08); }
.producto-foto {
  height: 180px; background: var(--bg); position: relative;
  display: flex; align-items: center; justify-content: center; color: #AEAEB2;
}
.producto-foto img { width: 100%; height: 100%; object-fit: cover; }
.insignia {
  position: absolute; top: 12px; padding: 4px 9px; border-radius: 10px; font-size: 11px; font-weight: 600;
}
.producto-cuerpo { padding: 16px 18px 12px; display: flex; flex-direction: column; gap: 10px; flex-grow: 1; }
.producto-cat { font-size: 12px; color: var(--text2); }
.producto-nombre { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.producto-prov { font-size: 13px; color: var(--text2); }
.precio-fila { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.precio { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.precio-u { font-size: 13px; color: var(--text2); margin-left: 4px; }
.tendencia { font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 8px; white-space: nowrap; }
.caja { font-size: 13px; color: var(--text2); }
.producto-pie {
  display: flex; align-items: center; justify-content: space-between; gap: 4px 8px; flex-wrap: wrap;
  margin-top: auto; padding-top: 4px; border-top: 1px solid #F0F0F2; min-height: 48px;
}
.frescura { font-size: 12px; color: var(--text2); text-align: right; }
.frescura.vieja { color: var(--amber); }

.interruptor { display: inline-flex; align-items: center; gap: 10px; height: 44px; padding: 0; border: none; background: transparent; font-size: 14px; }
.interruptor .pista { width: 44px; height: 26px; border-radius: 13px; background: #D1D1D6; position: relative; transition: background 0.2s; flex-shrink: 0; }
.interruptor .bola { position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 11px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: left 0.2s; }
.interruptor[aria-pressed="true"] .pista { background: var(--switch); }
.interruptor[aria-pressed="true"] .bola { left: 20px; }

.pill { display: inline-block; padding: 4px 10px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.pill-gris { background: #E8E8ED; color: var(--text3); }
.pill-azul { background: var(--accent-soft); color: var(--accent-text); }
.pill-verde { background: var(--green-soft); color: var(--green); }
.pill-rojo { background: var(--red-soft); color: var(--red); }
.pill-naranja { background: var(--orange-soft); color: var(--orange); }

.vacio {
  background: var(--card); border-radius: var(--radius); padding: 56px 32px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--text2);
}
.vacio h2 { margin: 0; color: var(--text); font-size: 20px; }
.vacio p { margin: 0; max-width: 420px; }

/* ---------- Proveedores ---------- */
.proveedores { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; }
.proveedor {
  background: var(--card); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px; cursor: pointer;
}
.proveedor-cab { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 52px; height: 52px; border-radius: 14px; background: var(--text); color: #fff; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 17px; font-weight: 700; overflow: hidden;
}
.logo img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.proveedor h3 { margin: 0; font-size: 17px; font-weight: 600; }
.proveedor .sub { font-size: 13px; color: var(--text2); }
.contactos { display: flex; flex-wrap: wrap; gap: 8px; }
.contacto {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 17px;
  background: var(--soft); color: var(--accent-text); font-size: 13px; font-weight: 600;
}
.contacto:hover { text-decoration: none; background: #E8E8ED; }
.proveedor-pie { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--text2); }

/* ---------- Ventana (modal) ---------- */
.fondo {
  position: fixed; inset: 0; background: rgba(0,0,0,0.32); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto;
}
.ventana {
  width: 100%; max-width: 640px; background: var(--bg); border-radius: 22px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.25); display: flex; flex-direction: column;
}
.ventana-cab {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 22px; border-bottom: 1px solid var(--line); background: rgba(251,251,253,0.96);
  border-radius: 22px 22px 0 0; position: sticky; top: 0; z-index: 2;
}
.ventana-cab h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.015em; }
.cerrar { width: 36px; height: 36px; border-radius: 18px; border: none; background: #E8E8ED; color: var(--text3); display: flex; align-items: center; justify-content: center; }
.ventana-cuerpo { padding: 8px 22px 22px; display: flex; flex-direction: column; }
.ventana-pie {
  display: flex; align-items: center; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line);
  background: rgba(251,251,253,0.96); border-radius: 0 0 22px 22px; position: sticky; bottom: 0; z-index: 2;
}
.ventana-pie .espacio { flex-grow: 1; }

.seccion-t { margin: 20px 10px 6px; font-size: 13px; font-weight: 500; color: var(--text2); text-transform: uppercase; letter-spacing: 0.02em; }
.grupo { background: var(--card); border-radius: 14px; overflow: hidden; }
.fila { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 4px 16px; border-bottom: 1px solid #EFEFF4; }
.fila:last-child { border-bottom: none; }
.fila > label, .fila > .etq { font-size: 15px; width: 170px; flex-shrink: 0; }
.fila input:not([type=checkbox]):not([type=file]), .fila select {
  flex-grow: 1; min-width: 0; border: none; outline: none; background: transparent; text-align: right;
  font-size: 15px; color: var(--text3); padding: 8px 0;
}
.fila select { text-align-last: right; cursor: pointer; }
.fila input::placeholder { color: #AEAEB2; }
.fila.req > label::after { content: " *"; color: var(--red); }
.fila-col { flex-direction: column; align-items: stretch; padding: 12px 16px; gap: 8px; }
.fila-col > label, .fila-col > .etq { width: auto; }
textarea.area {
  width: 100%; border: none; outline: none; resize: vertical; min-height: 90px; background: transparent;
  font-size: 15px; line-height: 1.45; color: var(--text3);
}
.ayuda { font-size: 12px; color: var(--text2); margin: 6px 10px 0; }
.error-campo { font-size: 13px; font-weight: 600; color: var(--red); margin: 12px 10px 0; }

.foto-zona { display: flex; gap: 16px; align-items: center; padding: 14px 16px; }
.foto-previa {
  width: 120px; height: 120px; border-radius: 14px; background: var(--bg); overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #AEAEB2;
}
.foto-previa img { width: 100%; height: 100%; object-fit: cover; }
.foto-previa.redonda { border-radius: 26px; }
.foto-botones { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line2); background: var(--card);
  font-size: 13px; font-weight: 600; color: var(--text3);
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: #B7D3F5; color: var(--accent-text); }

.tel-fila { display: flex; align-items: center; gap: 10px; }
.tel-fila input[type=tel] { flex-grow: 1; min-width: 0; border: 1px solid var(--line2); border-radius: 10px; padding: 8px 12px; font-size: 15px; outline: none; }
.tel-fila label { font-size: 13px; display: flex; align-items: center; gap: 6px; color: var(--text3); white-space: nowrap; }
.quitar { width: 34px; height: 34px; border-radius: 17px; border: none; background: var(--soft); color: var(--red); flex-shrink: 0; }

.mini-form { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px 14px; background: #FAFAFC; border-top: 1px solid #EFEFF4; }
.mini-form input[type=text], .mini-form select, .campo {
  height: 40px; padding: 0 12px; border: 1px solid var(--line2); border-radius: 10px; background: var(--card);
  font-size: 15px; outline: none; width: 100%;
}
.mini-form .botones { display: flex; justify-content: flex-end; gap: 8px; }
.mini-form .t { font-size: 13px; font-weight: 600; }

.historial { display: flex; flex-direction: column; }
.historial-fila { display: flex; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid #EFEFF4; font-size: 14px; }
.historial-fila:last-child { border-bottom: none; }
.historial-fila span:last-child { color: var(--text2); }

.usuarios-lista .fila { justify-content: space-between; }

/* ---------- Acceso ---------- */
.acceso { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.acceso-caja {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  padding: 36px 30px 30px; display: flex; flex-direction: column; gap: 14px;
}
.acceso-caja .marca { padding: 0; margin-bottom: 10px; }
.acceso-caja h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -0.02em; }
.acceso-caja label { font-size: 13px; font-weight: 600; color: var(--text3); }
.acceso-caja .campo { height: 46px; }
.acceso-caja .btn { width: 100%; margin-top: 6px; }
.acceso-error { font-size: 14px; color: var(--red); font-weight: 500; }

/* ---------- Avisos ---------- */
.aviso {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 80;
  background: rgba(29,29,31,0.92); color: #fff; padding: 12px 20px; border-radius: 22px; font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25); max-width: calc(100% - 40px);
}
.aviso.error { background: var(--red); }
.cargando { padding: 60px; text-align: center; color: var(--text2); }

/* ---------- Móvil ---------- */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 20; padding: 10px 12px;
    flex-direction: row; align-items: center; gap: 10px; border-right: none; border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }
  .marca-sub, .marca-nombre { display: none; }
  .marca { padding: 0; }
  .nav { flex-direction: row; }
  .nav-item { width: auto; white-space: nowrap; }
  .nav-pronto, .nav-item:disabled { display: none; }
  .usuario { margin-top: 0; margin-left: auto; padding: 6px; border: none; background: transparent; }
  .usuario-nombre, .usuario-rol { display: none; }
  .main { padding: 20px 16px 60px; gap: 18px; }
  .cabecera h1 { font-size: 28px; }
  .metricas { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .metrica .num { font-size: 24px; }
  .buscador { width: 100%; }
  .segmentado { max-width: 100%; overflow-x: auto; }
  .segmentado button { padding: 0 12px; font-size: 13px; }
  .producto-cuerpo { padding: 14px 14px 10px; }
  .producto-pie > div { align-items: flex-start !important; }
  .interruptor { font-size: 13px; gap: 8px; }
  .rejilla { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .producto-foto { height: 140px; }
  .precio { font-size: 20px; }
  .proveedores { grid-template-columns: 1fr; }
  .fondo { padding: 0; }
  .ventana { border-radius: 0; min-height: 100%; max-width: none; }
  .ventana-cab, .ventana-pie { border-radius: 0; top: 0; bottom: 0; }
  .fila > label, .fila > .etq { width: 130px; }
  .menu { width: min(320px, calc(100vw - 32px)); }
}
