/* ============================================================================
   Facturación — Diseño profesional (desktop first, mobile responsive)
   Paleta: slate + indigo. Tipografía: Inter.
   ============================================================================ */

:root {
  /* Superficies */
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --line: #e5e7eb;
  --line-strong: #d1d5db;

  /* Texto */
  --ink: #0f172a;
  --ink-soft: #1e293b;
  --text: #334155;
  --muted: #64748b;
  --muted-soft: #94a3b8;

  /* Brand */
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --primary-ink: #ffffff;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-ring: rgba(79, 70, 229, .2);

  /* Estados */
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #0284c7;
  --info-soft: #eff6ff;

  /* Radios y espacios */
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 1px rgba(15, 23, 42, .03);
  --shadow: 0 1px 3px rgba(15, 23, 42, .05), 0 4px 12px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .08), 0 4px 10px rgba(15, 23, 42, .04);

  /* Layout */
  --sidebar-w: 248px;
  --header-h: 64px;
  --tap: 40px;
  --font: 'Inter', -apple-system, 'Segoe UI', Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1, h2, h3, h4 { color: var(--ink); font-weight: 600; letter-spacing: -0.01em; }

/* ============================================================================
   LOGIN
   ============================================================================ */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(79, 70, 229, .08), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, rgba(15, 23, 42, .05), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.login-brand {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 28px;
}
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .25);
}
.brand-mark::after {
  content: 'F';
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 20px; letter-spacing: -0.02em;
}
.brand-text .brand-name {
  font-size: 17px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em;
}
.brand-text .brand-sub {
  font-size: 12px; color: var(--muted); margin-top: 2px;
}
.form-field { margin-bottom: 18px; }
.form-field label {
  display: block;
  font-size: 13px; font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}
.form-field label .muted { color: var(--muted-soft); font-weight: 400; }
.login-hint {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 20px 0 0;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}
.login-hint strong { color: var(--ink); font-weight: 600; }

/* ============================================================================
   APP SHELL — Layout
   ============================================================================ */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "nav header"
    "nav main";
}
.app-nav    { grid-area: nav; }
.app-header { grid-area: header; }
.app-main   { grid-area: main; }

/* ============================================================================
   SIDEBAR
   ============================================================================ */
.app-nav {
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
}
.nav-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px;
  border-bottom: 1px solid var(--line);
  min-height: var(--header-h);
}
.nav-brand .brand-text { flex: 1; min-width: 0; }
.nav-brand .brand-name { font-size: 15px; font-weight: 700; color: var(--ink); }
.nav-brand .brand-sub {
  font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}

.nav-items {
  display: flex; flex-direction: column;
  gap: 2px;
  padding: 14px 10px;
  flex: 1;
}
.nav-items a {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px; font-weight: 500;
  position: relative;
  transition: background .12s, color .12s;
}
.nav-items a:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.nav-items a.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-items a.active::before {
  content: ''; position: absolute;
  left: -10px; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-items a .nav-ic {
  width: 18px; height: 18px;
  flex-shrink: 0;
  stroke-width: 1.75;
  color: var(--muted);
  transition: color .12s;
}
.nav-items a:hover .nav-ic,
.nav-items a.active .nav-ic { color: currentColor; }
.nav-items .nav-highlight {
  background: var(--primary);
  color: #fff;
  margin: 6px 0;
}
.nav-items .nav-highlight:hover {
  background: var(--primary-hover);
  color: #fff;
}
.nav-items .nav-highlight .nav-ic { color: #fff; }
.nav-items .nav-highlight.active {
  background: var(--primary);
  color: #fff;
}
.nav-items .nav-highlight.active::before { display: none; }

.nav-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--line);
}
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: background .12s;
}
.user-chip:hover { background: var(--surface-2); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-info .user-name {
  font-size: 13px; font-weight: 500; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-info .user-role {
  font-size: 11px; color: var(--muted);
}

/* ============================================================================
   HEADER
   ============================================================================ */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 32px;
  position: sticky; top: 0; z-index: 10;
}
.header-title h1 {
  font-size: 20px; font-weight: 600; color: var(--ink);
  margin: 0;
  letter-spacing: -0.015em;
}
.header-sub {
  font-size: 12px; color: var(--muted);
  margin-top: 2px;
}
.header-actions { display: flex; align-items: center; gap: 12px; }
#empresa-switcher select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 32px 7px 12px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  max-width: 260px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
#empresa-switcher select:hover { border-color: var(--line-strong); }
#empresa-switcher select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* ============================================================================
   MAIN
   ============================================================================ */
.app-main {
  padding: 28px 32px;
  max-width: 1400px;
  width: 100%;
}

/* ============================================================================
   BOTONES
   ============================================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px; font-weight: 500;
  text-decoration: none;
  transition: all .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }

.btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }

.btn-ghost { background: transparent; border: 0; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.icon-btn {
  background: transparent; color: var(--muted); border: 0;
  padding: 7px; border-radius: var(--radius-sm);
  cursor: pointer; min-width: 34px; min-height: 34px;
  display: inline-grid; place-items: center;
  transition: color .12s, background .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; stroke-width: 1.75; }

/* ============================================================================
   INPUTS / LABELS
   ============================================================================ */
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
input::placeholder, textarea::placeholder { color: var(--muted-soft); }
textarea { min-height: 90px; resize: vertical; }

label {
  display: block;
  font-size: 13px; font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.field { margin-bottom: 16px; }
.fields-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px)  { .fields-grid.two   { grid-template-columns: 1fr 1fr; } }
@media (min-width: 800px)  { .fields-grid.three { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .fields-grid.four  { grid-template-columns: repeat(4, 1fr); } }

/* ============================================================================
   CARDS
   ============================================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.card .card-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.card .card-head h2 { margin: 0; flex: 1; }

/* ============================================================================
   STATS CARDS (Dashboard)
   ============================================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 24px;
}
@media (min-width: 640px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color .12s, box-shadow .12s;
}
.stat-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
}
.stat-card.ok::before    { background: var(--ok); }
.stat-card.warn::before  { background: var(--warn); }
.stat-card.muted-stat::before { background: var(--muted-soft); }

.stat-card .stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.stat-card .stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat-card .stat-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* ============================================================================
   LISTAS (card-list, mobile) y TABLAS (data-table, desktop)
   ============================================================================ */
.card-list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
}
.list-item:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title {
  font-size: 14px; font-weight: 500; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item .li-sub {
  font-size: 12.5px; color: var(--muted); margin-top: 2px;
}
.list-item .li-right { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }

.data-table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
  text-align: left;
  padding: 11px 16px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.data-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--ink);
  vertical-align: middle;
}
.data-table tbody tr {
  cursor: pointer;
  transition: background .1s;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num, .data-table .monto { font-variant-numeric: tabular-nums; }
.data-table .monto { text-align: right; white-space: nowrap; font-weight: 500; }
.data-table .acc-col { text-align: right; white-space: nowrap; }

/* Visibilidad responsive: cards en móvil, tabla en desktop */
.card-list { display: flex; }
.data-table-wrap { display: none; }
@media (min-width: 1024px) {
  .card-list { display: none; }
  .data-table-wrap { display: block; }
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
  font-size: 13.5px;
}

/* ============================================================================
   BADGES / CHIPS
   ============================================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 500;
  white-space: nowrap;
  line-height: 1.5;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-ok     { background: var(--ok-soft);     color: var(--ok); }
.badge-warn   { background: var(--warn-soft);   color: var(--warn); }
.badge-info   { background: var(--info-soft);   color: var(--info); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted  { background: var(--surface-2);   color: var(--muted); border: 1px solid var(--line); }
.badge-muted::before { background: var(--muted); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  color: var(--text);
}

/* ============================================================================
   TABLA DE ITEMS (factura nueva)
   ============================================================================ */
.items-table {
  width: 100%; border-collapse: collapse;
  margin: 10px 0 4px;
  font-size: 13.5px;
}
.items-table th, .items-table td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.items-table th {
  font-size: 11px; color: var(--muted);
  font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em;
  padding-bottom: 10px;
}
.items-table input, .items-table select {
  min-height: 34px; padding: 6px 10px; font-size: 13px;
}
.items-table .col-cant input { width: 80px; }
.items-table .col-precio input { width: 120px; text-align: right; }
.items-table .col-iva select { width: 90px; }
.items-table .col-sub { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; }
.items-table .col-acc { width: 40px; }

.items-mobile { display: none; }
@media (max-width: 720px) {
  .items-table { display: none; }
  .items-mobile { display: block; }
  .item-card {
    background: var(--surface-2);
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .item-card .full { grid-column: 1 / -1; }
  .item-card .item-sub {
    grid-column: 1 / -1;
    display: flex; justify-content: space-between; align-items: center;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
    font-weight: 600;
  }
}

/* ============================================================================
   TOTALES BOX
   ============================================================================ */
.totales {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 20px;
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
}
.totales .label { color: var(--muted); }
.totales .right { text-align: right; color: var(--ink); font-weight: 500; }
.totales .total-final {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 6px;
  display: flex; justify-content: space-between;
  font-size: 18px; font-weight: 700; color: var(--ink);
  letter-spacing: -0.01em;
}

/* ============================================================================
   DIÁLOGOS
   ============================================================================ */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: grid; place-items: center;
  padding: 16px;
  animation: fade-in .15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.dialog {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px 26px;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: slide-up .2s ease;
}
@keyframes slide-up {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.dialog h3 {
  margin: 0 0 20px;
  font-size: 17px; font-weight: 600; color: var(--ink);
}
.dialog-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* ============================================================================
   AUTOCOMPLETE
   ============================================================================ */
.autocomplete { position: relative; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  max-height: 240px;
  overflow: auto;
  z-index: 10;
  box-shadow: var(--shadow-lg);
}
.autocomplete-list div {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.autocomplete-list div:last-child { border-bottom: 0; }
.autocomplete-list div:hover,
.autocomplete-list div.hl { background: var(--accent-soft); color: var(--accent); }
.autocomplete-list div small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

/* ============================================================================
   FILTROS
   ============================================================================ */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.filters > * { min-height: 38px; }
.filters .search { flex: 2; min-width: 220px; }
.filters select { min-width: 150px; max-width: 200px; }

/* ============================================================================
   ALERTS
   ============================================================================ */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.5;
  border: 1px solid;
}
.alert .alert-ic { flex-shrink: 0; font-size: 14px; line-height: 1.3; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.alert-warn  { background: var(--warn-soft);   color: var(--warn);   border-color: #fde68a; }
.alert-info  { background: var(--info-soft);   color: var(--info);   border-color: #bfdbfe; }
.alert-ok    { background: var(--ok-soft);     color: var(--ok);     border-color: #86efac; }
.feedback-stack { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }

/* ============================================================================
   CHECKBOX LIST (actividades de timbrado, etc.)
   ============================================================================ */
.checkbox-list {
  display: flex; flex-direction: column; gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-2);
  max-height: 240px;
  overflow-y: auto;
}
.checkbox-list .check-item {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer;
  padding: 6px 4px;
  margin: 0;
  font-size: 13.5px;
  color: var(--ink);
  font-weight: 500;
  min-height: 32px;
  border-radius: var(--radius-sm);
}
.checkbox-list .check-item:hover { background: rgba(79, 70, 229, .05); }
.checkbox-list .check-item input {
  width: auto; min-height: auto; margin: 0;
  accent-color: var(--accent);
}

/* ============================================================================
   UTILIDADES
   ============================================================================ */
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.ok    { color: var(--ok); }
.warn  { color: var(--warn); }
.right { text-align: right; }
.hide  { display: none !important; }
.row-between {
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
}
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ============================================================================
   TOAST
   ============================================================================ */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px; left: auto;
  transform: none;
  z-index: 50;
  display: flex; flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in .22s cubic-bezier(.16, 1, .3, 1);
  max-width: 90vw;
}
.toast.ok  { background: var(--ok); }
.toast.err { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================================
   CALIBRACIÓN — editor visual
   ============================================================================ */
.calib-wrap { display: flex; flex-direction: column; gap: 16px; }
.calib-toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
}
.calib-printer-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}
.calib-printer-bar select { max-width: 280px; flex: 1; min-width: 180px; }
.calib-printer-bar label { margin: 0; }
.calib-main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
}
@media (max-width: 1100px) {
  .calib-main { grid-template-columns: 1fr; }
}
.calib-preview-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  overflow: auto;
}
.calib-page {
  position: relative;
  width: 210mm;
  background: #fff;
  border: 1px solid var(--line-strong);
  box-shadow: 0 4px 14px rgba(15,23,42,.08);
  margin: 0 auto;
  /* El usuario puede achicar con zoom CSS propio si quiere */
  transform-origin: top left;
}
@media (max-width: 900px) {
  .calib-page { transform: scale(0.5); margin-bottom: calc(-312mm * 0.5); }
}
.calib-factura {
  position: relative;
  width: 210mm;
  height: 156mm;
  background-image:
    linear-gradient(to right, rgba(15, 23, 42, .04) 0, rgba(15, 23, 42, .04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(15, 23, 42, .04) 0, rgba(15, 23, 42, .04) 1px, transparent 1px);
  background-size: 10mm 10mm;
  overflow: hidden;
}
.calib-sep {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 8px 0;
  border-top: 1px dashed var(--line-strong);
  border-bottom: 1px dashed var(--line-strong);
  background: var(--surface-2);
}
.calib-field {
  position: absolute;
  padding: 2px 6px;
  background: rgba(79, 70, 229, .08);
  border: 1px solid rgba(79, 70, 229, .3);
  border-radius: 3px;
  font-size: 10pt;
  line-height: 1.1;
  white-space: nowrap;
  cursor: move;
  user-select: none;
  color: var(--ink);
  transition: background .1s, border-color .1s, box-shadow .1s;
}
.calib-field:hover {
  background: rgba(79, 70, 229, .15);
  border-color: var(--accent);
  z-index: 2;
}
.calib-field.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(79, 70, 229, .4);
  z-index: 3;
}
.calib-field.tick {
  font-weight: 700;
  font-size: 12pt;
  background: rgba(220, 38, 38, .1);
  border-color: rgba(220, 38, 38, .4);
  color: var(--danger);
}
.calib-field.tick.active { background: var(--danger); color: #fff; border-color: var(--danger); }
.calib-field.solo_x {
  background: rgba(5, 150, 105, .08);
  border-color: rgba(5, 150, 105, .35);
  color: var(--ok);
}
.calib-field.solo_x.active { background: var(--ok); color: #fff; border-color: var(--ok); }
.calib-field.solo_y {
  background: rgba(217, 119, 6, .08);
  border-color: rgba(217, 119, 6, .35);
  color: var(--warn);
  font-size: 9pt;
}
.calib-field.solo_y.active { background: var(--warn); color: #fff; border-color: var(--warn); }

.calib-side {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  align-self: start;
  position: sticky;
  top: calc(var(--header-h) + 16px);
  max-height: calc(100vh - var(--header-h) - 32px);
  overflow-y: auto;
}
.calib-side h3 {
  font-size: 14px;
  margin: 0 0 8px;
  font-weight: 600;
  color: var(--ink);
}
.calib-field-list {
  display: flex; flex-direction: column;
  gap: 2px;
  margin-top: 8px;
  max-height: 480px;
  overflow-y: auto;
}
.calib-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text);
  transition: background .1s;
}
.calib-row:hover { background: var(--surface-2); }
.calib-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.calib-row.modif .calib-row-label::before {
  content: '●';
  color: var(--warn);
  margin-right: 6px;
  font-size: 10px;
}
.calib-row-coords {
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}
.calib-row.active .calib-row-coords { color: var(--accent); }

/* ============================================================================
   MOBILE / TABLET (< 960px)  — sidebar se convierte en bottom nav
   ============================================================================ */
@media (max-width: 959px) {
  :root { --sidebar-w: 0px; --header-h: 56px; }
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr auto;
    grid-template-areas:
      "header"
      "main"
      "nav";
  }
  .app-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: auto;
    flex-direction: row;
    border-right: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
    z-index: 15;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
  }
  .nav-brand { display: none; }
  .nav-items {
    flex-direction: row;
    padding: 6px 8px;
    gap: 2px;
    flex: 1;
    justify-content: space-around;
  }
  .nav-items a {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    font-size: 10.5px;
    font-weight: 500;
    flex: 1;
    min-height: 54px;
    border-radius: var(--radius-sm);
  }
  .nav-items a.active::before { display: none; }
  .nav-items a.active { background: var(--accent-soft); }
  .nav-items .nav-highlight {
    background: transparent;
    color: var(--accent);
  }
  .nav-items .nav-highlight .nav-ic {
    background: var(--accent);
    color: #fff;
    width: 32px; height: 32px;
    padding: 7px;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(79, 70, 229, .3);
  }
  .nav-items .nav-highlight:hover {
    background: transparent;
    color: var(--accent);
  }
  .nav-items .nav-highlight span:not(.nav-ic) { display: none; }
  .nav-footer { display: none; }
  .app-header { padding: 0 16px; }
  .app-main {
    padding: 16px;
    padding-bottom: 80px;
  }
  .header-title h1 { font-size: 17px; }
  #empresa-switcher select { max-width: 160px; font-size: 12px; }
}
