html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

:root {
  --bg-1: #f4f8ff;
  --bg-2: #eef2ff;
  --surface: #ffffff;
  --surface-2: #f8fbff;
  --text: #1f2937;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --accent: #14b8a6;
  --border: #e2e8f0;
  --shadow: 0 10px 30px rgba(37, 99, 235, 0.08);
  --sidebar-width: 268px;
}

html,
body {
  min-height: 100%;
}

body.app-body {
  margin: 0;
  background: linear-gradient(145deg, var(--bg-1), var(--bg-2));
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
  transition: background .3s ease;
}

.app-sidebar {
  width: var(--sidebar-width);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(8px);
  color: #e2e8f0;
  padding: 1rem;
  border-right: 1px solid rgba(148, 163, 184, 0.18);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: width .2s ease, transform .2s ease;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: .2px;
  color: #f8fafc;
  padding: .6rem .75rem;
  border-radius: .8rem;
  background: linear-gradient(135deg, rgba(37, 99, 235, .24), rgba(20, 184, 166, .24));
}

.brand-dot {
  width: .65rem;
  height: .65rem;
  border-radius: 50%;
  background: #22d3ee;
  box-shadow: 0 0 10px #22d3ee;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.sidebar-link,
.sidebar-sublink,
.sidebar-toggle {
  color: #cbd5e1;
  text-decoration: none;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  border-radius: .75rem;
  padding: .65rem .75rem;
  display: flex;
  align-items: center;
  gap: .65rem;
  transition: all .18s ease;
}

.sidebar-toggle {
  justify-content: space-between;
}

.sidebar-link:hover,
.sidebar-sublink:hover,
.sidebar-toggle:hover,
.sidebar-link:focus,
.sidebar-sublink:focus,
.sidebar-link.active,
.sidebar-sublink.active {
  color: #f8fafc;
  background: rgba(59, 130, 246, .24);
}

.sidebar-submenu {
  margin-left: .75rem;
  border-left: 1px dashed rgba(148, 163, 184, .35);
  padding-left: .55rem;
}

.sidebar-user {
  margin-top: auto;
  border-top: 1px solid rgba(148, 163, 184, .25);
  padding-top: .9rem;
}

.sidebar-user .navbar-nav {
  width: 100%;
}

.sidebar-user .nav-link,
.sidebar-user .dropdown-item,
.sidebar-user .dropdown-menu {
  color: #e2e8f0;
}

.sidebar-user .dropdown-menu {
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, .25);
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 1030;
}

.topbar-title {
  font-weight: 600;
  color: #334155;
}

.app-content {
  padding: 0.5rem 1.1rem 1.25rem;
}

.app-content > .container,
.app-content .container-fluid {
  max-width: 100%;
}

.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.65);
  padding: .75rem 1rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.card,
.modal-content,
.table,
.alert {
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: .95rem;
  background: var(--surface);
}

.table thead th {
  background: var(--surface-2);
  color: #334155;
  border-bottom: 1px solid var(--border);
}

.btn {
  border-radius: .72rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  transition: transform .14s ease, box-shadow .14s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-auto-icon {
  font-size: .82rem;
  opacity: .9;
}

.btn-primary,
.btn-success,
.btn-info,
.btn-warning,
.btn-danger {
  border: 0;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #0d9488);
}

.btn-info {
  background: linear-gradient(135deg, #06b6d4, #0ea5e9);
}

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #f97316);
  color: #fff;
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}

.form-control,
.form-select {
  border-radius: .65rem;
  border-color: #dbe4f0;
}

.form-control:focus,
.form-select:focus,
.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .17);
}

.app-shell.sidebar-collapsed .app-sidebar {
  width: 86px;
}

.app-shell.sidebar-collapsed .sidebar-brand span:last-child,
.app-shell.sidebar-collapsed .sidebar-link span,
.app-shell.sidebar-collapsed .sidebar-toggle span,
.app-shell.sidebar-collapsed .sidebar-toggle .bi-chevron-down,
.app-shell.sidebar-collapsed .sidebar-submenu,
.app-shell.sidebar-collapsed .sidebar-user {
  display: none;
}

@media (max-width: 991px) {
  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    height: 100vh;
    z-index: 1050;
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }

  .app-shell.sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .app-main {
    width: 100%;
  }

  .app-shell.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, .35);
    z-index: 1040;
  }
}

.auth-body {
  background: radial-gradient(circle at 20% 20%, rgba(37, 99, 235, .15), transparent 40%),
              radial-gradient(circle at 80% 0%, rgba(20, 184, 166, .16), transparent 45%),
              linear-gradient(145deg, var(--bg-1), var(--bg-2));
}

.auth-shell {
  min-height: 100vh;
}

.auth-content {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-wrap .row {
  margin: 0;
}

.login-card {
  border-radius: 1.2rem;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(6px);
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 1rem;
  display: grid;
  place-items: center;
  background: transparent;
  box-shadow: none;
}

.login-card .input-group-text {
  background: #f8fafc;
  border-color: #dbe4f0;
  color: #64748b;
}

.auth-body .app-footer {
  display: none !important;
}

.factura-page {
  padding-top: 0;
}

.factura-header-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: .8rem;
  display: grid;
  place-items: center;
  color: #2563eb;
  background: var(--primary-soft);
}

.factura-top-fields {
  margin-top: 0;
}

.factura-card {
  min-height: calc(100vh - 100px);
}

.factura-card-body {
  padding: 1rem 1.25rem 1.5rem;
}

.factura-section {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: .95rem;
  background: var(--surface-2);
}

.factura-form {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  gap: .35rem;
}

.factura-detalle-wrapper {
  flex: 0 0 auto;
  height: 38vh;
  min-height: 260px;
  max-height: 38vh;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: .8rem;
  background: #fff;
}

.factura-detalle-wrapper #detalleTable thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.factura-detalle-wrapper table {
  margin-bottom: 0;
}

.factura-form .form-label {
  font-weight: 600;
  color: #334155;
}

.factura-form .form-control[readonly] {
  background-color: #f8fafc;
}

.factura-form .position-sticky {
  border-radius: .95rem .95rem 0 0;
}

.factura-form .list-group {
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .12);
}

.factura-form .btn i {
  font-size: .9rem;
}

.factura-form #resTotal {
  font-size: 1.08rem;
  font-weight: 700;
}

.factura-form #tributosDesglose {
  overflow-x: auto;
  white-space: nowrap;
  font-size: .78rem;
}

.factura-form #tributosDesglose span {
  display: inline-block;
  margin-right: .25rem;
}

.factura-detalle-wrapper table th {
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
}

.factura-detalle-wrapper table td {
  vertical-align: middle;
  padding: .4rem .5rem;
}

.factura-detalle-wrapper table input {
  font-size: .85rem;
}

.bg-success-subtle {
  background-color: #d1f4e0 !important;
  border-color: #10b981 !important;
}

@media (max-width: 991px) {
  .factura-page {
    padding-top: .35rem;
  }

  .factura-card {
    min-height: auto;
  }

  .factura-detalle-wrapper {
    height: 45vh;
    min-height: 220px;
    max-height: 45vh;
  }

  .factura-section {
    padding: .85rem;
  }
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — Facturación
   ════════════════════════════════════════════════════════════ */

.factura-detalle-wrapper {
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 767px) {
  .factura-page { padding: 0; }
  .factura-card { border-radius: 0; border-left: 0; border-right: 0; }
  .factura-card-body { padding-left: .75rem; padding-right: .75rem; }

  .factura-header-icon { font-size: 1.2rem; }
  .factura-card .card-header h5 { font-size: 1rem; }
  .factura-card .card-header small { display: none; }

  #detalleTable thead th { font-size: .72rem; padding: .3rem .4rem; white-space: nowrap; }
  #detalleTable tbody td { padding: .3rem .4rem; }
  #detalleTable .form-control-sm { font-size: .82rem; }
  #detalleTable td:nth-child(2), #detalleTable th:nth-child(2) { width: 64px; }
  #detalleTable td:nth-child(4), #detalleTable th:nth-child(4) { width: 52px; }

  .factura-totales-row .col-md-2 { flex: 0 0 50%; max-width: 50%; }
  .factura-totales-row .col-md-2:last-child { flex: 0 0 100%; max-width: 100%; }

  #btnAbrirCobro { width: 100%; font-size: 1.05rem; padding: .75rem; }
  .factura-acciones { flex-direction: column; gap: .5rem !important; }
  .factura-acciones .btn { width: 100%; }
}

/* ── Footer móvil: chips de totales ── */
.factura-total-chip {
  display: flex;
  flex-direction: column;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  padding: .35rem .5rem;
  min-width: 0;
}
.chip-label {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: #6c757d;
  white-space: nowrap;
}
.chip-value {
  font-size: .82rem;
  font-weight: 700;
  color: #212529;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Barra inferior total + botones móvil */
.factura-mob-footer {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: #fff;
  border-top: 2px solid #198754;
  border-radius: 0 0 .5rem .5rem;
  padding: .5rem .4rem .3rem;
}
.factura-mob-total {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.mob-total-label {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #198754;
  letter-spacing: .4px;
}
.mob-total-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: #198754;
  white-space: nowrap;
}
.btn-mob-cobrar {
  font-size: .95rem;
  font-weight: 700;
  padding: .55rem .8rem;
}
.btn-mob-action {
  padding: .55rem .65rem;
  font-size: 1rem;
  flex-shrink: 0;
}

@media (max-width: 767.98px) {

  /* Bottom sheet en móvil */
  #modalCobro .modal-dialog {
    margin: 0;
    max-width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none !important;
  }
  #modalCobro .modal-content {
    border-radius: 1.2rem 1.2rem 0 0;
    max-height: 92vh;
    overflow-y: auto;
  }
  #modalCobro .modal-body { padding: 1rem 1.1rem .75rem; }
  #modalCobro .modal-footer { padding: .5rem 1.1rem 1.2rem; }
  .cobro-total-badge { font-size: 1.8rem; }
  .cobro-cambio-row { font-size: 1.2rem; }

  #toastAtajo { display: none !important; }
}

@media (max-width: 480px) {
  #detalleTable td:nth-child(4),
  #detalleTable th:nth-child(4) { display: none; }
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — Comandas
   ════════════════════════════════════════════════════════════ */

.filtros-scroll {
  display: flex;
  gap: .5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap;
  padding-bottom: .25rem;
  scrollbar-width: none;
}
.filtros-scroll::-webkit-scrollbar { display: none; }
.filtros-scroll .filtro-btn { flex-shrink: 0; }

@media (max-width: 575px) {
  #comandasContainer .col-md-6,
  #comandasContainer .col-lg-4 { flex: 0 0 100%; max-width: 100%; }
  #comandasContainer .card-footer .btn { padding: .5rem .75rem; font-size: .9rem; }
}

@media (max-width: 767px) {
  #modalNuevaComanda .modal-dialog { margin: 0; max-width: 100%; height: 100%; }
  #modalNuevaComanda .modal-content { height: 100%; border-radius: 0; }
  #modalNuevaComanda .modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #catalogoProductos .col-6 { flex: 0 0 33.33%; max-width: 33.33%; }
  #modalNuevaComanda .col-lg-4,
  #modalNuevaComanda .col-lg-8 { flex: 0 0 100%; max-width: 100%; }
  #buscarProducto { max-width: 100% !important; width: 100% !important; }
  #catalogoProductos .card-body { padding: .4rem !important; }
  #modalNuevaComanda .modal-footer { flex-direction: column; gap: .5rem; }
  #modalNuevaComanda .modal-footer .btn { width: 100%; }
}

@media (max-width: 480px) {
  #catalogoProductos .col-6 { flex: 0 0 50%; max-width: 50%; }
}

/* ════════════════════════════════════════════════════════════
   COMPONENTES — Alertas de comanda (cmd-alert)
   ════════════════════════════════════════════════════════════ */

@keyframes slideInToast {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

.card-producto { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.card-producto:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12) !important; }

.cmd-alert {
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: .85rem 1.1rem;
  border-radius: 12px;
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  margin-bottom: 1rem;
}
.cmd-alert .cmd-alert-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 1.15rem;
}
.cmd-alert .cmd-alert-body { flex: 1; }
.cmd-alert .cmd-alert-title { font-weight: 700; font-size: .9rem; }
.cmd-alert .cmd-alert-msg   { font-size: .8rem; opacity: .8; }

.cmd-alert-warning { background: #fffbeb; border-left: 4px solid #f59e0b; }
.cmd-alert-warning .cmd-alert-icon { background: #fef3c7; color: #d97706; }
.cmd-alert-warning .cmd-alert-title { color: #92400e; }
.cmd-alert-success { background: #f0fdf4; border-left: 4px solid #22c55e; }
.cmd-alert-success .cmd-alert-icon { background: #dcfce7; color: #16a34a; }
.cmd-alert-success .cmd-alert-title { color: #14532d; }
.cmd-alert-danger  { background: #fef2f2; border-left: 4px solid #ef4444; }
.cmd-alert-danger  .cmd-alert-icon { background: #fee2e2; color: #dc2626; }
.cmd-alert-danger  .cmd-alert-title { color: #7f1d1d; }
.cmd-alert-info    { background: #eff6ff; border-left: 4px solid #3b82f6; }
.cmd-alert-info    .cmd-alert-icon { background: #dbeafe; color: #2563eb; }
.cmd-alert-info    .cmd-alert-title { color: #1e3a8a; }