/* ============================================================
   KontrolesPS — Punto de Venta
   Diseño optimizado para tablet/móvil en mostrador
   ============================================================ */

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

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #334155;
  --border:    #475569;
  --accent:    #0ea5e9;
  --accent2:   #38bdf8;
  --success:   #22c55e;
  --danger:    #ef4444;
  --warning:   #f59e0b;
  --text:      #f1f5f9;
  --text-muted:#94a3b8;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
}

/* ── Loading ──────────────────────────────────────────────── */
#loading-screen {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100dvh; gap: 24px;
}
.loading-logo { display: flex; align-items: center; gap: 12px; font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Layout principal POS ─────────────────────────────────── */
#pos-view {
  display: grid;
  grid-template-rows: 56px 1fr;
  grid-template-columns: 1fr 380px;
  height: 100dvh;
  gap: 0;
}

/* ── Header ───────────────────────────────────────────────── */
.pos-header {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px; gap: 16px;
}
.pos-header .brand {
  font-weight: 700; font-size: 1.1rem; color: var(--accent);
  display: flex; align-items: center; gap: 8px;
}
.pos-header .empresa-info {
  color: var(--text-muted); font-size: 0.85rem; flex: 1;
}
.pos-header .header-actions { display: flex; gap: 8px; }

/* ── Panel izquierdo: búsqueda + carrito ──────────────────── */
.pos-left {
  display: flex; flex-direction: column;
  background: var(--bg); overflow: hidden;
}

/* Barra de búsqueda / scanner */
.search-bar {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; gap: 8px;
}
.search-bar input {
  flex: 1;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.1rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: var(--text-muted); }

/* Resultados de búsqueda */
.search-results {
  position: absolute;
  top: 56px; left: 0; right: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  max-height: 300px;
  overflow-y: auto;
  display: none;
}
.search-results.visible { display: block; }
.search-result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  transition: background 0.15s;
}
.search-result-item:hover { background: var(--surface2); }
.search-result-item .prod-name { font-weight: 600; }
.search-result-item .prod-code { font-size: 0.78rem; color: var(--text-muted); }
.search-result-item .prod-price { color: var(--accent); font-weight: 700; font-size: 1rem; }

/* Carrito */
.cart-area {
  flex: 1; overflow-y: auto; padding: 8px;
}
.cart-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; gap: 12px; color: var(--text-muted);
}
.cart-empty svg { opacity: 0.3; }

.cart-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 4px 8px;
  border-left: 3px solid var(--accent);
}
.cart-item .item-name { font-weight: 600; font-size: 0.95rem; }
.cart-item .item-code { font-size: 0.75rem; color: var(--text-muted); }
.cart-item .item-controls {
  display: flex; align-items: center; gap: 6px;
  grid-row: 1 / -1; grid-column: 2;
}
.cart-item .item-subtotal { color: var(--accent); font-weight: 700; text-align: right; }
.qty-btn {
  background: var(--surface2); border: none; color: var(--text);
  width: 28px; height: 28px; border-radius: 6px;
  font-size: 1.1rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.qty-btn:hover { background: var(--accent); }
.qty-display { min-width: 32px; text-align: center; font-weight: 700; }
.remove-btn {
  background: none; border: none; color: var(--danger);
  cursor: pointer; padding: 4px; border-radius: 4px;
  transition: background 0.15s;
}
.remove-btn:hover { background: rgba(239,68,68,0.15); }

/* ── Panel derecho: cobro ─────────────────────────────────── */
.pos-right {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* Cliente selector */
.cliente-bar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.cliente-bar:hover { background: var(--surface2); }
.cliente-bar .cliente-icon { color: var(--text-muted); }
.cliente-bar .cliente-nombre { flex: 1; font-size: 0.9rem; }
.cliente-bar .cliente-nit { font-size: 0.75rem; color: var(--text-muted); }

/* Resumen de venta */
.sale-summary {
  padding: 16px;
  flex: 1;
  display: flex; flex-direction: column; gap: 8px;
}
.summary-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.9rem;
}
.summary-row.total-row {
  font-size: 1.5rem; font-weight: 700;
  color: var(--accent);
  border-top: 1px solid var(--border);
  padding-top: 12px; margin-top: 4px;
}
.summary-row .label { color: var(--text-muted); }

/* Tipo de pago */
.payment-type {
  padding: 0 16px 12px;
  display: flex; gap: 6px;
}
.pay-btn {
  flex: 1; padding: 8px 4px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text); font-size: 0.8rem;
  cursor: pointer; text-align: center;
  transition: all 0.15s;
}
.pay-btn.active { background: var(--accent); border-color: var(--accent); font-weight: 700; }

/* Monto recibido */
.monto-recibido {
  padding: 0 16px 12px;
}
.monto-recibido label { font-size: 0.8rem; color: var(--text-muted); display: block; margin-bottom: 4px; }
.monto-recibido input {
  width: 100%; background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text); font-size: 1.4rem;
  padding: 8px 12px; outline: none; text-align: right;
  transition: border-color 0.2s;
}
.monto-recibido input:focus { border-color: var(--accent); }

.cambio-display {
  padding: 0 16px 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.cambio-display .cambio-label { color: var(--text-muted); font-size: 0.85rem; }
.cambio-display .cambio-valor { font-size: 1.4rem; font-weight: 700; color: var(--success); }

/* Botón cobrar */
.btn-cobrar {
  margin: 0 16px 16px;
  background: linear-gradient(135deg, var(--success), #16a34a);
  border: none; border-radius: var(--radius);
  color: white; font-size: 1.2rem; font-weight: 700;
  padding: 16px;
  cursor: pointer; width: calc(100% - 32px);
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 4px 16px rgba(34,197,94,0.3);
}
.btn-cobrar:hover { opacity: 0.9; }
.btn-cobrar:active { transform: scale(0.98); }
.btn-cobrar:disabled { opacity: 0.4; cursor: not-allowed; }

/* Teclado numérico rápido */
.numpad {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 4px; padding: 0 16px 12px;
}
.numpad-btn {
  background: var(--surface2); border: none; border-radius: 8px;
  color: var(--text); font-size: 1.1rem; font-weight: 600;
  padding: 12px; cursor: pointer;
  transition: background 0.15s;
}
.numpad-btn:hover { background: var(--border); }
.numpad-btn.clear { color: var(--warning); }
.numpad-btn.backspace { color: var(--danger); }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  width: 100%; max-width: 440px;
  box-shadow: var(--shadow);
}
.modal h2 { font-size: 1.2rem; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; }

/* ── Botones generales ────────────────────────────────────── */
.btn {
  border: none; border-radius: var(--radius);
  padding: 10px 20px; font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: opacity 0.2s;
}
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn:hover { opacity: 0.85; }

/* ── Login ────────────────────────────────────────────────── */
#login-view {
  display: flex; align-items: center; justify-content: center;
  height: 100dvh; padding: 16px;
  background: radial-gradient(ellipse at center, #1e293b 0%, #0f172a 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 32px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.login-logo {
  text-align: center; margin-bottom: 32px;
  color: var(--accent); font-size: 1.6rem; font-weight: 800;
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; }
.form-group input {
  width: 100%; background: var(--bg);
  border: 1.5px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 1rem; padding: 12px 14px; outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 0.85rem; text-align: center; margin-top: 8px; }
.btn-login {
  width: 100%; background: var(--accent); border: none;
  border-radius: var(--radius); color: white; font-size: 1rem;
  font-weight: 700; padding: 14px; cursor: pointer; margin-top: 8px;
  transition: opacity 0.2s;
}
.btn-login:hover { opacity: 0.9; }

/* ── Historial (pantalla secundaria) ──────────────────────── */
#historial-view {
  display: flex; flex-direction: column; height: 100dvh;
}
.historial-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 16px; display: flex; align-items: center; gap: 12px;
}
.historial-list { flex: 1; overflow-y: auto; padding: 8px; }
.historial-item {
  background: var(--surface); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 6px;
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; transition: background 0.15s;
}
.historial-item:hover { background: var(--surface2); }
.historial-item.anulada { opacity: 0.5; }
.historial-item .doc-no { font-weight: 700; font-size: 0.95rem; }
.historial-item .doc-cliente { font-size: 0.8rem; color: var(--text-muted); }
.historial-item .doc-total { color: var(--accent); font-weight: 700; }
.historial-item .doc-estado {
  font-size: 0.72rem; font-weight: 700;
  padding: 2px 8px; border-radius: 20px;
}
.estado-CO { background: rgba(34,197,94,0.2); color: var(--success); }
.estado-DR { background: rgba(234,179,8,0.2); color: var(--warning); }
.estado-VO { background: rgba(239,68,68,0.2); color: var(--danger); }

/* ── Toast notifications ──────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 16px; right: 16px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface2); border-radius: var(--radius);
  padding: 12px 16px; font-size: 0.9rem;
  box-shadow: var(--shadow); min-width: 220px;
  border-left: 4px solid var(--accent);
  animation: slideIn 0.3s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Responsive: tablet vertical ─────────────────────────── */
@media (max-width: 768px) {
  #pos-view {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr auto;
  }
  .pos-right {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 45dvh;
    overflow-y: auto;
  }
  .search-results { right: 0; }
}
