@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Fraunces:opsz,wght@9..144,600;9..144,700&display=swap');

:root {
  --bg: #f7f4fa;
  --surface: #ffffff;
  --ink: #2a1f36;
  --muted: #6d6278;
  --line: #e4dceb;
  --brand: #682c84;
  --brand-dark: #4a1f5f;
  --brand-soft: #f0e6f6;
  --accent: #c45c26;
  --ok: #1f7a4d;
  --danger: #b42318;
  --sidebar: #3d1f52;
  --sidebar-2: #682c84;
  --shadow: 0 16px 40px rgba(104, 44, 132, 0.12);
  --radius: 16px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 78px;
  --footer-h: 78px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% 0%, #e8d8f2 0%, transparent 55%),
    radial-gradient(800px 380px at 100% 0%, #f6e2d6 0%, transparent 50%),
    var(--bg);
}

button, input, select { font: inherit; }
button { cursor: pointer; border: 0; }
a { color: inherit; text-decoration: none; }

/* ========== LOGIN ========== */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
}
.login-hero {
  background:
    linear-gradient(160deg, rgba(61,31,82,.88), rgba(104,44,132,.78)),
    url('../assets/logoinicio.png') center/cover;
  color: #fff;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: .6rem;
}
.login-hero h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2rem, 4vw, 3rem);
  max-width: 12ch;
  line-height: 1.1;
}
.login-hero p { margin: 0; opacity: .9; max-width: 34ch; }
.login-panel {
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 2rem 1.6rem;
}
.login-card .logo-row {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-bottom: 1.2rem;
}
.login-card .logo-row img { height: 42px; }
.login-card h2 {
  margin: 0 0 .25rem;
  font-family: var(--display);
  font-size: 1.7rem;
  color: var(--brand-dark);
}
.login-card .sub { color: var(--muted); margin: 0 0 1.4rem; }
.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field label { font-size: .88rem; color: var(--muted); font-weight: 600; }
.field-hint {
  display: block;
  margin-top: .25rem;
  font-size: .75rem;
  color: var(--muted);
}
.dir-options {
  display: grid;
  gap: .45rem;
  max-height: 220px;
  overflow: auto;
  padding: .15rem;
}
.dir-option {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  margin: 0;
  padding: .7rem .8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.dir-option:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.dir-option:has(input:checked) {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 22%, transparent);
}
.dir-option input {
  margin-top: .2rem;
  flex: 0 0 auto;
  width: auto;
}
.dir-option-text {
  display: grid;
  gap: .15rem;
  font-size: .9rem;
  line-height: 1.35;
  color: var(--ink);
}
.dir-option-text strong {
  font-weight: 700;
  color: var(--brand-dark);
}
.dir-option-text .dir-addr {
  color: var(--muted);
  font-size: .84rem;
}

.field input, .field select, .search input, .modal input, .modal select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .78rem .9rem;
  background: #fff;
  outline: none;
}
.field input:not([type="checkbox"]):not([type="radio"]):focus,
.search input:focus,
.modal input:not([type="checkbox"]):not([type="radio"]):focus,
.modal select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(104,44,132,.15);
}
/* No estilizar checkboxes/radios como campos de texto */
.modal input[type="checkbox"],
.modal input[type="radio"],
.field input[type="checkbox"],
.field input[type="radio"] {
  width: auto;
  padding: 0;
  border: initial;
  border-radius: initial;
  background: initial;
  box-shadow: none;
}
.hint {
  margin-top: 1rem;
  padding: .85rem 1rem;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: .86rem;
}

/* ========== APP SHELL ========== */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  transition: grid-template-columns .22s ease;
}
.app.collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #fff;
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
  overflow: hidden;
}
.side-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .4rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid rgba(255,255,255,.15);
}
.side-brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-width: 0;
}
.side-brand img {
  height: 34px;
  width: 34px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  padding: 3px;
  flex-shrink: 0;
}
.side-brand-text strong {
  display: block;
  font-family: var(--display);
  font-size: 1.05rem;
}
.side-brand-text small { opacity: .8; font-size: .75rem; }
.collapse-btn {
  background: rgba(255,255,255,.12);
  color: #fff;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  font-size: 1rem;
  display: grid;
  place-items: center;
  line-height: 1;
  z-index: 2;
  position: relative;
}
.collapse-btn:hover { background: rgba(255,255,255,.22); }

.side-user {
  background: rgba(255,255,255,.1);
  border-radius: 14px;
  padding: .75rem .8rem;
  text-align: center;
}
.side-user strong {
  display: block;
  font-size: .95rem;
  text-align: center;
}

.nav { display: grid; gap: .35rem; flex: 1; }
.nav button {
  display: flex;
  align-items: center;
  gap: .7rem;
  text-align: left;
  padding: .72rem .8rem;
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font-weight: 600;
  width: 100%;
  transition: background .15s ease;
}
.nav button:hover, .nav button.active { background: rgba(255,255,255,.16); }
.nav .ico {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.12);
  font-size: .85rem;
  flex-shrink: 0;
}
.side-foot { padding-top: .35rem; }
.side-foot .btn { width: 100%; display: flex; justify-content: center; align-items: center; gap: .4rem; }
.side-foot .ico-only { display: none; }

/* Collapsed sidebar (desktop) */
.app.collapsed .side-brand-text,
.app.collapsed .side-user,
.app.collapsed .nav-label {
  display: none;
}
.app.collapsed .nav button {
  justify-content: center;
  padding: .75rem;
}
.app.collapsed .side-top { justify-content: center; flex-direction: column; align-items: center; }
.app.collapsed .side-brand { justify-content: center; }
.app.collapsed .side-foot .nav-label { display: none; }
.app.collapsed .side-foot .ico-only { display: inline; }

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.content {
  padding: 1rem 1.2rem calc(var(--footer-h) + 1.2rem);
  flex: 1;
  min-width: 0;
}
.top-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.top-left {
  display: flex;
  align-items: center;
  gap: .65rem;
}
.top-strip h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.35rem, 2.5vw, 1.75rem);
  color: var(--brand-dark);
}
.mobile-menu-btn {
  display: none;
  background: var(--brand);
  color: #fff;
  border-radius: 12px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
}
.chips { display: flex; gap: .5rem; flex-wrap: wrap; }
.chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .4rem .8rem;
  font-size: .84rem;
  color: var(--muted);
  box-shadow: 0 4px 14px rgba(0,0,0,.04);
}
.chip strong { color: var(--ink); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.05rem;
}
.cart-panel { width: 100%; }

.client-box {
  display: grid;
  gap: .3rem;
  padding: .9rem 1rem;
  border-radius: 14px;
  background: linear-gradient(135deg, #faf7fc, #f3eaf8);
  border: 1px dashed #c9b3d8;
  margin-bottom: .85rem;
}
.client-box strong { font-size: 1.02rem; }
.client-box small { color: var(--muted); }
.row-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .9rem;
}
.search {
  display: flex;
  gap: .5rem;
  margin-bottom: .9rem;
}
.btn {
  border-radius: 999px;
  padding: .65rem 1rem;
  font-weight: 700;
  background: #fff;
  color: var(--brand);
  border: 1px solid var(--line);
  transition: transform .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(0,0,0,.08); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-danger { background: #fff; color: var(--danger); border-color: #f0c9c5; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.25); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; min-width: 620px; }
th, td { padding: .65rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th {
  background: #f7f2fa;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  position: sticky;
  top: 0;
  z-index: 1;
}
td.num, th.num { text-align: right; }

/* Carrito: texto más compacto y armonioso */
.cart-panel table { min-width: 560px; font-size: .78rem; }
.cart-panel th {
  font-size: .65rem;
  padding: .45rem .5rem;
  letter-spacing: .03em;
}
.cart-panel td {
  padding: .42rem .5rem;
  font-size: .78rem;
  line-height: 1.25;
  color: var(--ink);
}
.cart-panel td:first-child {
  font-size: .72rem;
  font-weight: 600;
  color: var(--brand-dark);
  white-space: nowrap;
}
.cart-panel td:nth-child(2) {
  font-size: .76rem;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cart-panel td.num {
  font-size: .74rem;
  font-variant-numeric: tabular-nums;
}
.cart-panel .qty-input,
.cart-panel .price-input {
  width: 88px;
  font-size: .74rem;
  padding: .28rem .35rem;
  border-radius: 8px;
  pointer-events: auto;
  background: #fff;
}
.cart-panel .price-input {
  width: 110px;
  min-width: 96px;
}
.price-input.price-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(180, 40, 40, .2);
  animation: price-shake .35s ease;
}
@keyframes price-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.cart-panel .lista-badge {
  font-size: .68rem;
  padding: .12rem .45rem;
  font-weight: 600;
}
.cart-panel .btn-danger {
  font-size: .68rem;
  padding: .32rem .55rem;
}

.qty-input, .price-input {
  width: 82px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .35rem .4rem;
  text-align: right;
}
.lista-badge {
  display: inline-block;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-radius: 999px;
  padding: .15rem .55rem;
  font-size: .76rem;
  font-weight: 700;
}

/* Fixed totals footer */
.totals-footer {
  position: sticky;
  bottom: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .6rem;
  align-items: center;
  padding: .75rem 1.1rem;
  min-height: var(--footer-h);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 30px rgba(104, 44, 132, 0.1);
}
.tf-item {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  padding: .35rem .55rem;
  border-radius: 12px;
  background: #faf7fc;
  border: 1px solid var(--line);
}
.tf-item span { font-size: .75rem; color: var(--muted); font-weight: 600; }
.tf-item strong { font-size: clamp(.95rem, 2vw, 1.15rem); }
.tf-total {
  background: linear-gradient(135deg, var(--brand), #8a45a8);
  border: 0;
  color: #fff;
}
.tf-total span { color: rgba(255,255,255,.85); }

/* Botón fijo Generar PDF — inferior derecha */
.fab-generar {
  position: fixed;
  right: 1.25rem;
  bottom: calc(var(--footer-h) + .85rem);
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  padding: .85rem 1.25rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #d96a32);
  color: #fff;
  font-weight: 700;
  font-size: .92rem;
  box-shadow: 0 12px 32px rgba(196, 92, 38, 0.45);
  transition: transform .15s ease, box-shadow .15s ease;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.fab-generar .fab-icon,
.fab-generar .fab-label {
  pointer-events: none;
}
.fab-generar:disabled {
  opacity: .65;
  cursor: wait;
  transform: none;
}
.fab-generar:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(196, 92, 38, 0.5);
}
.fab-generar:active { transform: translateY(0); }
.fab-icon { font-size: 1.1rem; line-height: 1; }
.fab-label { white-space: nowrap; }

/* Product list */
.prod-list { display: grid; gap: .7rem; max-height: min(58vh, 520px); overflow: auto; }
.prod-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .85rem;
  background: #fff;
}
.prod-card-head { margin-bottom: .6rem; }
.prod-card-head strong { display: block; }
.prod-card-head small { color: var(--muted); }
.price-lists { display: flex; flex-wrap: wrap; gap: .4rem; }
.price-chip {
  border: 1px solid var(--line);
  background: #faf7fc;
  border-radius: 12px;
  padding: .45rem .6rem;
  font-size: .8rem;
  color: var(--ink);
  font-weight: 600;
}
.price-chip:hover, .price-chip.selected {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.price-chip span {
  display: block;
  font-size: .7rem;
  color: var(--muted);
  font-weight: 500;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(34, 20, 45, .48);
  display: none;
  align-items: center;
  justify-content: center;
  padding: .75rem;
  z-index: 110;
}
.overlay.open { display: flex; }
.modal {
  width: min(820px, 100%);
  max-height: min(90vh, 920px);
  overflow: auto;
  background: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1.1rem;
}
.modal.sm { width: min(460px, 100%); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
  margin-bottom: .85rem;
}
.modal-head h3 { margin: 0; font-family: var(--display); font-size: 1.15rem; }
.list { display: grid; gap: .5rem; max-height: 52vh; overflow: auto; }
.list-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .75rem .85rem;
  display: flex;
  justify-content: space-between;
  gap: .7rem;
  align-items: center;
  background: #fff;
  text-align: left;
  width: 100%;
}
.list-item:hover { border-color: var(--brand); background: #faf7fc; }
.list-item strong { display: block; }
.list-item small { color: var(--muted); }
.client-modal-toolbar {
  display: flex;
  gap: .5rem;
  margin-bottom: .65rem;
}
.client-modal-toolbar .btn {
  width: 100%;
  justify-content: center;
}
.client-manual-badge {
  display: inline-block;
  margin-top: .25rem;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  background: #fff3e8;
  color: #a85a1a;
  border: 1px solid #f0d0b0;
}
.radio-row { display: grid; gap: .5rem; margin: 1rem 0; }
.radio-row label {
  display: flex;
  gap: .55rem;
  align-items: center;
  padding: .7rem .85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.modal-hint {
  margin: 0 0 .85rem;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.4;
}
.modal-hint strong { color: var(--ink); }

.currency-options {
  display: grid;
  gap: .55rem;
  margin: 0 0 .25rem;
}
.currency-option {
  display: block;
  cursor: pointer;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: .75rem .85rem;
  background: #faf9fc;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.currency-option:hover {
  border-color: #c9b3d8;
  background: #f7f2fa;
}
.currency-option:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 0 0 3px rgba(104, 44, 132, 0.12);
}
.currency-option.is-disabled {
  opacity: .45;
  pointer-events: none;
  cursor: not-allowed;
}
.currency-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}
.currency-option-body {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
}
.currency-flag {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  background: #fff;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.currency-text {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  min-width: 0;
  flex: 1;
}
.currency-text strong {
  font-size: .95rem;
  color: var(--ink);
  line-height: 1.2;
}
.currency-text small {
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.25;
}

.modal-actions {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* Historial ventana completa */
.overlay-full {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0 !important;
  margin: 0;
  align-items: stretch !important;
  justify-content: stretch !important;
  background: #fff;
  z-index: 120;
}
.modal-fullscreen,
#modalHistorial .modal.hist-screen {
  width: 100% !important;
  max-width: none !important;
  height: 100% !important;
  max-height: none !important;
  min-height: 100%;
  border-radius: 0 !important;
  box-shadow: none;
  padding: 0 !important;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden !important;
  background: #fff;
}
.hist-screen-head {
  flex: 0 0 auto;
  padding: .5rem .85rem;
  margin: 0;
  background: linear-gradient(120deg, var(--brand-dark), var(--brand));
  color: #fff;
  border-bottom: 0;
}
.hist-screen-head h3 {
  color: #fff;
  font-size: 1.1rem;
  margin: 0;
}
.hist-screen-head .modal-hint { display: none; }
.hist-screen-head .btn {
  background: #fff;
  color: var(--brand-dark);
  border-color: #fff;
  padding: .4rem .85rem;
}
.hist-head-meta {
  display: block;
  color: rgba(255,255,255,.85);
  font-size: .78rem;
  margin-top: .15rem;
}
.hist-head-actions {
  display: flex;
  gap: .45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.hist-head-actions .btn:not(.btn-primary) {
  background: transparent;
  color: #fff;
  border-color: rgba(255,255,255,.45);
}
.hist-resumen,
.hist-resumen-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 .8rem;
  align-items: center;
  padding: .45rem .85rem;
  margin-bottom: 0;
  border-radius: 0;
  background: linear-gradient(135deg, #faf7fc, #f3eaf8);
  border: 0;
  border-bottom: 1px solid var(--line);
}
.hist-resumen strong,
.hist-resumen-bar strong { font-size: .85rem; grid-column: 1; line-height: 1.2; }
.hist-resumen small,
.hist-resumen-bar small { color: var(--muted); grid-column: 1; font-size: .72rem; }
.hist-resumen span,
.hist-resumen-bar span {
  margin-top: 0;
  grid-column: 2;
  grid-row: 1 / span 2;
  font-weight: 700;
  color: var(--brand-dark);
  font-size: .92rem;
  text-align: right;
}
.hist-resumen-actions {
  display: none;
  gap: .35rem;
  align-items: center;
  grid-column: 3;
  grid-row: 1 / span 2;
}
.hist-resumen-actions .btn-sm {
  padding: .28rem .55rem;
  font-size: .78rem;
  min-width: 2rem;
}
/* Modo dividido: barra compacta solo nombre + total + acciones */
.hist-screen.is-split .hist-screen-head { display: none !important; }
.hist-screen.is-split .hist-resumen-bar {
  grid-template-columns: 1fr auto auto;
  padding: .4rem .65rem;
  background: #fff;
}
.hist-screen.is-split .hist-nit { display: none !important; }
.hist-screen.is-split .hist-resumen-bar strong {
  grid-column: 1;
  grid-row: 1;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-screen.is-split .hist-resumen-bar span {
  grid-column: 2;
  grid-row: 1;
  font-size: .9rem;
}
.hist-screen.is-split .hist-resumen-actions {
  display: flex;
}
.hist-screen.is-split #histResumenActions { display: flex; }

.hist-split-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.hist-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.hist-pane-top {
  flex: 1 1 auto;
  min-height: 0;
}
.hist-screen.is-split {
  --hist-top-pct: 50%;
}
.hist-screen.is-split .hist-pane-top {
  flex: 0 0 var(--hist-top-pct);
  max-height: none;
  border-bottom: 0;
}
.hist-screen.is-split .hist-pane-bottom {
  display: flex !important;
  flex: 1 1 auto;
  min-height: 0;
  background: #f7f4fa;
}
.hist-pane-bottom[hidden] { display: none !important; }
.hist-splitter {
  flex: 0 0 10px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: row-resize;
  touch-action: none;
  background: linear-gradient(180deg, #ebe0f2, #e0d0eb);
  border-top: 1px solid #d4c0e0;
  border-bottom: 1px solid #d4c0e0;
  z-index: 5;
  user-select: none;
}
.hist-screen.is-split .hist-splitter:not([hidden]) {
  display: flex;
}
.hist-splitter:hover,
.hist-splitter.is-dragging {
  background: linear-gradient(180deg, #dcc8ea, #c9aedc);
}
.hist-splitter-grip {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: var(--brand);
  opacity: .55;
  pointer-events: none;
}
.hist-splitter:hover .hist-splitter-grip,
.hist-splitter.is-dragging .hist-splitter-grip {
  opacity: 1;
}
body.hist-resizing {
  cursor: row-resize !important;
  user-select: none !important;
}
.hist-pane-bottom-title {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  padding: .35rem .85rem;
  background: linear-gradient(120deg, #4a1f5f, #682c84);
  color: #fff;
}
.hist-pane-bottom-title strong { font-size: .85rem; }
.hist-pane-bottom-title small { display: none; }
.split-cart-host {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: .65rem .75rem .5rem;
}
.split-cart-host .cart-panel {
  margin: 0;
  box-shadow: none;
}
.hist-pane-bottom > .totals-footer {
  flex: 0 0 auto;
  position: relative;
  bottom: auto;
  box-shadow: 0 -6px 18px rgba(104, 44, 132, 0.08);
}
.hist-hint { display: none !important; }
.hist-table tbody tr.hist-clickable { cursor: pointer; }
.hist-table tbody tr.hist-clickable:hover td {
  background: #efe4f6 !important;
}

.field-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .65rem;
}
.hist-filter-actions {
  justify-content: space-between;
  margin-top: 1.1rem;
}
.hist-filter-actions .btn-primary { margin-left: auto; }
.hist-toolbar { display: none; }
.hist-filters { display: none; }

#modalHistorial .hist-table-host {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  box-shadow: none;
}
#modalHistorial .hist-table-host .empty {
  padding: 2rem 1rem;
}

.check-split {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  margin: .85rem 0 .2rem;
  padding: .75rem .85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #faf7fc;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  z-index: 2;
  pointer-events: auto;
}
.check-split:hover {
  border-color: var(--brand);
  background: #f3eaf8;
}
.check-split:has(input:checked) {
  border-color: var(--brand);
  background: #efe4f6;
  box-shadow: 0 0 0 2px rgba(104, 44, 132, .18);
}
.check-split input[type="checkbox"] {
  margin-top: .15rem;
  width: 1.15rem !important;
  height: 1.15rem !important;
  min-width: 1.15rem;
  accent-color: var(--brand);
  flex-shrink: 0;
  cursor: pointer;
  pointer-events: auto;
  opacity: 1 !important;
  appearance: auto;
  -webkit-appearance: checkbox;
}
.check-split span {
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.check-split strong { font-size: .9rem; color: var(--ink); }
.check-split small { font-size: .78rem; color: var(--muted); }

/* En pantalla dividida el FAB sigue usable sobre el historial */
body.hist-split-active .fab-generar {
  z-index: 140;
  bottom: calc(var(--footer-h) + .85rem);
}
/* Modales (productos, PDF, filtros) por encima del historial en modo split */
body.hist-split-active .overlay:not(#modalHistorial) {
  z-index: 150;
}

@media (max-width: 768px) {
  .hist-screen.is-split .hist-pane-top {
    flex: 0 0 var(--hist-top-pct, 50%);
  }
  .hist-screen.is-split .hist-pane-bottom {
    flex: 1 1 auto;
  }
}
.hist-table {
  width: max-content;
  min-width: 980px;
  border-collapse: collapse;
  font-size: .78rem;
}
.hist-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--brand);
  color: #fff;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  font-weight: 700;
  padding: .55rem .65rem;
  white-space: nowrap;
  text-align: left;
  border: none;
}
.hist-table tbody td {
  padding: .45rem .65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
  color: var(--ink);
  background: #fff;
}
.hist-table tbody tr:hover td { background: #faf7fc; }
.hist-table .col-desc {
  white-space: normal;
  min-width: 220px;
  max-width: 320px;
  line-height: 1.3;
}
.hist-table .col-num { text-align: right; font-variant-numeric: tabular-nums; }
.hist-table .col-factura {
  font-weight: 700;
  color: var(--brand-dark);
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  box-shadow: 4px 0 8px rgba(104, 44, 132, 0.06);
}
.hist-table thead th.col-factura {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--brand-dark);
}
.hist-table .factura-group td {
  background: #f3eaf8;
  font-weight: 700;
  color: var(--brand-dark);
  border-bottom: 1px solid #d9c7e6;
  padding: .55rem .65rem;
}
.hist-table .factura-group td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #f3eaf8;
}
.hist-table .factura-total {
  font-weight: 700;
  color: var(--brand);
}
.hist-table tbody tr.alt td { background: #fcfafd; }
.hist-table tbody tr.alt .col-factura { background: #fcfafd; }
.hist-table tbody tr.alt:hover td,
.hist-table tbody tr.alt:hover .col-factura { background: #faf7fc; }

.toast {
  position: fixed;
  left: 1rem;
  right: auto;
  bottom: calc(var(--footer-h) + .8rem);
  background: var(--ink);
  color: #fff;
  padding: .85rem 1rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: .25s ease;
  z-index: 300;
  max-width: min(360px, calc(100% - 2rem));
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 1.5rem .8rem; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20,10,30,.4);
  z-index: 25;
}
.sidebar-backdrop.open { display: block; }

.flash-cart {
  animation: flashCart .9s ease;
}
@keyframes flashCart {
  0% { box-shadow: 0 0 0 0 rgba(104,44,132,.45); }
  40% { box-shadow: 0 0 0 6px rgba(104,44,132,.2); }
  100% { box-shadow: var(--shadow); }
}

/* ========== TABLET / PC — colapsar solo con clase .collapsed ========== */
@media (min-width: 769px) and (max-width: 1024px) {
  .totals-footer {
    grid-template-columns: repeat(3, 1fr);
    gap: .45rem;
  }
}

/* ========== MOBILE ========== */
@media (max-width: 768px) {
  .login-page { grid-template-columns: 1fr; }
  .login-hero { min-height: 200px; padding: 1.4rem; }

  .app, .app.collapsed {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform .22s ease;
    height: 100vh;
  }
  .app.mobile-open .sidebar { transform: none; }
  .app.mobile-open .side-brand-text,
  .app.mobile-open .side-user { display: block; }
  .app.mobile-open .nav-label { display: inline; }
  .app.mobile-open .nav button { justify-content: flex-start; padding: .72rem .8rem; }
  .app.mobile-open .side-foot .nav-label { display: inline; }
  .app.mobile-open .side-foot .ico-only { display: none; }

  .mobile-menu-btn { display: inline-grid; place-items: center; }
  .collapse-btn { display: none; }
  .content { padding: .85rem .75rem calc(var(--footer-h) + 5.5rem); }

  .row-actions .btn { flex: 1 1 calc(50% - .4rem); text-align: center; }

  .totals-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    grid-template-columns: 1fr 1fr 1fr;
    padding: .55rem .65rem .65rem;
    --footer-h: 72px;
  }
  .tf-item strong { font-size: .92rem; }

  .fab-generar {
    right: .85rem;
    bottom: calc(72px + .65rem);
    padding: .75rem 1rem;
    font-size: .84rem;
  }
  .fab-label { display: none; }
  .fab-generar .fab-icon { font-size: 1.25rem; }
  .fab-generar {
    width: 52px;
    height: 52px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .hist-filters {
    grid-template-columns: 1fr 1fr;
  }
  .hist-filters .btn { grid-column: 1 / -1; }
  .hist-toolbar { padding: .45rem .65rem; }
  .hist-screen-head { padding: .45rem .65rem; }
  #modalHistorial .hist-table-host { margin: 0; }
  .hist-resumen {
    grid-template-columns: 1fr;
  }
  .hist-resumen span {
    grid-column: 1;
    grid-row: auto;
    text-align: left;
    margin-top: .2rem;
  }

  .modal { border-radius: 16px; padding: .9rem; }
  #modalHistorial .modal.hist-screen { border-radius: 0; padding: 0; }
  .toast { bottom: 7.5rem; left: 1rem; right: auto; max-width: min(360px, calc(100% - 2rem)); }
}

@media (max-width: 480px) {
  table { min-width: 540px; }
  th:nth-child(3), td:nth-child(3) { /* lista visible pero compacta */ }
  .chips { width: 100%; }
  .chip { flex: 1; text-align: center; }
}

/* ========== BOOT LOADER (bloquea UI hasta cargar catálogo) ========== */
.boot-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(104, 44, 132, .35), transparent 55%),
    linear-gradient(160deg, #2a1538 0%, #4a1f5f 45%, #1c1028 100%);
  pointer-events: all;
  cursor: wait;
}
.boot-loader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .35s ease, visibility .35s ease;
}
.boot-loader-card {
  width: min(360px, 100%);
  text-align: center;
  color: #fff;
  padding: 1.75rem 1.4rem 1.5rem;
  border-radius: 20px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .16);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
  backdrop-filter: blur(10px);
}
.boot-logo {
  width: 150px;
  max-width: 70%;
  height: auto;
  margin: 0 auto 1.1rem;
  display: block;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, .25));
}
.boot-spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto .95rem;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .22);
  border-top-color: #fff;
  animation: boot-spin .8s linear infinite;
}
@keyframes boot-spin {
  to { transform: rotate(360deg); }
}
@keyframes boot-bar {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
.boot-loader-card strong {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: .35rem;
}
.boot-loader-card p {
  margin: 0 0 1rem;
  font-size: .9rem;
  color: rgba(255, 255, 255, .82);
  line-height: 1.35;
  min-height: 2.4em;
}
.boot-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .18);
  overflow: hidden;
}
.boot-bar span {
  display: block;
  height: 100%;
  width: 35%;
  border-radius: inherit;
  background: linear-gradient(90deg, #c45c26, #f0a060, #c45c26);
  background-size: 200% 100%;
  animation: boot-bar 1.2s ease-in-out infinite;
}
.boot-loader.is-error .boot-spinner {
  border-top-color: #ff8a80;
  animation: none;
  border-style: solid;
}
.boot-loader.is-error .boot-bar { display: none; }
.boot-loader .btn {
  pointer-events: auto;
  cursor: pointer;
}
body.boot-busy {
  overflow: hidden;
}
body.boot-busy .app,
body.boot-busy .fab-generar {
  pointer-events: none !important;
  user-select: none;
}

/* ========== PWA install ========== */
.pwa-install-btn {
  width: 100%;
  margin-top: .85rem;
}
.chips .pwa-install-btn {
  width: auto;
  margin-top: 0;
  padding: .35rem .75rem;
  font-size: .8rem;
}
.pwa-ios-tip {
  margin: .85rem 0 0;
  padding: .65rem .75rem;
  font-size: .78rem;
  line-height: 1.35;
  color: #5a3a6e;
  background: rgba(104, 44, 132, .08);
  border: 1px solid rgba(104, 44, 132, .18);
  border-radius: 10px;
}
