:root {
  --bg: #0f1419;
  --surface: #1a222d;
  --surface-2: #243041;
  --text: #f2f5f8;
  --muted: #9aa7b5;
  --accent: #2bb673;
  --accent-2: #e8b84a;
  --danger: #e85d5d;
  --warn: #e8b84a;
  --radius: 14px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #1e3a2f 0%, transparent 50%),
    radial-gradient(900px 500px at 100% 0%, #2a3340 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  background: rgba(26, 34, 45, 0.92);
  border-bottom: 1px solid #2c3a4c;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.brand {
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 1.15rem;
}

.brand span { color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sucursal-chip {
  color: var(--muted);
  font-size: 0.85rem;
}

.sucursal-form select {
  width: auto;
  max-width: min(58vw, 280px);
  min-width: 7rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.85rem;
  min-height: 40px;
}

.logout-link {
  color: var(--muted);
  font-size: 0.9rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.pos-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.pay-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pay-medio.is-selected {
  background: var(--accent) !important;
  color: #062316 !important;
  border-color: transparent !important;
}

.pago-panel {
  margin-top: 0.75rem;
}

.pago-campo { margin-bottom: 0.5rem; }

.btn-alerta {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border-radius: 10px;
  background: #3b1d1d;
  border: 1px solid #e85d5d66;
  color: #ffb4b4;
  font-weight: 700;
  font-size: 0.9rem;
}

.reader-box {
  margin-top: 0.75rem;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #2c3a4c;
  max-width: 420px;
}

.cart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.cart-head h2 { margin: 0; }

.cart-right {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.cart-name {
  flex: 1;
  min-width: 0;
}

.cart-qty {
  min-width: 1.4rem;
  text-align: center;
  font-weight: 700;
}

.alerta-caja {
  background: #3b321d;
  border: 1px solid #e8b84a66;
  border-radius: 12px;
  padding: 1rem;
}

.venta-ok {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.venta-ok-box {
  background: var(--surface);
  border: 1px solid #2bb67366;
  border-radius: 16px;
  padding: 1.4rem 1.2rem;
  text-align: center;
  width: min(100%, 340px);
}

.venta-ok-title {
  margin: 0;
  color: var(--accent);
  font-weight: 800;
  font-size: 1.1rem;
}

.venta-ok-monto {
  margin: 0.5rem 0 0.25rem;
  font-size: 2rem;
  font-weight: 800;
}

.btn-mini {
  background: transparent;
  border: 1px solid #3a4b60;
  color: var(--muted);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 1rem;
}

/* Fix: .btn { display:inline-flex } pisa el atributo HTML hidden */
[hidden] { display: none !important; }

.header-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

/* Escritorio: pills arriba */
.nav-desktop {
  display: none;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.85rem 1.1rem;
}

.nav-desktop a {
  background: var(--surface);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid #2c3a4c;
  font-weight: 650;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
}

.nav-desktop a:hover,
.nav-desktop a[aria-current="page"] {
  border-color: var(--accent);
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  margin-left: 0.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
}

.nav-bottom-item {
  position: relative;
}

.nav-badge-float {
  position: absolute;
  top: 2px;
  right: 8px;
  margin: 0;
}

/* Móvil: barra inferior tipo app */
.nav-bottom {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: rgba(18, 24, 32, 0.97);
  border-top: 1px solid #2c3a4c;
  padding: 0.3rem 0.2rem calc(0.3rem + env(safe-area-inset-bottom));
  justify-content: space-around;
  gap: 0.1rem;
  backdrop-filter: blur(10px);
}

.nav-bottom-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 48px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 10px;
  text-decoration: none;
}

.nav-bottom-item.is-active {
  color: var(--accent);
  background: #1a2e24;
}

/* Vender resaltado pero compacto (sin tapar el cuerpo) */
.nav-bottom-item.is-primary {
  position: relative;
  top: -6px;
  flex: 1.05;
  min-height: 52px;
  max-width: 4.8rem;
  margin: 0 auto;
  border-radius: 14px;
  background: var(--accent);
  color: #062316;
  box-shadow: 0 4px 12px rgba(43, 182, 115, 0.3);
  font-size: 0.7rem;
}

.nav-bottom-item.is-primary .nav-ico {
  width: 22px;
  height: 22px;
}

.nav-bottom-item.is-primary.is-active {
  background: #34d399;
  color: #042016;
}

.nav-desktop a[href*="vender"] {
  background: var(--accent);
  color: #062316;
  border-color: transparent;
}

.nav-ico {
  width: 22px;
  height: 22px;
  display: block;
  background: currentColor;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}

.nav-ico[data-icon="cart"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='9' cy='20' r='1'/%3E%3Ccircle cx='17' cy='20' r='1'/%3E%3Cpath d='M3 3h2l2.4 12.2a2 2 0 0 0 2 1.8h7.4a2 2 0 0 0 2-1.6L21 7H6'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='9' cy='20' r='1'/%3E%3Ccircle cx='17' cy='20' r='1'/%3E%3Cpath d='M3 3h2l2.4 12.2a2 2 0 0 0 2 1.8h7.4a2 2 0 0 0 2-1.6L21 7H6'/%3E%3C/svg%3E");
}
.nav-ico[data-icon="box"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M21 8l-9-5-9 5v8l9 5 9-5V8z'/%3E%3Cpath d='M3.3 7.5L12 12l8.7-4.5M12 12v9'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M21 8l-9-5-9 5v8l9 5 9-5V8z'/%3E%3Cpath d='M3.3 7.5L12 12l8.7-4.5M12 12v9'/%3E%3C/svg%3E");
}
.nav-ico[data-icon="cash"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='2' y='6' width='20' height='12' rx='2'/%3E%3Ccircle cx='12' cy='12' r='2.5'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='2' y='6' width='20' height='12' rx='2'/%3E%3Ccircle cx='12' cy='12' r='2.5'/%3E%3C/svg%3E");
}
.nav-ico[data-icon="chart"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M4 19V5M8 19v-7M12 19v-4M16 19V9M20 19V7'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M4 19V5M8 19v-7M12 19v-4M16 19V9M20 19V7'/%3E%3C/svg%3E");
}
.nav-ico[data-icon="gear"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4'/%3E%3C/svg%3E");
}
.nav-ico[data-icon="warn"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M12 3L2 20h20L12 3z'/%3E%3Cpath d='M12 9v5M12 17h.01'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M12 3L2 20h20L12 3z'/%3E%3Cpath d='M12 9v5M12 17h.01'/%3E%3C/svg%3E");
}

@media (max-width: 768px) {
  .nav-desktop { display: none !important; }
  .nav-bottom { display: flex; }
  body.has-app-nav main {
    padding-bottom: calc(4.25rem + env(safe-area-inset-bottom));
  }
}

@media (min-width: 769px) {
  .nav-desktop { display: flex; }
  .nav-bottom { display: none !important; }
}

main {
  padding: 0.5rem 1.1rem 2rem;
  max-width: 980px;
  margin: 0 auto;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.flash-wrap { padding: 0 1.1rem; max-width: 980px; margin: 0.5rem auto 0; }

.flash {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 0.5rem;
}

.flash.success { background: #1d3b2e; border: 1px solid #2bb67355; }
.flash.danger { background: #3b1d1d; border: 1px solid #e85d5d55; }
.flash.warning { background: #3b321d; border: 1px solid #e8b84a55; }

.card {
  background: var(--surface);
  border: 1px solid #2c3a4c;
  border-radius: var(--radius);
  padding: 0.95rem;
  margin-bottom: 0.85rem;
}

h1, h2 { margin-top: 0; }

.muted { color: var(--muted); }

label {
  display: block;
  margin: 0.65rem 0 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border-radius: 10px;
  border: 1px solid #3a4b60;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.05rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 42px;
  padding: 0.55rem 1rem;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--accent);
  color: #062316;
}

.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid #3a4b60; }
.btn.warn { background: var(--accent-2); color: #2a1f05; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 700px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  text-align: left;
  padding: 0.65rem 0.4rem;
  border-bottom: 1px solid #2c3a4c;
  font-size: 0.95rem;
  white-space: nowrap;
}

@media (max-width: 700px) {
  .card { padding: 0.9rem; }
  .app-header { padding: 0.65rem 0.75rem; gap: 0.5rem; }
  .brand { font-size: 1rem; }
  .logout-link { font-size: 0.8rem; }
  .pay-quick .btn,
  .pay-quick .btn.secondary {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 0;
    font-size: 0.9rem;
    padding: 0.65rem 0.5rem;
  }
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge.low { background: #3b1d1d; color: #ffb4b4; }
.badge.ok { background: #1d3b2e; color: #a8f0c8; }

/* POS */
.pos-code {
  font-size: 1.35rem;
  min-height: 56px;
}

.cart-list { list-style: none; padding: 0; margin: 0; }
.cart-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid #2c3a4c;
}

.total-line {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0.8rem 0;
}

.login-wrap {
  max-width: 420px;
  margin: 12vh auto;
  padding: 0 1rem;
}
