/* ===== VARIABLES ===== */
:root {
  --bg: #f0f2f5;
  --surface: #fff;
  --surface2: #f8f9fb;
  --border: #e2e5ea;
  --border2: #d0d5dd;
  --text: #1a1d23;
  --text2: #5a6070;
  --text3: #8b92a0;
  --accent: #2563eb;
  --accent-bg: #eff6ff;
  --accent-text: #1d4ed8;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --radius: 8px;
  --nav-w: 220px;
  --mob-nav-w: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ===== DESKTOP LAYOUT ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--nav-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 20;
  top: 0; left: 0;
}
.main { margin-left: var(--nav-w); flex: 1; padding: 24px; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%);
}
.logo-name { font-size: 22px; font-weight: 900; color: #fff; letter-spacing: -1px; }
.logo-sub { font-size: 11px; color: rgba(255,255,255,0.7); margin-top: 2px; }
.sidebar-nav { padding: 12px 8px; flex: 1; overflow-y: auto; }
.nav-section {
  font-size: 10px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .8px; padding: 12px 10px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 7px; cursor: pointer;
  color: var(--text2); font-size: 13px; font-weight: 500;
  margin-bottom: 2px; border: none; background: none;
  width: 100%; text-align: left; transition: all .15s;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent-text); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text3);
}

/* ===== MOBILE RIGHT NAV ===== */
.mobile-rightnav {
  display: none;
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: var(--mob-nav-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 30;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 0;
  box-shadow: -2px 0 12px rgba(0,0,0,.08);
}
.mob-nav-btn {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 10px 6px; cursor: pointer; border: none;
  background: none; color: var(--text3); font-size: 9px; font-weight: 600;
  border-radius: 10px; margin: 2px 6px; width: 52px;
  transition: all .15s; text-transform: uppercase; letter-spacing: .3px;
}
.mob-nav-btn.active { color: var(--accent); background: var(--accent-bg); }
.mob-nav-btn svg { width: 22px; height: 22px; }

/* ===== MOBILE TOP BAR ===== */
.mobile-topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0;
  height: 52px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 25; align-items: center;
  padding: 0 80px 0 16px;
  justify-content: space-between;
}
.mobile-topbar .logo-name { font-size: 18px; font-weight: 900; color: var(--accent); }

/* ===== FAB ===== */
.mob-fab {
  position: fixed; bottom: 24px; left: 16px;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  cursor: pointer; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(37,99,235,.4);
  z-index: 25; font-size: 24px; line-height: 1;
}

/* ===== PAGE ===== */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 10px; flex-wrap: wrap;
}
.page-title { font-size: 20px; font-weight: 700; }
.page-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ===== STATS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px; margin-bottom: 20px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px;
  transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.07); }
.stat-label { font-size: 10px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .5px; }
.stat-val { font-size: 24px; font-weight: 800; color: var(--text); margin-top: 6px; }
.stat-val-sm { font-size: 18px; }

/* ===== CARD ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.card-title {
  font-size: 14px; font-weight: 600; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px; color: var(--text);
}

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--surface2); padding: 9px 14px; text-align: left;
  font-weight: 700; font-size: 11px; color: var(--text2);
  text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 11px 14px; color: var(--text); vertical-align: middle; }
.td-m { color: var(--text2); }

/* ===== MOBILE CARDS LIST ===== */
.list-cards { display: none; }
.list-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; margin-bottom: 10px;
}
.list-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.list-card-title { font-weight: 700; font-size: 14px; }
.list-card-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.list-card-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 13px; }
.list-card-label { color: var(--text3); font-size: 12px; }
.list-card-actions { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; padding: 3px 9px;
  border-radius: 99px; font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-blue { background: var(--accent-bg); color: var(--accent-text); }
.badge-yellow { background: var(--warning-bg); color: var(--warning); }
.badge-red { background: var(--danger-bg); color: var(--danger); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; font-size: 13px;
  font-weight: 600; cursor: pointer; border: none;
  transition: all .15s; touch-action: manipulation; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover, .btn-primary:active { background: #1d4ed8; transform: translateY(-1px); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border2); }
.btn-secondary:hover, .btn-secondary:active { background: var(--bg); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ===== FORM ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1/-1; }
label { font-size: 12px; font-weight: 600; color: var(--text2); }
input, select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border2); border-radius: 8px;
  font-size: 14px; color: var(--text); background: var(--surface);
  outline: none; transition: border .15s; font-family: inherit;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
input[readonly] { background: var(--surface2); color: var(--text2); }
textarea { resize: vertical; min-height: 70px; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%238b92a0' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* ===== SEARCH BAR ===== */
.search-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.search-input-wrap { position: relative; flex: 1; min-width: 160px; }
.search-input-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text3); width: 15px; height: 15px; pointer-events: none; }
.search-input-wrap input { padding-left: 32px; }

/* ===== FILTERS ===== */
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-row .active-filter { background: var(--accent-bg); color: var(--accent-text); border-color: var(--accent); }

/* ===== AUTOCOMPLETE ===== */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 60; max-height: 240px; overflow-y: auto; margin-top: 4px;
}
.autocomplete-item { padding: 10px 14px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover, .autocomplete-item:active { background: var(--bg); }
.autocomplete-code { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 100; display: flex; align-items: flex-start;
  justify-content: center; padding: 24px 14px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 16px;
  width: 100%; max-width: 760px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  padding: 18px 20px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.modal-title { font-size: 16px; font-weight: 700; line-height: 1.3; }
.modal-body { padding: 18px 20px; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}
.close-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text3); padding: 6px; border-radius: 7px; display: flex; flex-shrink: 0;
}
.close-btn:hover { background: var(--bg); color: var(--text); }

/* ===== LINEAS PEDIDO ===== */
.linea-head {
  display: grid;
  grid-template-columns: minmax(0,2fr) 72px 100px 70px 90px 38px;
  gap: 6px; padding: 5px 8px; font-size: 10px; font-weight: 700;
  color: var(--text3); text-transform: uppercase; letter-spacing: .4px;
}
.linea-item {
  display: grid;
  grid-template-columns: minmax(0,2fr) 72px 100px 70px 90px 38px;
  gap: 6px; align-items: center; padding: 7px 8px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 5px;
}
.linea-item input { padding: 5px 8px; font-size: 12px; border-radius: 6px; }
.linea-importe { font-weight: 700; font-size: 13px; text-align: right; }
.linea-del {
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid #fecaca; border-radius: 6px; padding: 5px 8px;
  cursor: pointer; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.linea-mob {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; margin-bottom: 8px;
}
.linea-mob-name { font-weight: 600; font-size: 13px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.linea-mob-fields { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.linea-mob-fields .form-group { gap: 3px; }
.linea-mob-fields label { font-size: 10px; }
.linea-mob-fields input { padding: 6px 8px; font-size: 13px; }
.linea-mob-total { margin-top: 6px; text-align: right; font-size: 13px; font-weight: 700; color: var(--accent-text); }
.prod-add-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }

/* ===== TOTALS ===== */
.totals-box { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-top: 14px; }
.total-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; color: var(--text2); }
.total-row.grand { font-size: 16px; font-weight: 800; color: var(--text); border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px; }

/* ===== ALERTS ===== */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-info { background: var(--accent-bg); color: var(--accent-text); border: 1px solid #bfdbfe; }

/* ===== MISC ===== */
.loading { display: flex; align-items: center; justify-content: center; padding: 48px; color: var(--text3); flex-direction: column; gap: 12px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 48px 20px; color: var(--text3); }
.empty-icon { font-size: 40px; margin-bottom: 10px; }
.section { display: none; }
.section.active { display: block; }

/* ===== PRINT TICKET ===== */
/* ============================================================================
   IMPRESION — punto de venta (80 mm y 58 mm)
   ========================================================================== */
@media print {
  @page { margin: 0; }

  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; }

  body * { visibility: hidden !important; }
  #ticket-print-area, #ticket-print-area * { visibility: visible !important; }

  #ticket-print-area {
    display: block !important;
    position: absolute; top: 0; left: 0;
    width: auto;
  }

  .tk { page-break-after: always; }
  .tk:last-child { page-break-after: auto; }
  .tk-corte { display: block; height: 12mm; }
}
.ticket {
  width: 80mm; padding: 10px; font-family: 'Courier New', monospace;
  font-size: 12px; color: #000; background: #fff;
}
.ticket-header { text-align: center; margin-bottom: 8px; border-bottom: 1px dashed #000; padding-bottom: 8px; }
.ticket-title { font-size: 16px; font-weight: bold; }
.ticket-sub { font-size: 11px; }
.ticket-row { display: flex; justify-content: space-between; padding: 2px 0; }
.ticket-divider { border-top: 1px dashed #000; margin: 6px 0; }
.ticket-total { font-weight: bold; font-size: 14px; }
.ticket-footer { text-align: center; margin-top: 8px; font-size: 10px; border-top: 1px dashed #000; padding-top: 6px; }
.ticket-product-line { display: flex; justify-content: space-between; }
.ticket-product-desc { color: #444; font-size: 11px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main {
    margin-left: 0;
    margin-right: var(--mob-nav-w);
    padding: 14px;
    padding-top: 66px;
    padding-bottom: 20px;
  }
  .mobile-rightnav { display: flex; }
  .mobile-topbar { display: flex; right: var(--mob-nav-w); }
  .mob-fab { display: flex; }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-val { font-size: 20px; }
  .stat-val-sm { font-size: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: 1; }

  .desktop-only { display: none !important; }
  .list-cards { display: block; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: 20px 20px 0 0; max-height: 92vh;
    display: flex; flex-direction: column; margin-right: var(--mob-nav-w);
  }
  .modal-body { overflow-y: auto; flex: 1; }
  .modal-footer { flex-direction: column; }
  .modal-footer .btn { width: 100%; justify-content: center; }

  .linea-head, .linea-item { display: none; }
  .linea-mob { display: block; }
  .page-header .btn.desktop-btn { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-title { font-size: 17px; }
}

@media (min-width: 769px) {
  .linea-mob { display: none; }
  .linea-item { display: grid; }
  .linea-head { display: grid; }
  .mobile-rightnav { display: none; }
  .mob-fab { display: none !important; }
}

@media (min-width: 769px) and (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(6, 1fr); }
}

/* ===== Identidad visual: logotipo ===== */
.logo-img {
  display: block;
  width: 100%;
  max-width: 170px;
  height: auto;
  border-radius: 8px;
  background: #fff;
  padding: 6px 8px;
}
.logo-img-sm {
  display: block;
  height: 30px;
  width: auto;
  border-radius: 6px;
  background: #fff;
  padding: 3px 5px;
}


/* ============================================================================
   TICKET — estructura comun a pantalla e impresora
   ========================================================================== */
.tk {
  width: 80mm;
  padding: 3mm 2mm;
  margin: 0 auto;
  background: #fff;
  color: #000;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11.5px;
  line-height: 1.35;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.tk[data-ancho="58mm"] { width: 58mm; font-size: 10px; padding: 2mm 1.5mm; }

.tk-head  { text-align: center; }
.tk-logo  { display: block; max-width: 42mm; margin: 0 auto 2mm; filter: grayscale(1) contrast(1.6); }
.tk[data-ancho="58mm"] .tk-logo { max-width: 32mm; }
.tk-emp   { font-size: 14px; font-weight: 700; letter-spacing: .5px; }
.tk[data-ancho="58mm"] .tk-emp { font-size: 12px; }
.tk-min   { font-size: 9.5px; }
.tk-doc   { text-align: center; font-weight: 700; font-size: 12px; margin: 1mm 0; }

.tk-sep   { border-top: 1px dashed #000; margin: 1.5mm 0; }
.tk-l     { display: flex; justify-content: space-between; gap: 4px; }
.tk-l > span:last-child { text-align: right; }
.tk-tot   { font-weight: 700; font-size: 13.5px; }
.tk[data-ancho="58mm"] .tk-tot { font-size: 12px; }

.tk-item   { margin-bottom: 1.2mm; }
.tk-item-n { font-weight: 600; }
.tk-item-l { display: flex; justify-content: space-between; }

.tk-letras { font-size: 9.5px; text-align: center; margin-top: 1mm; font-style: italic; }

.tk-firma   { margin-top: 8mm; text-align: center; }
.tk-firma-l { border-top: 1px solid #000; width: 70%; margin: 0 auto 1mm; }

.tk-marca  { text-align: center; font-weight: 700; letter-spacing: 3px; margin-top: 2mm; font-size: 10px; }
.tk-foot   { text-align: center; font-size: 9.5px; }
.tk-gracias{ margin-top: 1.5mm; font-weight: 600; }
.tk-corte  { height: 6mm; }

/* Vista dentro de la pagina (no impresion) */
#ticket-print-area { background: #fff; }
body.imprimiendo { overflow: hidden; }

/* ============================================================================
   FORMULARIOS — clientes y productos
   ========================================================================== */
.form-section {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text3);
  margin: 16px 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--border);
}
.form-section:first-of-type { margin-top: 4px; }

.form-check-row {
  display: flex; flex-wrap: wrap; gap: 14px;
  margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border);
}
.check {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.check input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

.hint-inline { font-size: 11px; color: var(--text3); white-space: nowrap; align-self: center; }

.td-acciones { white-space: nowrap; text-align: right; }
.td-acciones .btn { margin-left: 5px; }

/* Barra de configuracion de la impresora */
.pos-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pos-config { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text2); }
.pos-config label { font-size: 11px; color: var(--text3); margin: 0; }
.pos-config select { padding: 5px 8px; font-size: 12px; border-radius: 6px; border: 1px solid var(--border2); background: var(--surface); }
.pos-acciones { display: flex; gap: 8px; }

@media (max-width: 768px) {
  .pos-footer { flex-direction: column; align-items: stretch; }
  .pos-acciones { justify-content: flex-end; }
  .form-check-row { flex-direction: column; gap: 10px; }
}
