/* ===========================================================================
   Ringer - Hoja de estilos base (mobile-first)
   Disenada para el telefono de la tienda; escala bien a tablet/escritorio.
   =========================================================================== */

:root {
  --bg: #FAFAF9;
  --surface: #FFFFFF;
  --ink: #1C1917;
  --muted: #78716C;
  --brand: #FFFFFF;
  --brand-text: #1C1917;
  --accent: #059669;
  --ok: #059669;
  --warn: #EA580C;
  --danger: #DC2626;
  --border: #F5F5F4;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --radius: 10px;
  --tap: 48px; /* altura minima recomendada para objetivos tactiles */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Encabezado ----------------------------------------------------------- */
.app-header {
  background: var(--brand);
  color: var(--brand-text);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: calc(16px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}
.app-brand {
  color: var(--brand-text);
  font-weight: 700;
  font-size: 1.3rem;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.nav-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 1.2rem;
  width: auto;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.nav-toggle:hover {
  background: var(--bg);
}

/* --- Navegacion ----------------------------------------------------------- */
.app-nav {
  display: none;
  flex-direction: column;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-nav.open { display: flex; }
.app-nav a, .app-nav .nav-user {
  color: var(--ink);
  text-decoration: none;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  min-height: var(--tap);
  display: flex;
  align-items: center;
  font-weight: 500;
  transition: background 0.15s;
}
.app-nav a:hover, .app-nav a:active { background: var(--bg); }
.nav-user { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.nav-logout { color: var(--danger) !important; }

@media (min-width: 768px) {
  .nav-toggle { display: none; }
  .app-nav {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    background: var(--surface);
    border-radius: 0;
    border-bottom: 1px solid var(--border);
  }
  .app-nav a, .app-nav .nav-user {
    border-bottom: none;
    padding: 12px 16px;
  }
  .nav-user { margin-left: auto; }
}

/* --- Contenido principal -------------------------------------------------- */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px;
}

.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* --- Tarjetas ------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.card h1 { margin-top: 0; font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.center { text-align: center; }
.muted { color: var(--muted); }

/* --- Botones (objetivos tactiles grandes) --------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); filter: brightness(0.95); }
.btn-block { width: 100%; }
.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* --- Campos de formulario ------------------------------------------------- */
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}
label { display: block; font-weight: 600; margin-bottom: 8px; color: var(--ink); }
.field { margin-bottom: 16px; }

/* --- Mensajes flash ------------------------------------------------------- */
.flash-area { max-width: 720px; margin: 0 auto; padding: 0 20px; }
.flash {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  border: 1px solid;
  font-weight: 500;
}
.flash-success { background: #ECFDF5; color: #065F46; border-color: #A7F3D0; }
.flash-warning { background: #FFF7ED; color: #9A3412; border-color: #FED7AA; }
.flash-danger, .flash-error { background: #FEF2F2; color: #991B1B; border-color: #FECACA; }
.flash-info { background: #EFF6FF; color: #1E40AF; border-color: #BFDBFE; }

/* --- Insignias / estado --------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--border);
  font-size: 0.85rem;
  font-weight: 600;
}
.badge-ok { background: #ECFDF5; color: #065F46; }
.badge-warn { background: #FFF7ED; color: #9A3412; }
.badge-danger { background: #FEF2F2; color: #991B1B; }

.status-grid {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 20px;
}
.status-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.status-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

/* --- Listas tipo tarjeta (mejor que tablas en el telefono) ---------------- */
.item-list { list-style: none; margin: 0; padding: 0; }
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.item-row:last-child { border-bottom: none; }
.item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item-title { font-weight: 600; }
.item-sub { font-size: 0.85rem; color: var(--muted); }
.item-actions { display: flex; gap: 8px; flex-shrink: 0; }
.item-inactive { opacity: 0.55; }

/* Botones pequenos para acciones en filas */
.btn-sm {
  min-height: 38px;
  padding: 0 14px;
  font-size: 0.85rem;
}
.btn-danger { background: var(--danger); color: #fff; box-shadow: var(--shadow-sm); }
.btn-warn { background: var(--warn); color: #fff; box-shadow: var(--shadow-sm); }

/* Formularios en linea (un solo boton de accion) */
.inline-form { display: inline; margin: 0; }

/* Encabezado de seccion con accion */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.section-head h1 { margin: 0; font-size: 1.3rem; }

/* Cuadricula de estadisticas del panel */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s;
}
.stat-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.stat-num { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-label { font-size: 0.85rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card.alert { border-color: var(--warn); background: #FFF7ED; }
.stat-card.alert .stat-num { color: var(--warn); }

.help-text { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; }
.checkbox-row input { width: auto; min-height: auto; }

/* Tabla simple para historiales */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.data-table th { color: var(--muted); font-size: 0.8rem; }

/* --- Punto de venta: autocompletado --------------------------------------- */
.autocomplete {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 320px;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.autocomplete:empty { display: none; }
.autocomplete-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: var(--tap);
  transition: background 0.15s;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--bg); }
.autocomplete-item:active { background: #ECFDF5; }
.autocomplete-item.disabled { opacity: 0.5; cursor: not-allowed; }
.ac-name { font-weight: 600; }
.ac-meta { font-size: 0.82rem; color: var(--muted); }

/* --- Punto de venta: carrito --------------------------------------------- */
.qty-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.qty-num { font-weight: 700; min-width: 24px; text-align: center; }

.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 14px 0;
  border-top: 2px solid var(--ink);
  margin-top: 8px;
}

/* --- Cobro: denominaciones ----------------------------------------------- */
.denom-currency {
  font-size: 0.95rem;
  margin: 16px 0 8px;
  color: var(--brand);
}
.denom-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.denom-cell label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.denom-kind { color: var(--muted); font-weight: 400; font-size: 0.78rem; }
.denom-input { text-align: center; }

.pay-btn { font-size: 1.05rem; }
.pay-panel {
  border: 2px solid var(--accent);
  box-shadow: var(--shadow);
  background: #ECFDF5;
}

/* --- Caja: colores de descuadre ------------------------------------------ */
.disc-ok { color: var(--ok); }
.disc-short { color: var(--danger); }
.disc-over { color: var(--warn); }

/* --- Editor de recibo ----------------------------------------------------- */
.code-area {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  min-height: 320px;
}
.receipt-preview {
  width: 100%;
  height: 520px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 4px;
}

/* --- Escritorio / tablet -------------------------------------------------- */
@media (min-width: 768px) {
  body { font-size: 17px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .denom-grid { grid-template-columns: repeat(3, 1fr); }
}

/* --- Impresion (reportes) ------------------------------------------------- */
@media print {
  .app-header, .app-nav, .app-footer, .flash-area,
  .no-print, .nav-toggle {
    display: none !important;
  }
  body { background: #fff; }
  .app-main { max-width: none; padding: 0; }
  .card {
    border: none;
    padding: 8px 0;
    margin-bottom: 8px;
    page-break-inside: avoid;
  }
  .stat-card { border: 1px solid #ccc; }
}
