/* ==========================================================================
   MONSTER - estilos globales (mobile-first)
   ========================================================================== */
:root {
  --red: #e11d2e;
  --red-dark: #b31222;
  --red-soft: #fdecee;
  --ink: #15161a;
  --ink-soft: #2b2d33;
  --muted: #6b7280;
  --muted-light: #9ca3af;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --success: #0f9d58;
  --success-soft: #e8f7ef;
  --warning: #c2410c;
  --warning-soft: #fff4e8;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #1d4ed8;
  --info-soft: #eef2ff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  --topbar-h: 64px;
  --sidebar-w: 248px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body.nav-open {
  overflow: hidden;
}

h1, h2, h3, h4 {
  margin: 0;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

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

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

img, svg {
  display: block;
  max-width: 100%;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.app-shell {
  min-height: 100vh;
  overflow-x: clip;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--red), #8d0c1b);
  color: #fff;
  font-weight: 900;
  font-size: 17px;
  letter-spacing: -0.04em;
  box-shadow: 0 4px 10px rgba(225, 29, 46, 0.28);
  flex: 0 0 auto;
}

.brand-text {
  display: flex;
  flex-direction: column;
  font-weight: 800;
  font-size: 16px;
  line-height: 1;
  letter-spacing: 0.08em;
}

.brand-text small {
  margin-top: 3px;
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.28em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-soft);
}

.icon-btn:hover {
  background: #f3f4f6;
}

.icon-btn svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.alerts-badge {
  position: absolute;
  top: 5px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--surface);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 12px;
  min-width: 0;
}

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  flex: 0 0 auto;
}

.user-chip-text {
  display: none;
  min-width: 0;
}

.user-chip-text strong {
  display: block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.user-chip-text small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.sidebar {
  position: fixed;
  z-index: 60;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(84vw, var(--sidebar-w));
  padding: 18px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  transform: translateX(-105%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.32s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  will-change: transform;
}

.sidebar.is-open {
  transform: translateX(0);
  box-shadow: 24px 0 60px rgba(15, 23, 42, 0.18);
}

.sidebar-store {
  padding: 12px 12px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.sidebar-store strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  word-break: break-word;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

.nav-link::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
  flex: 0 0 auto;
}

.nav-link:hover {
  background: #f6f7f9;
}

.nav-link.is-active {
  background: var(--red-soft);
  color: var(--red-dark);
}

.nav-link.is-active::before {
  background: var(--red);
}

.sidebar-footer {
  margin-top: auto;
  padding: 18px 12px 6px;
}

.sidebar-overlay {
  position: fixed;
  z-index: 55;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  animation: overlay-in 0.24s ease both;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.main {
  width: auto;
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px 14px 48px;
  min-width: 0;
}

/* --------------------------------------------------------------------------
   Encabezados y tarjetas
   -------------------------------------------------------------------------- */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.page-head h1 {
  margin-top: 3px;
  font-size: clamp(23px, 4vw, 30px);
}

.page-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13.5px;
  max-width: 70ch;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.card + .card {
  margin-top: 14px;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.card-header h2 {
  font-size: 16px;
}

.card-header p {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 3px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid > * {
  min-width: 0;
}

.grid-2 {
  grid-template-columns: 1fr;
}

.grid-3 {
  grid-template-columns: 1fr;
}

.grid-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
  padding: 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.stat-value {
  display: block;
  margin-top: 7px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.stat-hint {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

/* --------------------------------------------------------------------------
   Botones
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #eceef1;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--red);
  color: #fff;
  box-shadow: 0 4px 12px rgba(225, 29, 46, 0.22);
}

.btn-primary:hover {
  background: var(--red-dark);
}

.btn-dark {
  background: var(--ink);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink-soft);
}

.btn-ghost:hover {
  background: #f6f7f9;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger:hover {
  background: #fee2e2;
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 9px;
}

.btn-block {
  width: 100%;
}

.btn-link {
  border: 0;
  background: transparent;
  color: var(--red);
  font-weight: 650;
  padding: 4px;
  min-height: 32px;
}

/* --------------------------------------------------------------------------
   Formularios
   -------------------------------------------------------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-group label,
.form-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.form-group .required {
  color: var(--red);
}

.input,
.select,
.textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="search"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  outline: none;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.input:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(225, 29, 46, 0.12);
}

.input:disabled,
input:disabled,
select:disabled {
  background: #f3f4f6;
  color: var(--muted);
}

.form-hint {
  color: var(--muted);
  font-size: 11.5px;
}

.form-error {
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
}

.scan-feedback {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
}

.scan-feedback[hidden] {
  display: none;
}

.scan-feedback.is-success { color: var(--success); }
.scan-feedback.is-warning { color: var(--warning); }
.scan-feedback.is-error { color: var(--danger); }

.fieldset-note {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--info-soft);
  color: #1e3a8a;
  font-size: 12.5px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.checkbox-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--red);
}

.filter-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

/* --------------------------------------------------------------------------
   Tablas
   -------------------------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: var(--surface);
}

thead th {
  padding: 10px 12px;
  background: #f8f9fa;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody td {
  padding: 12px;
  border-bottom: 1px solid #f0f1f3;
  font-size: 13.5px;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fafafa;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-end;
}

.table-actions .btn {
  min-height: 32px;
  padding: 0 9px;
  font-size: 11.5px;
}

.cell-strong {
  font-weight: 700;
}

.cell-mono {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12.5px;
  letter-spacing: 0.02em;
}

.cell-muted {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  padding: 34px 16px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
}

/* --------------------------------------------------------------------------
   Badges / avisos
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #f1f2f4;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

.badge-role::before {
  display: none;
}

.badge-active {
  background: var(--success-soft);
  color: #067647;
}

.badge-inactive,
.badge-vendido {
  background: #f3f4f6;
  color: #6b7280;
}

.badge-en_stock {
  background: var(--success-soft);
  color: #067647;
}

.badge-en_servicio {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-prestado {
  background: var(--info-soft);
  color: var(--info);
}

.badge-superadministrador {
  background: var(--ink);
  color: #fff;
}

.badge-administrador {
  background: var(--red-soft);
  color: var(--red-dark);
}

.badge-vendedor {
  background: var(--info-soft);
  color: var(--info);
}

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--info-soft);
  color: #1e3a8a;
  font-size: 12.5px;
  line-height: 1.45;
}

.notice-warning {
  background: var(--warning-soft);
  color: #9a3412;
}

.notice strong {
  font-weight: 800;
}

/* --------------------------------------------------------------------------
   Utilidades
   -------------------------------------------------------------------------- */
.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.xs {
  font-size: 11px;
}

.strong {
  font-weight: 700;
}

.mono {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-between {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 18px; }

.divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}

.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 12px;
  font-size: 13px;
}

.kv dt {
  color: var(--muted);
  font-weight: 600;
}

.kv dd {
  margin: 0;
  font-weight: 650;
  word-break: break-word;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-light);
  margin-right: 6px;
}

.status-dot.ok { background: var(--success); }
.status-dot.error { background: var(--danger); }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   SweetAlert2 (ajustes de marca)
   -------------------------------------------------------------------------- */
.swal2-popup {
  font-family: var(--font) !important;
  border-radius: 18px !important;
  padding: 22px !important;
}

.swal2-title {
  font-size: 20px !important;
  font-weight: 800 !important;
}

.swal2-html-container {
  font-size: 14px !important;
  text-align: left !important;
  margin-top: 8px !important;
}

.swal2-confirm,
.swal2-cancel,
.swal2-deny {
  border-radius: 10px !important;
  font-weight: 700 !important;
  min-height: 44px;
  padding: 0 18px !important;
}

.swal2-confirm {
  background: var(--red) !important;
}

.swal2-deny {
  background: #15161a !important;
  color: #fff !important;
}

.swal2-html-container .form-grid {
  margin-top: 10px;
  text-align: left;
}

.swal2-html-container .form-group {
  margin-bottom: 2px;
}

.swal2-html-container .form-group label {
  display: block;
  margin-bottom: 5px;
}

.swal-form-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (min-width: 640px) {
  .main {
    padding: 24px 20px 60px;
  }
  .grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid .span-2 {
    grid-column: 1 / -1;
  }
  .filter-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .user-chip-text {
    display: block;
  }
}

@media (min-width: 900px) {
  .topbar {
    padding: 0 22px;
  }
  #btn-menu {
    display: inline-grid;
  }
  .sidebar {
    top: var(--topbar-h);
    transform: none;
    width: var(--sidebar-w);
    box-shadow: none;
    border-right: 1px solid var(--line);
    padding-top: 16px;
  }
  body.sidebar-collapsed .sidebar {
    transform: translateX(calc(-100% - 10px));
    box-shadow: none;
  }
  .sidebar .nav-link,
  .sidebar .sidebar-store,
  .sidebar .sidebar-footer {
    transition: opacity 0.2s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }
  body.sidebar-collapsed .sidebar .nav-link,
  body.sidebar-collapsed .sidebar .sidebar-store,
  body.sidebar-collapsed .sidebar .sidebar-footer {
    opacity: 0;
    transform: translateX(-12px);
  }
  .sidebar-overlay {
    display: none !important;
  }
  .main {
    margin-left: var(--sidebar-w);
    padding: 28px 30px 64px;
    max-width: calc(1360px + var(--sidebar-w));
    transition: margin-left 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  }
  body.sidebar-collapsed .main {
    margin-left: 0;
  }
  .grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .filter-bar {
    grid-template-columns: 220px 180px 1fr auto;
    align-items: end;
  }
}

@media (min-width: 1200px) {
  .topbar {
    padding-left: 28px;
  }
  .main {
    padding-left: 40px;
    padding-right: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   Fase 2 - catálogo, inventario, compras de usados y etiquetas
   ========================================================================== */
.badge-info {
  background: var(--info-soft);
  color: var(--info);
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

.store-picker {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 150px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.store-picker select {
  min-height: 40px;
  padding: 7px 10px;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
}

/* Tabs ------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

.tab {
  flex: 1 0 auto;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 700;
}

.tab.is-active {
  background: var(--ink);
  color: #fff;
}

.tab-panel {
  margin-top: 14px;
}

/* Escaneo ---------------------------------------------------------------- */
.scan-card {
  border-color: #c7d2fe;
}

.scan-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.scan-result {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfe;
}

.scan-result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.scan-result-head h3 {
  margin-top: 6px;
  font-size: 17px;
}

/* Compras de usados ------------------------------------------------------ */
.purchase-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-section {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.form-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.form-section h3 {
  margin-bottom: 10px;
  font-size: 14px;
}

.purchase-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.purchase-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbfc;
}

.purchase-item-head {
  margin-bottom: 10px;
}

.selected-person {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: #fbfcfe;
}

.purchase-footer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding: 14px 0 2px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.purchase-total {
  display: block;
  margin-top: 3px;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  margin-top: 8px;
  overflow-y: auto;
}

.result-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
}

.result-item:hover {
  border-color: var(--red);
}

.result-empty {
  padding: 12px;
  color: var(--muted);
  font-size: 12.5px;
}

/* Etiquetas -------------------------------------------------------------- */
.label-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.label-layout > * {
  min-width: 0;
}

.label-filters {
  margin-bottom: 0;
}

.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 560px;
  overflow-y: auto;
}

.candidate-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.candidate-item:hover {
  border-color: var(--line-strong);
}

.candidate-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  accent-color: var(--red);
}

.candidate-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.candidate-body strong {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.candidate-price {
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.label-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  overflow-x: auto;
  min-height: 120px;
}

.label-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.2mm;
  width: var(--label-w, 50mm);
  height: var(--label-h, 30mm);
  flex: 0 0 auto;
  padding: 1mm;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: 2mm;
  background: #fff;
  color: #000;
  line-height: 1.05;
}

/* Las líneas de texto conservan su altura; el código de barras se queda con
   todo el espacio vertical libre para que las barras sean lo más altas
   posible dentro del mismo tamaño de etiqueta. */
.label-card > * {
  flex: 0 0 auto;
}

.label-brand {
  font-size: 2.4mm;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.label-model {
  font-size: 2.9mm;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.label-meta {
  font-size: 2.3mm;
  color: #333;
}

.label-variant {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 2.2mm;
  color: #222;
}

.label-imei {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 2.3mm;
  white-space: nowrap;
}

.label-price {
  font-size: 3.8mm;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.label-barcode {
  flex: 1 1 auto;
  display: flex;
  min-height: 5mm;
  margin-top: 0.3mm;
}

.label-barcode svg {
  display: block;
  width: 100%;
  height: 100%;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.timeline-item {
  padding-left: 12px;
  border-left: 3px solid var(--line);
}

.timeline-date {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.timeline-item strong {
  display: block;
  margin: 2px 0;
  font-size: 12.5px;
  text-transform: capitalize;
}

.timeline-item p {
  margin: 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.print-area {
  display: none;
}

@media (min-width: 900px) {
  .filter-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
  }

  .label-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .tabs {
    display: inline-flex;
  }

  .tab {
    flex: 0 0 auto;
  }
}

@media (min-width: 1100px) {
  .label-layout {
    grid-template-columns: 420px minmax(0, 1fr);
  }
}

@media print {
  @page {
    margin: 4mm;
  }

  body {
    background: #fff;
    min-height: 0;
  }

  .app-shell {
    display: none !important;
  }

  .print-area {
    display: flex !important;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0;
    width: var(--print-w, 50mm);
  }

  /* Los avisos flotantes (toast, carga, modales) no deben salir impresos ni
     aportar altura a la hoja. */
  .swal2-container,
  .offline-banner {
    display: none !important;
  }

  .print-area .label-card {
    border: 0;
    border-radius: 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

/* ==========================================================================
   Fase 3 - punto de venta, carrito e historial
   ========================================================================== */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}

.pos-layout > * {
  min-width: 0;
}

.scan-add {
  align-self: end;
  min-height: 42px;
  white-space: nowrap;
}

.pos-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 56vh;
  margin-top: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.pos-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  text-align: left;
}

.pos-item:hover {
  border-color: var(--red);
}

.pos-item.is-in-cart {
  border-color: var(--success);
  background: var(--success-soft);
}

.pos-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.pos-item-main strong {
  font-size: 13.5px;
  overflow-wrap: anywhere;
}

.pos-item-main .cell-muted {
  overflow-wrap: anywhere;
}

.pos-item-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex: 0 0 auto;
  text-align: right;
}

.pos-item-side strong {
  font-size: 13.5px;
  white-space: nowrap;
}

/* Carrito ----------------------------------------------------------------- */
.pos-cart-card .card-header {
  align-items: flex-start;
}

.cart-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 44vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.cart-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fafbfc;
}

.cart-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cart-item-main strong {
  font-size: 13.5px;
  overflow-wrap: anywhere;
}

.cart-item-main .cell-muted {
  overflow-wrap: anywhere;
}

.cart-item-price {
  color: var(--muted);
  font-size: 12px;
}

.cart-item-side {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cart-line-total {
  margin-left: auto;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.qty-control {
  display: inline-flex;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fff;
}

.qty-btn {
  width: 34px;
  min-height: 34px;
  border: 0;
  background: #fff;
  color: var(--ink);
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
}

.qty-btn:hover {
  background: #f3f4f6;
}

.qty-control span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
}

.cart-totals {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
}

.cart-total-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 18px;
  font-weight: 800;
}

.cart-total-row span:first-child {
  color: var(--ink);
}

.mixed-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #c7d2fe;
  border-radius: 12px;
  background: #f8faff;
}

.mixed-summary strong {
  display: block;
  margin-top: 3px;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.pos-checkout {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.is-invalid {
  border-color: var(--danger) !important;
}

.doc-number {
  margin-top: 2px;
  font-size: 16px;
  font-weight: 800;
}

/* Historial --------------------------------------------------------------- */
.filter-actions {
  display: flex;
  align-items: flex-end;
}

.filter-actions .btn {
  width: 100%;
}

@media (min-width: 640px) {
  .filter-bar.sales-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .cart-items {
    max-height: 40vh;
  }
  .pos-results {
    max-height: 50vh;
  }
}

@media (min-width: 900px) {
  .pos-layout {
    grid-template-columns: minmax(0, 1.45fr) minmax(340px, 0.85fr);
  }
  .pos-side {
    position: sticky;
    top: calc(var(--topbar-h) + 16px);
  }
  .filter-bar.sales-filters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .pos-results {
    max-height: 62vh;
  }
}

@media (min-width: 1200px) {
  .filter-bar.sales-filters {
    grid-template-columns: 1.4fr 0.9fr 0.9fr 0.9fr 0.9fr auto;
  }
}

/* Ajustes Fase 3 tras revisión visual --------------------------------------- */
.cell-nowrap {
  white-space: nowrap;
}

.swal2-html-container .table-wrap {
  max-width: 100%;
}

.swal2-html-container table {
  min-width: 620px;
}

@media (max-width: 639px) {
  .pos-page-actions {
    width: 100%;
  }
  .pos-page-actions .store-picker {
    flex: 1 1 100%;
  }
  .pos-page-actions .btn {
    flex: 1 1 0;
    justify-content: center;
  }
}

@media (min-width: 900px) {
  .pos-side {
    position: static;
  }
  .pos-checkout {
    position: static;
  }
}

/* ==========================================================================
   Fase 4 - mantenimientos, técnicos, préstamos y alertas
   ========================================================================== */
.detail-title {
  margin-top: 3px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.detail-actions .btn {
  flex: 1 1 auto;
}

/* Alertas ---------------------------------------------------------------- */
.alert-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.alert-section-title {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.alert-section-title:first-of-type {
  margin-top: 4px;
}

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.alert-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--warning);
  border-radius: 12px;
  background: #fff;
}

.alert-card.alert-prestamo {
  border-left-color: var(--info);
}

.alert-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.alert-card-head strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.alert-kind {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.alert-subtitle,
.alert-detail {
  margin: 0;
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.alert-subtitle {
  color: var(--ink-soft);
}

.alert-detail {
  color: var(--danger);
  font-weight: 650;
}

.alert-card.alert-prestamo .alert-detail {
  color: var(--info);
}

.alert-card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.alert-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.alert-store {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f1f2f4;
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 700;
}

.alert-meta,
.alert-note {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  overflow-wrap: anywhere;
}

.alert-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}

.alert-actions .btn {
  min-height: 32px;
  padding: 0 9px;
  font-size: 11.5px;
}

.alert-empty {
  padding: 26px 12px;
}

/* Préstamos -------------------------------------------------------------- */
.draft-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.draft-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbfc;
}

.draft-item strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.draft-item {
  flex-direction: column;
  align-items: stretch;
}

.draft-item-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.draft-item-head > div:first-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 180px;
}

.draft-pricing {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.draft-price-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.margin-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.margin-btn {
  padding: 4px 9px;
  font-size: 11.5px;
}

.draft-total {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid #c7d2fe;
  border-radius: 12px;
  background: #f8faff;
  font-size: 13px;
}

.draft-total strong {
  display: block;
  margin-top: 2px;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.loan-product-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px auto;
  gap: 8px;
  align-items: center;
}

.loan-product-row select {
  min-width: 0;
}

@media (min-width: 640px) {
  .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px 22px;
  }

  .detail-actions .btn {
    flex: 0 1 auto;
  }
}

@media (max-width: 520px) {
  .loan-product-row {
    grid-template-columns: minmax(0, 1fr) 70px;
  }

  .loan-product-row .btn {
    grid-column: 1 / -1;
  }

  .alert-actions {
    margin-left: 0;
    width: 100%;
  }

  .alert-actions .btn {
    flex: 1 1 0;
    justify-content: center;
  }
}

/* ==========================================================================
   Fase 5: dashboard, caja y reportes
   ========================================================================== */
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-height: 190px;
  padding-top: 8px;
  overflow: hidden;
}

.chart-bar-item {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  height: 190px;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.chart-bar-value {
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 9.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-bar-track {
  display: flex;
  align-items: flex-end;
  width: 100%;
  height: 130px;
  overflow: hidden;
  border-radius: 7px;
  background: #f1f2f4;
}

.chart-bar-fill {
  width: 100%;
  min-height: 3px;
  border-radius: 7px 7px 0 0;
  background: linear-gradient(180deg, #ef4444, var(--red));
}

.chart-bar-label {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.chart-bars.is-dense {
  gap: 3px;
}

.chart-bars.is-dense .chart-bar-value {
  display: none;
}

.chart-bars.is-dense .chart-bar-label {
  font-size: 8px;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar-list-row {
  min-width: 0;
}

.bar-list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 12px;
}

.bar-list-label {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.bar-list-value {
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.bar-list-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #f1f2f4;
}

.bar-list-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ink), var(--red));
}

.data-list {
  display: flex;
  flex-direction: column;
}

.data-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #f0f1f3;
}

.data-row:last-child {
  border-bottom: 0;
}

.data-row-main {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.data-row-main strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.data-row-side {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
}

.data-row-value {
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.rank-badge {
  display: inline-grid;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.data-list .empty-state {
  padding: 20px 8px;
}

.cash-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #ffffff, #fafbfc);
  box-shadow: var(--shadow-sm);
}

.cash-banner-main {
  min-width: 0;
}

.cash-banner-main h2 {
  margin-top: 8px;
  font-size: 20px;
}

.cash-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cash-banner-actions .btn {
  min-height: 40px;
}

.report-export-actions {
  margin-top: 12px;
}

.report-filters {
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .report-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .report-filters {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
  }
}

@media (max-width: 520px) {
  .cash-banner-actions {
    width: 100%;
  }

  .cash-banner-actions .btn {
    flex: 1 1 0;
    justify-content: center;
  }

  .data-row-side {
    max-width: 46%;
  }

  .data-row-value {
    white-space: normal;
  }
}

/* ==========================================================================
   Fase 6 - PWA, configuración de impresión y pulido final
   ========================================================================== */

/* Accesibilidad y safe areas ------------------------------------------------ */
:focus-visible {
  outline: 3px solid rgba(225, 29, 46, 0.45);
  outline-offset: 2px;
}

.btn:focus-visible,
.icon-btn:focus-visible,
.nav-link:focus-visible,
.width-option:focus-within {
  outline: 3px solid rgba(225, 29, 46, 0.4);
  outline-offset: 2px;
}

.topbar {
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
}

.sidebar {
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

.main {
  padding-bottom: calc(48px + env(safe-area-inset-bottom));
}

/* Evita el zoom automático de iOS al enfocar campos. */
@media (max-width: 899px) {
  @supports (-webkit-touch-callout: none) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="search"],
    input[type="date"],
    select,
    textarea {
      font-size: 16px;
    }
  }
}

/* PWA: instalación, conexión y actualización ------------------------------- */
.install-app-btn {
  width: 100%;
  margin-bottom: 10px;
  justify-content: flex-start;
  gap: 8px;
}

.install-app-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.offline-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 130;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #15161a;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.35;
}

.offline-banner strong {
  color: #ffb4bb;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pwa-update {
  position: fixed;
  top: calc(var(--topbar-h) + 10px + env(safe-area-inset-top));
  left: 50%;
  z-index: 130;
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 8px 10px 8px 14px;
  border-radius: 999px;
  background: #15161a;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 12.5px;
  transform: translateX(-50%);
}

.pwa-update .btn {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.install-steps {
  margin: 10px auto 0;
  padding-left: 20px;
  text-align: left;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}

.install-steps li + li {
  margin-top: 4px;
}

@media (min-width: 640px) {
  .offline-banner {
    left: auto;
    right: 18px;
    max-width: 380px;
  }
}

/* Configuración de impresión ------------------------------------------------ */
.width-options {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
}

.width-options legend {
  margin-bottom: 2px;
  padding: 0;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.width-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.width-option:hover {
  border-color: var(--muted-light);
}

.width-option input {
  width: 18px;
  height: 18px;
  min-height: 0;
  margin: 2px 0 0;
  padding: 0;
  accent-color: var(--red);
}

.width-option-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.width-option-body strong {
  font-size: 14px;
}

.width-option-body small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.width-option:has(input:checked) {
  border-color: var(--red);
  background: #fff7f8;
  box-shadow: 0 0 0 3px rgba(225, 29, 46, 0.1);
}

.width-option input:checked + .width-option-body strong {
  color: var(--red);
}

.settings-note {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.settings-note strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

#settings-status {
  min-height: 18px;
}

.form-hint.is-ok {
  color: var(--success);
  font-weight: 600;
}

.form-hint.is-error {
  color: var(--danger);
  font-weight: 600;
}

/* Vista previa del ticket -------------------------------------------------- */
.ticket-preview-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 18px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f8fa;
  overflow-x: auto;
}

.ticket-preview {
  --preview-w: 80mm;
  width: min(var(--preview-w), 100%);
  padding: 12px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 4px;
  background: #fff;
  color: #111;
  box-shadow: var(--shadow-sm);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, "Courier New", monospace;
  font-size: 11.5px;
  line-height: 1.4;
  transition: width 0.2s ease, font-size 0.2s ease;
}

.ticket-preview.is-narrow {
  padding: 9px 10px;
  font-size: 10px;
}

.ticket-preview-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed #bbb;
  text-align: center;
}

.ticket-preview-head strong {
  font-size: 1.1em;
  letter-spacing: 0.04em;
}

.ticket-preview-head span {
  color: #555;
  font-size: 0.92em;
}

.ticket-preview-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
}

.ticket-preview-row strong {
  white-space: nowrap;
}

.ticket-preview-row.total {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #bbb;
  font-weight: 700;
}

.ticket-preview-warranty {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #bbb;
  color: #555;
  font-size: 0.9em;
  white-space: pre-wrap;
}

.ticket-preview-warranty.is-empty {
  color: #999;
  font-style: italic;
}

/* ==========================================================================
   Dispositivos - selección y prueba de impresoras y escáner
   ========================================================================== */
.device-browser-note {
  align-items: flex-start;
}

.device-grid {
  grid-template-columns: 1fr;
}

.device-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.device-card.is-busy {
  opacity: 0.75;
}

.device-status {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fafbfc;
}

.device-status strong {
  display: block;
  font-size: 13px;
  line-height: 1.3;
}

.device-status p {
  margin: 2px 0 0;
  line-height: 1.35;
}

.device-status-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--muted-light);
  box-shadow: 0 0 0 4px rgba(156, 163, 175, 0.16);
}

.device-status-dot.is-connected {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(15, 157, 88, 0.16);
}

.device-status-dot.is-missing {
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(194, 65, 12, 0.16);
}

.device-status-dot.is-selected {
  background: var(--info);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.14);
}

.device-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.device-meta {
  margin-top: 0;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.device-meta dt {
  font-size: 11.5px;
}

.device-meta dd {
  font-size: 12.5px;
}

.device-test-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 11px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
}

.device-test-box label {
  font-size: 12px;
  font-weight: 700;
}

.device-test-input {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
}

.device-test-input:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(225, 29, 46, 0.12);
}

.device-test-box .form-hint {
  margin: 0;
}

@media (min-width: 900px) {
  .device-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1320px) {
  .device-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* --------------------------------------------------------------------------
   Página independiente de prueba de impresión
   -------------------------------------------------------------------------- */
.device-test-page {
  min-height: 100vh;
  padding: 18px;
  background: var(--bg);
}

.device-test-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.device-test-toolbar-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.device-test-toolbar-text strong {
  font-size: 16px;
}

.device-test-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.device-test-help {
  max-width: 980px;
  margin: 10px auto;
  text-align: center;
}

.device-test-stage {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 320px;
  padding: 18px 0;
  overflow-x: auto;
}

.device-test-sheet.is-thermal {
  display: flex;
  justify-content: center;
}

.test-ticket {
  width: var(--ticket-w, 80mm);
  max-width: 100%;
  padding: 4mm 3.5mm;
  background: #fff;
  color: #000;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  line-height: 1.35;
  box-shadow: var(--shadow);
}

.test-ticket.is-58 {
  font-size: 10px;
}

.test-ticket-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  text-align: center;
}

.test-ticket-head strong {
  font-size: 15px;
  letter-spacing: 0.08em;
}

.test-ticket-head span {
  font-size: 10px;
  letter-spacing: 0.14em;
}

.test-ticket-center {
  margin: 3px 0;
  text-align: center;
}

.test-ticket-device {
  font-weight: 700;
  word-break: break-word;
}

.test-ticket-rule {
  margin: 6px 0;
  border-top: 1px dashed #000;
}

.test-ticket-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 1px 0;
}

.test-ticket-row strong {
  white-space: nowrap;
}

.test-ticket-row.total {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px solid #000;
  font-weight: 700;
}

.test-ticket-barcode {
  margin: 8px auto 3px;
  max-width: 100%;
}

.test-ticket-barcode svg {
  display: block;
  width: 100%;
  height: auto;
}

.test-ticket-code {
  font-size: 9px;
  letter-spacing: 0.08em;
}

.test-ticket-foot {
  margin-top: 8px;
  font-size: 9px;
  letter-spacing: 0.08em;
}

.test-label {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.2mm;
  width: var(--label-w, 50mm);
  height: var(--label-h, 30mm);
  padding: 1mm;
  overflow: hidden;
  background: #fff;
  color: #000;
  line-height: 1.05;
  box-shadow: var(--shadow);
}

.test-label > * {
  flex: 0 0 auto;
}

.test-label .label-brand {
  font-size: 2.4mm;
}

.test-label .label-model {
  font-size: 2.9mm;
}

.test-label .label-meta {
  overflow: hidden;
  font-size: 2.1mm;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.test-label .label-imei {
  font-size: 2.3mm;
}

.test-label-barcode {
  flex: 1 1 auto;
  display: flex;
  min-height: 5mm;
  margin-top: 0.3mm;
}

.test-label-barcode svg {
  display: block;
  width: 100%;
  height: 100%;
}

.device-test-status {
  max-width: 980px;
  margin: 6px auto 0;
  text-align: center;
}

.device-test-status.is-ok {
  color: var(--success);
}

.device-test-status.is-error {
  color: var(--danger);
}

@media (max-width: 620px) {
  .device-test-page {
    padding: 10px;
  }

  .device-test-toolbar {
    padding: 12px;
  }

  .device-test-toolbar-actions {
    width: 100%;
  }

  .device-test-toolbar-actions .btn {
    flex: 1 1 auto;
  }
}

@media print {
  .device-test-page {
    padding: 0;
    background: #fff;
  }

  .device-test-toolbar,
  .device-test-help,
  .device-test-status {
    display: none !important;
  }

  .device-test-stage {
    display: block;
    min-height: 0;
    padding: 0;
    overflow: visible;
  }

  .device-test-sheet {
    display: block;
  }

  .test-ticket,
  .test-label {
    box-shadow: none;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .test-ticket {
    width: 100%;
    max-width: none;
    padding: 0;
  }

  .test-label {
    width: 50mm;
    height: 30mm;
  }
}
