/* ============================================================
   Kami Sushi / PCM — Cotizador
   Paleta: rojo laca (marca) + acento jengibre + fondo washi cálido.
   Tipografía: Manrope (una sola familia, jugando con peso/tamaño
   para dar personalidad sin sumar una segunda fuente).
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --primary: #b3382a;
  --primary-dark: #8f2c21;
  --primary-soft: #f6e6e2;
  --accent: #c98a2b;
  --accent-soft: #f7ecd8;
  --bg: #f7f2ea;
  --panel: #ffffff;
  --border: #e8e0d3;
  --text: #241f1a;
  --muted: #8a8073;
  --success: #1e7a34;
  --success-soft: #e3f3e6;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(36, 31, 26, 0.04), 0 8px 24px -12px rgba(36, 31, 26, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */

.topbar {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 18px 20px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 4px 16px -8px rgba(0,0,0,0.35);
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.subtitle { margin: 3px 0 0; font-size: 12.5px; opacity: 0.85; font-weight: 500; }
.topbar-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar-user { font-size: 13px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-weight: 600; }
.topbar-user a { color: white; text-decoration: none; opacity: 0.92; border-bottom: 1.5px solid rgba(255,255,255,0.4); padding-bottom: 1px; }
.topbar-user a:hover { opacity: 1; border-color: white; }
#usuario-nombre { opacity: 0.95; }

/* ---------- Layout base ---------- */

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 140px; /* deja espacio para la barra fija del carrito en mobile */
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

h2 { font-size: 17px; font-weight: 800; margin: 0 0 4px; letter-spacing: -0.01em; }

/* ---------- Selección de región/local ---------- */

.region-panel { text-align: center; padding: 32px 20px; }
.region-panel h2 { margin-bottom: 18px; }
.region-cards { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.region-card {
  padding: 16px 22px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--panel);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  min-width: 150px;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
}
.region-card:hover { border-color: var(--primary); background: var(--primary-soft); }
.region-card:active { transform: scale(0.98); }

.region-actual {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  padding: 12px 18px;
}
.region-actual strong { color: var(--text); font-size: 15px; }
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  margin-left: auto;
}

/* ---------- Formulario / filtros ---------- */

.form-header { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 12px; }
.form-header-simple { grid-template-columns: 1fr; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.02em; }
.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--panel);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); }

.categorias-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em; display: block; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  background: var(--panel);
  color: var(--text);
  white-space: nowrap;
  user-select: none;
  transition: all 0.15s;
}
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ---------- Layout principal: lista de productos + carrito ---------- */

.layout-principal { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }

.tabla-panel { padding: 8px; }

/* Lista de productos como tarjetas (mejor en mobile que una tabla) */
#lista-productos { display: flex; flex-direction: column; gap: 8px; }
.producto-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.producto-card:hover { background: #faf7f2; }
.producto-info { flex: 1; min-width: 0; }
.producto-nombre { font-size: 14.5px; font-weight: 700; line-height: 1.3; }
.producto-meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.producto-categoria { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.sku-chip { font-size: 10.5px; color: var(--muted); background: #f1ede4; padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.producto-precio { font-size: 14px; font-weight: 800; color: var(--text); white-space: nowrap; min-width: 78px; text-align: right; }

.stepper { display: flex; align-items: center; gap: 0; border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; flex-shrink: 0; }
.stepper button {
  width: 34px; height: 38px;
  border: none; background: #faf7f2; color: var(--primary);
  font-size: 18px; font-weight: 800; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.stepper button:active { background: var(--primary-soft); }
.cantidad-input {
  width: 46px; height: 38px;
  border: none; border-left: 1.5px solid var(--border); border-right: 1.5px solid var(--border);
  text-align: center; font-size: 14px; font-weight: 700; font-family: inherit;
  -moz-appearance: textfield;
}
.cantidad-input::-webkit-outer-spin-button, .cantidad-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cantidad-input:focus { outline: none; }

.loading { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 14px; }

/* ---------- Carrito ---------- */

.carrito-panel { position: sticky; top: 88px; }
.carrito-panel h3 { margin: 0 0 12px; font-size: 15px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--primary); color: white; font-size: 12px; font-weight: 800; border-radius: 999px; padding: 2px 9px; }

.carrito-items { max-height: 320px; overflow-y: auto; margin-bottom: 12px; }
.carrito-vacio { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 0; }
.carrito-item { padding: 9px 0; border-bottom: 1px solid #f1ede4; }
.carrito-item-info { display: flex; justify-content: space-between; gap: 8px; }
.carrito-item-nombre { font-size: 13px; font-weight: 700; line-height: 1.3; }
.carrito-item-detalle { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.carrito-item-detalle strong { color: var(--text); font-weight: 800; }
.quitar-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 2px 4px; line-height: 1; }
.quitar-btn:hover { color: var(--primary); }

.carrito-totales { border-top: 1.5px dashed var(--border); padding-top: 10px; margin-bottom: 12px; }
.carrito-totales div { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 2px 0; }
.carrito-totales div:last-child { font-size: 15px; color: var(--text); font-weight: 800; padding-top: 4px; }
.carrito-totales strong { font-weight: 800; }

#btnEnviar {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  padding: 13px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}
#btnEnviar:hover { background: var(--primary-dark); }
#btnEnviar:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-glosa { font-size: 11.5px; color: var(--muted); margin: 8px 0 0; text-align: center; line-height: 1.4; }

.carrito-toggle { display: none; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  line-height: 1.5;
  max-width: 92vw;
  box-shadow: 0 8px 24px -6px rgba(0,0,0,0.35);
  transition: opacity 0.2s;
  z-index: 50;
}
.toast a { color: #ffd9c9; font-weight: 700; }
.toast.hidden { opacity: 0; pointer-events: none; }
.toast.error { background: var(--primary-dark); }

.hidden { display: none !important; }

/* ============================================================
   Mobile (<= 720px): barra de carrito fija abajo + lista apilada
   ============================================================ */

@media (max-width: 720px) {
  main { padding: 12px; padding-bottom: 170px; }
  .topbar { padding: 14px 16px; }
  .topbar h1 { font-size: 17px; }
  .topbar-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .topbar-user { font-size: 12.5px; gap: 10px; }

  .form-header { grid-template-columns: 1fr; }
  .panel { padding: 14px; }

  .layout-principal { grid-template-columns: 1fr; }

  /* El carrito se convierte en una barra fija al fondo de la pantalla.
     Colapsada, solo se ven: el resumen (badge + total) y el boton de
     descarga -- el detalle de items Y el desglose Neto/IVA/Total se
     revelan al tocar la barra (evita duplicar el total dos veces). */
  .carrito-panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    top: auto;
    z-index: 40;
    border-radius: 18px 18px 0 0;
    margin: 0;
    box-shadow: 0 -8px 28px -10px rgba(36,31,26,0.25);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .carrito-panel h3 { display: none; }
  .carrito-items {
    max-height: 0;
    overflow-y: auto;
    margin-bottom: 0;
    transition: max-height 0.25s ease;
  }
  .carrito-totales {
    display: none;
    margin-bottom: 12px;
  }
  .carrito-panel.expandido .carrito-items { max-height: 40vh; margin-bottom: 12px; }
  .carrito-panel.expandido .carrito-vacio { padding: 20px 0; }
  .carrito-panel.expandido .carrito-totales { display: block; }

  .carrito-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: none;
    border: none;
    font-family: inherit;
    padding: 2px 0 12px;
    cursor: pointer;
    color: var(--text);
  }
  .carrito-toggle .badge { margin-right: 8px; }
  .carrito-toggle-label { font-size: 14px; font-weight: 800; display: flex; align-items: center; }
  .carrito-toggle-chevron { font-size: 12px; color: var(--muted); transition: transform 0.2s; }
  .carrito-panel.expandido .carrito-toggle-chevron { transform: rotate(180deg); }

  .producto-card { padding: 10px 6px; }
  .producto-precio { min-width: 64px; font-size: 13px; }
  .stepper button { width: 30px; height: 36px; }
  .cantidad-input { width: 40px; height: 36px; }

  .toast { bottom: 170px; }
}

@media (min-width: 721px) {
  .carrito-toggle { display: none !important; }
  .carrito-items { max-height: 320px !important; }
}
