/* ============================================================
   CELTEC — Componentes compartidos de las páginas internas
   Requiere celtec-tokens.css (enlazarlo primero).
   Enlazar DESPUÉS del <style> de la página y ANTES de dark-mode.css.

   Se conservan los nombres de clase que ya usa el JS de cada página.
   NO incluye estilos específicos de módulo: .cart-*, .metodo-*,
   #scanner-feedback, .pci-*, .estado-*, tickets/etiquetas/impresión.
   No contiene reglas @media print.

   Índice
     1. Base y foco               8. Tarjetas, estadísticas, filtros
     2. Sidebar (+ colapsado)     9. Tablas y estados vacíos
     3. Layout y menú móvil      10. Badges de estado
     4. Botones                  11. Modales
     5. Formularios              12. Toast, carga y mensajes
     6. Pestañas                 13. Utilidades
     7. Encabezado de página     14. Movimiento reducido
   ============================================================ */

/* ── 1. Base y foco ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

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

body {
    font-family: var(--font-sans);
    font-size: var(--fs-md);
    line-height: var(--lh-base);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; }

/* Anillo de foco visible solo con teclado */
:where(a, button, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
}
.sidebar :focus-visible { outline-color: #fff; outline-offset: -2px; }

/* ── 2. Sidebar ────────────────────────────────────────────── */
/* Reglas migradas tal cual de pos.html (l.19-60), con tokens.
   Incluye .sidebar.collapsed, tooltip del modo colapsado y drawer móvil. */
.sidebar { position: fixed; top: 0; left: 0; width: var(--sidebar-width); height: 100vh; background: var(--sidebar-bg); color: #fff; transition: all 0.3s; z-index: var(--z-sidebar); display: flex; flex-direction: column; }
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar-header { padding: 1.5rem; border-bottom: 1px solid var(--sidebar-border); display: flex; align-items: center; justify-content: space-between; }
.sidebar-logo { display: flex; align-items: center; gap: 0.75rem; }
.sidebar-logo-icon { font-size: 1.5rem; }
.sidebar-logo-text { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.sidebar.collapsed .sidebar-logo { display: none; }
.sidebar-toggle { background: none; border: none; color: #fff; font-size: 1.25rem; cursor: pointer; padding: 0.5rem; border-radius: var(--radius-sm); min-width: var(--control-h); min-height: var(--control-h); }
.sidebar-toggle:hover { background: var(--sidebar-hover); }
.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 1.5rem; min-height: 44px; color: var(--sidebar-text); text-decoration: none; cursor: pointer; white-space: nowrap; transition: background 0.2s, color 0.2s; position: relative; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active-bg); color: #fff; border-right: 3px solid #fff; }
.nav-item-icon { font-size: 1.2rem; min-width: 24px; text-align: center; flex-shrink: 0; }
.nav-item-text { overflow: hidden; }
.sidebar.collapsed .nav-item-text { display: none; }
.nav-section { padding: 1rem 1.5rem 0.5rem; font-size: var(--fs-xs); font-weight: 600; color: var(--sidebar-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.sidebar.collapsed .nav-section { display: none; }
.sidebar-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--sidebar-border); }
.user-info { display: flex; align-items: center; gap: 0.75rem; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand-600); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.user-details { overflow: hidden; }
.sidebar.collapsed .user-details { display: none; }
.user-name { font-weight: 600; font-size: 0.9rem; }
.user-role { font-size: var(--fs-xs); color: var(--sidebar-text-muted); }
.btn-logout-sidebar { width: 100%; margin-top: 8px; padding: 6px; min-height: var(--control-h); background: rgba(239,68,68,0.15); border: 1px solid rgba(252,165,165,0.4); color: #FECACA; border-radius: var(--radius-sm); cursor: pointer; font-size: var(--fs-xs); transition: background 0.2s; }
.btn-logout-sidebar:hover { background: rgba(239,68,68,0.3); }
.sidebar.collapsed .nav-item { padding: 0.75rem 0; justify-content: center; }
.sidebar.collapsed .nav-item::after { content: attr(title); position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%); background: var(--navy-900); color: #fff; padding: 5px 10px; border-radius: var(--radius-sm); font-size: var(--fs-xs); white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity 0.15s; border: 1px solid rgba(255,255,255,0.15); z-index: 1100; }
.sidebar.collapsed .nav-item:hover::after,
.sidebar.collapsed .nav-item:focus-visible::after { opacity: 1; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 1.25rem 0; }
.sidebar.collapsed .sidebar-footer { padding: 0.75rem 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.sidebar.collapsed .user-info { justify-content: center; }
.sidebar.collapsed .btn-logout-sidebar { width: var(--control-h); height: var(--control-h); padding: 0; display: flex; align-items: center; justify-content: center; font-size: 16px; border-radius: var(--radius-md); margin-top: 0; }
.sidebar.collapsed .btn-logout-sidebar .logout-text { display: none; }
.sidebar.collapsed .dark-mode-toggle { display: flex; align-items: center; justify-content: center; width: var(--control-h); height: var(--control-h); }
.sidebar.collapsed #sucursalSelectorWrapper { display: none !important; }
.sidebar.collapsed .nav-item.active { border-right: none; border-radius: var(--radius-md); margin: 0 8px; width: calc(100% - 16px); justify-content: center; }
/* Controles táctiles del sidebar: 40 px en escritorio, 44 px en pantallas táctiles (--control-h) */
.dark-mode-toggle { min-width: var(--control-h); min-height: var(--control-h); }
#sucursalSelect { min-height: var(--control-h); }
.sucursal-selector { padding: 8px 12px; border-bottom: 1px solid var(--sidebar-border); display: none; }
.sucursal-selector select { width: 100%; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.25); color: #fff; border-radius: var(--radius-sm); padding: 5px 8px; min-height: 36px; font-size: var(--fs-xs); cursor: pointer; }
.sucursal-selector select option { background: var(--navy-950); color: #fff; }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: calc(var(--z-sidebar) - 1); }
.sidebar-overlay.active { display: block; }

/* ── 3. Layout y menú móvil ────────────────────────────────── */
.main-content { margin-left: var(--sidebar-width); transition: margin-left 0.3s; padding: 2rem; min-height: 100vh; }
.main-content.expanded { margin-left: var(--sidebar-collapsed); }
.container { max-width: 1600px; margin: 0 auto; }

.mobile-menu-btn { display: none; position: fixed; top: 1rem; left: 1rem; z-index: calc(var(--z-sidebar) - 2); background: var(--surface); color: var(--text); border: 1px solid var(--border); width: 48px; height: 48px; border-radius: var(--radius-lg); font-size: 1.5rem; cursor: pointer; box-shadow: var(--shadow-md); }
.mobile-menu-btn:hover { background: var(--surface-2); }
/* 12 páginas tienen este botón vacío (sin icono ni texto): se dibuja
   una hamburguesa solo cuando está vacío. Los que ya traen ☰ no cambian. */
.mobile-menu-btn:empty::before {
    content: "";
    display: block;
    width: 24px;
    height: 24px;
    margin: auto;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6h16M4 12h16M4 18h16'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6h16M4 12h16M4 18h16'/%3E%3C/svg%3E") center / contain no-repeat;
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.mobile-open { transform: translateX(0); }
    .sidebar.collapsed { width: var(--sidebar-width); }
    .main-content { margin-left: 0 !important; padding: 1rem; }
    .mobile-menu-btn { display: flex; align-items: center; justify-content: center; }
}

/* ── 4. Botones ────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    min-height: var(--control-h); padding: 0.5rem 1.25rem;
    border: 1.5px solid transparent; border-radius: var(--radius-md);
    font-size: var(--fs-sm); font-weight: var(--fw-semibold); line-height: 1.2;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast);
}
.btn:disabled, .btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary   { background: var(--brand-600);   color: #fff; }
.btn-primary:hover:not(:disabled)   { background: var(--brand-700); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-success   { background: var(--success-600); color: #fff; }
.btn-success:hover:not(:disabled)   { background: #065F46; }
.btn-danger    { background: var(--danger-600);  color: #fff; }
.btn-danger:hover:not(:disabled)    { background: #B91C1C; }
.btn-info      { background: var(--info-600);    color: #fff; }
.btn-info:hover:not(:disabled)      { background: #1D4ED8; }
.btn-warning   { background: var(--warning-600); color: #fff; }
.btn-warning:hover:not(:disabled)   { background: #92400E; }
.btn-outline   { background: transparent; border-color: currentColor; color: var(--text); }
.btn-outline-danger { color: var(--danger-600); }
.btn-outline-danger:hover:not(:disabled) { background: var(--danger-600); border-color: var(--danger-600); color: #fff; }
.btn-sm  { min-height: 36px; padding: 0.35rem 0.75rem; font-size: var(--fs-xs); border-radius: var(--radius-sm); }
.btn-lg  { min-height: 52px; padding: 0.875rem 2rem; font-size: var(--fs-lg); border-radius: var(--radius-lg); }
.btn-icon { min-width: var(--control-h); padding: 0.35rem; }
.btn-block { display: flex; width: 100%; }
.btn-group { display: flex; gap: var(--space-4); flex-wrap: wrap; }
/* Estado de carga (clase nueva; el JS la usará en una fase posterior) */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 1.1em; height: 1.1em; border: 2px solid #fff; border-right-color: transparent; border-radius: 50%; animation: celtec-spin 0.7s linear infinite; }
.btn-secondary.is-loading::after, .btn-outline.is-loading::after { border-color: var(--text); border-right-color: transparent; }

@media (pointer: coarse) {
    .btn-sm { min-height: var(--tap); }
}

/* ── 5. Formularios ────────────────────────────────────────── */
/* Selectores :where() → especificidad 0: cualquier regla propia de la
   página (p. ej. .cart-qty input) gana sin necesitar !important. */
.form-group { margin-bottom: var(--space-4); display: flex; flex-direction: column; gap: 0.4rem; }
.form-group.full-width { grid-column: 1 / -1; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4) var(--space-6); }
/* Dentro de una cuadrícula el espacio lo da el gap: sin margen propio (si no, se duplica) */
.form-grid > .form-group { margin-bottom: 0; }
.form-group label, .form-label, .filter-group label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text); }
.filter-group label { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.required { color: var(--danger-600); }

:where(.form-group, .filter-group, .search-box, .form-control) :where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="hidden"]), select, textarea),
input.form-control, select.form-control, textarea.form-control {
    width: 100%; min-height: var(--control-h); padding: 0.5rem 0.875rem;
    background: var(--surface); color: var(--text);
    border: 1.5px solid var(--border-input); border-radius: var(--radius-md);
    font-size: var(--fs-md);   /* 16 px: evita el zoom al enfocar en iOS */
    transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
:where(.form-group) textarea, textarea.form-control { min-height: 88px; resize: vertical; }
:where(input, select, textarea)::placeholder { color: var(--text-muted); opacity: 1; }
:where(input, select, textarea):focus,
:where(input, select, textarea):focus-visible {
    outline: 2px solid transparent;          /* visible en modo alto contraste */
    border-color: var(--brand-600);
    box-shadow: var(--ring);
}
:where(input, select, textarea)[readonly] { background: var(--surface-2); }
:where(input, select, textarea):disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand-600); width: 1.125rem; height: 1.125rem; }
.campo-error, .campo-error:focus { border-color: var(--danger-600) !important; box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2) !important; }
.error-msg, .field-error { color: var(--danger-600); font-size: var(--fs-xs); margin-top: 4px; }
body.dark-mode .error-msg, body.dark-mode .field-error { color: var(--danger-fg); }
.field-hint, .form-hint { color: var(--text-muted); font-size: var(--fs-xs); }

.filters-card { background: var(--surface); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; margin-bottom: var(--space-6); box-shadow: var(--shadow-sm); }
.filters-row, .filters { display: flex; gap: var(--space-4); flex-wrap: wrap; align-items: flex-end; }
.filter-group { display: flex; flex-direction: column; gap: 0.4rem; }

/* ── 6. Pestañas ───────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: var(--space-6); gap: var(--space-2); background: var(--surface); overflow-x: auto; }
.tab { padding: 0.75rem 1.25rem; min-height: var(--control-h); background: none; border: none; border-bottom: 3px solid transparent; margin-bottom: -2px; cursor: pointer; font-weight: var(--fw-semibold); font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--link); border-bottom-color: var(--brand-600); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── 7. Encabezado de página ───────────────────────────────── */
.page-header { background: var(--surface); padding: var(--space-8); border-radius: var(--radius-lg); margin-bottom: var(--space-8); box-shadow: var(--shadow-sm); }
.header-top { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }
.page-title { font-size: var(--fs-3xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); letter-spacing: -0.01em; }
.page-subtitle { color: var(--text-muted); margin-top: var(--space-2); font-size: var(--fs-sm); }

@media (max-width: 768px) {
    .page-header { padding: 1rem; padding-top: 4.5rem; border-radius: 0 0 var(--radius-xl) var(--radius-xl); }
    .header-top { flex-direction: column; align-items: flex-start; }
    .page-title { font-size: var(--fs-2xl); }
    .form-grid { grid-template-columns: 1fr; }
    /* Ancho completo solo en formularios y modales, nunca en tablas */
    .modal-footer .btn, .modal-actions .btn, form .btn-group .btn, .btn-block-mobile { width: 100%; }
    .modal-footer { flex-direction: column-reverse; }
    .filters-row .filter-group, .filters .filter-group { flex: 1 1 100%; }
}

/* ── 8. Tarjetas, estadísticas ─────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: var(--space-8); }
.card-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--space-3); }
.card-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.card-count { font-size: var(--fs-sm); color: var(--text-muted); font-weight: var(--fw-medium); }
.card-body { padding: 1.5rem; }

/* Migrado de ventas.html (l.86-94) */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-6); margin-bottom: var(--space-8); }
.stat-card { background: var(--surface); border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow-sm); }
.stat-card-inner { display: flex; align-items: flex-start; gap: var(--space-4); }
.stat-icon { font-size: 2.25rem; line-height: 1; flex-shrink: 0; }
.stat-label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.3rem; }
.stat-value { font-size: 1.65rem; font-weight: var(--fw-bold); color: var(--text); line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-card-inner > div { min-width: 0; }
.stat-sub { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 0.35rem; }

@media (max-width: 1200px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px)  { .stats-grid { gap: var(--space-4); } .stat-card { padding: 1rem; } .stat-value { font-size: 1.35rem; } }
@media (max-width: 480px)  { .stats-grid { grid-template-columns: 1fr; } }

/* ── 9. Tablas y estados vacíos ────────────────────────────── */
/* Contenedor con sombras laterales que indican que hay más contenido a los lados */
:root { --scroll-shadow: rgba(15, 27, 61, 0.32); }
body.dark-mode { --scroll-shadow: rgba(0, 0, 0, 0.7); }
.table-container, .table-scroll {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    background:
        linear-gradient(to right, var(--surface) 30%, transparent) left center / 28px 100% no-repeat local,
        linear-gradient(to left,  var(--surface) 30%, transparent) right center / 28px 100% no-repeat local,
        radial-gradient(farthest-side at 0 50%,   var(--scroll-shadow), transparent) left center / 14px 100% no-repeat scroll,
        radial-gradient(farthest-side at 100% 50%, var(--scroll-shadow), transparent) right center / 14px 100% no-repeat scroll;
}
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th, thead th { padding: 0.75rem 1rem; background: var(--surface-2); font-weight: var(--fw-semibold); text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); white-space: nowrap; }
td, tbody td { padding: 0.875rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-hover); }
.acciones-cell, .action-buttons { display: flex; gap: 0.4rem; flex-wrap: nowrap; }

/* Migrado de ventas.html (l.118-119). `.empty-state` es el nombre nuevo. */
.table-empty, .empty-state { padding: 4rem 1.5rem; text-align: center; color: var(--text-muted); }
.table-empty-icon, .empty-state-icon { font-size: 3rem; display: block; margin-bottom: 0.75rem; opacity: 0.5; }
.empty-state-title { font-weight: var(--fw-semibold); color: var(--text); margin-bottom: var(--space-1); }

@media (max-width: 768px) {
    th, td, thead th, tbody td { padding: 0.75rem 0.5rem; }
    .table-empty, .empty-state { padding: 3rem 1rem; }
}

/* ── 10. Badges de estado ──────────────────────────────────── */
/* Unifica los nombres que emite el JS de cada página:
   inventario: success/warning/danger/info · ventas: +primary/gray
   cotizaciones: blue/green/red/orange/gray · reparaciones: secondary */
.badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.25rem 0.65rem; border-radius: var(--radius-full); font-size: var(--fs-xs); font-weight: var(--fw-bold); line-height: 1.3; white-space: nowrap; }
.badge-success, .badge-green  { background: var(--success-bg); color: var(--success-fg); }
.badge-warning, .badge-orange { background: var(--warning-bg); color: var(--warning-fg); }
.badge-danger,  .badge-red    { background: var(--danger-bg);  color: var(--danger-fg); }
.badge-info, .badge-blue, .badge-primary { background: var(--info-bg); color: var(--info-fg); }
.badge-gray, .badge-secondary { background: var(--neutral-bg); color: var(--neutral-fg); }

/* ── 11. Modales ───────────────────────────────────────────── */
/* .modal-content (pos, inventario, reparaciones) y .modal-box (ventas) */
.modal { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: var(--z-modal); align-items: center; justify-content: center; padding: var(--space-6); overflow-y: auto; }
.modal.active { display: flex; }
.modal-content, .modal-box { background: var(--surface); color: var(--text); border-radius: var(--radius-xl); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow-lg); margin: auto; }
.modal-box { display: flex; flex-direction: column; }
.modal-sm { max-width: 480px; }
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 1000px; }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-title { font-size: var(--fs-xl); font-weight: var(--fw-bold); }
.modal-close { background: none; border: none; font-size: 1.6rem; line-height: 1; color: var(--text-muted); cursor: pointer; min-width: var(--tap); min-height: var(--tap); border-radius: var(--radius-md); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--space-3); position: sticky; bottom: 0; background: var(--surface); }

@media (max-width: 768px) {
    .modal { padding: 0; }
    .modal-content { max-width: 100%; max-height: 100vh; min-height: 100vh; border-radius: 0; }
    /* Hoja inferior para los modales de detalle de ventas */
    .modal-box { max-width: 100%; border-radius: var(--radius-xl) var(--radius-xl) 0 0; max-height: 95vh; margin-bottom: 0; }
    .modal.has-box, .modal:has(> .modal-box) { align-items: flex-end; }
    .modal-header, .modal-body, .modal-footer { padding-left: 1rem; padding-right: 1rem; }
}

/* ── 12. Toast, carga y mensajes ───────────────────────────── */
/* Toast migrado de ventas.html (l.136-139) */
.toast-container { position: fixed; top: 1.5rem; right: 1.5rem; z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-3); pointer-events: none; }
.toast { background: var(--navy-900); color: #fff; padding: 1rem 1.25rem; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: var(--fs-sm); font-weight: var(--fw-medium); max-width: 360px; display: flex; align-items: center; gap: var(--space-3); animation: celtec-toast-in 0.3s var(--ease); pointer-events: auto; }
.toast.success { background: #065F46; border-left: 4px solid #34D399; }
.toast.error   { background: #991B1B; border-left: 4px solid #FCA5A5; }
.toast.info    { background: var(--navy-800); border-left: 4px solid var(--brand-200); }
.toast.warning { background: #92400E; border-left: 4px solid #FCD34D; }
/* `.error` (mensaje en línea, más abajo) también alcanza a `.toast.error`: sin esto el texto salía
   rojo sobre rojo, con margen inferior de más y otro radio. Solo afecta a `.toast.error`. */
.toast.error { color: #fff; margin-bottom: 0; border-radius: 10px; }
@media (max-width: 768px) {
    .toast-container { left: 1rem; right: 1rem; top: 4.75rem; }
    .toast { max-width: none; }
}

.spinner { width: 44px; height: 44px; border: 4px solid var(--border); border-top-color: var(--brand-600); border-radius: 50%; animation: celtec-spin 0.8s linear infinite; }
.spinner-sm { width: 20px; height: 20px; border-width: 3px; }
.loading-overlay { display: none; position: fixed; inset: 0; background: rgba(244, 246, 251, 0.8); z-index: var(--z-toast); align-items: center; justify-content: center; flex-direction: column; gap: var(--space-4); }
body.dark-mode .loading-overlay { background: rgba(11, 18, 38, 0.8); }
.loading-overlay.active { display: flex; }
/* `.loading` ya existe en el HTML como texto "Cargando…": se le añade un spinner sin tocar el HTML */
.loading { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); text-align: center; padding: 4rem 1rem; color: var(--text-muted); }
.loading::before { content: ""; width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand-600); border-radius: 50%; animation: celtec-spin 0.8s linear infinite; }

.skeleton { display: block; min-height: 1em; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: celtec-shimmer 1.4s ease infinite; color: transparent; }

/* Mensajes en línea (clases que el JS ya genera) */
.success-message, .error, .alert { padding: 1rem 1.25rem; border-radius: var(--radius-md); margin-bottom: var(--space-4); border-left: 4px solid; font-size: var(--fs-sm); }
.success-message, .alert-success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-600); }
.error, .alert-danger            { background: var(--danger-bg);  color: var(--danger-fg);  border-color: var(--danger-600); }
.alert-warning                   { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-600); }
.alert-info                      { background: var(--info-bg);    color: var(--info-fg);    border-color: var(--brand-600); }

@keyframes celtec-spin { to { transform: rotate(360deg); } }
@keyframes celtec-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@keyframes celtec-toast-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }

/* ── 13. Utilidades ────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }

/* ── 14. Movimiento reducido ───────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ── 15. Chip de código, botones tonales y tabla apilada (Fase 7b) ──
   Solo clases NUEVAS (añadidas al final): no modifican ninguna regla anterior.
   Todo con tokens; los colores se adaptan solos al modo oscuro. */

/* Folio u otro código corto: no se parte en dos líneas */
.code-chip {
    display: inline-block; padding: 0.15rem 0.5rem;
    font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: var(--fw-semibold); line-height: 1.4;
    white-space: nowrap; color: var(--text);
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}

/* Botón tonal: fondo suave del color semántico y texto de su pareja `-fg` (contraste ≥ 4.5:1) */
.btn-soft {
    --soft-bg: var(--neutral-bg); --soft-fg: var(--neutral-fg);
    min-height: 36px; min-width: 36px; padding: 0.35rem 0.65rem;
    background: var(--soft-bg); color: var(--soft-fg); border-color: transparent;
}
.btn-soft:hover:not(:disabled) { border-color: currentColor; filter: brightness(0.97); }
.btn-soft-info    { --soft-bg: var(--info-bg);    --soft-fg: var(--info-fg); }
.btn-soft-success { --soft-bg: var(--success-bg); --soft-fg: var(--success-fg); }
.btn-soft-warning { --soft-bg: var(--warning-bg); --soft-fg: var(--warning-fg); }
.btn-soft-danger  { --soft-bg: var(--danger-bg);  --soft-fg: var(--danger-fg); }
/* Violeta: no hay token propio; se mezcla del azul y el rojo de la paleta (sin hex nuevos) */
.btn-soft-violet  { --soft-bg: var(--info-bg);    --soft-fg: var(--info-fg); }
@supports (background: color-mix(in srgb, red, blue)) {
    .btn-soft-violet {
        --soft-bg: color-mix(in srgb, var(--info-bg) 55%, var(--danger-bg) 45%);
        --soft-fg: color-mix(in srgb, var(--info-fg) 60%, var(--danger-fg) 40%);
    }
}
/* Táctil: 44 px (--tap) */
@media (max-width: 768px), (pointer: coarse) {
    .btn-soft { min-height: var(--tap); min-width: var(--tap); }
}

/* Tabla apilada en móvil: cada <tr> es una tarjeta y cada <td> una línea "Etiqueta: valor".
   Requiere data-label="…" en cada <td>. Las celdas de acciones llevan la clase .cell-actions
   (sin etiqueta, botones en una fila al final). Poner la clase en el <table>. */
@media (max-width: 640px) {
    .table-stack { min-width: 0; }
    .table-stack thead {
        position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
    }
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack tbody { padding: var(--space-3); }
    .table-stack tr {
        margin-bottom: var(--space-3); padding: 0.5rem 0.875rem;
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    }
    .table-stack tbody tr:last-child { margin-bottom: 0; }
    .table-stack tbody tr:hover td { background: transparent; }
    .table-stack td {
        display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4);
        padding: 0.45rem 0; border-bottom: 1px solid var(--border); text-align: right;
    }
    .table-stack td:last-child { border-bottom: none; }
    .table-stack td::before {
        content: attr(data-label); flex: 0 0 auto; max-width: 40%;
        font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-muted);
        text-transform: uppercase; letter-spacing: 0.04em; text-align: left; padding-top: 0.15rem;
    }
    .table-stack td > * { min-width: 0; }
    .table-stack .cell-actions { display: block; padding-top: 0.75rem; text-align: left; }
    .table-stack .cell-actions::before { display: none; }
}

/* ── 16. Formularios largos, zona de fotos, miniaturas y resumen de totales (Fase 7c-1) ──
   Solo clases NUEVAS (añadidas al final). Todo con tokens: se adapta al modo oscuro. */

/* Encabezado de sección dentro de una .form-grid */
.form-section-title {
    grid-column: 1 / -1; margin: var(--space-2) 0 0; padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
    font-size: var(--fs-xs); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-muted);
}
.form-section-title:first-child { margin-top: 0; }

/* Casillas en línea con texto de ayuda */
.checkbox-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; font-size: var(--fs-sm); }
.checkbox-row label { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; }
@media (pointer: coarse) { .checkbox-row label { min-height: var(--tap); } }

/* Zona para elegir o soltar archivos */
.dropzone {
    display: flex; flex-direction: column; align-items: center; gap: 0.25rem;
    padding: 2rem 1rem; text-align: center; cursor: pointer;
    background: var(--surface-2); border: 2px dashed var(--border); border-radius: var(--radius-lg);
    transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.dropzone:hover { border-color: var(--brand-600); }
.dropzone:has(+ input:focus-visible) { border-color: var(--brand-600); box-shadow: var(--ring); }
.dropzone-icon { font-size: 2rem; line-height: 1; }
.dropzone-title { font-weight: var(--fw-semibold); color: var(--link); }
.dropzone-hint { font-size: var(--fs-xs); color: var(--text-muted); }

/* Cuadrícula de miniaturas (fotos) con botón de quitar y pie de foto */
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--space-2); margin-bottom: var(--space-4); }
.thumb-grid:empty { display: none; }
.thumb { position: relative; aspect-ratio: 1; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb img.thumb-open { cursor: zoom-in; }
.thumb-caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 6px; font-size: var(--fs-xs); text-transform: capitalize; color: var(--text); background: var(--surface); opacity: 0.92; }
.thumb-remove {
    position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1rem; line-height: 1; cursor: pointer;
    color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 50%;
}
.thumb-remove:hover { background: var(--surface-2); }
.thumb-remove-danger { color: var(--danger-fg); background: var(--danger-bg); border-color: transparent; }
@media (pointer: coarse) { .thumb-remove { width: 36px; height: 36px; } }

/* Versión compacta de .empty-state para paneles y modales */
.empty-state-compact { padding: 1.25rem 1rem; font-size: var(--fs-sm); }

/* Resumen de totales: bloque alineado a la derecha, cifras tabulares (mismos inputs de siempre) */
.form-summary {
    grid-column: 1 / -1;   /* ocupa todo el ancho dentro de una .form-grid */
    display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
    font-variant-numeric: tabular-nums;
}
.form-summary .form-group { width: 100%; margin: 0; flex-direction: row; align-items: center; justify-content: flex-end; gap: var(--space-4); }
.form-summary .form-group label { font-size: var(--fs-md); }
.form-summary .form-group input { width: 12rem; text-align: right; font-weight: var(--fw-bold); }
.form-summary .form-group:last-child label { font-size: var(--fs-lg); }
.form-summary-line { margin-top: var(--space-4); text-align: right; font-variant-numeric: tabular-nums; }

/* ── 17. Control segmentado, autocompletado, tarjeta seleccionada y banner de código (Fase 7c-2) ──
   Solo clases NUEVAS (añadidas al final). Todo con tokens. */

/* Control segmentado: una fila de botones .btn (la opción activa es el que lleva .btn-primary) */
.segmented {
    display: flex; width: 100%; overflow: hidden;
    background: var(--surface); border: 1.5px solid var(--border-input); border-radius: var(--radius-md);
}
.segmented .btn {
    flex: 1 1 0; min-height: var(--tap); padding: 0.4rem 0.5rem;
    border: 0; border-radius: 0; white-space: normal; line-height: 1.2; text-align: center;
}
.segmented .btn + .btn { border-left: 1px solid var(--border-input); }
.segmented .btn-secondary { background: transparent; color: var(--text); }
.segmented .btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.segmented .btn:focus-visible { outline-offset: -3px; }

/* Lista de resultados de un buscador (los elementos son <button>: se operan con Tab y Enter) */
.autocomplete-list {
    max-height: calc(var(--tap) * 8); overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
}
.autocomplete-list:empty { display: none; }
.autocomplete-item {
    display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem;
    width: 100%; min-height: var(--tap); padding: 0.5rem 0.875rem;
    background: transparent; color: var(--text); border: 0; border-bottom: 1px solid var(--border);
    font: inherit; text-align: left; cursor: pointer;
}
.autocomplete-item:last-child { border-bottom: 0; }
.autocomplete-item:hover { background: var(--surface-hover); }
.autocomplete-item:focus-visible { background: var(--surface-hover); outline: 2px solid var(--focus-color); outline-offset: -2px; }
.autocomplete-empty { padding: 0.75rem 0.875rem; font-size: var(--fs-sm); color: var(--text-muted); }

/* Tarjeta de lo elegido (p. ej. el cliente) con botón para cambiarlo */
.selected-card {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
    margin-top: var(--space-2); padding: 0.625rem 0.875rem;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.selected-card-body { display: flex; flex-direction: column; min-width: 0; }
.selected-card-title { font-weight: var(--fw-semibold); overflow-wrap: anywhere; }
.selected-card-meta { font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: anywhere; }
.selected-card .btn { flex: 0 0 auto; }

/* Banner con un código (folio) y sus acciones */
.code-banner {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3);
    margin-bottom: var(--space-3); padding: 0.625rem 0.875rem;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.code-banner-label { display: block; margin-bottom: 0.2rem; font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.code-banner .code-chip { font-size: var(--fs-md); }
.code-banner-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* ── 18. Pulido final de reparaciones (Fase 7d) ───────────── */
/* Recuadro de resultado tras guardar (éxito): solo tokens, claro y oscuro */
.result-banner { background: var(--success-bg); color: var(--success-fg); border: 2px solid var(--success-600); border-radius: var(--radius-lg); padding: var(--space-4); margin-bottom: var(--space-3); text-align: center; }
.result-banner-title { font-size: var(--fs-sm); font-weight: var(--fw-semibold); margin-bottom: var(--space-2); }
.result-banner-label { font-size: var(--fs-xs); margin-bottom: var(--space-1); }
.result-banner-code { font-size: 1.4rem; font-weight: var(--fw-bold); letter-spacing: 1px; margin-bottom: var(--space-3); user-select: all; }
.result-banner-note { font-size: var(--fs-xs); margin-top: var(--space-2); }

/* Color de texto semántico (cifras de estadísticas) */
.text-warning { color: var(--warning-text); }
.text-info    { color: var(--info-fg); }
.text-success { color: var(--success-text); }

.textarea-lg { min-height: 120px; }

/* Campo + sufijo/segundo campo en una fila (p. ej. descuento monto y %) */
.input-pair { display: flex; gap: var(--space-2); align-items: center; }
.input-pair-main { flex: 1; min-width: 0; }
.input-pair-narrow { width: 72px; }
.input-pair-suffix { white-space: nowrap; font-size: var(--fs-sm); }

/* Lista de repuestos del formulario */
.repuesto-sub { color: var(--text-muted); font-size: var(--fs-xs); }
.repuesto-controles { display: flex; align-items: center; gap: var(--space-4); }
.repuesto-qty { width: 64px; padding: 0.25rem; }
.repuestos-buscador { margin-bottom: var(--space-4); }

/* ── 19. Compatibilidad: capa .modal-overlay con caja .modal (Fase 8a) ──
   Patrón de cotizaciones, creditos, encargos, gastos, recargas y usuarios:
     <div class="modal-overlay [active]"> <div class="modal"> … </div> </div>
   Aquí .modal es la CAJA, no la capa (en la sección 11 .modal es la capa
   fija a pantalla completa y oculta hasta tener .active). La regla
   `.modal-overlay > .modal` (más específica) la deja como bloque estático, así
   los modales abren y cierran solo con .modal-overlay.active, igual que antes.
   Las páginas que usan .modal como capa (pos, inventario, ventas, reparaciones)
   no tienen ningún hijo directo de .modal-overlay: no les afecta. */
.modal-overlay { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: var(--z-modal); align-items: flex-start; justify-content: center; padding: var(--space-8) var(--space-4); overflow-y: auto; }
.modal-overlay.active, .modal-overlay.open { display: flex; }   /* .open: usuarios y encargos alternan esa clase */
.modal-overlay > .modal {
    display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; position: static; inset: auto; padding: 0; margin: 0; z-index: auto; overflow: hidden;
    width: 100%; max-width: 780px; max-height: calc(100vh - 2 * var(--space-8)); max-height: calc(100dvh - 2 * var(--space-8));
    background: var(--surface); color: var(--text);
    border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
}
/* Armazón (8c): cabecera, pestañas y pie fijos; solo el cuerpo hace scroll */
.modal-overlay > .modal > :is(.modal-header, .modal-footer, .tabs) { flex: 0 0 auto; position: static; }
.modal-overlay > .modal > .modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
@media (max-width: 640px) {
    .modal-overlay { padding: var(--space-3); }
    .modal-overlay > .modal { max-height: calc(100vh - 2 * var(--space-3)); max-height: calc(100dvh - 2 * var(--space-3)); }
}

/* ── 20. Estado vacío de error (Fase 8b) ───────────────────── */
/* Variante de .empty-state para "no se pudo cargar": título en el color de peligro y botón de reintento debajo */
.empty-state-error .empty-state-title { color: var(--danger-600); }
body.dark-mode .empty-state-error .empty-state-title { color: var(--danger-fg); }
.empty-state-error .btn { margin-top: var(--space-3); }

/* ── 21. Diálogos, resumen y opciones de pago (Fase 8c) ────── */
/* Anchos de diálogo para la caja .modal dentro de .modal-overlay */
.modal-overlay > .modal.modal-dialog-sm { max-width: 380px; }
.modal-overlay > .modal.modal-dialog-md { max-width: 420px; }

/* Cuerpo centrado de un diálogo de confirmación: icono, título, texto y acciones apiladas */
.modal-body.modal-center { padding: var(--space-8) var(--space-6); text-align: center; }
.modal-icon-ok {
    display: flex; align-items: center; justify-content: center; width: 56px; height: 56px; margin: 0 auto var(--space-4);
    border-radius: 50%; background: var(--success-bg); color: var(--success-fg); font-size: 1.5rem; font-weight: var(--fw-bold);
}
.modal-heading { margin-bottom: var(--space-1); font-size: var(--fs-xl); font-weight: var(--fw-bold); }
.modal-sub { margin-bottom: var(--space-6); font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: anywhere; }
.modal-lead { margin-bottom: var(--space-4); color: var(--text-muted); overflow-wrap: anywhere; }
.stack-actions { display: flex; flex-direction: column; gap: var(--space-3); }
.stack-actions-row { flex-direction: row; justify-content: center; flex-wrap: wrap; }

/* Opciones grandes en rejilla (p. ej. método de pago) */
.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.option-btn { min-height: var(--tap); padding: var(--space-4); font-size: var(--fs-md); }
@media (max-width: 380px) { .option-grid { grid-template-columns: 1fr; } }

/* La tarjeta de lo elegido no se muestra mientras no tenga contenido */
.selected-card:empty { display: none; }

/* Resumen de una cotización o documento */
.resumen-box { padding: 1.25rem; background: var(--surface-2); border-radius: var(--radius-lg); }
.resumen-section { margin-bottom: 1.25rem; }
.resumen-section h4 { margin-bottom: var(--space-2); font-size: var(--fs-xs); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.resumen-text { font-size: var(--fs-sm); overflow-wrap: anywhere; }
.resumen-note { margin-top: var(--space-1); font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: anywhere; }
.resumen-empty { text-align: center; color: var(--text-muted); }
.resumen-item { display: flex; justify-content: space-between; gap: var(--space-4); padding: 0.35rem 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.resumen-item > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.resumen-item > span:last-child { white-space: nowrap; }
.resumen-item:last-child { border-bottom: none; }
.resumen-item-danger { color: var(--danger-600); }
body.dark-mode .resumen-item-danger { color: var(--danger-fg); }
.resumen-total { display: flex; justify-content: space-between; gap: var(--space-4); margin-top: var(--space-3); padding-top: var(--space-3); border-top: 2px solid var(--text); font-size: var(--fs-lg); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }

/* ── 22. Usuarios, pasos y acciones de fila (Fase 9a) ──────── */
/* Formulario en dos columnas dentro de modales (una en ≤500 px) */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }
@media (max-width: 500px) { .form-row { grid-template-columns: 1fr; } }

/* Texto de color semántico para cifras (se suma a .text-warning/-info/-success de la sección 18) */
.text-danger { color: var(--danger-600); }
body.dark-mode .text-danger { color: var(--danger-fg); }

/* Insignias de rol. Admin: violeta mezclado de azul y rojo (sin hex nuevos); si el navegador no soporta color-mix, queda en azul. */
.badge-role-admin    { background: var(--info-bg); color: var(--info-fg); }
@supports (background: color-mix(in srgb, red, blue)) {
    .badge-role-admin {
        background: color-mix(in srgb, var(--info-bg) 55%, var(--danger-bg) 45%);
        color: color-mix(in srgb, var(--info-fg) 60%, var(--danger-fg) 40%);
    }
}
.badge-role-gerente  { background: var(--info-bg);    color: var(--info-fg); }
.badge-role-tecnico  { background: var(--success-bg); color: var(--success-fg); }
.badge-role-vendedor { background: var(--warning-bg); color: var(--warning-fg); }

/* Avatar con iniciales y celda de usuario (avatar + nombre + dato secundario) */
.avatar-mini {
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--brand-600); color: var(--on-brand); font-size: var(--fs-xs); font-weight: var(--fw-bold);
}
.user-cell { display: flex; align-items: center; gap: 0.625rem; text-align: left; min-width: 0; }
.user-cell-name { font-weight: var(--fw-semibold); overflow-wrap: break-word; }
.user-cell-sub { font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: break-word; }

/* Celdas que ocupan toda la fila de una tabla (cargando, vacío, error); en la vista apilada sin etiqueta */
.cell-state { padding: 0; }
@media (max-width: 640px) {
    .table-stack .cell-state { display: block; }
    .table-stack .cell-state::before { display: none; }
}

/* Acciones de fila en grupos: solo icono en escritorio (con title + aria-label), texto en la vista apilada */
.row-actions { display: flex; flex-wrap: wrap; gap: 0.3rem 0.6rem; }
.row-actions .action-group { display: inline-flex; gap: 0.3rem; }
.row-actions .btn-text { display: none; }
@media (max-width: 768px) { .row-actions .btn { min-height: var(--tap); min-width: var(--tap); } }
@media (max-width: 640px) {
    .row-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .row-actions .action-group { display: contents; }
    .row-actions .btn { width: 100%; justify-content: center; }
    .row-actions .btn-text { display: inline; }
    .row-actions .action-group:only-child .btn:only-child { grid-column: 1 / -1; }
}

/* Pasos numerados (instalaciones, guías) */
.steps { display: flex; flex-direction: column; }
.step { display: flex; gap: var(--space-4); align-items: flex-start; padding: 1.25rem 0; border-bottom: 1px solid var(--border); }
.step:last-child { border-bottom: none; }
.step-number {
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 36px; height: 36px; border-radius: 50%; background: var(--brand-600); color: var(--on-brand); font-weight: var(--fw-bold);
}
.step-body { min-width: 0; }
.step-body h4 { margin-bottom: 0.4rem; font-size: var(--fs-md); }
.step-body p { color: var(--text-muted); font-size: var(--fs-sm); line-height: 1.5; }
.step-note { margin-top: 0.5rem; font-size: var(--fs-sm); color: var(--text-muted); }
.step-body .btn { margin-top: 0.5rem; }

/* Línea de estado: punto (el color lo pone el JS o una clase) + texto, sobre fondo suave */
.status-line { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4); background: var(--surface-2); border-radius: var(--radius-md); }
.status-dot { width: 12px; height: 12px; flex-shrink: 0; border-radius: 50%; background: var(--text-muted); }
.status-line a { color: var(--link); font-weight: var(--fw-semibold); }
@media (max-width: 768px) { .status-line a { display: inline-flex; align-items: center; min-height: var(--tap); } }
.text-muted { color: var(--text-muted); }

/* ── 23. Tarjetas de gráfica, variaciones y alertas (Fase 9b) ── */
/* Variación respecto a otro periodo: color por significado (sube / baja / sin cambio) */
.stat-compare { display: block; margin-top: 0.4rem; font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.stat-compare.up      { color: var(--success-text); }
.stat-compare.down    { color: var(--danger-600); }
.stat-compare.neutral { color: var(--text-muted); }
body.dark-mode .stat-compare.down { color: var(--danger-fg); }

/* Rejilla de tarjetas de gráfica: 2 columnas en escritorio, 1 en pantallas ≤900 px */
.charts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-6); margin-bottom: var(--space-8); }
@media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }

/* Tarjeta de gráfica: cabecera con título y subtítulo, cuerpo con altura fija para el <canvas>.
   La altura la da .chart-wrapper (el canvas se adapta; Chart.js con maintainAspectRatio:false). */
.chart-card { min-width: 0; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.chart-card-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); }
.chart-card-title { font-size: var(--fs-md); font-weight: var(--fw-bold); }
.chart-card-subtitle { margin-top: 0.2rem; font-size: var(--fs-sm); color: var(--text-muted); }
.chart-card-body { position: relative; padding: 1.5rem; }
.chart-wrapper { position: relative; height: 280px; }
.chart-wrapper canvas { max-width: 100%; max-height: 100% !important; }
@media (max-width: 640px) {
    .chart-card-header { padding: 1rem; }
    .chart-card-body { padding: 1rem; }
    .chart-wrapper { height: 240px; }
}
/* Estado "sin datos" sobre el área del gráfico (el JS añade/quita .visible y oculta el canvas) */
.chart-no-data { display: none; position: absolute; inset: 0; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2); color: var(--text-muted); text-align: center; }
.chart-no-data.visible { display: flex; }

/* Aviso con borde y fondo suaves según urgencia (con icono, texto y acción) */
.alert-banner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-3); padding: 0.9rem 1.25rem; border: 1px solid; border-radius: var(--radius-md); }
.alert-banner-main { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.alert-banner-icon { font-size: 1.4rem; line-height: 1; }
.alert-banner-sub { margin-top: 0.15rem; font-size: var(--fs-sm); opacity: 0.85; }
.alert-banner-warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-600); }
.alert-banner-danger  { background: var(--danger-bg);  color: var(--danger-fg);  border-color: var(--danger-600); }
.alert-banner .btn { white-space: nowrap; }

/* ── 24. Etiqueta de filtro sin control (Fase 9c) ───────────── */
/* Texto que hace de etiqueta en un .filter-group sin campo (p. ej. "Filtrado por tu sucursal"); mismo aspecto que .filter-group label */
.filter-label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ── 25. Cifras alineadas a la derecha en tablas (Fase 9d) ───── */
.col-num { text-align: right; font-variant-numeric: tabular-nums; }
td.col-num { white-space: nowrap; }

/* ── 26. Sidebar.js y auth.js: estilos que antes iban en línea (Fase 9k-6) ───────────── */
.sidebar-header-acciones { display: flex; align-items: center; gap: 0.25rem; }
.nav-externo { font-size: var(--fs-xs); opacity: 0.55; margin-left: 2px; }
.sucursal-wrapper { margin-bottom: 0.75rem; }
.sucursal-caja { display: flex; align-items: center; gap: 0.5rem; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 8px; padding: 0.4rem 0.75rem; }
.sucursal-icono { font-size: 0.9rem; flex-shrink: 0; }
/* Especificidad alta a propósito: antes iba en línea y dark-mode.css (body.dark-mode select) no podía pisarlo */
.sidebar .sucursal-caja .sucursal-select { flex: 1; background: transparent; border: none; color: rgba(255, 255, 255, 0.85); font-size: 0.8rem; font-weight: 600; cursor: pointer; outline: none; min-width: 0; }
.acceso-denegado { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: var(--space-4); background: var(--bg); color: var(--text); }
.acceso-denegado-caja { text-align: center; padding: 48px; background: var(--surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-md); max-width: 400px; }
.acceso-denegado-icono { width: 64px; height: 64px; margin: 0 auto 16px; color: var(--danger-600); }
.acceso-denegado-titulo { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.acceso-denegado-texto { color: var(--text-muted); margin-bottom: 24px; }

/* ── 10h. Objetivos táctiles: 40 px con puntero fino, 44 px (--tap) en táctil ──
   Las reglas de página de .filter-btn, .badge-periodo, .input-cell, .qty-input y .approve-qty-input solo
   miran el ancho, no el puntero; por eso se repiten aquí con `button.`/`input.` delante para ganarles
   en especificidad. Con puntero fino solo desde 769 px: por debajo siguen mandando sus 44 px por ancho. */
@media (pointer: fine) {
    .repuesto-qty { min-height: 40px; }
    .checkbox-row label { min-height: 40px; }
}
@media (pointer: fine) and (max-width: 768px) {
    .btn-sm:where(:not(.btn-soft)) { min-height: 40px; min-width: 40px; }   /* especificidad de clase simple: no baja los 44 px que otras reglas ya dan por ancho */
}
@media (pointer: fine) and (min-width: 769px) {
    .btn-sm:not(.btn-soft), .btn-soft { min-height: 40px; min-width: 40px; }
    button.filter-btn, button.badge-periodo, input.input-cell, input.qty-input, input.approve-qty-input { min-height: 40px; }
}
@media (pointer: coarse) {
    button.filter-btn, button.badge-periodo, input.input-cell, input.qty-input, input.approve-qty-input, .repuesto-qty { min-height: var(--tap); }
    .btn-sm { min-width: var(--tap); }
    .checkbox-row label { min-height: var(--tap); }
}
/* Círculo de quitar foto: el aspecto no cambia; solo crece el área de toque con ::after.
   .thumb recorta (overflow: hidden), así que el área no sale por arriba ni por la derecha. */
.thumb-remove::after { content: ""; position: absolute; }
@media (pointer: fine)   { .thumb-remove::after { inset: -5px -5px -9px -9px; } }   /* caja de relleno 26 + 14 = 40 (el botón tiene borde de 1px) */
@media (pointer: coarse) { .thumb-remove::after { inset: -5px; } }                  /* caja de relleno 34 + 10 = 44 */
