/* ============================================
   Jaque — Sistema de diseño
   ============================================ */

:root {
  /* Color tokens */
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-muted: #e2e8f0;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-soft-hover: #e0e7ff;

  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0284c7;
  --info-soft: #e0f2fe;

  --sidebar-bg: #0b1220;
  --sidebar-bg-2: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-text-strong: #e2e8f0;
  --sidebar-hover: #1e293b;

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-full: 999px;

  /* Shadows */
  --sh-sm: 0 1px 2px 0 rgb(15 23 42 / 0.04);
  --sh-md: 0 4px 12px -2px rgb(15 23 42 / 0.08), 0 2px 4px -2px rgb(15 23 42 / 0.04);
  --sh-lg: 0 12px 24px -8px rgb(15 23 42 / 0.12), 0 4px 8px -4px rgb(15 23 42 / 0.06);
  --sh-primary: 0 4px 12px -2px rgb(79 70 229 / 0.25);

  /* Typography */
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
          Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, "JetBrains Mono", "Cascadia Code", monospace;
}

/* ============================================ Reset / base ============================================ */
* { box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; min-height: 100%;
  font-family: var(--font);
  font-size: 14px; line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ============================================ Typography ============================================ */
h1 {
  margin: 0 0 var(--s-5);
  font-size: 24px; font-weight: 700;
  letter-spacing: -0.02em; line-height: 1.25;
  color: var(--text);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
h2 { margin: 0 0 var(--s-3); font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
h3 { margin: 0 0 var(--s-2); font-size: 14px; font-weight: 600; }

a { color: var(--primary); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--primary-hover); }

code { font-family: var(--mono); font-size: 12px; padding: 2px 6px;
       background: var(--bg-subtle); border-radius: 4px; color: var(--text); }

/* ============================================ Buttons ============================================ */
button, .btn {
  font: inherit; font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--r-md);
  transition: background-color 0.15s, border-color 0.15s, transform 0.05s, box-shadow 0.15s;
  line-height: 1.2; min-height: 38px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  user-select: none; white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--text-subtle);
}
button:active:not(:disabled), .btn:active:not(:disabled) { transform: translateY(1px); }
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

button.primary, .btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: var(--sh-primary);
}
button.primary:hover:not(:disabled), .btn.primary:hover:not(:disabled) {
  background: var(--primary-hover); border-color: var(--primary-hover);
}

button.danger, .btn.danger {
  background: var(--bg-elevated);
  color: var(--danger);
  border-color: var(--border-strong);
}
button.danger:hover:not(:disabled), .btn.danger:hover:not(:disabled) {
  background: var(--danger-soft); border-color: var(--danger);
}

button.ghost, .btn.ghost { background: transparent; border-color: transparent; }
button.ghost:hover:not(:disabled), .btn.ghost:hover:not(:disabled) { background: var(--bg-subtle); }

button svg, .btn svg, a.btn svg {
  width: 16px; height: 16px;
  flex-shrink: 0;
  display: inline-block;
}
button.primary svg, .btn.primary svg { width: 16px; height: 16px; }

/* ============================================ Inputs ============================================ */
input, select, textarea {
  font: inherit; font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg-elevated);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 38px;
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(79 70 229 / 0.12);
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
input[type="number"] { font-variant-numeric: tabular-nums; }
textarea { min-height: 80px; resize: vertical; }

label {
  display: block;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.field { margin-bottom: var(--s-4); }
.field:last-child { margin-bottom: 0; }

/* ============================================ Login ============================================ */
.login-wrap {
  min-height: 100vh;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 15% 15%, rgb(79 70 229 / 0.09), transparent 35%),
    radial-gradient(circle at 85% 85%, rgb(129 140 248 / 0.10), transparent 35%),
    var(--bg);
  padding: var(--s-4);
}
.login-card {
  background: var(--bg-elevated);
  padding: 36px 32px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  width: 380px; max-width: 100%;
  box-shadow: var(--sh-lg);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  border-radius: 10px;
  display: grid; place-items: center;
  color: white; font-weight: 800; font-size: 22px;
  box-shadow: var(--sh-primary);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.brand-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.login-card button { width: 100%; min-height: 44px; margin-top: 8px; }

/* ============================================ Layout ============================================ */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ============================================ Sidebar ============================================ */
.sidebar {
  background: linear-gradient(180deg, var(--sidebar-bg-2), var(--sidebar-bg));
  color: var(--sidebar-text);
  padding: 22px 0 16px;
  display: flex; flex-direction: column;
  border-right: 1px solid rgb(255 255 255 / 0.04);
}
.sidebar .brand {
  margin: 0 20px 24px; padding: 0;
  color: var(--sidebar-text-strong);
}
.sidebar .brand-name { color: white; font-size: 18px; }
.sidebar .brand-sub { color: var(--sidebar-text); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }

.sidebar nav { flex: 1; padding: 0 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  color: var(--sidebar-text);
  border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.sidebar nav a:hover {
  background: var(--sidebar-hover);
  color: white;
  text-decoration: none;
}
.sidebar nav a.active {
  background: linear-gradient(135deg, var(--primary), #6366f1);
  color: white;
  box-shadow: 0 2px 8px rgb(79 70 229 / 0.35);
}
.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.sidebar nav a.active svg { opacity: 1; }
.sidebar nav .pending-count {
  margin-left: auto;
  font-size: 11px; font-weight: 700;
  background: var(--warning); color: white;
  padding: 1px 7px; border-radius: var(--r-full);
}
.sidebar nav .pending-count:empty { display: none; }

.sidebar .user-info {
  margin: 16px 12px 0;
  padding: 14px;
  background: rgb(255 255 255 / 0.04);
  border-radius: var(--r-md);
  border: 1px solid rgb(255 255 255 / 0.06);
  font-size: 13px;
}
.sidebar .user-name { color: white; font-weight: 600; margin-bottom: 2px; }
.sidebar .user-role {
  color: var(--sidebar-text); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.sidebar .logout-link {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 10px; font-size: 12px;
  color: #94a3b8;
}
.sidebar .logout-link:hover { color: white; }

/* ============================================ Main ============================================ */
.main {
  padding: 28px 32px 60px;
  background: var(--bg);
  min-width: 0;
}

/* ============================================ Toolbar ============================================ */
.toolbar {
  display: flex; gap: 8px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.toolbar input, .toolbar select { width: auto; min-width: 200px; }
.toolbar .spacer { flex: 1 1 auto; }

/* ============================================ Cards ============================================ */
.card, .card-form {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--sh-sm);
}
.card-form { margin-bottom: 16px; }

/* Stat cards (dashboard) */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--sh-sm);
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-md);
  border-color: var(--border-strong);
}
.stat-card .stat-icon {
  width: 38px; height: 38px;
  border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
  flex-shrink: 0;
}
.stat-card .stat-icon svg { width: 20px; height: 20px; }
.stat-card.success .stat-icon { background: var(--success-soft); color: var(--success); }
.stat-card.warning .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat-card.info .stat-icon { background: var(--info-soft); color: var(--info); }
.stat-label {
  color: var(--text-muted);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.stat-value {
  font-size: 24px; font-weight: 700;
  margin-top: 4px;
  color: var(--text);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

/* Detail block (info en pedido) */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 24px;
}
.detail-grid .item label {
  font-size: 10px;
  margin-bottom: 2px;
}
.detail-grid .item .value {
  font-size: 14px; color: var(--text);
}

/* ============================================ Tables ============================================ */
.table-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elevated);
}
.table-wrap > table { border: none; box-shadow: none; }
thead { background: var(--bg-subtle); }
th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
th {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
}
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--bg-subtle); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { background: var(--bg-subtle); font-weight: 600; border-top: 1px solid var(--border-strong); border-bottom: none; }

/* Standalone table without wrap inherits same look */
:not(.table-wrap) > table {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--sh-sm);
}

/* ============================================ Badges ============================================ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  line-height: 1.4;
}
.badge.borrador { background: var(--bg-muted); color: #475569; }
.badge.confirmado { background: var(--info-soft); color: #0c4a6e; }
.badge.exportado { background: var(--success-soft); color: #14532d; }
.badge.cancelado { background: var(--danger-soft); color: #7f1d1d; }

/* Precio que incluye IVA */
.precio-iva { color: var(--success); font-weight: 600; }

/* Input de edición de precio inline */
.precio-edit {
  width: 130px;
  text-align: right;
  font-weight: 700;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-subtle);
  transition: border-color .15s, background .4s;
}
.precio-edit:focus { outline: none; border-color: var(--primary); background: #fff; }
.precio-edit.saved { background: var(--success-soft); border-color: #4ade80; }

/* ============================================ Banners ============================================ */
.banner {
  padding: 12px 16px;
  border-radius: var(--r-md);
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid transparent;
  display: flex; align-items: flex-start; gap: 10px;
  line-height: 1.5;
}
.banner.warn { background: var(--warning-soft); color: #78350f; border-color: #fbbf24; }
.banner.info { background: var(--info-soft); color: #075985; border-color: #38bdf8; }
.banner.error { background: var(--danger-soft); color: #7f1d1d; border-color: #fca5a5; }
.banner.success { background: var(--success-soft); color: #14532d; border-color: #4ade80; }

/* ============================================ Status badge (online/offline) ============================================ */
.status-badge {
  position: fixed; top: 14px; right: 16px; z-index: 60;
  padding: 5px 11px;
  border-radius: var(--r-full);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.02em;
  display: inline-flex; align-items: center; gap: 6px;
  box-shadow: var(--sh-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.status-badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%; display: inline-block;
}
.status-badge.online { background: var(--success-soft); color: #14532d; border-color: #86efac; }
.status-badge.online::before { background: var(--success); box-shadow: 0 0 0 2px rgb(22 163 74 / 0.2); }
.status-badge.offline { background: var(--danger-soft); color: #7f1d1d; border-color: #fca5a5; }
.status-badge.offline::before { background: var(--danger); }

/* ============================================ Toast ============================================ */
#toast {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100; pointer-events: none;
}
.toast {
  background: var(--text); color: white;
  padding: 12px 16px;
  border-radius: var(--r-md);
  min-width: 240px; max-width: 380px;
  box-shadow: var(--sh-lg);
  font-size: 14px;
  animation: toast-in 0.22s ease;
  pointer-events: auto;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--success); }
@keyframes toast-in {
  from { transform: translateX(16px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================ Modal ============================================ */
.modal-bg {
  position: fixed; inset: 0;
  background: rgb(15 23 42 / 0.55);
  display: grid; place-items: center;
  z-index: 50;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 0.18s ease;
  padding: var(--s-4);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  padding: 24px;
  width: min(580px, 100%);
  max-height: 90vh; overflow: auto;
  box-shadow: var(--sh-lg);
  animation: modal-in 0.22s ease;
}
@keyframes modal-in {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.modal h2 { margin: 0 0 18px; font-size: 18px; }
.modal-actions {
  display: flex; justify-content: flex-end;
  gap: 8px; margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ============================================ Combobox (búsqueda predictiva) ============================================ */
.combobox { position: relative; }
.combobox-input { padding-right: 36px; }
.combobox-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none;
  font-size: 16px; color: var(--text-muted);
  cursor: pointer;
  width: 28px; height: 28px;
  min-height: 28px; padding: 0;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  line-height: 1;
}
.combobox-clear:hover { background: var(--bg-subtle); color: var(--text); }
.combobox-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  max-height: 340px; overflow-y: auto;
  list-style: none; padding: 4px;
  margin: 0; z-index: 30;
  box-shadow: var(--sh-md);
}
.combobox-list li {
  padding: 9px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.1s;
}
.combobox-list li:hover, .combobox-list li.hl {
  background: var(--primary-soft);
  color: var(--primary);
}
.combobox-list li.combobox-more {
  color: var(--text-muted); font-size: 12px;
  cursor: default; font-style: italic;
  background: transparent !important;
  text-align: center; padding: 8px;
}
.combobox-list li.hl.combobox-more { background: transparent; color: var(--text-muted); }
.combobox-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; font-weight: normal; }
.combobox-list li.hl .combobox-sub { color: var(--primary); opacity: 0.75; }

/* ============================================ Mobile / Tablet ============================================ */
.menu-btn {
  display: none;
  position: fixed; top: 12px; left: 12px;
  z-index: 60;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  width: 44px; height: 44px; padding: 0;
  border-radius: var(--r-md);
  font-size: 20px; cursor: pointer;
  box-shadow: var(--sh-sm);
}
.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgb(15 23 42 / 0.55);
  z-index: 40;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px; z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 16px rgb(0 0 0 / 0.18);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar nav a { padding: 12px 14px; font-size: 15px; }
  .menu-btn { display: grid; place-items: center; }
  .main { padding: 64px 16px 80px; }
  .main h1 { font-size: 22px; }
  .status-badge { top: 14px; right: 14px; }

  /* Touch targets */
  input, select, textarea, button { min-height: 44px; font-size: 16px; padding: 10px 12px; }
  button { padding: 10px 16px; }
  .combobox-clear { min-height: 32px; height: 32px; width: 32px; }

  .grid2, .detail-grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input, .toolbar select, .toolbar button { width: 100%; min-width: 0; }
  .toolbar .spacer { display: none; }

  /* Tablas con scroll horizontal */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .table-wrap { overflow-x: auto; }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 20px; }

  .modal { padding: 20px; }
  .login-card { padding: 28px 20px; }
}

@media (max-width: 480px) {
  .main { padding: 60px 12px 80px; }
  h1 { font-size: 20px; }
  .stats-grid { grid-template-columns: 1fr; }
}

/* Fila Agregar producto (Nuevo pedido) */
.prod-add-row {
  display: flex; gap: 8px; align-items: stretch;
  margin-bottom: 14px;
}
.prod-add-cb { flex: 1 1 auto; min-width: 0; }
.prod-add-btn { flex: 0 0 auto; white-space: nowrap; }

/* Items: lista de tarjetas */
.items-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.item-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  box-shadow: var(--sh-sm);
  display: flex; flex-direction: column; gap: 12px;
}
.item-card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.item-card-head .item-code { margin-bottom: 4px; }
.item-card-head .item-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.item-card-head .item-del {
  min-width: 40px; padding: 6px 10px; flex-shrink: 0;
}
.item-card-head .item-del svg { width: 16px; height: 16px; }
.item-card-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.item-card-inputs .field { margin-bottom: 0; }
.item-card-inputs input { text-align: right; font-variant-numeric: tabular-nums; }
.item-card-totals {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.item-card-totals > div {
  display: flex; flex-direction: column;
  font-variant-numeric: tabular-nums;
}
.item-card-totals .muted {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.04em; font-weight: 600;
  margin-bottom: 2px;
}
.item-card-totals strong { font-size: 16px; }

/* Barra de totales (gran) */
.totals-bar {
  display: flex; gap: 24px;
  justify-content: flex-end; align-items: baseline;
  padding: 14px 18px; margin-bottom: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  flex-wrap: wrap;
}
.totals-bar > div {
  display: flex; flex-direction: column; align-items: flex-end;
  font-variant-numeric: tabular-nums;
}
.totals-bar .muted {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.04em; font-weight: 600;
  margin-bottom: 2px;
}
.totals-bar strong { font-size: 20px; color: var(--primary); }

@media (max-width: 900px) {
  .item-card-inputs, .item-card-totals { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .totals-bar { justify-content: space-between; gap: 12px; padding: 12px 14px; }
  .totals-bar > div { align-items: flex-start; }
  .totals-bar strong { font-size: 18px; }
}

/* Icon-only link en tablas (mapa, etc.) */
.icon-link {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  color: var(--primary);
  transition: background 0.12s;
}
.icon-link:hover { background: var(--primary-soft); text-decoration: none; }
.icon-link svg { width: 18px; height: 18px; }

/* ============================================ Skeleton loading (shimmer) ============================================ */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.skel {
  display: inline-block;
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--bg-muted) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 4px;
  vertical-align: middle;
}
.skel-text { height: 12px; width: 100%; }
.skel-pill { height: 18px; width: 64px; border-radius: var(--r-full); }
.skel-block { display: block; width: 100%; height: 38px; border-radius: var(--r-md); }
.skel-circle { width: 38px; height: 38px; border-radius: 50%; }
.skel-line { display: block; height: 14px; margin: 6px 0; }

/* Stat card skeleton */
.stat-card.skel-card { pointer-events: none; }
.stat-card.skel-card .stat-icon { background: var(--bg-subtle); color: transparent; }

/* Fade-in para filas y secciones */
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fade-in-up 0.28s ease both; }
.fade-in-fast { animation: fade-in-up 0.18s ease both; }

/* Stagger en tablas: cada fila aparece con delay incremental */
@keyframes row-in {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}
tbody.stagger tr {
  animation: row-in 0.25s ease both;
}
tbody.stagger tr:nth-child(1)  { animation-delay: 0ms; }
tbody.stagger tr:nth-child(2)  { animation-delay: 25ms; }
tbody.stagger tr:nth-child(3)  { animation-delay: 50ms; }
tbody.stagger tr:nth-child(4)  { animation-delay: 75ms; }
tbody.stagger tr:nth-child(5)  { animation-delay: 100ms; }
tbody.stagger tr:nth-child(6)  { animation-delay: 125ms; }
tbody.stagger tr:nth-child(7)  { animation-delay: 150ms; }
tbody.stagger tr:nth-child(8)  { animation-delay: 175ms; }
tbody.stagger tr:nth-child(9)  { animation-delay: 200ms; }
tbody.stagger tr:nth-child(10) { animation-delay: 225ms; }
tbody.stagger tr:nth-child(n+11) { animation-delay: 250ms; }

/* Empty state (cuando no hay registros) */
.empty {
  text-align: center;
  padding: 48px 24px;
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  color: var(--text-muted);
}
.empty-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-sub { font-size: 13px; }

/* ============================================ Utility ============================================ */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.num { font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

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

/* Scrollbar suave (WebKit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }
