/* ============================================================
   POS Sistema — app.css
   PHP 8.2+ | Sistema Punto de Venta
   ============================================================ */

/* ── Variables ── */
:root {
  --primary:   #0ea5e9;
  --primary-d: #0284c7;
  --success:   #10b981;
  --danger:    #ef4444;
  --warning:   #f59e0b;
  --info:      #6366f1;
  --dark:      #0f172a;
  --dark2:     #1e293b;
  --dark3:     #334155;
  --muted:     #64748b;
  --border:    #e2e8f0;
  --bg:        #f1f5f9;
  --white:     #ffffff;
  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --sidebar-w: 220px;
  --topbar-h:  56px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing:border-box; margin:0; padding:0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--dark2);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ════════════════════════════════════════════════════════════
   LAYOUT
════════════════════════════════════════════════════════════ */
.layout-wrap {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 200;
  transition: transform .25s ease;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  background: rgba(255,255,255,.05);
  border-bottom: 1px solid rgba(255,255,255,.06);
  font-weight: 700;
  font-size: 15px;
}
.sb-logo { font-size: 22px; }
.sb-title { color: #fff; }

.sb-nav { flex: 1; padding: 8px 0; }
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: rgba(255,255,255,.65);
  font-size: 13.5px;
  transition: all .15s;
  border-left: 3px solid transparent;
}
.sb-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sb-item.active {
  background: rgba(14,165,233,.15);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}
.sb-icon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }

.sb-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sb-user {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; font-size: 12px;
  color: rgba(255,255,255,.6);
  border-radius: var(--radius);
  margin-bottom: 6px;
}
.sb-uicon { font-size: 18px; }
.sb-uname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-logout {
  display: block; text-align: center; padding: 7px;
  background: rgba(239,68,68,.15); color: #fca5a5;
  border-radius: var(--radius); font-size: 12px;
  transition: background .15s;
}
.sb-logout:hover { background: rgba(239,68,68,.25); text-decoration: none; }

/* ── Page Container ── */
.page-container {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left .25s;
}
.page-container.expanded { margin-left: 0; }

/* ── Topbar ── */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-toggle {
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  padding: 6px; border-radius: var(--radius);
  color: var(--muted);
  transition: background .15s;
}
.topbar-toggle:hover { background: var(--bg); }
.topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--dark);
  flex: 1;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ── Page Body ── */
.page-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

/* ════════════════════════════════════════════════════════════
   COMPONENTES UI
════════════════════════════════════════════════════════════ */

/* ── Botones ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all .15s;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none !important;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary  { background: var(--primary);  color:#fff; border-color: var(--primary); }
.btn-primary:hover  { background: var(--primary-d); border-color: var(--primary-d); }
.btn-success  { background: var(--success);  color:#fff; border-color: var(--success); }
.btn-success:hover  { background: #059669; }
.btn-danger   { background: var(--danger);   color:#fff; border-color: var(--danger); }
.btn-danger:hover   { background: #dc2626; }
.btn-warning  { background: var(--warning);  color:#fff; border-color: var(--warning); }
.btn-secondary{ background: #f1f5f9; color: var(--dark3); border-color: var(--border); }
.btn-secondary:hover{ background: var(--border); }
.btn-ghost    { background: transparent; color: var(--dark3); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: 7px; width: 34px; height: 34px; justify-content: center; }

/* ── Cards ── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-header h2 { font-size: 14px; font-weight: 700; color: var(--dark); }
.card-body { padding: 18px; }

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.kpi-card.blue::before   { background: var(--primary); }
.kpi-card.green::before  { background: var(--success); }
.kpi-card.orange::before { background: var(--warning); }
.kpi-card.purple::before { background: var(--info); }
.kpi-card.red::before    { background: var(--danger); }

.kpi-label { font-size: 11px; font-weight: 700; text-transform: uppercase;
             letter-spacing: .05em; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 800; color: var(--dark); line-height: 1; }
.kpi-sub   { font-size: 11.5px; color: var(--muted); }
.kpi-icon  { position: absolute; top: 14px; right: 16px; font-size: 28px; opacity: .2; }

/* ── Formularios ── */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12.5px; font-weight: 600; color: var(--dark3); }
.form-label span { color: var(--danger); }
.form-control {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--dark);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14,165,233,.1);
}
.form-control::placeholder { color: #94a3b8; }
.form-grid { display: grid; gap: 14px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-hint { font-size: 11.5px; color: var(--muted); }

/* ── Tablas ── */
.tbl-wrap { overflow-x: auto; }
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.tbl thead th {
  background: var(--bg);
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.tbl tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: #f8fafc; }
.tbl .tc { text-align: center; }
.tbl .tr { text-align: right; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
  white-space: nowrap;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #e0f2fe; color: #0369a1; }
.badge-muted   { background: #f1f5f9; color: #475569; }
.badge-purple  { background: #ede9fe; color: #5b21b6; }

/* ── Alertas / Flash ── */
.alert {
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 14px;
  border: 1px solid;
  display: flex; align-items: center; gap: 8px;
}
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-error   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }

/* ── Modales ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 900;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 20px;
  cursor: pointer; color: var(--muted); padding: 4px;
  border-radius: var(--radius); line-height: 1;
}
.modal-close:hover { background: var(--bg); }
.modal-body   { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ── Búsqueda ── */
.search-wrap {
  position: relative;
}
.search-wrap input { padding-left: 34px; }
.search-icon {
  position: absolute;
  left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px; pointer-events: none;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state .ico { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* ── Utilidades ── */
.fw-bold  { font-weight: 700; }
.fw-semi  { font-weight: 600; }
.text-sm  { font-size: 12px; }
.text-xs  { font-size: 11px; }
.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-primary { color: var(--primary); }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 6px; }
.mb-3 { margin-bottom: 18px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* ════════════════════════════════════════════════════════════
   LOGIN
════════════════════════════════════════════════════════════ */
.login-body {
  background: linear-gradient(135deg,#0f172a 0%,#1e3a5f 50%,#0f172a 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--white);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,.4);
}
.login-logo { text-align: center; font-size: 48px; margin-bottom: 8px; }
.login-title {
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  color: var(--dark);
  margin-bottom: 4px;
}
.login-sub {
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 28px;
}

/* ════════════════════════════════════════════════════════════
   MÓDULO POS (PANTALLA DE VENTA)
════════════════════════════════════════════════════════════ */
body[data-pos-mode="1"] {
  background: #0d1117;
}
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  height: calc(100vh - var(--topbar-h));
  gap: 0;
  overflow: hidden;
}

/* Panel izquierdo */
.pos-left {
  display: flex;
  flex-direction: column;
  background: #111827;
  overflow: hidden;
}

/* Barra de búsqueda POS */
.pos-search-bar {
  padding: 12px 14px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  display: flex;
  gap: 8px;
}
.pos-search-input {
  flex: 1;
  background: #0f172a;
  border: 1.5px solid #334155;
  color: #f1f5f9;
  padding: 10px 14px 10px 38px;
  border-radius: 8px;
  font-size: 14px;
}
.pos-search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}
.pos-search-input::placeholder { color: #475569; }

/* Grilla de productos POS */
.pos-products-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.pos-product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px,1fr));
  gap: 10px;
}
.pos-product-card {
  background: #1e293b;
  border: 1.5px solid #334155;
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
  user-select: none;
}
.pos-product-card:hover {
  border-color: var(--primary);
  background: #1a3050;
  transform: translateY(-1px);
}
.pos-product-card:active { transform: scale(.97); }
.pos-product-card.sin-stock { opacity: .45; cursor: not-allowed; }
.pos-prod-nombre {
  font-size: 13px; font-weight: 600;
  color: #e2e8f0; line-height: 1.3;
}
.pos-prod-codigo { font-size: 11px; color: #64748b; }
.pos-prod-precio {
  font-size: 16px; font-weight: 800;
  color: var(--primary); margin-top: 4px;
}
.pos-prod-stock { font-size: 11px; color: #94a3b8; }
.pos-prod-stock.low { color: var(--warning); }
.pos-prod-stock.empty { color: var(--danger); }

/* Panel derecho — carrito */
.pos-right {
  background: #0f172a;
  border-left: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Cabecera carrito */
.pos-cart-header {
  padding: 12px 14px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pos-cart-title {
  font-size: 13px; font-weight: 700;
  color: #e2e8f0;
}
.pos-cart-cliente {
  font-size: 12px; color: #64748b; margin-top: 2px;
}

/* Items del carrito */
.pos-cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pos-cart-item {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px 12px;
}
.pos-cart-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.pos-cart-item-nombre {
  font-size: 13px; font-weight: 600;
  color: #e2e8f0; line-height: 1.3; flex: 1;
}
.pos-cart-item-del {
  background: rgba(239,68,68,.15);
  border: none; color: #fca5a5;
  padding: 3px 7px; border-radius: 5px;
  cursor: pointer; font-size: 12px;
  transition: background .15s;
}
.pos-cart-item-del:hover { background: rgba(239,68,68,.3); }
.pos-cart-item-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.pos-qty-wrap {
  display: flex; align-items: center; gap: 4px;
}
.pos-qty-btn {
  background: #334155;
  border: none; color: #e2e8f0;
  width: 26px; height: 26px;
  border-radius: 5px; cursor: pointer;
  font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .1s;
}
.pos-qty-btn:hover { background: #475569; }
.pos-qty-input {
  width: 50px; text-align: center;
  background: #0f172a; border: 1px solid #334155;
  color: #f1f5f9; padding: 4px;
  border-radius: 5px; font-size: 14px; font-weight: 700;
}
.pos-item-precio-unit {
  flex: 1; font-size: 12px; color: #64748b;
}
.pos-item-subtotal {
  font-size: 14px; font-weight: 700; color: var(--primary);
}

/* Totales carrito */
.pos-cart-totales {
  background: #1e293b;
  border-top: 1px solid #334155;
  padding: 12px 14px;
}
.pos-tot-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 13px;
}
.pos-tot-row .lbl { color: #94a3b8; }
.pos-tot-row .val { color: #e2e8f0; font-weight: 600; }
.pos-tot-row.grand {
  border-top: 2px solid #334155;
  margin-top: 8px;
  padding-top: 10px;
}
.pos-tot-row.grand .lbl { color: #e2e8f0; font-size: 15px; font-weight: 700; }
.pos-tot-row.grand .val { color: var(--primary); font-size: 22px; font-weight: 900; }

/* Botones acción POS */
.pos-actions {
  padding: 12px;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.btn-cobrar {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff; border: none;
  padding: 14px; border-radius: 10px;
  font-size: 16px; font-weight: 800;
  cursor: pointer;
  transition: all .15s;
  box-shadow: 0 4px 14px rgba(5,150,105,.4);
  width: 100%; text-align: center;
}
.btn-cobrar:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(5,150,105,.5); }
.btn-cobrar:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.pos-action-row { display: flex; gap: 8px; }
.pos-action-row .btn { flex: 1; justify-content: center; font-size: 12px; }

/* Modal de cobro */
.cobro-modal .modal { max-width: 480px; }
.metodo-pago-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.metodo-btn {
  padding: 10px 6px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  background: var(--white);
  transition: all .15s;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.metodo-btn .ico { font-size: 20px; }
.metodo-btn:hover { border-color: var(--primary); background: #eff6ff; }
.metodo-btn.activo { border-color: var(--primary); background: #eff6ff; color: var(--primary); }
.resumen-cobro {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.resumen-cobro .tot { font-size: 28px; font-weight: 900; color: var(--success); text-align: center; }
.resumen-cobro .sub { text-align: center; font-size: 12px; color: var(--muted); }
.vuelto-display {
  text-align: center;
  font-size: 18px; font-weight: 700;
  color: var(--warning);
  margin-top: 8px;
}

/* ════════════════════════════════════════════════════════════
   CAJA
════════════════════════════════════════════════════════════ */
.caja-estado-card {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 20px;
}
.caja-estado-card.cerrada {
  background: linear-gradient(135deg, #1e293b, #334155);
}
.caja-monto { font-size: 36px; font-weight: 900; }
.caja-label { font-size: 13px; opacity: .8; margin-bottom: 4px; }

/* ════════════════════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: translateX(0); }
  .page-container { margin-left: 0; }
  .pos-layout { grid-template-columns: 1fr; }
  .pos-right  { height: 45vh; border-left: none; border-top: 1px solid #1e293b; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Scrollbar personalizado ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.pos-left ::-webkit-scrollbar-thumb,
.pos-cart-items ::-webkit-scrollbar-thumb { background: #334155; }
