<!DOCTYPE html>
<html lang="es" data-theme="industrial">
<head>
  <script>/*pos_theme_early*/(function(){var t=localStorage.getItem("pos_theme")||"industrial";document.documentElement.setAttribute("data-theme",t);})()</script>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Nexus Autoparts — Punto de Venta</title>
  <link rel="stylesheet" href="/pos/static/css/tokens.css" />

  <style>
    /* =====================================================================
       BASE RESET & LAYOUT SHELL
       ===================================================================== */

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

    html, body {
      height: 100%;
      overflow: hidden;
    }

    body {
      font-family: var(--font-body);
      font-size: var(--text-body);
      font-weight: var(--font-weight-regular);
      background-color: var(--color-bg-base);
      color: var(--color-text-primary);
      transition: background-color var(--duration-normal) var(--ease-in-out),
                  color var(--duration-normal) var(--ease-in-out);
      display: flex;
      flex-direction: column;
    }

    /* Dot-grid for modern theme */
    [data-theme="modern"] body,
    [data-theme="modern"].pos-shell {
      background-color: var(--color-bg-base);
      background-image: radial-gradient(
        circle,
        var(--dot-grid-color) 1px,
        transparent 1px
      );
      background-size: var(--dot-grid-size) var(--dot-grid-size);
    }

    /* =====================================================================
       STATUS BAR (very top)
       ===================================================================== */

    .status-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 36px;
      padding: 0 var(--space-5);
      background-color: var(--color-surface-3);
      border-bottom: 1px solid var(--color-border);
      font-size: var(--text-caption);
      font-weight: var(--font-weight-semibold);
      letter-spacing: var(--tracking-wider);
      text-transform: uppercase;
      color: var(--color-text-muted);
      flex-shrink: 0;
      z-index: var(--z-sticky);
    }

    [data-theme="industrial"] .status-bar {
      background-color: #111111;
      border-bottom-color: var(--color-primary-muted);
    }

    .status-bar__store {
      display: flex;
      align-items: center;
      gap: var(--space-3);
      color: var(--color-text-accent);
      font-family: var(--font-heading);
      font-weight: var(--heading-weight-primary);
      font-size: 0.8rem;
      letter-spacing: var(--tracking-widest);
    }

    .status-bar__store-dot {
      width: 7px;
      height: 7px;
      background-color: var(--color-success);
      border-radius: var(--radius-full);
      box-shadow: 0 0 6px var(--color-success);
      animation: pulse-dot 2.5s ease-in-out infinite;
    }

    @keyframes pulse-dot {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.4; }
    }

    .status-bar__center {
      display: flex;
      align-items: center;
      gap: var(--space-6);
    }

    .status-bar__right {
      display: flex;
      align-items: center;
      gap: var(--space-4);
    }

    .status-bar__user {
      display: flex;
      align-items: center;
      gap: var(--space-2);
      color: var(--color-text-secondary);
    }

    .status-bar__user-avatar {
      width: 20px;
      height: 20px;
      border-radius: var(--radius-full);
      background-color: var(--color-primary);
      color: var(--color-text-inverse);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.6rem;
      font-weight: var(--font-weight-bold);
    }

    /* =====================================================================
       MAIN CONTENT -- split layout
       ===================================================================== */

    .pos-shell {
      display: flex;
      flex-direction: column;
      flex: 1;
      overflow: hidden;
    }

    .pos-main {
      display: flex;
      flex: 1;
      overflow: hidden;
      gap: 0;
    }

    /* =====================================================================
       LEFT PANEL -- Product Browser (60%)
       ===================================================================== */

    .panel-products {
      display: flex;
      flex-direction: column;
      width: 60%;
      min-width: 0;
      border-right: 1px solid var(--color-border);
      background-color: var(--color-bg-base);
      overflow: hidden;
    }

    [data-theme="modern"] .panel-products {
      background-color: transparent;
    }

    /* Search bar row */
    .search-row {
      display: flex;
      align-items: center;
      gap: var(--space-3);
      padding: var(--space-4) var(--space-5);
      background-color: var(--color-surface-1);
      border-bottom: 1px solid var(--color-border);
      flex-shrink: 0;
    }

    .search-wrap {
      position: relative;
      flex: 1;
    }

    .search-icon {
      position: absolute;
      left: var(--space-4);
      top: 50%;
      transform: translateY(-50%);
      color: var(--color-text-muted);
      pointer-events: none;
    }

    .search-input {
      width: 100%;
      height: 48px;
      padding: 0 var(--space-4) 0 44px;
      background-color: var(--color-bg-overlay);
      border: 1.5px solid var(--color-border);
      border-radius: var(--radius-md);
      font-family: var(--font-body);
      font-size: var(--text-body-lg);
      font-weight: var(--font-weight-regular);
      color: var(--color-text-primary);
      outline: none;
      transition: var(--transition-fast);
    }

    .search-input::placeholder { color: var(--color-text-muted); }

    .search-input:focus {
      border-color: var(--color-border-focus);
      box-shadow: var(--shadow-focus);
      background-color: var(--color-bg-overlay);
    }

    [data-theme="modern"] .search-input {
      border-radius: var(--radius-lg);
      background-color: #fff;
    }

    .btn-scan {
      width: 48px; height: 48px;
      display: flex; align-items: center; justify-content: center;
      background-color: var(--btn-secondary-bg);
      border: 1.5px solid var(--btn-secondary-border);
      border-radius: var(--radius-md);
      color: var(--color-primary);
      cursor: pointer;
      transition: var(--transition-fast);
      flex-shrink: 0;
    }

    .btn-scan:hover {
      background-color: var(--btn-secondary-bg-hover);
      box-shadow: var(--shadow-accent);
    }

    /* Quick category buttons */
    .categories-row {
      display: flex; align-items: center; gap: var(--space-2);
      padding: var(--space-3) var(--space-5);
      border-bottom: 1px solid var(--color-border);
      overflow-x: auto; flex-shrink: 0; scrollbar-width: none;
    }
    .categories-row::-webkit-scrollbar { display: none; }

    .category-label {
      font-size: var(--text-caption);
      font-weight: var(--font-weight-semibold);
      letter-spacing: var(--tracking-wider);
      text-transform: uppercase;
      color: var(--color-text-muted);
      white-space: nowrap;
      margin-right: var(--space-1);
    }

    .cat-btn {
      display: flex; align-items: center; gap: var(--space-2);
      padding: var(--space-2) var(--space-4);
      border: 1.5px solid var(--color-border);
      border-radius: var(--radius-sm);
      background-color: transparent;
      font-family: var(--font-body);
      font-size: var(--text-body-sm);
      font-weight: var(--font-weight-semibold);
      color: var(--color-text-secondary);
      cursor: pointer; white-space: nowrap;
      transition: var(--transition-fast);
    }
    .cat-btn:hover {
      border-color: var(--color-primary); color: var(--color-primary);
      background-color: var(--color-primary-muted);
    }
    .cat-btn.active {
      border-color: var(--color-primary); background-color: var(--color-primary);
      color: var(--color-text-inverse);
    }
    [data-theme="industrial"] .cat-btn.active { color: #000; }
    [data-theme="modern"] .cat-btn { border-radius: var(--radius-full); }

    /* Product grid */
    .product-grid-wrap {
      flex: 1; overflow-y: auto;
      padding: var(--space-4) var(--space-5);
      scrollbar-width: thin;
      scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    }
    .product-grid-wrap::-webkit-scrollbar { width: 6px; }
    .product-grid-wrap::-webkit-scrollbar-track { background: var(--scrollbar-track); }
    .product-grid-wrap::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb); border-radius: var(--radius-full); }

    .product-grid {
      display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3);
    }
    @media (max-width: 1100px) { .product-grid { grid-template-columns: repeat(2, 1fr); } }

    /* Product card */
    .product-card {
      position: relative; display: flex; flex-direction: column;
      padding: var(--space-4);
      background-color: var(--color-surface-1);
      border: 1px solid var(--color-border);
      border-radius: var(--radius-md);
      cursor: pointer; transition: var(--transition-fast); overflow: hidden;
    }
    .product-card:hover {
      border-color: var(--color-primary); box-shadow: var(--shadow-md); transform: translateY(-1px);
    }
    .product-card:hover .product-card__add { opacity: 1; transform: scale(1); }

    [data-theme="industrial"] .product-card { background-color: var(--color-surface-1); border-color: #2a2a2a; }
    [data-theme="industrial"] .product-card:hover { border-color: var(--color-primary); box-shadow: 0 0 0 1px var(--color-primary), var(--shadow-md); }
    [data-theme="modern"] .product-card { border-radius: var(--radius-lg); background-color: #fff; box-shadow: var(--shadow-sm); }
    [data-theme="modern"] .product-card:hover { box-shadow: var(--shadow-lg); }

    .product-card__category {
      font-size: var(--text-caption); font-weight: var(--font-weight-semibold);
      letter-spacing: var(--tracking-widest); text-transform: uppercase;
      color: var(--color-primary); margin-bottom: var(--space-1);
    }
    .product-card__name {
      font-family: var(--font-heading); font-size: var(--text-body);
      font-weight: var(--heading-weight-primary); line-height: var(--leading-h5);
      color: var(--color-text-primary); margin-bottom: var(--space-1);
    }
    .product-card__oem {
      font-family: var(--font-mono); font-size: var(--text-caption);
      color: var(--color-text-muted); margin-bottom: var(--space-3);
    }
    .product-card__footer {
      display: flex; align-items: flex-end; justify-content: space-between;
      margin-top: auto; gap: var(--space-2);
    }
    .product-card__price {
      font-family: var(--font-mono); font-size: 1.1rem;
      font-weight: var(--font-weight-bold); color: var(--color-text-primary); line-height: 1;
    }
    .product-card__stock { font-size: var(--text-caption); color: var(--color-text-muted); margin-top: 2px; }
    .product-card__stock.low { color: var(--color-warning); }
    .product-card__stock.out { color: var(--color-error); }

    .product-card__add {
      width: 32px; height: 32px; border: none; border-radius: var(--radius-sm);
      background-color: var(--color-primary); color: var(--color-text-inverse);
      font-size: 1.2rem; font-weight: var(--font-weight-bold);
      display: flex; align-items: center; justify-content: center;
      cursor: pointer; opacity: 0.75; transform: scale(0.95);
      transition: var(--transition-fast); flex-shrink: 0;
    }
    .product-card__add:hover { background-color: var(--color-primary-hover); opacity: 1; transform: scale(1.08) !important; }
    [data-theme="industrial"] .product-card__add { color: #000; }
    [data-theme="modern"] .product-card__add { border-radius: var(--radius-md); }

    @keyframes card-flash {
      0%   { background-color: var(--color-primary-muted); }
      100% { background-color: transparent; }
    }
    .product-card.added { animation: card-flash 0.4s ease forwards; }

    /* =====================================================================
       RIGHT PANEL -- Cart / Ticket (40%)
       ===================================================================== */

    .panel-cart {
      display: flex; flex-direction: column; width: 40%; min-width: 320px;
      background-color: var(--color-surface-1); overflow: hidden; position: relative;
    }
    [data-theme="modern"] .panel-cart { background-color: #fff; box-shadow: -4px 0 20px rgba(26,26,46,0.06); }
    [data-theme="industrial"] .panel-cart { background-color: #141414; border-left: 1px solid #2a2a2a; }

    /* Cart header */
    .cart-header {
      padding: var(--space-4) var(--space-5);
      border-bottom: 1px solid var(--color-border);
      flex-shrink: 0; background-color: var(--color-surface-2);
    }
    [data-theme="industrial"] .cart-header { background-color: #1a1a1a; border-bottom-color: var(--color-primary-muted); }

    .cart-header__top {
      display: flex; align-items: center; justify-content: space-between;
      margin-bottom: var(--space-3);
    }

    .cart-header__sale-id {
      font-family: var(--font-heading); font-size: var(--text-h5);
      font-weight: var(--heading-weight-primary); color: var(--color-text-primary);
      display: flex; align-items: center; gap: var(--space-2);
    }
    .cart-header__sale-id::before {
      content: ''; display: block; width: 4px; height: 20px;
      background-color: var(--color-primary); border-radius: 2px; flex-shrink: 0;
    }

    .cart-header__status {
      font-size: var(--text-caption); font-weight: var(--font-weight-semibold);
      letter-spacing: var(--tracking-wider); text-transform: uppercase;
      color: var(--color-success); background-color: rgba(34,197,94,0.12);
      padding: 3px var(--space-3); border-radius: var(--radius-full);
      border: 1px solid rgba(34,197,94,0.25);
    }

    /* Customer row */
    .customer-row {
      display: flex; align-items: center; gap: var(--space-3);
    }
    .customer-icon {
      width: 34px; height: 34px; border-radius: var(--radius-full);
      background-color: var(--color-primary-muted); border: 1.5px solid var(--color-primary);
      display: flex; align-items: center; justify-content: center;
      color: var(--color-primary); flex-shrink: 0;
    }
    .customer-info { flex: 1; min-width: 0; }
    .customer-info__name {
      font-size: var(--text-body-sm); font-weight: var(--font-weight-semibold);
      color: var(--color-text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .customer-info__label { font-size: var(--text-caption); color: var(--color-text-muted); }
    .btn-change-customer {
      padding: var(--space-1) var(--space-3); border: 1px solid var(--color-border);
      border-radius: var(--radius-full); background: transparent;
      font-family: var(--font-body); font-size: var(--text-caption);
      font-weight: var(--font-weight-semibold); color: var(--color-text-muted);
      cursor: pointer; transition: var(--transition-fast); white-space: nowrap;
    }
    .btn-change-customer:hover { border-color: var(--color-primary); color: var(--color-primary); }

    /* Banner Cliente */
    .banner-cliente {
      padding: var(--space-3) var(--space-4);
      border-bottom: 2px solid var(--color-primary);
      background: var(--color-primary-muted);
      display: none;
    }
    .banner-cliente.visible { display: block; }
    .banner-top { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-2); }
    .banner-avatar {
      width: 36px; height: 36px; border-radius: var(--radius-full);
      background: var(--color-primary); display: flex; align-items: center; justify-content: center;
      font-family: var(--font-heading); font-size: var(--text-body-sm);
      font-weight: var(--font-weight-bold); color: var(--color-text-inverse); flex-shrink: 0;
    }
    .banner-name-block { flex: 1; min-width: 0; }
    .banner-name {
      font-family: var(--font-heading); font-size: var(--text-body);
      font-weight: var(--heading-weight-primary); color: var(--color-text-primary);
      line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .banner-rfc {
      font-family: var(--font-mono); font-size: var(--text-caption);
      color: var(--color-text-muted); letter-spacing: var(--tracking-wide);
    }
    .banner-close {
      width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
      background: transparent; border: 1px solid var(--color-border);
      border-radius: var(--radius-md); cursor: pointer;
      color: var(--color-text-muted); font-size: 14px; transition: var(--transition-fast); flex-shrink: 0;
    }
    .banner-close:hover { background: var(--color-surface-2); color: var(--color-text-primary); }
    .banner-info {
      display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-2);
    }
    .banner-info-item {
      padding: var(--space-2) var(--space-3); background: var(--color-bg-elevated);
      border: 1px solid var(--color-border); border-radius: var(--radius-md);
    }
    .banner-info-label {
      font-size: 10px; color: var(--color-text-muted); text-transform: uppercase;
      letter-spacing: var(--tracking-widest); font-weight: var(--font-weight-semibold);
    }
    .banner-info-value {
      font-size: var(--text-body-sm); font-weight: var(--font-weight-semibold);
      color: var(--color-text-primary); margin-top: 1px;
    }
    .banner-info-value.credit-ok { color: var(--color-success); }
    .banner-info-value.credit-low { color: var(--color-warning-dark); }
    .banner-info-value.credit-none { color: var(--color-error); }

    /* Cart items list */
    .cart-items {
      flex: 1; overflow-y: auto; padding: var(--space-3) var(--space-4);
      scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    }
    .cart-items::-webkit-scrollbar { width: 4px; }
    .cart-items::-webkit-scrollbar-track { background: transparent; }
    .cart-items::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb); border-radius: var(--radius-full); }

    .cart-empty {
      display: flex; flex-direction: column; align-items: center; justify-content: center;
      height: 120px; color: var(--color-text-muted); font-size: var(--text-body-sm); gap: var(--space-2); opacity: 0.6;
    }

    .cart-item {
      display: flex; align-items: center; gap: var(--space-3);
      padding: var(--space-3) var(--space-2); border-bottom: 1px solid var(--color-border);
      transition: var(--transition-fast);
      animation: item-slide-in 0.2s ease;
    }
    @keyframes item-slide-in {
      from { opacity: 0; transform: translateX(10px); }
      to   { opacity: 1; transform: translateX(0); }
    }
    .cart-item:hover { background-color: var(--color-primary-muted); border-radius: var(--radius-sm); }
    .cart-item:last-child { border-bottom: none; }

    .cart-item__qty-ctrl { display: flex; align-items: center; gap: var(--space-1); flex-shrink: 0; }
    .qty-btn {
      width: 26px; height: 26px; border: 1px solid var(--color-border-strong);
      border-radius: var(--radius-sm); background-color: var(--color-surface-3);
      color: var(--color-text-primary); font-size: 0.9rem; font-weight: var(--font-weight-bold);
      cursor: pointer; display: flex; align-items: center; justify-content: center;
      transition: var(--transition-fast); line-height: 1;
    }
    .qty-btn:hover { border-color: var(--color-primary); background-color: var(--color-primary); color: var(--color-text-inverse); }
    [data-theme="industrial"] .qty-btn:hover { color: #000; }
    .qty-display {
      font-family: var(--font-mono); font-size: var(--text-body-sm);
      font-weight: var(--font-weight-bold); color: var(--color-text-primary); min-width: 24px; text-align: center;
    }

    .cart-item__info { flex: 1; min-width: 0; }
    .cart-item__name {
      font-size: var(--text-body-sm); font-weight: var(--font-weight-semibold);
      color: var(--color-text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .cart-item__unit { font-family: var(--font-mono); font-size: var(--text-caption); color: var(--color-text-muted); }
    .cart-item__total {
      font-family: var(--font-mono); font-size: var(--text-body-sm);
      font-weight: var(--font-weight-bold); color: var(--color-text-primary); text-align: right; min-width: 72px;
    }
    .cart-item__remove {
      width: 24px; height: 24px; border: none; border-radius: var(--radius-sm);
      background: transparent; color: var(--color-text-muted); font-size: 1rem;
      cursor: pointer; display: flex; align-items: center; justify-content: center;
      transition: var(--transition-fast); flex-shrink: 0; line-height: 1;
    }
    .cart-item__remove:hover { background-color: rgba(239,68,68,0.15); color: var(--color-error); }

    /* Columnas Costo/Margen (hidden by default, visible with permission) */
    .cart-item__cost, .cart-item__margin {
      display: none; font-family: var(--font-mono); font-size: var(--text-caption);
      text-align: right; min-width: 56px; flex-shrink: 0;
    }
    .cart-item__cost { color: var(--color-text-muted); }
    .cart-item__margin { font-weight: var(--font-weight-bold); }
    .cart-item__margin.margin-high { color: var(--color-success); }
    .cart-item__margin.margin-mid  { color: var(--color-warning); }
    .cart-item__margin.margin-low  { color: var(--color-error); }

    body.show-cost-columns .cart-item__cost,
    body.show-cost-columns .cart-item__margin { display: block; }

    .margin-summary {
      display: none; padding: var(--space-2) var(--space-5);
      border-top: 1px dashed var(--color-border);
      font-size: var(--text-caption); color: var(--color-text-muted);
    }
    body.show-cost-columns .margin-summary { display: flex; justify-content: space-between; }
    .margin-summary__value { font-family: var(--font-mono); font-weight: var(--font-weight-bold); }

    .cost-toggle {
      display: flex; align-items: center; gap: var(--space-2);
      padding: var(--space-1) var(--space-3); border: 1px solid var(--color-border);
      border-radius: var(--radius-sm); background: transparent;
      color: var(--color-text-muted); font-size: 10px; font-family: var(--font-body);
      letter-spacing: var(--tracking-wide); text-transform: uppercase;
      cursor: pointer; transition: var(--transition-fast);
    }
    .cost-toggle:hover { border-color: var(--color-primary); color: var(--color-text-accent); }
    .cost-toggle.active { background: var(--color-primary-muted); border-color: var(--color-primary); color: var(--color-text-accent); }

    /* Cart footer (totals + payment) */
    .cart-footer {
      flex-shrink: 0; border-top: 1px solid var(--color-border);
      background-color: var(--color-surface-2);
    }
    [data-theme="industrial"] .cart-footer { background-color: #1a1a1a; border-top-color: var(--color-primary-muted); }

    .totals-block { padding: var(--space-3) var(--space-5) var(--space-2); }
    .totals-row { display: flex; justify-content: space-between; align-items: center; padding: var(--space-1) 0; }
    .totals-row__label { font-size: var(--text-body-sm); color: var(--color-text-muted); }
    .totals-row__value { font-family: var(--font-mono); font-size: var(--text-body-sm); color: var(--color-text-secondary); }

    .totals-row--total { margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--color-border); }
    .totals-row--total .totals-row__label {
      font-family: var(--font-heading); font-size: var(--text-body-lg);
      font-weight: var(--heading-weight-primary); color: var(--color-text-primary);
      letter-spacing: var(--tracking-wide); text-transform: uppercase;
    }
    .totals-row--total .totals-row__value {
      font-family: var(--font-mono); font-size: 1.5rem;
      font-weight: var(--font-weight-bold); color: var(--color-primary);
    }

    /* COBRAR Button */
    .btn-cobrar {
      display: flex; align-items: center; justify-content: center; gap: var(--space-3);
      width: calc(100% - var(--space-10)); margin: var(--space-3) var(--space-5);
      height: 56px; background-color: var(--btn-primary-bg); border: none;
      border-radius: var(--radius-md);
      font-family: var(--font-heading); font-size: 1.2rem;
      font-weight: var(--heading-weight-primary);
      letter-spacing: var(--tracking-widest); text-transform: uppercase;
      color: var(--btn-primary-text); cursor: pointer;
      transition: var(--transition-fast); box-shadow: var(--shadow-md);
    }
    .btn-cobrar:hover { background-color: var(--btn-primary-bg-hover); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
    .btn-cobrar:active { background-color: var(--btn-primary-bg-active); transform: translateY(0); }
    .btn-cobrar:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
    [data-theme="industrial"] .btn-cobrar { clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%); }
    [data-theme="modern"] .btn-cobrar { border-radius: var(--radius-lg); }

    /* Secondary actions row */
    .secondary-actions {
      display: flex; gap: var(--space-2); padding: 0 var(--space-5) var(--space-4);
    }
    .btn-secondary-action {
      flex: 1; display: flex; align-items: center; justify-content: center; gap: var(--space-1);
      height: 34px; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
      background: transparent; font-family: var(--font-body); font-size: var(--text-caption);
      font-weight: var(--font-weight-semibold); letter-spacing: var(--tracking-wide);
      text-transform: uppercase; color: var(--color-text-muted); cursor: pointer;
      transition: var(--transition-fast);
    }
    .btn-secondary-action:hover { border-color: var(--color-border-strong); color: var(--color-text-secondary); background-color: var(--color-surface-3); }
    .btn-secondary-action.danger:hover { border-color: var(--color-error); color: var(--color-error); background-color: rgba(239,68,68,0.08); }
    [data-theme="modern"] .btn-secondary-action { border-radius: var(--radius-md); }

    /* =====================================================================
       F-KEYS FOOTER BAR
       ===================================================================== */
    .fkeys-footer {
      position: fixed; bottom: 0; left: 0; right: 0;
      background: var(--color-surface-2); border-top: 2px solid var(--color-primary);
      padding: var(--space-2) var(--space-4);
      display: flex; align-items: center; justify-content: center; gap: var(--space-1);
      z-index: var(--z-sticky); box-shadow: var(--shadow-lg);
    }
    .fkey {
      display: flex; align-items: center; gap: var(--space-1);
      padding: var(--space-2) var(--space-3); background: transparent;
      border: 1px solid var(--color-border); border-radius: var(--radius-md);
      cursor: pointer; transition: var(--transition-fast); white-space: nowrap; flex-shrink: 0;
    }
    .fkey:hover { background: var(--color-primary-muted); border-color: var(--color-primary); }
    .fkey:active { background: var(--color-primary); transform: scale(0.96); }
    .fkey:active .fkey-label { color: var(--color-text-inverse); }
    .fkey:active .fkey-key { background: rgba(0,0,0,0.2); color: var(--color-text-inverse); border-color: transparent; }
    .fkey-key {
      display: inline-flex; align-items: center; justify-content: center;
      min-width: 28px; height: 22px; padding: 0 var(--space-2);
      background: var(--color-bg-base); border: 1px solid var(--color-border-strong);
      border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: 11px;
      font-weight: var(--font-weight-bold); color: var(--color-text-accent); line-height: 1;
    }
    .fkey-label {
      font-size: var(--text-caption); font-weight: var(--font-weight-semibold);
      color: var(--color-text-secondary);
    }
    .fkey-sep { width: 1px; height: 24px; background: var(--color-border); margin: 0 var(--space-1); flex-shrink: 0; }
    .fkey.highlight {
      background: var(--color-primary-muted); border-color: var(--color-primary);
    }
    .fkey.highlight .fkey-key {
      background: var(--color-primary); color: var(--color-text-inverse); border-color: var(--color-primary);
    }
    .fkey.highlight .fkey-label { color: var(--color-text-accent); font-weight: var(--font-weight-bold); }

    /* =====================================================================
       MODAL DE PAGO
       ===================================================================== */
    .modal-overlay {
      position: fixed; inset: 0;
      background: var(--overlay-backdrop);
      display: flex; align-items: center; justify-content: center;
      z-index: var(--z-modal);
      opacity: 0; pointer-events: none;
      transition: var(--transition-normal);
    }
    .modal-overlay.open { opacity: 1; pointer-events: auto; }

    .modal-pago {
      background: var(--color-bg-elevated); border: 1px solid var(--color-border);
      border-radius: var(--radius-lg); box-shadow: var(--shadow-xl);
      width: 560px; max-width: 95vw; max-height: 90vh; overflow-y: auto;
      transform: translateY(20px); transition: var(--transition-normal);
    }
    .modal-overlay.open .modal-pago { transform: translateY(0); }

    .modal-header {
      display: flex; align-items: center; justify-content: space-between;
      padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--color-border);
    }
    .modal-header h3 {
      font-family: var(--font-heading); font-size: var(--text-h4);
      font-weight: var(--heading-weight-primary); color: var(--color-text-primary);
    }
    .modal-close {
      width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
      background: transparent; border: 1px solid var(--color-border);
      border-radius: var(--radius-md); cursor: pointer;
      color: var(--color-text-muted); font-size: 18px; transition: var(--transition-fast);
    }
    .modal-close:hover { background: var(--color-surface-2); color: var(--color-text-primary); }

    .total-banner {
      background: var(--color-primary-muted); border-bottom: 2px solid var(--color-primary);
      padding: var(--space-4) var(--space-6);
      display: flex; align-items: center; justify-content: space-between;
    }
    .total-label {
      font-size: var(--text-body); font-weight: var(--font-weight-semibold);
      color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: var(--tracking-wide);
    }
    .total-amount {
      font-family: var(--font-mono); font-size: var(--text-h3);
      font-weight: var(--font-weight-bold); color: var(--color-text-accent);
    }

    .items-summary {
      padding: var(--space-3) var(--space-6); border-bottom: 1px solid var(--color-border);
      font-size: var(--text-body-sm); color: var(--color-text-muted); display: flex; gap: var(--space-4);
    }

    .pago-tabs {
      display: flex; border-bottom: 2px solid var(--color-border); padding: 0 var(--space-6);
    }
    .pago-tab {
      padding: var(--space-3) var(--space-5); font-family: var(--font-body);
      font-size: var(--text-body-sm); font-weight: var(--font-weight-semibold);
      background: transparent; border: none; color: var(--color-text-muted);
      cursor: pointer; border-bottom: 2px solid transparent;
      margin-bottom: -2px; transition: var(--transition-fast);
      display: flex; align-items: center; gap: var(--space-2);
    }
    .pago-tab:hover { color: var(--color-text-primary); }
    .pago-tab.active { color: var(--color-text-accent); border-bottom-color: var(--color-primary); }

    .tab-content { padding: var(--space-6); display: none; }
    .tab-content.active { display: block; }

    .form-group { margin-bottom: var(--space-4); }
    .form-label {
      display: block; font-size: var(--text-caption); font-weight: var(--font-weight-semibold);
      color: var(--color-text-secondary); margin-bottom: var(--space-2);
      text-transform: uppercase; letter-spacing: var(--tracking-wide);
    }
    .form-input {
      width: 100%; padding: var(--space-3) var(--space-4);
      font-family: var(--font-body); font-size: var(--text-body);
      background: var(--color-bg-base); color: var(--color-text-primary);
      border: 1px solid var(--color-border); border-radius: var(--radius-md);
      transition: var(--transition-fast);
    }
    .form-input:focus { outline: none; border-color: var(--color-border-focus); box-shadow: var(--shadow-focus); }
    .form-input-lg {
      font-family: var(--font-mono); font-size: var(--text-h3);
      font-weight: var(--font-weight-bold); text-align: right;
      padding: var(--space-4) var(--space-5);
    }

    .cambio-display {
      background: var(--color-surface-2); border: 1px solid var(--color-border);
      border-radius: var(--radius-md); padding: var(--space-4) var(--space-5);
      display: flex; align-items: center; justify-content: space-between; margin-top: var(--space-4);
    }
    .cambio-label { font-size: var(--text-body-sm); color: var(--color-text-secondary); font-weight: var(--font-weight-semibold); }
    .cambio-amount { font-family: var(--font-mono); font-size: var(--text-h4); font-weight: var(--font-weight-bold); }
    .cambio-amount.positive { color: var(--color-success); }
    .cambio-amount.negative { color: var(--color-error); }

    .quick-amounts { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); margin-top: var(--space-3); }
    .quick-btn {
      padding: var(--space-2) var(--space-3); font-family: var(--font-mono); font-size: var(--text-body-sm);
      font-weight: var(--font-weight-semibold); background: var(--color-surface-2);
      color: var(--color-text-primary); border: 1px solid var(--color-border);
      border-radius: var(--radius-md); cursor: pointer; transition: var(--transition-fast); text-align: center;
    }
    .quick-btn:hover { background: var(--color-primary-muted); border-color: var(--color-primary); }

    .split-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: var(--space-3); align-items: end; margin-bottom: var(--space-3); }
    .split-method {
      padding: var(--space-2) var(--space-3); font-size: var(--text-body-sm);
      font-weight: var(--font-weight-semibold); background: var(--color-surface-2);
      color: var(--color-text-secondary); border-radius: var(--radius-md);
      text-align: center; border: 1px solid var(--color-border);
    }
    .split-remaining {
      background: var(--color-surface-2); border-radius: var(--radius-md);
      padding: var(--space-3) var(--space-4);
      display: flex; align-items: center; justify-content: space-between;
      font-size: var(--text-body-sm); margin-top: var(--space-3);
    }
    .split-remaining .amount { font-family: var(--font-mono); font-weight: var(--font-weight-bold); color: var(--color-text-accent); }

    .cfdi-check {
      display: flex; align-items: center; gap: var(--space-3);
      padding: var(--space-4) var(--space-6); border-top: 1px solid var(--color-border);
      background: var(--color-surface-1);
    }
    .cfdi-check input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--color-primary); cursor: pointer; }
    .cfdi-check label { font-size: var(--text-body-sm); font-weight: var(--font-weight-semibold); color: var(--color-text-secondary); cursor: pointer; }
    .cfdi-check .cfdi-hint { font-size: var(--text-caption); color: var(--color-text-muted); margin-left: auto; }

    .modal-footer {
      padding: var(--space-4) var(--space-6); border-top: 1px solid var(--color-border);
      display: flex; gap: var(--space-3); justify-content: flex-end;
    }

    .btn {
      display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
      padding: var(--space-3) var(--space-6); font-family: var(--font-body); font-size: var(--text-body);
      font-weight: var(--font-weight-semibold); line-height: 1;
      border: 2px solid transparent; border-radius: var(--radius-md);
      cursor: pointer; transition: var(--transition-fast); white-space: nowrap;
    }
    .btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
    .btn:active { transform: scale(0.97); }
    .btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-text); }
    .btn-primary:hover { background: var(--btn-primary-bg-hover); }
    .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
    .btn-ghost { background: transparent; color: var(--color-text-muted); border-color: var(--color-border); }
    .btn-ghost:hover { background: var(--color-surface-2); }
    .btn-lg { padding: var(--space-4) var(--space-8); font-size: var(--text-body-lg); }

    .ref-field { display: flex; gap: var(--space-3); align-items: end; }
    .ref-field .form-group { flex: 1; }
    .form-hint { font-size: var(--text-caption); color: var(--color-text-muted); margin-top: var(--space-1); }
    .status-indicator {
      display: flex; align-items: center; gap: var(--space-2);
      padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
      font-size: var(--text-body-sm); font-weight: var(--font-weight-semibold);
    }
    .status-indicator.pending { background: var(--color-warning-light); color: var(--color-warning-dark); }
    .status-indicator.confirmed { background: var(--color-success-light); color: var(--color-success-dark); }

    .terminal-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
    .terminal-card {
      padding: var(--space-4); background: var(--color-surface-2); border: 2px solid var(--color-border);
      border-radius: var(--radius-md); cursor: pointer; transition: var(--transition-fast); text-align: center;
    }
    .terminal-card:hover { border-color: var(--color-primary); }
    .terminal-card.selected { border-color: var(--color-primary); background: var(--color-primary-muted); }
    .terminal-card .terminal-name { font-size: var(--text-body-sm); font-weight: var(--font-weight-semibold); color: var(--color-text-primary); }
    .terminal-card .terminal-type { font-size: var(--text-caption); color: var(--color-text-muted); margin-top: var(--space-1); }

    /* =====================================================================
       MODAL CONFIRMACION
       ===================================================================== */
    @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
    @keyframes scaleIn { from { opacity: 0; transform: translate(-50%, -50%) scale(0.92); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
    @keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
    @keyframes scaleOut { from { opacity: 1; transform: translate(-50%, -50%) scale(1); } to { opacity: 0; transform: translate(-50%, -50%) scale(0.92); } }

    .confirm-overlay {
      position: fixed; inset: 0; background: var(--overlay-backdrop);
      z-index: calc(var(--z-modal) + 1); display: none; animation: fadeIn 0.2s ease-out forwards;
    }
    .confirm-overlay.active { display: block; }
    .confirm-overlay.closing { animation: fadeOut 0.2s ease-in forwards; }

    .confirm-dialog {
      position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
      z-index: calc(var(--z-modal) + 2);
      background: var(--color-bg-elevated); border: 1px solid var(--color-border);
      border-radius: var(--radius-xl); box-shadow: var(--shadow-xl);
      width: 90%; max-width: 420px; padding: var(--space-6); text-align: center;
      display: none; animation: scaleIn 0.25s ease-out forwards;
    }
    .confirm-dialog.active { display: block; }
    .confirm-dialog.closing { animation: scaleOut 0.2s ease-in forwards; }

    .modal__icon {
      width: 56px; height: 56px; border-radius: var(--radius-full);
      display: flex; align-items: center; justify-content: center;
      font-size: 26px; margin: 0 auto var(--space-4);
    }
    .modal__icon--warning { background: var(--color-warning-light); }
    .modal__title {
      font-family: var(--font-heading); font-size: var(--text-h4);
      font-weight: var(--heading-weight-primary); color: var(--color-text-primary); margin-bottom: var(--space-2);
    }
    .modal__desc {
      font-size: var(--text-body-sm); color: var(--color-text-muted);
      line-height: 1.6; margin-bottom: var(--space-6); padding: 0 var(--space-2);
    }
    .modal__actions { display: flex; gap: var(--space-3); justify-content: center; }
    .modal__btn {
      flex: 1; max-width: 180px; padding: var(--space-3) var(--space-4);
      font-family: var(--font-body); font-size: var(--text-body-sm); font-weight: 600;
      border-radius: var(--radius-md); cursor: pointer; transition: var(--transition-fast);
      border: 1px solid transparent;
    }
    .modal__btn--secondary {
      background: var(--btn-secondary-bg); color: var(--btn-secondary-text); border-color: var(--btn-secondary-border);
    }
    .modal__btn--secondary:hover { background: var(--btn-secondary-bg-hover); }
    .modal__btn--danger {
      background: var(--btn-danger-bg, var(--color-error)); color: var(--btn-danger-text, #fff);
      border-color: var(--btn-danger-bg, var(--color-error));
    }
    .modal__btn--danger:hover { opacity: 0.9; }

    /* =====================================================================
       TICKET TERMICO (hidden, for print)
       ===================================================================== */
    .ticket-print-area { display: none; }

    .ticket {
      background: #ffffff; color: #000000;
      font-family: 'Courier New', 'Consolas', monospace;
      font-size: 11px; line-height: 1.4; padding: 12px; text-align: left;
      border: 1px dashed #ccc;
    }
    .ticket-80 { width: 302px; }
    .ticket .store-name { font-size: 14px; font-weight: bold; text-align: center; margin-bottom: 2px; }
    .ticket .store-tagline { font-size: 9px; text-align: center; color: #555; margin-bottom: 4px; }
    .ticket .store-info { font-size: 9px; text-align: center; color: #333; margin-bottom: 6px; line-height: 1.3; }
    .ticket .divider { border: none; border-top: 1px dashed #999; margin: 6px 0; }
    .ticket .divider-double { border: none; border-top: 2px solid #333; margin: 6px 0; }
    .ticket .ticket-row { display: flex; justify-content: space-between; }
    .ticket .folio-line { font-size: 10px; font-weight: bold; display: flex; justify-content: space-between; margin-bottom: 4px; }
    .ticket .total-section { margin-top: 4px; }
    .ticket .total-line { display: flex; justify-content: space-between; font-size: 11px; }
    .ticket .total-line.grand { font-size: 14px; font-weight: bold; margin-top: 2px; padding-top: 2px; border-top: 1px solid #333; }
    .ticket .payment-section { margin-top: 4px; font-size: 10px; }
    .ticket .footer-section { text-align: center; margin-top: 8px; font-size: 9px; color: #555; }
    .ticket .footer-section .thanks { font-size: 11px; font-weight: bold; color: #000; margin-bottom: 2px; }
    .ticket-80 .item-line-wide {
      display: grid; grid-template-columns: auto 1fr auto auto;
      gap: 8px; align-items: baseline; font-size: 10px; margin-bottom: 3px;
    }
    .ticket-80 .item-line-wide .qty { font-weight: bold; min-width: 24px; text-align: right; }
    .ticket-80 .item-line-wide .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .ticket-80 .item-line-wide .price { text-align: right; min-width: 55px; }
    .ticket-80 .item-line-wide .subtotal { text-align: right; font-weight: bold; min-width: 60px; }

    @media print {
      body * { display: none !important; }
      .ticket-print-area, .ticket-print-area * { display: block !important; }
      .ticket-print-area { position: fixed; top: 0; left: 0; }
      .ticket { border: none; box-shadow: none; padding: 4px; }
      .ticket .item-line-wide { display: grid !important; }
      .ticket .ticket-row, .ticket .folio-line, .ticket .total-line { display: flex !important; }
    }

    /* =====================================================================
       TOAST NOTIFICATION
       ===================================================================== */
    .toast-container {
      position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
      z-index: var(--z-toast); display: flex; flex-direction: column;
      gap: var(--space-2); pointer-events: none;
    }
    .toast {
      padding: var(--space-3) var(--space-5);
      background-color: var(--color-surface-3); border: 1px solid var(--color-border);
      border-left: 3px solid var(--color-primary); border-radius: var(--radius-md);
      font-size: var(--text-body-sm); font-weight: var(--font-weight-semibold);
      color: var(--color-text-primary); box-shadow: var(--shadow-lg); white-space: nowrap;
      animation: toast-in 0.25s ease, toast-out 0.3s ease 1.7s forwards;
    }
    @keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
    @keyframes toast-out { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-6px); } }

    /* =====================================================================
       RESPONSIVE
       ===================================================================== */
    @media (max-width: 900px) {
      .pos-main { flex-direction: column; }
      .panel-products, .panel-cart { width: 100%; min-width: 0; }
      .panel-products { border-right: none; border-bottom: 1px solid var(--color-border); max-height: 55%; }
      .panel-cart { max-height: 45%; }
      .product-grid { grid-template-columns: repeat(2, 1fr); }
      .status-bar__center { display: none; }
      .fkeys-footer { flex-wrap: wrap; }
    }

    @media (max-width: 768px) {
      .fkeys-footer { flex-wrap: wrap; gap: var(--space-1); padding: var(--space-2); }
      .fkey { padding: var(--space-1) var(--space-2); }
      .fkey-label { font-size: 10px; }
      .fkey-key { min-width: 24px; height: 20px; font-size: 10px; }
      .fkey-sep { display: none; }
    }

    .sr-only {
      position: absolute; width: 1px; height: 1px; padding: 0;
      margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0;
    }

    /* Add padding at bottom so content isn't hidden by fixed fkeys bar */
    body { padding-bottom: 50px; }
  </style>
</head>

<body class="pos-shell" id="appBody">

  <!-- ================================================================
       STATUS BAR
       ================================================================ -->
  <header class="status-bar" role="banner">
    <div class="status-bar__store">
      <span class="status-bar__store-dot"></span>
      <span id="branchName">Nexus Autoparts</span>
    </div>
    <div class="status-bar__center">
      <span id="registerInfo">Caja #--</span>
      <span id="statusClock"></span>
    </div>
    <div class="status-bar__right">
      <div class="status-bar__user" aria-label="Usuario activo">
        <div class="status-bar__user-avatar" aria-hidden="true">--</div>
        <span id="employeeName">Empleado</span>
      </div>
    </div>
  </header>

  <!-- ================================================================
       MAIN POS LAYOUT
       ================================================================ -->
  <main class="pos-main" role="main">

    <!-- ============================================================
         LEFT -- PRODUCT BROWSER
         ============================================================ -->
    <section class="panel-products" aria-label="Catalogo de productos">
      <div class="search-row">
        <div class="search-wrap">
          <svg class="search-icon" width="18" height="18" viewBox="0 0 24 24" fill="none"
            stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
            <circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>
          </svg>
          <input class="search-input" type="search" id="itemSearch"
            placeholder="Buscar por nombre, No. parte, codigo..."
            autocomplete="off" spellcheck="false" aria-label="Buscar productos" />
        </div>
      </div>

      <!-- Search Results Dropdown -->
      <div id="searchResults" class="product-grid-wrap" style="display:none;"></div>

      <!-- Totals Panel / Product Grid -->
      <div class="product-grid-wrap" id="totalsPanel">
        <div class="product-grid" id="productGrid" role="list" aria-label="Productos disponibles">
          <!-- Populated by search -->
        </div>
      </div>
    </section>

    <!-- ============================================================
         RIGHT -- CART / TICKET
         ============================================================ -->
    <aside class="panel-cart" aria-label="Carrito de venta">

      <!-- Cart Header -->
      <div class="cart-header">
        <div class="cart-header__top">
          <div class="cart-header__sale-id">Venta Activa</div>
          <button class="cost-toggle" id="costToggle" title="Mostrar costo/margen (Admin)" style="display:none;">C/M</button>
          <span class="cart-header__status">Activa</span>
        </div>

        <!-- Customer Search -->
        <div class="customer-row" id="customerSearchWrap">
          <div class="customer-icon" aria-hidden="true">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none"
              stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
              <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/>
            </svg>
          </div>
          <div class="customer-info" style="flex:1;position:relative;">
            <input type="text" id="customerSearch" class="search-input"
              style="height:34px;font-size:var(--text-body-sm);padding-left:var(--space-3);"
              placeholder="F2 — Buscar cliente..." autocomplete="off" />
            <div id="customerAutocomplete" style="display:none;position:absolute;top:100%;left:0;right:0;z-index:100;background:var(--color-bg-elevated);border:1px solid var(--color-border);border-radius:var(--radius-md);max-height:200px;overflow-y:auto;box-shadow:var(--shadow-lg);">
            </div>
          </div>
          <button class="btn-change-customer" onclick="POS.showNewCustomerModal()" aria-label="Nuevo cliente">+ Nuevo</button>
        </div>

        <!-- Selected Customer Display -->
        <div id="customerSelected" style="display:none;" class="customer-row">
          <div class="customer-icon" aria-hidden="true">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none"
              stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
              <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/>
            </svg>
          </div>
          <div class="customer-info">
            <div class="customer-info__name" id="customerName">--</div>
            <div class="customer-info__label">
              <span id="customerTier">P1</span> |
              <span id="customerCredit">Credito: $0 / $0</span>
            </div>
          </div>
          <button class="btn-change-customer" onclick="POS.clearCustomer()" aria-label="Cambiar cliente">Cambiar</button>
        </div>
      </div>

      <!-- Banner Cliente (shown when customer selected) -->
      <div class="banner-cliente" id="vehicleBanner">
        <div class="banner-info">
          <div class="banner-info-item">
            <div class="banner-info-label">Vehiculo</div>
            <div class="banner-info-value" id="vehicleInfo">--</div>
          </div>
          <div class="banner-info-item">
            <div class="banner-info-label">Ultima compra</div>
            <div class="banner-info-value" id="lastPurchaseInfo">--</div>
          </div>
        </div>
      </div>

      <!-- Cart Items -->
      <div class="cart-items" id="cartItems" role="list" aria-label="Articulos en carrito">
        <!-- Empty state -->
        <div id="cartEmpty" class="cart-empty" role="status">
          <svg width="32" height="32" viewBox="0 0 24 24" fill="none"
            stroke="currentColor" stroke-width="1.5" opacity="0.4" aria-hidden="true">
            <circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/>
            <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/>
          </svg>
          <span>Carrito vacio -- agrega productos con F1</span>
        </div>

        <!-- Cart table -->
        <table id="cartTable" style="display:none;width:100%;border-collapse:collapse;font-size:var(--text-body-sm);">
          <thead>
            <tr style="border-bottom:1px solid var(--color-border);">
              <th style="text-align:left;padding:var(--space-2);">#</th>
              <th style="text-align:left;padding:var(--space-2);">Producto</th>
              <th style="text-align:center;padding:var(--space-2);">Cant</th>
              <th style="text-align:right;padding:var(--space-2);">P.Unit</th>
              <th style="text-align:center;padding:var(--space-2);">Desc%</th>
              <th style="text-align:right;padding:var(--space-2);">Importe</th>
              <th id="thCost" style="display:none;text-align:right;padding:var(--space-2);">Costo</th>
              <th id="thMargin" style="display:none;text-align:center;padding:var(--space-2);">Margen</th>
              <th style="width:30px;"></th>
            </tr>
          </thead>
          <tbody id="cartBody"></tbody>
        </table>
      </div>

      <!-- Margin Summary -->
      <div class="margin-summary" id="marginSummary">
        <span>Margen promedio:</span>
        <span class="margin-summary__value" id="avgMargin">--</span>
      </div>

      <!-- Cart Footer -->
      <div class="cart-footer">
        <div class="totals-block">
          <div class="totals-row">
            <span class="totals-row__label">Subtotal</span>
            <span class="totals-row__value" id="dispSubtotal">$0.00</span>
          </div>
          <div class="totals-row" id="discountRow" style="display:none;">
            <span class="totals-row__label">Descuento</span>
            <span class="totals-row__value" id="dispDiscount">$0.00</span>
          </div>
          <div class="totals-row">
            <span class="totals-row__label">IVA (16%)</span>
            <span class="totals-row__value" id="dispTax">$0.00</span>
          </div>
          <div class="totals-row totals-row--total">
            <span class="totals-row__label">Total</span>
            <span class="totals-row__value" id="dispTotal">$0.00</span>
          </div>
        </div>

        <!-- COBRAR Button -->
        <button class="btn-cobrar" id="btnCobrar" onclick="POS.checkout()" aria-label="Procesar cobro">
          <span>COBRAR</span>
        </button>

        <!-- Secondary Actions -->
        <div class="secondary-actions" role="toolbar" aria-label="Acciones secundarias">
          <button class="btn-secondary-action" onclick="POS.saveQuotation()" title="Cotizacion (F4)">Cotizar</button>
          <button class="btn-secondary-action" onclick="POS.showLastSale()" title="Ultima venta (F5)">Ult.Venta</button>
          <button class="btn-secondary-action danger" id="btnCancelSale" title="Cancelar (Esc)">Cancelar</button>
        </div>
      </div>
    </aside>
  </main>

  <!-- ================================================================
       F-KEYS FOOTER BAR
       ================================================================ -->
  <div class="fkeys-footer" id="fkeysFooter">
    <div class="fkey" onclick="document.getElementById('itemSearch').focus()" title="Buscar producto">
      <span class="fkey-key">F1</span><span class="fkey-label">Buscar</span>
    </div>
    <div class="fkey" onclick="document.getElementById('customerSearch').focus()" title="Seleccionar cliente">
      <span class="fkey-key">F2</span><span class="fkey-label">Cliente</span>
    </div>
    <div class="fkey highlight" onclick="POS.checkout()" title="Cobrar venta">
      <span class="fkey-key">F3</span><span class="fkey-label">Cobrar</span>
    </div>
    <div class="fkey" onclick="POS.saveQuotation()" title="Cotizacion">
      <span class="fkey-key">F4</span><span class="fkey-label">Cotizacion</span>
    </div>
    <div class="fkey-sep"></div>
    <div class="fkey" onclick="POS.showLastSale()" title="Ultima venta">
      <span class="fkey-key">F5</span><span class="fkey-label">Ult.Venta</span>
    </div>
    <div class="fkey" onclick="POS.openDrawer()" title="Abrir cajon">
      <span class="fkey-key">F6</span><span class="fkey-label">Cajon</span>
    </div>
    <div class="fkey-sep"></div>
    <div class="fkey" title="Cantidad +/-">
      <span class="fkey-key">+/-</span><span class="fkey-label">Cantidad</span>
    </div>
    <div class="fkey" title="Descuento">
      <span class="fkey-key">*</span><span class="fkey-label">Descuento</span>
    </div>
    <div class="fkey-sep"></div>
    <div class="fkey" id="fkeyEsc" title="Cancelar">
      <span class="fkey-key">Esc</span><span class="fkey-label">Cancelar</span>
    </div>
  </div>

  <!-- ================================================================
       PAYMENT MODAL (modal-pago + calculadora-cambio)
       ================================================================ -->
  <div class="modal-overlay" id="paymentModal">
    <div class="modal-pago">
      <!-- Header -->
      <div class="modal-header">
        <h3>Cobrar Venta</h3>
        <button class="modal-close" onclick="POS.closePaymentModal()">&#x2715;</button>
      </div>

      <!-- Total Banner -->
      <div class="total-banner">
        <span class="total-label">Total a Cobrar</span>
        <span class="total-amount" id="modalTotal">$0.00</span>
      </div>

      <!-- Items Summary -->
      <div class="items-summary" id="modalSummary">
        <span id="modalItemCount">0 productos</span>
        <span>&#x2022;</span>
        <span id="modalCustomerName">Publico General</span>
      </div>

      <!-- Payment Tabs -->
      <div class="pago-tabs">
        <button class="pago-tab active" data-method="efectivo" onclick="POS.selectPaymentMethod('efectivo', this)">
          Efectivo
        </button>
        <button class="pago-tab" data-method="transferencia" onclick="POS.selectPaymentMethod('transferencia', this)">
          Transferencia
        </button>
        <button class="pago-tab" data-method="tarjeta" onclick="POS.selectPaymentMethod('tarjeta', this)">
          Tarjeta
        </button>
        <button class="pago-tab" data-method="mixto" onclick="POS.selectPaymentMethod('mixto', this)">
          Mixto
        </button>
      </div>

      <!-- TAB: Efectivo -->
      <div class="tab-content active" id="cashPayment">
        <div class="form-group">
          <label class="form-label">Monto recibido</label>
          <input type="number" class="form-input form-input-lg" id="cashReceived"
            placeholder="0.00" step="0.01" min="0" oninput="POS.updateChange()" />
        </div>
        <div class="quick-amounts" id="quickAmounts">
          <!-- Populated dynamically -->
        </div>
        <div class="cambio-display">
          <span class="cambio-label">Cambio</span>
          <span class="cambio-amount positive" id="changeDisplay">$0.00</span>
        </div>
      </div>

      <!-- TAB: Transferencia / Tarjeta -->
      <div class="tab-content" id="refPayment">
        <div class="form-group">
          <label class="form-label">Monto</label>
          <input type="text" class="form-input form-input-lg" id="refAmount" readonly />
        </div>
        <div class="form-group">
          <label class="form-label">Referencia / No. operacion</label>
          <input type="text" class="form-input" id="paymentRef" placeholder="No. de referencia" />
        </div>
        <div class="form-hint">Verificar que el pago se haya recibido antes de confirmar</div>
      </div>

      <!-- TAB: Mixto -->
      <div class="tab-content" id="mixedPayment">
        <div class="mixed-row" style="margin-bottom:var(--space-3);">
          <div class="form-group">
            <label class="form-label">Metodo 1</label>
            <select class="form-input" style="margin-bottom:var(--space-2);">
              <option value="efectivo">Efectivo</option>
              <option value="tarjeta">Tarjeta</option>
              <option value="transferencia">Transferencia</option>
            </select>
            <input type="number" class="form-input mixed-amount" placeholder="0.00" step="0.01" oninput="POS.updateMixedTotal()" />
            <input type="text" class="form-input" placeholder="Referencia (si aplica)" style="margin-top:var(--space-2);" />
          </div>
        </div>
        <div class="mixed-row" style="margin-bottom:var(--space-3);">
          <div class="form-group">
            <label class="form-label">Metodo 2</label>
            <select class="form-input" style="margin-bottom:var(--space-2);">
              <option value="tarjeta">Tarjeta</option>
              <option value="efectivo">Efectivo</option>
              <option value="transferencia">Transferencia</option>
            </select>
            <input type="number" class="form-input mixed-amount" placeholder="0.00" step="0.01" oninput="POS.updateMixedTotal()" />
            <input type="text" class="form-input" placeholder="Referencia (si aplica)" style="margin-top:var(--space-2);" />
          </div>
        </div>
        <div class="split-remaining">
          <span>Restante:</span>
          <span class="amount" id="mixedRemaining">$0.00</span>
        </div>
      </div>

      <!-- CFDI Checkbox -->
      <div class="cfdi-check">
        <input type="checkbox" id="cfdiCheck" />
        <label for="cfdiCheck">Facturar CFDI</label>
        <span class="cfdi-hint" id="cfdiHint"></span>
      </div>

      <!-- Footer -->
      <div class="modal-footer">
        <button class="btn btn-ghost" onclick="POS.closePaymentModal()">Cancelar</button>
        <button class="btn btn-primary btn-lg" id="btnConfirmPayment" onclick="POS.confirmPayment()">Confirmar Pago</button>
      </div>
    </div>
  </div>

  <!-- ================================================================
       CANCEL SALE CONFIRMATION MODAL
       ================================================================ -->
  <div class="confirm-overlay" id="overlay-cancelar-venta" onclick="if(event.target===this) closeCancelModal()"></div>
  <div class="confirm-dialog" id="modal-cancelar-venta">
    <div class="modal__icon modal__icon--warning">&#x26A0;</div>
    <div class="modal__title">Cancelar venta?</div>
    <div class="modal__desc">Se perderan los articulos agregados al ticket actual.</div>
    <div class="modal__actions">
      <button class="modal__btn modal__btn--secondary" onclick="closeCancelModal()">No, continuar</button>
      <button class="modal__btn modal__btn--danger" id="btnConfirmCancel">Si, cancelar</button>
    </div>
  </div>

  <!-- ================================================================
       TICKET PRINT AREA (hidden div for thermal print)
       ================================================================ -->
  <div class="ticket-print-area" id="ticketPrintArea">
    <div class="ticket ticket-80" id="ticketContent">
      <!-- Populated by JS after successful sale -->
    </div>
  </div>

  <!-- ================================================================
       TICKET PREVIEW MODAL (on-screen after sale)
       ================================================================ -->
  <div class="modal-overlay" id="ticketModal">
    <div class="modal-pago" style="width:380px;">
      <div class="modal-header">
        <h3>Ticket de Venta</h3>
        <button class="modal-close" onclick="POS.closeTicketModal()">&#x2715;</button>
      </div>
      <div style="padding:var(--space-4);display:flex;justify-content:center;">
        <div class="ticket ticket-80" id="ticketPreviewContent">
          <!-- Populated by JS -->
        </div>
      </div>
      <div class="modal-footer">
        <button class="btn btn-ghost" onclick="POS.closeTicketModal()">Cerrar</button>
        <button class="btn btn-primary" onclick="POS.printTicket()">Imprimir</button>
      </div>
    </div>
  </div>

  <!-- ================================================================
       NEW CUSTOMER MODAL
       ================================================================ -->
  <div class="modal-overlay" id="newCustomerModal">
    <div class="modal-pago" style="width:480px;">
      <div class="modal-header">
        <h3>Nuevo Cliente</h3>
        <button class="modal-close" onclick="POS.closeNewCustomerModal()">&#x2715;</button>
      </div>
      <div style="padding:var(--space-6);">
        <div class="form-group">
          <label class="form-label">Nombre *</label>
          <input type="text" class="form-input" id="ncName" placeholder="Nombre o Razon Social" />
        </div>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:var(--space-3);">
          <div class="form-group">
            <label class="form-label">RFC</label>
            <input type="text" class="form-input" id="ncRfc" placeholder="XAXX010101000" maxlength="13" />
          </div>
          <div class="form-group">
            <label class="form-label">Telefono</label>
            <input type="text" class="form-input" id="ncPhone" placeholder="55 1234 5678" />
          </div>
        </div>
        <div class="form-group">
          <label class="form-label">Razon Social</label>
          <input type="text" class="form-input" id="ncRazonSocial" placeholder="Razon Social para facturacion" />
        </div>
        <div class="form-group">
          <label class="form-label">Email</label>
          <input type="email" class="form-input" id="ncEmail" placeholder="correo@ejemplo.com" />
        </div>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:var(--space-3);">
          <div class="form-group">
            <label class="form-label">Lista de precios</label>
            <select class="form-input" id="ncPriceTier">
              <option value="1">P1 Mostrador</option>
              <option value="2">P2 Taller</option>
              <option value="3">P3 Mayoreo</option>
            </select>
          </div>
          <div class="form-group">
            <label class="form-label">Limite de credito</label>
            <input type="number" class="form-input" id="ncCreditLimit" placeholder="0.00" step="0.01" />
          </div>
        </div>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:var(--space-3);">
          <div class="form-group">
            <label class="form-label">Regimen Fiscal</label>
            <select class="form-input" id="ncRegimenFiscal">
              <option value="">-- Seleccionar --</option>
              <option value="601">601 - General de Ley PM</option>
              <option value="612">612 - Personas Fisicas</option>
              <option value="621">621 - Inc. Fiscal</option>
              <option value="626">626 - RESICO</option>
            </select>
          </div>
          <div class="form-group">
            <label class="form-label">Uso CFDI</label>
            <select class="form-input" id="ncUsoCfdi">
              <option value="G03">G03 - Gastos en general</option>
              <option value="G01">G01 - Adq. de mercancias</option>
              <option value="P01">P01 - Por definir</option>
            </select>
          </div>
        </div>

        <div style="margin-top:var(--space-4);border-top:1px solid var(--color-border);padding-top:var(--space-4);">
          <div class="form-label" style="margin-bottom:var(--space-3);">Vehiculo (opcional)</div>
          <div style="display:grid;grid-template-columns:1fr 1fr;gap:var(--space-3);">
            <div class="form-group"><input type="text" class="form-input" id="ncVehMake" placeholder="Marca" /></div>
            <div class="form-group"><input type="text" class="form-input" id="ncVehModel" placeholder="Modelo" /></div>
            <div class="form-group"><input type="text" class="form-input" id="ncVehYear" placeholder="Ano" /></div>
            <div class="form-group"><input type="text" class="form-input" id="ncVehPlates" placeholder="Placas" /></div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button class="btn btn-ghost" onclick="POS.closeNewCustomerModal()">Cancelar</button>
        <button class="btn btn-primary" onclick="POS.saveNewCustomer()">Guardar Cliente</button>
      </div>
    </div>
  </div>

  <!-- ================================================================
       TOAST CONTAINER
       ================================================================ -->
  <div class="toast-container" id="toastContainer" aria-live="assertive" aria-atomic="true"></div>

  <!-- ================================================================
       JAVASCRIPT
       ================================================================ -->
  <script src="/pos/static/js/app-init.js"></script>
  <script src="/pos/static/js/pos.js"></script>

  <script>
    // Cancel sale button wiring
    document.getElementById('btnCancelSale').addEventListener('click', function() {
      document.getElementById('overlay-cancelar-venta').classList.add('active');
      document.getElementById('modal-cancelar-venta').classList.add('active');
      document.body.style.overflow = 'hidden';
    });

    document.getElementById('btnConfirmCancel').addEventListener('click', function() {
      closeCancelModal();
      // Clear cart via POS module
      if (typeof POS !== 'undefined') {
        // Clear each item
        const tbody = document.getElementById('cartBody');
        while (tbody && tbody.firstChild) {
          POS.removeFromCart(0);
        }
        POS.clearCustomer();
      }
    });

    function closeCancelModal() {
      const overlay = document.getElementById('overlay-cancelar-venta');
      const dialog = document.getElementById('modal-cancelar-venta');
      overlay.classList.add('closing');
      dialog.classList.add('closing');
      setTimeout(() => {
        overlay.classList.remove('active', 'closing');
        dialog.classList.remove('active', 'closing');
        document.body.style.overflow = '';
      }, 200);
    }

    // Cost toggle (show only if permitted)
    document.getElementById('costToggle').addEventListener('click', function() {
      document.body.classList.toggle('show-cost-columns');
      this.classList.toggle('active');
    });

    // Clock
    function updateClock() {
      const now = new Date();
      const opts = { year: 'numeric', month: 'short', day: 'numeric',
                     hour: '2-digit', minute: '2-digit', hour12: true };
      const el = document.getElementById('statusClock');
      if (el) el.textContent = now.toLocaleString('es-MX', opts);
    }
    updateClock();
    setInterval(updateClock, 30000);
  </script>

</body>
</html>
