/* PAL'S B2B Portal — Material Design 3, light, accent #383838 */
/* Versión: API v1 */

:root {
  --pals: #383838;
  --pals-light: #f5f5f5;
  --pals-mid: #757575;
  --pals-dark: #1a1a1a;
  --surface: #ffffff;
  --surface-variant: #f4f4f4;
  --on-surface: #1c1c1c;
  --outline: #c8c8c8;
  --outline-strong: #888888;
  --error: #b3261e;
  --error-container: #ffdad6;
  --warning: #7a5700;
  --warning-container: #fff3cd;
  --success: #176b3e;
  --success-container: #c8f0d8;
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'IBM Plex Sans', 'Roboto', system-ui, -apple-system, sans-serif;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.05);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--pals-light);
  color: var(--on-surface);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.header {
  background: var(--pals);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}
.header-logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #fff;
  text-decoration: none;
  line-height: 1;
}
.header-logo span { font-weight: 300; opacity: .75; }
.header-subtitle {
  font-size: .8rem;
  opacity: .7;
  font-weight: 400;
  margin-top: 2px;
}

/* ── Progress stepper ── */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px 8px;
  gap: 0;
  overflow-x: auto;
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  position: relative;
}
.step:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 14px;
  left: calc(50% + 14px);
  right: calc(-50% + 14px);
  height: 2px;
  background: var(--outline);
  z-index: 0;
}
.step.done:not(:last-child)::after { background: var(--pals); }
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--outline);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 600;
  color: var(--pals-mid);
  position: relative;
  z-index: 1;
  transition: all .2s;
}
.step.active .step-dot {
  background: var(--pals);
  border-color: var(--pals);
  color: #fff;
  box-shadow: 0 0 0 4px rgba(56,56,56,.15);
}
.step.done .step-dot {
  background: var(--pals);
  border-color: var(--pals);
  color: #fff;
}
.step-label {
  font-size: .65rem;
  color: var(--pals-mid);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70px;
}
.step.active .step-label { color: var(--pals); font-weight: 600; }
.step.done .step-label { color: var(--pals); }

/* ── Container ── */
.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

/* ── Screens ── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Card ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--pals-dark);
  margin-bottom: 16px;
}
.card-subtitle {
  font-size: .85rem;
  color: var(--pals-mid);
  margin-top: -12px;
  margin-bottom: 16px;
}

/* ── Form elements ── */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--pals-mid);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

input[type="text"],
input[type="email"],
input[type="number"] {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--outline);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
  color: var(--on-surface);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus {
  border-color: var(--pals);
  box-shadow: 0 0 0 3px rgba(56,56,56,.12);
}
input.error {
  border-color: var(--error);
  background: #fff8f8;
}
input.error:focus {
  box-shadow: 0 0 0 3px rgba(179,38,30,.12);
}

.field-hint {
  font-size: .78rem;
  color: var(--pals-mid);
  margin-top: 4px;
}
.field-error {
  font-size: .78rem;
  color: var(--error);
  margin-top: 4px;
  display: none;
}
.field-error.visible { display: block; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  min-height: 48px;
  letter-spacing: .2px;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--pals);
  color: #fff;
  width: 100%;
}
.btn-primary:hover:not(:disabled) { background: #4a4a4a; }
.btn-primary:active:not(:disabled) { background: #2a2a2a; transform: scale(.98); }
.btn-primary:disabled {
  background: var(--outline);
  color: var(--pals-mid);
  cursor: not-allowed;
}
.btn-secondary {
  background: transparent;
  color: var(--pals);
  border: 1.5px solid var(--pals);
  width: 100%;
}
.btn-secondary:hover { background: rgba(56,56,56,.06); }
.btn-ghost {
  background: transparent;
  color: var(--pals);
  padding: 10px 16px;
  font-size: .9rem;
}
.btn-ghost:hover { background: rgba(56,56,56,.06); }

/* ── Loading spinner ── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.spinner-dark {
  border-color: rgba(56,56,56,.2);
  border-top-color: var(--pals);
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-inline {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  color: var(--pals-mid);
  font-size: .9rem;
}

/* ── Alerts / Badges ── */
.alert {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: .875rem;
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.alert-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.alert-error { background: var(--error-container); color: var(--error); border: 1px solid rgba(179,38,30,.2); }
.alert-warning { background: var(--warning-container); color: var(--warning); border: 1px solid rgba(122,87,0,.2); }
.alert-success { background: var(--success-container); color: var(--success); border: 1px solid rgba(23,107,62,.2); }
.alert-info { background: #e8f4fd; color: #1565c0; border: 1px solid rgba(21,101,192,.2); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.badge-warning { background: var(--warning-container); color: var(--warning); }
.badge-error { background: var(--error-container); color: var(--error); }
.badge-success { background: var(--success-container); color: var(--success); }

/* ── Sucursal list ── */
.sucursal-list { display: flex; flex-direction: column; gap: 10px; }
.sucursal-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1.5px solid var(--outline);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
  background: var(--surface);
  position: relative;
  text-align: left;
  width: 100%;
}
.sucursal-item:hover { border-color: var(--pals); background: var(--pals-light); }
.sucursal-item.selected { border-color: var(--pals); background: rgba(56,56,56,.04); }
.sucursal-radio {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--outline);
  flex-shrink: 0;
  margin-top: 2px;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sucursal-item.selected .sucursal-radio {
  border-color: var(--pals);
  background: var(--pals);
}
.sucursal-item.selected .sucursal-radio::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}
.sucursal-info { flex: 1; min-width: 0; }
.sucursal-nombre {
  font-weight: 600;
  font-size: .95rem;
  color: var(--on-surface);
  margin-bottom: 2px;
}
.sucursal-cp { font-size: .82rem; color: var(--pals-mid); }

/* ── Catalog grid ── */
.catalog-section-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--pals-mid);
  margin: 20px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1.5px solid var(--outline);
}
.catalog-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 380px) { .catalog-grid { grid-template-columns: 1fr; } }

.product-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  border: 1.5px solid transparent;
  transition: border-color .15s;
}
.product-card.has-qty { border-color: var(--pals); }
.product-card.qty-error { border-color: var(--error); }

.product-img-wrap {
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface-variant);
  overflow: hidden;
  position: relative;
}
.product-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.product-img-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--pals);
  background: linear-gradient(135deg, #f4f4f4, #e8e8e8);
  letter-spacing: -1px;
}

.product-body { padding: 10px 12px 12px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.product-nombre { font-size: .85rem; font-weight: 600; color: var(--on-surface); line-height: 1.3; }
.product-precio { font-size: 1rem; font-weight: 700; color: var(--pals-dark); }
.product-unit { font-size: .73rem; color: var(--pals-mid); font-weight: 400; }

/* Stepper de cantidad */
.qty-stepper {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}
.qty-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1.5px solid var(--outline);
  background: var(--surface);
  font-size: 1.2rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pals);
  transition: all .12s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.qty-btn:hover { background: var(--pals-light); border-color: var(--pals); }
.qty-btn:active { transform: scale(.9); }
.qty-input {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: 8px 4px;
  border: 1.5px solid var(--outline);
  border-radius: 8px;
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 600;
  color: var(--on-surface);
  background: var(--surface);
}
.qty-input:focus { border-color: var(--pals); outline: none; box-shadow: 0 0 0 3px rgba(56,56,56,.12); }
.qty-input.error { border-color: var(--error); }
.qty-error-msg { font-size: .72rem; color: var(--error); margin-top: 2px; }

/* ── Subtotal bar ── */
.subtotal-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--outline);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 -4px 12px rgba(0,0,0,.08);
  z-index: 50;
}
.subtotal-bar-left { display: flex; flex-direction: column; }
.subtotal-label { font-size: .75rem; color: var(--pals-mid); font-weight: 500; }
.subtotal-amount { font-size: 1.25rem; font-weight: 700; color: var(--pals-dark); }
.subtotal-bar .btn-primary { max-width: 180px; flex-shrink: 0; padding: 12px 20px; font-size: .9rem; }

/* ── Summary table ── */
.summary-lines { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.summary-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-variant);
  border-radius: var(--radius-sm);
}
.summary-line-name { flex: 1; font-size: .9rem; color: var(--on-surface); font-weight: 500; }
.summary-line-qty { font-size: .85rem; color: var(--pals-mid); min-width: 40px; text-align: right; }
.summary-line-total { font-size: .95rem; font-weight: 600; color: var(--on-surface); min-width: 80px; text-align: right; }

.summary-totals { display: flex; flex-direction: column; gap: 4px; padding-top: 12px; border-top: 1.5px solid var(--outline); }
.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: .9rem;
}
.summary-row.total-row {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--pals-dark);
  padding-top: 10px;
  border-top: 1.5px solid var(--outline);
  margin-top: 4px;
}
.summary-row-note { font-size: .75rem; color: var(--pals-mid); font-style: italic; margin-top: 6px; }

/* ── Confirm screen ── */
.confirm-folio {
  text-align: center;
  padding: 24px 16px;
}
.confirm-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}
.confirm-folio-num {
  font-size: 2rem;
  font-weight: 700;
  color: var(--pals-dark);
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}
.confirm-total {
  font-size: 1.2rem;
  color: var(--pals);
  font-weight: 600;
  margin-bottom: 16px;
}
.confirm-instructions { font-size: .9rem; color: var(--pals-mid); line-height: 1.6; }
.confirm-instructions strong { color: var(--on-surface); }

/* ── Divider ── */
.divider {
  border: none;
  border-top: 1px solid var(--outline);
  margin: 16px 0;
}

/* ── Utility ── */
.mt8 { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.mt24 { margin-top: 24px; }
.text-muted { color: var(--pals-mid); font-size: .85rem; }
.text-small { font-size: .8rem; }
.hidden { display: none !important; }

/* ── Responsive tweaks ── */
@media (max-width: 420px) {
  .card { padding: 18px 16px; }
  .catalog-grid { gap: 10px; }
  .product-body { padding: 8px 10px 10px; }
  .stepper { padding: 14px 8px 4px; }
  .step-label { font-size: .6rem; }
}

/* ── Focus visible (a11y) ── */
:focus-visible {
  outline: 2px solid var(--pals);
  outline-offset: 2px;
}
