/* ═══════════════════════════════════════════════════════════════════════════
   styles.css — component layer. Depends on tokens.css.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Base ────────────────────────────────────────────────────────────────── */
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: var(--font);
  font-size: var(--text-body-sm);
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  -webkit-font-smoothing: antialiased;
}
:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }
img, svg { display: block; }
a { color: inherit; text-decoration: none; }

/* ─── Skip link ───────────────────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: var(--z-toast);
  background: var(--purple);
  color: #fff;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-body-sm);
  font-weight: 500;
  transition: top var(--transition-fast);
}
.skip-link:focus-visible { top: var(--space-4); }

/* ─── Typography ──────────────────────────────────────────────────────────── */
h1 { font-size: var(--text-h1); line-height: var(--text-h1-lh); font-weight: 600; color: var(--ink); }
h2 { font-size: var(--text-h2); line-height: var(--text-h2-lh); font-weight: 600; color: var(--ink); }
h3 { font-size: var(--text-h3); line-height: var(--text-h3-lh); font-weight: 600; color: var(--ink); }
p  { font-size: var(--text-body); line-height: var(--text-body-lh); }

/* ─── Utilities ───────────────────────────────────────────────────────────── */
.sr-only, .visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: var(--text-mono); }
.num  { font-variant-numeric: tabular-nums; }

/* ─── Scrollbars ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar            { width: 6px; height: 6px; }
::-webkit-scrollbar-track      { background: transparent; }
::-webkit-scrollbar-thumb      { background: var(--border-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover{ background: var(--muted); }

/* ═══════════════════════════════════════════════════════════════════════════
   Badges
   ═══════════════════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-caption);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}
/* New token-based names */
.badge.teal    { background: rgba(0, 214, 197, 0.12); color: var(--teal-ink); }
.badge.purple  { background: var(--purple-soft);       color: var(--purple-ink); }
.badge.warn    { background: var(--warning-soft);      color: var(--warning); }
.badge.error   { background: var(--error-soft);        color: var(--error); }
.badge.info    { background: var(--info-soft);         color: var(--info); }
.badge.muted   { background: var(--surface-2);         color: var(--muted); }
.badge.ink     { background: var(--ink);               color: var(--surface); }
.badge.success { background: rgba(0, 163, 122, 0.12);  color: var(--success); }
.badge.green   { background: rgba(0, 163, 122, 0.12);  color: var(--success); }

/* Legacy badge class names (used by existing JS) */
.badge-success  { background: rgba(0, 163, 122, 0.12);      color: var(--success); }
.badge-warning  { background: var(--warning-soft);           color: var(--warning); }
.badge-danger   { background: var(--error-soft);             color: var(--error); }
.badge-info     { background: var(--info-soft);              color: var(--info); }
.badge-neutral  { background: var(--surface-2); color: var(--body); border: 0.5px solid var(--border); }
.badge-teal     { background: rgba(0, 214, 197, 0.12); color: var(--teal-ink); }
.badge-slate    { background: var(--surface-2); color: var(--muted); border: 0.5px solid var(--border); }
.badge-green    { background: rgba(0, 163, 122, 0.12); color: var(--success); }
.badge-muted    { background: var(--surface-2); color: var(--muted); }

[data-theme="dark"] .badge-teal  { background: rgba(0, 214, 197, 0.15); color: var(--teal); }
[data-theme="dark"] .badge-green,
[data-theme="dark"] .badge.green { background: rgba(0, 163, 122, 0.20); color: var(--teal); }

/* ═══════════════════════════════════════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-lg);
  font-family: var(--font);
  font-size: var(--text-body-sm);
  font-weight: 500;
  border: 0.5px solid transparent;
  cursor: pointer;
  transition: background var(--transition-default), border-color var(--transition-default),
              color var(--transition-default), opacity var(--transition-default);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
  -webkit-user-select: none;
  user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* Variants — new names */
.btn.primary { background: var(--purple); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--purple-ink); }
.btn.ghost   { background: transparent; color: var(--body); border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn.danger  { background: var(--error); color: #fff; }
.btn.danger:hover:not(:disabled) { background: var(--danger-hover); }

/* Legacy aliases (used by existing JS HTML strings) */
.btn-primary   { background: var(--purple); color: #fff; }
.btn-primary:hover:not(:disabled)   { background: var(--purple-ink); }
.btn-secondary { background: var(--surface-2); color: var(--ink); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-muted); border-color: var(--muted); }
.btn-ghost     { background: transparent; color: var(--body); border-color: transparent; }
.btn-ghost:hover:not(:disabled)     { background: var(--surface-2); color: var(--ink); }
.btn-danger    { background: var(--error); color: #fff; }
.btn-danger:hover:not(:disabled)    { background: var(--danger-hover); }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover:not(:disabled)   { background: color-mix(in srgb, var(--warning) 85%, #000); }

/* Sizes */
.btn.sm, .btn-sm { height: 28px; padding: 0 var(--space-3); font-size: var(--text-label); }
.btn-lg          { height: 40px; padding: 0 var(--space-5); font-size: var(--text-body); }
@media (max-width: 640px) {
  .btn-sm { height: 36px; }
  .btn-lg { height: 44px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Inputs
   ═══════════════════════════════════════════════════════════════════════════ */
.input {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-3);
  background: var(--surface);
  color: var(--ink);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  font-family: var(--font);
  font-size: var(--text-body-sm);
  transition: border-color var(--transition-default), box-shadow var(--transition-default);
}
.input::placeholder { color: var(--text-subtle); }
.input:hover:not(:disabled) { border-color: var(--muted); }
.input:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-soft); }
.input:disabled { opacity: 0.5; cursor: not-allowed; background: var(--surface-2); }
.input.error { border-color: var(--error); }
.input.error:focus { box-shadow: 0 0 0 3px var(--error-soft); }

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%237A7D8A' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: var(--space-8);
  cursor: pointer;
}

.label {
  display: block;
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--muted);
  margin-bottom: var(--space-1);
  line-height: var(--text-label-lh);
}
.helper {
  font-size: var(--text-label);
  color: var(--muted);
  margin-top: var(--space-1);
  line-height: var(--text-label-lh);
}
.helper.error { color: var(--error); }

/* ═══════════════════════════════════════════════════════════════════════════
   Cards
   ═══════════════════════════════════════════════════════════════════════════ */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
}
@media (max-width: 640px) { .card { padding: var(--space-4); } }

/* ═══════════════════════════════════════════════════════════════════════════
   Tables — legacy class names kept for existing JS
   ═══════════════════════════════════════════════════════════════════════════ */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body-sm);
  background: var(--surface);
}
.table th {
  text-align: left;
  padding: var(--space-3);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--text-label);
  font-weight: 500;
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
}
.table th:first-child { border-radius: var(--radius-lg) 0 0 0; }
.table th:last-child  { border-radius: 0 var(--radius-lg) 0 0; }
.table td {
  padding: var(--space-3);
  color: var(--ink);
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  text-align: right;
}

/* Skeleton rows */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.9; }
}
.skeleton-cell {
  height: 14px;
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}
.skeleton-row td { padding: var(--space-3); }

/* ═══════════════════════════════════════════════════════════════════════════
   App shell — sidebar layout
   ═══════════════════════════════════════════════════════════════════════════ */
.app-shell {
  display: flex;
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: var(--z-sidebar);
  transition: transform var(--transition-slow);
}

.side-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
}
.side-brand-logo {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-md);
  background: var(--purple);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.side-brand-name {
  font-size: var(--text-body-sm);
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}
.side-tenant {
  font-size: var(--text-caption);
  color: var(--muted);
  padding: 0 var(--space-4) var(--space-2);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Side nav — rendered by shell.js */
.side-nav {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  min-height: 0;
}

/* Legacy nav container that consolidado.js writes to */
#app-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: var(--space-3) var(--space-2);
}
/* When consolidado.js appends nav-link items into sidebar #app-nav,
   style them as sidebar items */
#app-nav .nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 34px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-body-sm);
  font-weight: 500;
  color: var(--muted);
  transition: background var(--transition-fast), color var(--transition-fast);
}
#app-nav .nav-link:hover { background: var(--surface-2); color: var(--ink); }
#app-nav .nav-link.active { background: var(--purple-soft); color: var(--purple); }
[data-theme="dark"] #app-nav .nav-link.active { background: rgba(105,28,255,0.15); color: var(--purple); }

.side-section {
  margin-bottom: var(--space-3);
}
.side-section-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 var(--space-3) var(--space-1);
}

.side-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 34px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-body-sm);
  font-weight: 500;
  color: var(--muted);
  transition: background var(--transition-fast), color var(--transition-fast);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  border: none;
  background: transparent;
  width: 100%;
}
.side-item svg { flex-shrink: 0; opacity: 0.7; }
.side-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item:hover { background: var(--surface-2); color: var(--ink); }
.side-item:hover svg { opacity: 1; }
.side-item.active { background: var(--purple-soft); color: var(--purple); font-weight: 600; }
.side-item.active svg { opacity: 1; }
[data-theme="dark"] .side-item.active { background: rgba(105,28,255,0.15); color: #A07AFF; }

.side-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--purple);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Spacer pushes user section to bottom */
.side-spacer { flex: 1; min-height: var(--space-4); }

/* Theme toggle in sidebar */
.side-theme {
  padding: var(--space-2) var(--space-4);
  border-top: 0.5px solid var(--border);
}

/* User section at bottom */
.side-user {
  border-top: 0.5px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
.side-user-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast);
  border-radius: 0;
}
.side-user-btn:hover { background: var(--surface-2); }

.side-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--purple-soft);
  color: var(--purple);
  font-size: var(--text-label);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.side-user-info { flex: 1; min-width: 0; }
.side-user-name {
  display: block;
  font-size: var(--text-body-sm);
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-user-role {
  display: block;
  font-size: var(--text-caption);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-chevron {
  flex-shrink: 0;
  color: var(--muted);
  transition: transform var(--transition-fast);
}
.side-user-btn[aria-expanded="true"] .side-chevron { transform: rotate(180deg); }

.side-user-popup {
  position: absolute;
  bottom: calc(100% + 4px);
  left: var(--space-3);
  right: var(--space-3);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  overflow: hidden;
}
.side-user-popup[hidden] { display: none; }
.side-user-email {
  display: block;
  font-size: var(--text-caption);
  color: var(--muted);
  padding: var(--space-3) var(--space-4) var(--space-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── App content (right of sidebar) ─────────────────────────────────────── */
.app-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-5);
  z-index: var(--z-sticky);
}
.topbar-crumb,
.topbar-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-body-sm);
  color: var(--ink);
  font-weight: 500;
  flex: 1;
  min-width: 0;
}
.crumb { color: var(--muted); }
.crumb.current { color: var(--ink); font-weight: 500; }
.crumb-sep { color: var(--border-strong); }
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

/* ─── Main content area ───────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}
@media (max-width: 640px) { .app-main { padding: var(--space-4); } }

/* ─── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
@media (max-width: 640px) {
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .btn { align-self: flex-start; }
}
.page-title {
  font-size: var(--text-h1);
  font-weight: 600;
  color: var(--ink);
  line-height: var(--text-h1-lh);
}
.page-subtitle {
  font-size: var(--text-body-sm);
  color: var(--muted);
  margin-top: 2px;
}

/* ─── Hamburger ───────────────────────────────────────────────────────────── */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  flex-shrink: 0;
}
.hamburger-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ─── Theme toggle ────────────────────────────────────────────────────────── */
.theme-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 2px;
  flex-shrink: 0;
}
.theme-toggle-btn {
  padding: 3px var(--space-2);
  font-family: var(--font);
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
}
.theme-toggle-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.theme-toggle-fixed {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-sticky);
}

/* ─── User dropdown (legacy topbar version, kept for possible reuse) ─────── */
.user-menu { position: relative; }
.user-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 var(--space-2);
  background: transparent;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  color: var(--body);
  transition: background var(--transition-fast);
}
.user-trigger:hover { background: var(--surface-2); }
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--purple-soft);
  color: var(--purple);
  font-size: var(--text-label);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-email-short {
  font-size: var(--text-body-sm);
  color: var(--body);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 640px) { .user-email-short { display: none; } }
.chevron-icon {
  color: var(--text-subtle);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}
.user-trigger[aria-expanded="true"] .chevron-icon { transform: rotate(180deg); }
.user-dropdown {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  z-index: var(--z-dropdown);
  overflow: hidden;
}
.user-dropdown[hidden] { display: none; }
.user-dropdown-info { padding: var(--space-4); display: flex; flex-direction: column; gap: 2px; }
.user-dropdown-name  { font-size: var(--text-body-sm); font-weight: 600; color: var(--ink); }
.user-dropdown-role  { font-size: var(--text-caption); color: var(--muted); }
.user-dropdown-email { font-size: var(--text-caption); color: var(--text-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown-divider    { border: none; border-top: 0.5px solid var(--border); margin: 0; }
.dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font);
  font-size: var(--text-body-sm);
  font-weight: 400;
  color: var(--body);
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.dropdown-item:hover { background: var(--surface-2); color: var(--ink); }
.dropdown-item.danger { color: var(--error); }
.dropdown-item.danger:hover { background: var(--error-soft); }

/* ═══════════════════════════════════════════════════════════════════════════
   Toast
   ═══════════════════════════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-body-sm);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  white-space: nowrap;
  max-width: calc(100vw - 48px);
}
.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success  { border-color: var(--success); }
.toast-error    { border-color: var(--error); color: var(--error); }

/* ═══════════════════════════════════════════════════════════════════════════
   Modal — two variants: existing admin modal + detalle.js inline modal
   ═══════════════════════════════════════════════════════════════════════════ */
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-4);
  animation: fade-in var(--transition-slow) ease;
}
.modal-overlay[hidden] { display: none; }

/* Admin page modal box */
.modal {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-6);
  animation: modal-in var(--transition-slow) ease;
}
.modal h2 { margin-bottom: var(--space-5); }

/* detalle.js inline modal box */
.modal-box {
  background: var(--surface);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--transition-slow) ease;
}
.modal-titulo {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--ink);
  margin-bottom: var(--space-2);
}
.modal-desc {
  font-size: var(--text-body-sm);
  color: var(--body);
  margin-bottom: var(--space-4);
  line-height: 1.5;
}
.modal-textarea {
  width: 100%;
  min-height: 80px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: var(--text-body-sm);
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  resize: vertical;
  outline: none;
  margin-bottom: var(--space-4);
  transition: border-color var(--transition-fast);
  display: block;
  box-sizing: border-box;
}
.modal-textarea:focus { border-color: var(--purple); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-3); }

.form-group { margin-bottom: var(--space-4); }
.form-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-6);
}
@media (max-width: 640px) {
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; height: 44px; }
}

/* ─── Password card ───────────────────────────────────────────────────────── */
.password-card {
  background: var(--surface-2);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-top: var(--space-4);
}
.password-label  { font-size: var(--text-body-sm); color: var(--muted); margin-bottom: var(--space-2); }
.password-display {
  font-family: var(--font-mono);
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--ink);
  word-break: break-all;
  margin-bottom: var(--space-3);
  letter-spacing: 0.04em;
}
.btn-copy { background: none; border: none; color: var(--purple); font-family: var(--font); font-size: var(--text-body-sm); font-weight: 500; cursor: pointer; padding: 0; }
.btn-copy:hover { text-decoration: underline; }

/* ─── Row actions ─────────────────────────────────────────────────────────── */
.row-actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }

/* ═══════════════════════════════════════════════════════════════════════════
   Empty state
   ═══════════════════════════════════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--muted);
}
.empty-state-title { font-size: var(--text-h2); color: var(--ink); margin-bottom: var(--space-2); }
.empty-state-desc  { font-size: var(--text-body-sm); max-width: 400px; margin: 0 auto var(--space-4); }

/* ═══════════════════════════════════════════════════════════════════════════
   Trigger status + status bar
   ═══════════════════════════════════════════════════════════════════════════ */
.trigger-status {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-body-sm);
  font-weight: 500;
  border: 0.5px solid transparent;
}
.trigger-status.success { background: rgba(0,163,122,0.10); color: var(--success); border-color: rgba(0,163,122,0.20); }
.trigger-status.error   { background: var(--error-soft);  color: var(--error);   border-color: var(--error-soft); }
.trigger-status.info    { background: var(--info-soft);   color: var(--info);    border-color: var(--info-soft); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.status-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-5);
  font-size: var(--text-label);
  color: var(--muted);
}
.status-dot          { width: 8px; height: 8px; border-radius: var(--radius-full); flex-shrink: 0; }
.status-dot.success  { background: var(--success); }
.status-dot.error    { background: var(--error); }
.status-dot.running  { background: var(--info); animation: pulse 1.5s ease-in-out infinite; }
.status-text         { flex: 1; min-width: 0; }
.status-link         { margin-left: auto; flex-shrink: 0; font-size: var(--text-caption); color: var(--info); }
.status-link:hover   { text-decoration: underline; }

/* ═══════════════════════════════════════════════════════════════════════════
   Login page
   ═══════════════════════════════════════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.login-card { max-width: 400px; width: 100%; box-shadow: var(--shadow-sm); }
.login-card-header { margin-bottom: var(--space-6); }
.login-brand { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); }
.login-title { font-size: var(--text-h2); font-weight: 600; color: var(--ink); margin: 0; }
.login-subtitle { font-size: var(--text-body-sm); color: var(--muted); margin-top: var(--space-1); }
.login-submit { width: 100%; margin-top: var(--space-2); }
.login-error {
  margin-top: var(--space-3);
  padding: var(--space-3);
  background: var(--error-soft);
  border-radius: var(--radius-lg);
  font-size: var(--text-body-sm);
  color: var(--error);
  border: 0.5px solid var(--error-soft);
}
.login-footer { margin-top: var(--space-6); text-align: center; font-size: var(--text-caption); color: var(--text-subtle); }

/* ═══════════════════════════════════════════════════════════════════════════
   Execution log panel
   ═══════════════════════════════════════════════════════════════════════════ */
#panel-ejecucion {
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  border: 0.5px solid var(--border);
}
#panel-ejecucion.ejecucion-corriendo { border-left: 3px solid var(--info); border-radius: 0 var(--radius-lg) var(--radius-lg) 0; }
#panel-ejecucion.ejecucion-error     { border-left: 3px solid var(--error); border-radius: 0 var(--radius-lg) var(--radius-lg) 0; }

.ejecucion-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.ejecucion-titulo { font-size: var(--text-body-sm); font-weight: 500; color: var(--ink); }
.ejecucion-meta   { font-size: var(--text-label); color: var(--muted); }
.ejecucion-corriendo-label { color: var(--info); font-weight: 500; }

.ejecucion-contadores {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
@media (max-width: 480px) { .ejecucion-contadores { grid-template-columns: repeat(2, 1fr); } }
.contador         { text-align: center; }
.contador-valor   { display: block; font-size: 20px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.contador-success { color: var(--success); }
.contador-warning { color: var(--warning); }
.contador-muted   { color: var(--muted); }
.contador-label   { display: block; font-size: var(--text-caption); color: var(--muted); margin-top: var(--space-1); }

.ejecucion-error-banner {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--error-soft);
  color: var(--error);
  border-radius: var(--radius-md);
  font-size: var(--text-body-sm);
}
.ejecucion-detalle summary {
  font-size: var(--text-label); color: var(--muted); cursor: pointer; user-select: none; list-style: none; padding: var(--space-1) 0;
}
.ejecucion-detalle summary::-webkit-details-marker { display: none; }
.ejecucion-detalle[open] summary { margin-bottom: var(--space-2); }

.tabla-correos, .tabla-historial {
  width: 100%; border-collapse: collapse; font-size: var(--text-label);
}
.tabla-correos th, .tabla-historial th {
  text-align: left; padding: var(--space-2); font-weight: 500; color: var(--muted);
  border-bottom: 0.5px solid var(--border);
}
.tabla-correos td, .tabla-historial td {
  padding: var(--space-2); color: var(--ink); border-bottom: 0.5px solid var(--border); vertical-align: middle;
}
.tabla-correos tr:last-child td, .tabla-historial tr:last-child td { border-bottom: none; }
.tabla-historial th:not(:first-child), .tabla-historial td:not(:first-child) { text-align: center; }
.tabla-historial th:last-child, .tabla-historial td:last-child { text-align: right; }
.tabla-empty   { color: var(--muted); font-style: italic; padding: var(--space-3) var(--space-2) !important; }
.tabla-row-muted td { color: var(--muted); font-style: italic; }

.historial-ejecuciones { margin-bottom: var(--space-5); }
.historial-ejecuciones > summary {
  font-size: var(--text-body-sm); font-weight: 500; color: var(--muted); cursor: pointer; user-select: none; list-style: none; padding: var(--space-1) 0;
}
.historial-ejecuciones > summary::-webkit-details-marker { display: none; }
.historial-ejecuciones[open] > summary { margin-bottom: var(--space-2); }

/* ═══════════════════════════════════════════════════════════════════════════
   Grid de órdenes (index / home)
   ═══════════════════════════════════════════════════════════════════════════ */
.grid-toolbar   { margin-bottom: var(--space-3); }
.grid-ordenes   {
  width: 100%; border-collapse: collapse; font-size: var(--text-body-sm); background: var(--surface);
}
.grid-ordenes th {
  text-align: left; padding: var(--space-2) var(--space-3); font-size: var(--text-label); font-weight: 500;
  color: var(--muted); border-bottom: 0.5px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
.grid-ordenes th:first-child { border-radius: var(--radius-lg) 0 0 0; }
.grid-ordenes th:last-child  { border-radius: 0 var(--radius-lg) 0 0; }
.grid-ordenes td {
  padding: var(--space-3); color: var(--ink); border-bottom: 0.5px solid var(--border); vertical-align: middle;
}
.grid-ordenes tr:last-child td { border-bottom: none; }
.grid-ordenes tbody tr { cursor: pointer; transition: background var(--transition-fast); }
.grid-ordenes tbody tr:hover td { background: var(--surface-2); }
.grid-ordenes tbody tr:focus-visible { outline: 2px solid var(--purple); outline-offset: -2px; }

.col-orden      { font-weight: 500; white-space: nowrap; }
.col-cliente    { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-ingreso    { white-space: nowrap; color: var(--muted); font-size: var(--text-label); }
.col-monto      { text-align: right !important; font-variant-numeric: tabular-nums; }
.col-lineas     { text-align: center !important; }
.col-confidence { text-align: center !important; }
.col-status     { text-align: center !important; }
.col-estado-op  { width: 100px; }

.btn-pdf-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: var(--space-1);
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
  transition: color var(--transition-fast);
}
.btn-pdf-inline:hover { color: var(--purple); }

/* Grid toolbar counters + filter */
.grid-toolbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); padding: var(--space-3) 0; flex-wrap: wrap;
}
.grid-counters {
  display: flex; align-items: center; gap: var(--space-3);
  font-size: var(--text-body-sm); color: var(--muted); flex-wrap: wrap;
}
.counter-item strong { color: var(--ink); font-weight: 600; margin-left: 4px; }
.counter-sep { color: var(--border-strong); }
.filtro-select-sm {
  height: 30px; padding: 0 var(--space-3); background: var(--bg); border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-md); font-size: var(--text-body-sm); color: var(--ink); font-family: var(--font);
  outline: none; cursor: pointer; transition: border-color var(--transition-fast);
}
.filtro-select-sm:focus { border-color: var(--purple); }

@media (max-width: 768px) {
  .grid-ordenes { font-size: var(--text-label); }
  .grid-ordenes th, .grid-ordenes td { padding: var(--space-2); }
  .col-confidence { display: none; }
  .col-cliente    { max-width: 140px; }
}
@media (max-width: 480px) {
  .col-monto { display: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Detalle de orden
   ═══════════════════════════════════════════════════════════════════════════ */
.detalle-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-6); flex-wrap: wrap; gap: var(--space-3);
}
.detalle-breadcrumb { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-body-sm); }
.breadcrumb-link    { color: var(--muted); text-decoration: none; }
.breadcrumb-link:hover { color: var(--ink); }
.breadcrumb-separator  { color: var(--muted); }
.breadcrumb-current    { color: var(--ink); font-weight: 500; }
.detalle-actions       { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.orden-cabecera {
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
}
.orden-campos {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}
.campo         { display: flex; flex-direction: column; gap: var(--space-1); }
.campo-label   { font-size: var(--text-caption); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500; }
.campo-valor   { font-size: var(--text-body-sm); color: var(--ink); font-weight: 500; }
.campo-monto   { font-variant-numeric: tabular-nums; }
.campo-mono    { font-family: var(--font-mono); font-size: var(--text-caption); word-break: break-all; font-weight: 400; }

/* Tabla de líneas */
.lineas-desktop { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.grid-lineas    { width: 100%; border-collapse: collapse; font-size: var(--text-body-sm); background: var(--surface); }
.grid-lineas th {
  text-align: left; padding: var(--space-2) var(--space-3); font-size: var(--text-label); font-weight: 500;
  color: var(--muted); border-bottom: 0.5px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
.grid-lineas th:first-child { border-radius: var(--radius-lg) 0 0 0; }
.grid-lineas th:last-child  { border-radius: 0 var(--radius-lg) 0 0; }
.grid-lineas td { padding: var(--space-3); color: var(--ink); border-bottom: 0.5px solid var(--border); vertical-align: middle; }
.grid-lineas tr:last-child td { border-bottom: none; }

.grid-lineas .col-num    { width: 40px; text-align: center; color: var(--muted); }
.grid-lineas .col-codigo { width: 100px; font-family: var(--font-mono); font-size: var(--text-label); }
.grid-lineas .col-desc   { min-width: 200px; }
.grid-lineas .col-cant   { width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.grid-lineas .col-unidad { width: 60px; text-align: center; }
.grid-lineas .col-precio { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.grid-lineas .col-total  { width: 120px; text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; }
.grid-lineas .col-entrega-linea { width: 100px; color: var(--muted); }

.lineas-totales { background: var(--surface-2); font-weight: 500; border-top: 1.5px solid var(--border-strong); }
.lineas-totales td { padding: var(--space-3); }
.totales-label  { text-align: right; color: var(--muted); font-weight: 400; }
.lineas-iva td  { padding: var(--space-2) var(--space-3); color: var(--muted); background: var(--surface-2); }
.lineas-total-final td { padding: var(--space-3); background: var(--surface-2); border-top: 1.5px solid var(--border-strong); }
.totales-label-final { font-weight: 600; color: var(--ink); }
.col-total-final     { font-weight: 600; color: var(--ink); }

/* Inline observaciones */
.linea-row.tiene-obs td { border-bottom: none; }
.linea-obs-row td       { padding: 0 8px 10px 8px; border-bottom: 0.5px solid var(--border); }
.linea-obs-texto        { font-size: 12px; color: var(--body); line-height: 1.4; }

/* Cards mobile */
.lineas-mobile { display: none; }
.linea-card    { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-2); }
.linea-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-2); }
.linea-num     { font-size: var(--text-label); color: var(--muted); font-weight: 500; }
.linea-total   { font-size: var(--text-body-sm); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); }
.linea-card-desc  { font-size: var(--text-body-sm); color: var(--ink); margin-bottom: var(--space-2); line-height: 1.4; }
.linea-card-chips { display: flex; gap: var(--space-1); flex-wrap: wrap; margin-bottom: var(--space-2); }
.linea-card-meta  { display: flex; gap: var(--space-3); font-size: var(--text-label); color: var(--muted); flex-wrap: wrap; }
.linea-card-entrega { font-size: var(--text-label); color: var(--muted); margin-top: var(--space-2); padding-top: var(--space-2); border-top: 0.5px solid var(--border); }

/* Metadata */
.orden-metadata { margin-top: var(--space-6); }
.orden-metadata > summary { font-size: var(--text-label); color: var(--muted); cursor: pointer; user-select: none; list-style: none; padding: var(--space-1) 0; }
.orden-metadata > summary::-webkit-details-marker { display: none; }
.orden-metadata[open] > summary { margin-bottom: var(--space-3); }
.metadata-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3);
  padding: var(--space-4); background: var(--surface-2); border: 0.5px solid var(--border); border-radius: var(--radius-lg);
}

@media (max-width: 768px) {
  .orden-campos    { grid-template-columns: repeat(3, 1fr); }
  .lineas-desktop  { display: none; }
  .lineas-mobile   { display: block; }
  .metadata-grid   { grid-template-columns: 1fr; }
  .detalle-header  { flex-direction: column; align-items: flex-start; }
  .detalle-actions { width: 100%; }
  .detalle-actions .btn { flex: 1; justify-content: center; }
}
@media (max-width: 480px) { .orden-campos { grid-template-columns: repeat(2, 1fr); } }

/* ═══════════════════════════════════════════════════════════════════════════
   Consolidado
   ═══════════════════════════════════════════════════════════════════════════ */
.filtros-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-4);
  padding: var(--space-4); background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius-lg); margin-bottom: var(--space-5);
}
.filtro-group         { display: flex; flex-direction: column; gap: var(--space-1); min-width: 160px; }
.filtro-group-agrupar { min-width: auto; }
.filtro-label { font-size: var(--text-caption); font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.filtro-input,
.filtro-select {
  height: 32px; padding: 0 var(--space-3); background: var(--bg); border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-md); font-size: var(--text-body-sm); color: var(--ink); font-family: var(--font);
  outline: none; transition: border-color var(--transition-fast);
}
.filtro-input:focus, .filtro-select:focus { border-color: var(--purple); }
.filtro-agrupar { display: flex; gap: var(--space-3); align-items: center; padding-top: var(--space-1); }
.filtro-radio { display: flex; align-items: center; gap: var(--space-1); font-size: var(--text-body-sm); color: var(--body); cursor: pointer; user-select: none; }
.filtro-radio input { accent-color: var(--purple); cursor: pointer; }

.resumen-cards {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); margin-bottom: var(--space-5);
}
.resumen-card {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-1);
  padding: var(--space-4) var(--space-3); background: var(--surface);
  border: 0.5px solid var(--border); border-radius: var(--radius-lg); text-align: center;
}
.resumen-card-value { font-size: 20px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.resumen-card-label { font-size: var(--text-caption); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.consolidado-desktop { display: flex; flex-direction: column; gap: var(--space-2); }
.accordion-item      { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.accordion-header    {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  cursor: pointer; user-select: none; transition: background var(--transition-fast);
}
.accordion-header:hover { background: var(--surface-2); }
.accordion-title   { flex: 1; font-size: var(--text-body-sm); font-weight: 500; color: var(--ink); }
.accordion-meta    { font-size: var(--text-caption); color: var(--muted); white-space: nowrap; }
.accordion-chevron { width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--muted); transition: transform var(--transition-fast); }
.accordion-chevron::before { content: '▸'; font-size: 10px; }
.accordion-header[aria-expanded="true"] .accordion-chevron { transform: rotate(90deg); }
.accordion-body       { border-top: 0.5px solid var(--border); overflow-x: auto; }
.accordion-body[hidden] { display: none; }

.grid-consolidado { width: 100%; border-collapse: collapse; font-size: var(--text-body-sm); }
.grid-consolidado thead th {
  padding: var(--space-2) var(--space-3); text-align: left; font-size: var(--text-caption); font-weight: 500;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--surface-2); border-bottom: 0.5px solid var(--border); white-space: nowrap;
}
.grid-consolidado tbody td {
  padding: var(--space-2) var(--space-3); color: var(--body);
  border-bottom: 0.5px solid var(--border); vertical-align: middle;
}
.grid-consolidado tbody tr:last-child td  { border-bottom: none; }
.grid-consolidado tbody tr:hover td       { background: var(--surface-2); }
.col-talla        { width: 64px; text-align: center; }
.col-cant-cons    { width: 72px; text-align: right; font-variant-numeric: tabular-nums; }
.col-unidad-cons  { width: 72px; text-align: center; color: var(--muted); }
.col-entrega-cons { width: 100px; color: var(--muted); }

.consolidado-mobile { display: none; }
.cons-mobile-card { background: var(--surface); border: 0.5px solid var(--border); border-radius: var(--radius-lg); margin-bottom: var(--space-3); overflow: hidden; }
.cons-mobile-header { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--surface-2); border-bottom: 0.5px solid var(--border); }
.cons-mobile-titulo { font-size: var(--text-body-sm); font-weight: 500; color: var(--ink); }
.cons-mobile-meta   { font-size: var(--text-caption); color: var(--muted); white-space: nowrap; }
.cons-mobile-linea  { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); padding: var(--space-2) var(--space-4); border-bottom: 0.5px solid var(--border); }
.cons-mobile-linea:last-child { border-bottom: none; }
.cons-ml-desc { font-size: var(--text-body-sm); color: var(--body); flex: 1; }
.cons-ml-qty  { font-size: var(--text-body-sm); font-weight: 500; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) { .resumen-cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) {
  .consolidado-desktop { display: none; }
  .consolidado-mobile  { display: block; }
  .filtros-bar         { gap: var(--space-3); }
  .filtro-group        { min-width: 140px; flex: 1; }
  .page-header         { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 480px) {
  .resumen-cards  { grid-template-columns: repeat(2, 1fr); }
  .filtro-group   { min-width: 100%; }
  .filtro-agrupar { flex-wrap: wrap; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive shell — mobile sidebar overlay
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .hamburger-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-sidebar);
  }
  .sidebar[data-open] { transform: translateX(0); }

  /* Overlay behind sidebar on mobile */
  .sidebar[data-open]::before {
    content: '';
    position: fixed;
    inset: 0;
    left: var(--sidebar-w);
    background: var(--modal-backdrop);
    z-index: -1;
  }

  /* When legacy #app-nav has data-open (consolidado.js), also show sidebar */
  .sidebar:has(#app-nav[data-open]) {
    transform: translateX(0);
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Pantalla de mapeo (s3-mapeo) — cola de asignación de productos
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Counters bar ─────────────────────────────────────────────────────────── */
.s3-counters {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.s3-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  gap: 2px;
}
.s3-counter .val {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}
.s3-counter .lbl {
  font-size: var(--text-caption);
  color: var(--muted);
  white-space: nowrap;
}
.s3-counter.danger  .val { color: var(--error); }
.s3-counter.warning .val { color: var(--warning); }
.s3-counter.teal    .val { color: var(--teal-ink); }

.s3-counter-sep { flex: 1; min-width: var(--space-2); }

.s3-shortcuts {
  font-size: var(--text-caption);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.s3-shortcuts kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-2);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--body);
}

/* ── Bulk action bar ──────────────────────────────────────────────────────── */
.s3-bulk-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--purple);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-lg);
  flex-wrap: wrap;
}
.s3-bulk-bar[hidden] { display: none; }

.s3-bulk-count {
  font-size: var(--text-body-sm);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.s3-bulk-select {
  flex: 1;
  min-width: 160px;
  height: 34px;
  padding: 0 var(--space-3);
  border: 0.5px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: var(--text-body-sm);
  font-family: var(--font);
  cursor: pointer;
}
.s3-bulk-select option { background: var(--purple-ink); color: #fff; }
.s3-bulk-select:focus  { outline: none; border-color: rgba(255,255,255,0.7); }

.s3-bulk-btn {
  height: 34px;
  padding: 0 var(--space-4);
  background: #fff;
  color: var(--purple);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-body-sm);
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity var(--transition-fast);
}
.s3-bulk-btn:hover    { opacity: 0.9; }
.s3-bulk-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.s3-bulk-close {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.s3-bulk-close:hover { background: rgba(255,255,255,0.28); }

/* ── List wrap ────────────────────────────────────────────────────────────── */
.s3-wrap { display: flex; flex-direction: column; gap: var(--space-2); }

/* ── Row card ─────────────────────────────────────────────────────────────── */
.s3-row {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition:
    border-color var(--transition-fast),
    box-shadow   var(--transition-fast);
}
.s3-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }

.s3-row.expanded {
  border-color: var(--purple);
  box-shadow: 0 0 0 2px var(--purple-soft);
}
[data-theme="dark"] .s3-row.expanded {
  box-shadow: 0 0 0 2px rgba(105,28,255,0.25);
}

.s3-row.selected > .s3-head { background: var(--purple-soft); }
[data-theme="dark"] .s3-row.selected > .s3-head { background: rgba(105,28,255,0.12); }

/* ── Row head (collapsed view) ────────────────────────────────────────────── */
.s3-head {
  display: grid;
  grid-template-columns: 28px 90px 120px 1fr auto auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  user-select: none;
  min-height: 48px;
}
.s3-head-check {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--purple);
  flex-shrink: 0;
}
.s3-head .mono {
  font-family: var(--font-mono);
  font-size: var(--text-label);
  font-weight: 600;
  color: var(--purple);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.s3-head .cliente {
  font-size: var(--text-body-sm);
  color: var(--body);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.s3-head .desc {
  font-size: var(--text-body-sm);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.s3-head .extract {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}
.s3-head .chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  font-size: var(--text-caption);
  font-weight: 500;
  background: var(--surface-2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--body);
  white-space: nowrap;
  flex-shrink: 0;
}
.s3-head .badge-wrap { display: flex; align-items: center; }

/* ── Row expanded panel ───────────────────────────────────────────────────── */
.s3-exp {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
  padding: var(--space-4) var(--space-5) var(--space-5);
  border-top: 0.5px solid var(--border);
  background: var(--surface-2);
}

.s3-exp-label {
  font-size: var(--text-label);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}
.s3-exp-desc {
  font-family: var(--font-mono);
  font-size: var(--text-body-sm);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  color: var(--ink);
  line-height: 1.5;
  word-break: break-word;
  margin-bottom: var(--space-4);
  white-space: pre-wrap;
}
.s3-fields {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}
.s3-field { display: flex; flex-direction: column; gap: 2px; }
.s3-field-label { font-size: var(--text-caption); color: var(--muted); }
.s3-field-value { font-size: var(--text-body-sm); font-weight: 500; color: var(--ink); }

/* ── Suggestion card ──────────────────────────────────────────────────────── */
.s3-suggest {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--teal-soft);
  border: 0.5px solid var(--teal-ink);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  cursor: default;
}
[data-theme="dark"] .s3-suggest {
  background: rgba(0,131,122,0.15);
  border-color: rgba(0,214,197,0.3);
}
.s3-suggest .icn {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--teal-ink);
  border-radius: var(--radius-md);
  color: #fff;
}
.s3-suggest-body { flex: 1; min-width: 0; }
.s3-suggest-title {
  font-size: var(--text-label);
  font-weight: 600;
  color: var(--teal-ink);
  margin-bottom: 2px;
}
.s3-suggest-name { font-size: var(--text-body-sm); color: var(--ink); font-weight: 500; }

.s3-no-suggest {
  padding: var(--space-3) var(--space-4);
  background: var(--error-soft);
  border: 0.5px solid var(--error);
  border-radius: var(--radius-lg);
  font-size: var(--text-body-sm);
  color: var(--error);
  margin-bottom: var(--space-3);
}
[data-theme="dark"] .s3-no-suggest { background: rgba(229,72,77,0.12); }

/* ── Product selector + confirm area ─────────────────────────────────────── */
.s3-conf { display: flex; flex-direction: column; gap: var(--space-3); }

.s3-prod-select {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-3);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-body-sm);
  font-family: var(--font);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%237A7D8A' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
}
.s3-prod-select:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 2px var(--purple-soft);
}

.s3-conf-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.s3-conf-actions .btn { flex: 1; min-width: 100px; }

/* ── Custom tooltips ──────────────────────────────────────────────────────── */
.tt {
  position: relative;
  display: inline-flex;
}
.tt-body {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 240px;
  padding: var(--space-1) var(--space-2);
  background: var(--ink);
  color: var(--bg);
  font-size: var(--text-caption);
  border-radius: var(--radius-sm);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  white-space: normal;
  text-align: center;
  z-index: 100;
}
.tt:hover .tt-body,
.tt:focus-within .tt-body {
  opacity: 1;
}

/* ── Page subtitle ────────────────────────────────────────────────────────── */
.page-subtitle {
  font-size: var(--text-body-sm);
  color: var(--muted);
  margin-top: 2px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .s3-head {
    grid-template-columns: 28px 1fr auto;
    grid-template-rows: auto auto;
    gap: var(--space-2);
  }
  .s3-head .mono     { grid-column: 2; grid-row: 1; }
  .s3-head .cliente  { display: none; }
  .s3-head .desc     { grid-column: 2 / -1; grid-row: 2; font-size: var(--text-label); color: var(--muted); }
  .s3-head .extract  { grid-column: 1 / -1; grid-row: 3; justify-content: flex-start; }
  .s3-head .badge-wrap { grid-column: 3; grid-row: 1; }

  .s3-exp { grid-template-columns: 1fr; }
  .s3-fields { grid-template-columns: repeat(2, 1fr); }
  .s3-shortcuts { display: none; }

  .s3-bulk-bar { flex-wrap: wrap; }
  .s3-bulk-select { min-width: 0; width: 100%; order: 3; }
  .s3-bulk-count  { order: 1; }
  .s3-bulk-btn    { order: 2; }
  .s3-bulk-close  { order: 0; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mejora 1 — Columna de progreso de mapeo (tabla órdenes)
   ═══════════════════════════════════════════════════════════════════════════ */

.col-mapeo { width: 110px; }

.mapeo-progress { display: inline-flex; align-items: center; gap: 8px; }
.mapeo-bar {
  width: 48px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}
.mapeo-bar > div {
  height: 100%;
  background: var(--teal);
  border-radius: 999px;
  transition: width 300ms ease;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mejora 2 — Columnas de campos extraídos (tabla líneas en detalle)
   ═══════════════════════════════════════════════════════════════════════════ */

.col-extracted {
  background: rgba(105,28,255,0.03);
  font-size: 12px;
}
[data-theme="dark"] .col-extracted { background: rgba(105,28,255,0.08); }

/* ═══════════════════════════════════════════════════════════════════════════
   Mejora 3 — Agrupación por orden en cola de mapeo
   ═══════════════════════════════════════════════════════════════════════════ */

.s3-order-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
}
.s3-order-group-header:first-child { margin-top: 0; }
.s3-order-group-header .mono { color: var(--ink); font-weight: 500; }
.s3-group-progress { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.s3-row.s3-in-group {
  border-top: none;
  border-radius: 0;
}
.s3-row.s3-in-group-last {
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mejora 4 — Animación al confirmar mapeo
   ═══════════════════════════════════════════════════════════════════════════ */

.s3-row.confirming {
  background: var(--teal-soft) !important;
  border-color: var(--teal-ink) !important;
  transition: background 200ms ease !important;
}
[data-theme="dark"] .s3-row.confirming {
  background: rgba(0,131,122,0.18) !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mejora 5 — Visor PDF embebido en detalle
   ═══════════════════════════════════════════════════════════════════════════ */

.app-main--full {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.detalle-layout {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.detalle-layout > #detalle-content {
  overflow-y: auto;
  padding: var(--space-6);
}

.detalle-pdf-panel {
  border-left: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pdf-toolbar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}
.pdf-filename {
  color: var(--ink);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-viewer {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 20px;
  background: #E9ECF2;
}
[data-theme="dark"] .pdf-viewer { background: #0A0A14; }

.pdf-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.pdf-viewer iframe {
  width: 100%;
  max-width: 560px;
  border: none;
  background: white;
  box-shadow: 0 4px 20px rgba(0,0,0,0.10);
  border-radius: 2px;
}

@media (max-width: 1024px) {
  .detalle-layout {
    grid-template-columns: 1fr;
  }
  .detalle-pdf-panel { display: none; }
  .detalle-layout > #detalle-content { padding: var(--space-4); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Catálogo de productos (s9)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Page header (above master-detail) ───────────────────────────────────── */
.s9-header {
  padding: var(--space-5) var(--space-6) var(--space-3);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ── Master-detail layout ─────────────────────────────────────────────────── */
.s9-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 380px;
}

.s9-left {
  overflow: auto;
  padding: 0 var(--space-6) var(--space-6);
}

.s9-right {
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Filters bar ──────────────────────────────────────────────────────────── */
.s9-filters {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
}
.s9-counter {
  font-size: var(--text-label);
  color: var(--muted);
  white-space: nowrap;
  margin-left: auto;
}

/* ── Catalog table (.tbl) ─────────────────────────────────────────────────── */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body-sm);
  background: var(--surface);
}
.tbl th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--muted);
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
.tbl th:first-child { border-radius: var(--radius-md) 0 0 0; }
.tbl th:last-child  { border-radius: 0 var(--radius-md) 0 0; }
.tbl td {
  padding: var(--space-2) var(--space-3);
  color: var(--ink);
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { cursor: pointer; transition: background var(--transition-fast); }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tbody tr:focus-visible { outline: 2px solid var(--purple); outline-offset: -2px; }
.tbl tbody tr.active td { background: var(--purple-soft); }
.tbl tbody tr.active:hover td { background: var(--purple-soft); }
[data-theme="dark"] .tbl tbody tr.active td { background: rgba(105,28,255,0.15); }

/* ── Size chips ───────────────────────────────────────────────────────────── */
.size-chip {
  display: inline-flex;
  padding: 1px 7px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-right: 3px;
  color: var(--body);
}

/* ── Toggle switch ────────────────────────────────────────────────────────── */
.toggle-sw {
  width: 30px;
  height: 18px;
  border-radius: 999px;
  background: var(--teal);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  border: none;
  padding: 0;
}
.toggle-sw::after {
  content: '';
  position: absolute;
  right: 2px;
  top: 2px;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: right 150ms ease, left 150ms ease;
}
.toggle-sw.off { background: var(--border-strong); }
.toggle-sw.off::after { right: auto; left: 2px; }

/* ── Edit panel ───────────────────────────────────────────────────────────── */
.s9-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--muted);
  font-size: var(--text-body-sm);
  text-align: center;
  padding: var(--space-6);
}

#s9-form {
  display: flex;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.s9-edit-head {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.s9-edit-code {
  font-size: var(--text-body-sm);
  font-weight: 600;
  color: var(--purple);
  display: block;
  margin-bottom: 2px;
}
.s9-edit-name {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}

.s9-edit-body {
  padding: var(--space-4) var(--space-5);
  overflow-y: auto;
  flex: 1;
}
.s9-edit-body .group {
  margin-bottom: var(--space-4);
}
.s9-edit-body .field-label {
  display: block;
  font-size: var(--text-label);
  font-weight: 500;
  color: var(--muted);
  margin-bottom: var(--space-1);
}
.s9-edit-body .field-error {
  font-size: var(--text-caption);
  color: var(--error);
  margin-top: var(--space-1);
}

/* ── Size grid ────────────────────────────────────────────────────────────── */
.s9-size-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.s9-size-box {
  padding: 6px 0;
  text-align: center;
  font-size: 12px;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--muted);
  transition: background 120ms, border-color 120ms, color 120ms;
  user-select: none;
}
.s9-size-box:hover { border-color: var(--border-strong); color: var(--ink); }
.s9-size-box.sel {
  background: var(--purple-soft);
  color: var(--purple-ink);
  border-color: rgba(105,28,255,0.35);
  font-weight: 600;
}
[data-theme="dark"] .s9-size-box.sel {
  background: rgba(105,28,255,0.18);
  border-color: rgba(105,28,255,0.4);
  color: var(--purple);
}

/* ── Usage indicator ──────────────────────────────────────────────────────── */
.s9-usage {
  background: linear-gradient(to right, rgba(105,28,255,0.06), rgba(0,214,197,0.04));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--body);
  line-height: 1.4;
}

/* ── Actions footer ───────────────────────────────────────────────────────── */
.s9-edit-actions {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-2);
  align-items: center;
  background: var(--surface-2);
  flex-shrink: 0;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .s9-wrap { grid-template-columns: 1fr; }
  .s9-right { display: none; }
}
@media (max-width: 768px) {
  .s9-header { padding: var(--space-4) var(--space-4) var(--space-2); }
  .s9-left   { padding: 0 var(--space-4) var(--space-4); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   s4 — Cruce OC vs inventario
   ═══════════════════════════════════════════════════════════════════════════ */

.s4-header {
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.s4-order-pick {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: center;
}
.s4-order-info {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.s4-order-info .kv  { display: flex; flex-direction: column; gap: 2px; }
.s4-order-info .kv .k {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.s4-order-info .kv .v { font-size: 13px; font-weight: 500; }

.s4-coverage {
  margin: 16px 24px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-shrink: 0;
}
.s4-cov-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--border);
  display: flex;
  overflow: hidden;
  margin: 12px 0 10px;
}
.s4-cov-legend {
  display: flex;
  gap: 22px;
  font-size: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.s4-cov-legend .sw {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}

.s4-controls {
  padding: 0 24px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.s4-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  display: inline-flex;
}
.s4-toggle button {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}
.s4-toggle button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.s4-table-wrap {
  padding: 0 24px 24px;
  flex: 1;
  overflow: auto;
  min-height: 0;
}
.s4-cell-qty {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.s4-cell-qty .dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .s4-order-pick { grid-template-columns: 1fr; }
  .s4-order-info { gap: 12px; }
  .s4-cov-legend { flex-direction: column; gap: 8px; }
  .s4-header     { padding: 12px 16px; }
  .s4-controls   { padding: 0 16px 10px; }
  .s4-table-wrap { padding: 0 16px 16px; }
  .s4-coverage   { margin: 12px 16px; }
}
