/* ===== Base ===== */
:root {
  --green: #15803d;
  --green-dark: #14532d;
  --green-light: #dcfce7;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1a2320;
  --muted: #64716b;
  --border: #e2e8e4;
  --red: #dc2626;
  --red-light: #fee2e2;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 40, 25, 0.08), 0 4px 14px rgba(15, 40, 25, 0.06);
  --nav-h: 62px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(21, 128, 61, 0.12);
}
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 5px; }
.hidden { display: none !important; }

/* ===== Layout ===== */
#app { display: flex; min-height: 100dvh; }
#view {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + 90px);
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

/* Bottom nav (celular) */
#bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 40;
}
#bottomnav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  position: relative;
}
#bottomnav button.active { color: var(--green); }
#bottomnav .nav-icon { font-size: 21px; line-height: 1; }
.nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 22px);
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* Sidebar (PC) */
#sidenav {
  width: 220px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100dvh;
}
#sidenav .brand {
  font-weight: 800;
  font-size: 17px;
  color: var(--green-dark);
  padding: 0 10px 16px;
}
#sidenav button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  text-align: left;
  position: relative;
}
#sidenav button.active { background: var(--green-light); color: var(--green-dark); }
#sidenav button:hover:not(.active) { background: var(--bg); }
#sidenav .nav-badge { position: static; margin-left: auto; }
#sidenav .user-chip {
  margin-top: auto;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

@media (min-width: 900px) {
  #sidenav { display: flex !important; }
  #bottomnav { display: none !important; }
  #view { padding-bottom: 40px; }
}

/* ===== Componentes ===== */
.page-title { font-size: 21px; font-weight: 800; margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 11px;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.secondary { background: #fff; color: var(--green-dark); border: 1.5px solid var(--border); }
.btn.danger { background: var(--red-light); color: var(--red); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
.tag {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--bg);
  color: var(--muted);
}
.tag.ok { background: var(--green-light); color: var(--green-dark); }
.tag.low { background: var(--amber-light); color: var(--amber); }
.tag.out { background: var(--red-light); color: var(--red); }

/* Búsqueda y chips */
.searchbar { margin-bottom: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 99px;
  background: #fff;
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.chip.active { background: var(--green); border-color: var(--green); color: #fff; }

/* Grid de productos (POS) */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.pos-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 2px solid transparent;
  transition: border-color 0.12s, transform 0.08s;
  position: relative;
}
.pos-card:active { transform: scale(0.97); }
.pos-card.in-cart { border-color: var(--green); }
.pos-card.out-of-stock { opacity: 0.45; }
.pos-card .p-name { font-weight: 700; font-size: 14px; line-height: 1.25; }
.pos-card .p-price { color: var(--green-dark); font-weight: 800; font-size: 15px; }
.pos-card .p-stock { font-size: 11.5px; color: var(--muted); }
.pos-card .qty-bubble {
  position: absolute;
  top: -7px; right: -7px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  min-width: 26px;
  height: 26px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

/* Barra del carrito */
#cartbar {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 45;
  max-width: 640px;
  margin: 0 auto;
}
@media (min-width: 900px) {
  #cartbar { bottom: 20px; left: 240px; }
}
#cartbar .cartbar-btn {
  width: 100%;
  background: var(--green-dark);
  color: #fff;
  border-radius: 14px;
  padding: 15px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 6px 20px rgba(15, 40, 25, 0.35);
}

/* Listas (inventario, ventas) */
.list-item {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  margin-bottom: 9px;
}
.list-item .li-title { font-weight: 700; font-size: 14.5px; }
.list-item .li-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
@media (min-width: 700px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.stat-card .s-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.stat-card .s-value { font-size: 19px; font-weight: 800; color: var(--green-dark); margin-top: 3px; }
.stat-card .s-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* Gráfica de barras */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 130px;
  padding-top: 8px;
}
.chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.chart .bar { width: 100%; max-width: 34px; background: var(--green); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .bar-label { font-size: 9.5px; color: var(--muted); }

/* Modal */
#modal-root .overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 15, 0.5);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 700px) { #modal-root .overlay { align-items: center; } }
#modal-root .modal {
  background: #fff;
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  animation: slideup 0.18s ease-out;
}
@media (min-width: 700px) { #modal-root .modal { border-radius: 20px; padding-bottom: 20px; } }
@keyframes slideup { from { transform: translateY(30px); opacity: 0.5; } to { transform: none; opacity: 1; } }
.modal h3 { font-size: 17px; margin-bottom: 10px; }
.modal .modal-close { position: sticky; float: right; font-size: 22px; color: var(--muted); padding: 0 4px; }

/* Carrito dentro del modal */
.cart-line { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.cart-line .cl-name { flex: 1; font-weight: 600; font-size: 14px; }
.qty-btn {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--bg);
  font-weight: 800;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pay-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.pay-methods .chip { text-align: center; padding: 10px 6px; }

/* Toasts */
#toast-root {
  position: fixed;
  top: 14px;
  left: 12px; right: 12px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--green-dark);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: 480px;
  animation: slideup 0.2s ease-out;
}
.toast.error { background: var(--red); }
.toast.warn { background: var(--amber); }

/* Login */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
  width: 100%;
  max-width: 400px;
}
.auth-card .logo { font-size: 40px; text-align: center; }
.auth-card h1 { font-size: 20px; text-align: center; margin: 8px 0 2px; }
.auth-card .page-sub { text-align: center; }

/* Alertas de stock bajo en dashboard */
.alert-banner {
  background: var(--amber-light);
  border: 1.5px solid #fcd34d;
  color: #92400e;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 12px;
}
.alert-banner.red { background: var(--red-light); border-color: #fca5a5; color: var(--red); }

table.mini { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.mini td { padding: 7px 4px; border-bottom: 1px solid var(--border); }
table.mini td:last-child { text-align: right; font-weight: 700; }
