/**
 * Sistema ERP - Diseño Moderno y Responsivo
 * Mobile-First Approach
 */

/* ==========================================
   IMPORTS
   ═══════════════════════════════════════════
   Design tokens → /assets/css/design-tokens.css
   ========================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* Responsive Typography */
@media (min-width: 1024px) {
    :root {
        --text-base: 1.125rem;
        --text-lg: 1.25rem;
        --text-xl: 1.5rem;
        --text-2xl: 1.875rem;
        --text-3xl: 2.25rem;
        --text-4xl: 3rem;
    }
}

/* ==========================================
   RESET & BASE
   ========================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--gray-800);
    background: var(--gray-50);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ==========================================
   INPUTS - DISEÑO UNIFICADO
   ========================================== */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]),
select,
textarea {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    line-height: 1.5;
    color: var(--gray-800);
    background: var(--surface-card);
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.85rem;
    width: 100%;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
    appearance: none;
    -webkit-appearance: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    padding-right: 2.2rem;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]):focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.10);
    background: var(--surface-card);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]):hover:not(:focus):not(:disabled),
select:hover:not(:focus):not(:disabled),
textarea:hover:not(:focus):not(:disabled) {
    border-color: var(--gray-400);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]):disabled,
select:disabled,
textarea:disabled {
    background: var(--gray-100);
    color: var(--gray-500);
    cursor: not-allowed;
    opacity: 0.75;
}

input::placeholder,
textarea::placeholder {
    color: var(--gray-400);
    font-weight: 400;
}

input::placeholder,
textarea::placeholder {
    color: var(--gray-400);
}

/* ==========================================
   LOGIN - DISEÑO MODERNO
   ========================================== */
.login-wrapper {
    position: fixed;
    inset: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: hsl(225deg 40% 92%);
}

.login-background { display: none; }

/* Login Container */
.login-container {
    position: relative;
    width: 100%;
    max-width: 420px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

/* Logo / Brand arriba del card */
.login-brand {
    text-align: center;
    width: 100%;
}

.brand-logo-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.brand-logo-wrap img {
    width: 64px;
    height: 64px;
    object-fit: contain;
    filter: drop-shadow(0 2px 8px rgba(30,58,95,.15));
}

.login-brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: hsl(233deg 45% 28%);
    letter-spacing: -0.3px;
    margin: 0;
}

.brand-subtitle {
    color: hsl(225deg 20% 55%);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 0;
}

/* Card principal — blanca, limpia */
.login-card {
    background: #ffffff;
    border-radius: 20px;
    padding: 2rem 2rem 1.75rem;
    box-shadow: 0 8px 40px rgba(90,110,180,.13), 0 1px 4px rgba(90,110,180,.08);
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    width: 100%;
}

@media (max-width: 480px) {
    .login-card { padding: 1.5rem; border-radius: 16px; }
}

/* Encabezado del card con avatar de usuario */
.card-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding-bottom: 0.2rem;
}

.card-header-icon {
    display: flex;
    width: 52px;
    height: 52px;
    margin: 0 auto 0.25rem;
    background: hsl(225deg 80% 95%);
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    color: hsl(233deg 45% 50%);
}

.card-header-icon svg { width: 26px; height: 26px; }

.card-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: hsl(233deg 45% 22%);
    margin: 0;
}

.card-header p {
    color: var(--gray-500);
    font-size: 0.82rem;
    margin: 0;
}

/* Input Groups */
.input-group {
    position: relative;
    margin-bottom: 0;
}

.input-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: hsl(233deg 30% 35%);
    margin-bottom: 6px;
    letter-spacing: 0.2px;
}

.input-shell {
    display: flex;
    align-items: center;
    background: #ffffff;
    border: 1.5px solid hsl(225deg 30% 88%);
    border-radius: 10px;
    transition: border-color .15s, box-shadow .15s;
    padding: 0.65rem 0.9rem;
    gap: 8px;
}

.input-shell:focus-within {
    border-color: hsl(233deg 45% 50%);
    box-shadow: 0 0 0 3px hsla(233deg, 45%, 50%, .12);
}

/* Anula el border/width global del CSS de inputs dentro del login */
.input-shell input,
.input-group input {
    flex: 1;
    width: 0 !important;
    min-width: 0;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    font-size: 0.88rem;
    color: var(--gray-800);
    outline: none;
}

.input-group input::placeholder { color: hsl(225deg 15% 65%); }

/* Input Icons */
.input-icon {
    flex: 0 0 auto;
    color: hsl(225deg 20% 65%);
    display: flex;
    align-items: center;
    transition: color .15s;
    pointer-events: none;
    line-height: 0;
}

.input-icon svg { width: 16px; height: 16px; }
.input-shell:focus-within .input-icon { color: hsl(233deg 45% 50%); }

/* Toggle Password */
.toggle-password {
    flex: 0 0 auto;
    background: none;
    border: none !important;
    width: auto !important;
    padding: 0 !important;
    cursor: pointer;
    color: hsl(225deg 20% 65%);
    display: flex;
    align-items: center;
    transition: color .15s;
    line-height: 0;
}

.toggle-password svg { width: 16px; height: 16px; }
.toggle-password:hover { color: hsl(233deg 45% 50%); }

/* Fila Recordarme + Olvidaste contraseña */
.login-remember-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
}

.login-remember-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--gray-600);
    cursor: pointer;
    font-weight: 500;
}

.login-remember-row input[type="checkbox"] {
    width: 15px !important;
    height: 15px !important;
    accent-color: hsl(233deg 45% 45%);
    border: none !important;
    border-radius: 3px !important;
    padding: 0 !important;
    background: none !important;
    box-shadow: none !important;
    flex: 0 0 auto;
}

.login-remember-row a {
    color: hsl(233deg 45% 50%);
    text-decoration: none;
    font-weight: 500;
}

.login-remember-row a:hover { text-decoration: underline; }

/* Divider acceso seguro */
.login-security {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.25rem;
}

.login-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    color: hsl(225deg 20% 70%);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.login-divider::before,
.login-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: hsl(225deg 30% 88%);
}

.login-security-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    color: hsl(225deg 20% 60%);
    font-size: 0.75rem;
}

.login-security-badge svg { width: 14px; height: 14px; }

/* ==========================================
   INPUT MODIFIERS
   ========================================== */

textarea.form-input {
    resize: vertical;
    min-height: 80px;
}

input[type="number"].form-input {
    text-align: right;
}

.form-input--sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
}

.form-input--error {
    border-color: var(--error);
}

.form-input--error:focus {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

/* Login Button */
.btn-login {
    width: 100%;
    padding: 0.85rem 1rem;
    background: hsl(233deg 45% 38%);
    color: #ffffff;
    border: none !important;
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, box-shadow .15s, transform .1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 0.3px;
}

.btn-login svg { width: 17px; height: 17px; }

.btn-login:hover {
    background: hsl(233deg 45% 30%);
    box-shadow: 0 6px 20px hsla(233deg, 45%, 38%, .32);
}

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

/* Error Message */
.form-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    margin-bottom: var(--space-4);
    border-left: 4px solid var(--error);
    animation: shake 0.4s;
}

.form-error.hidden {
    display: none;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-4px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(4px);
    }
}

/* Login Footer */
.login-footer {
    text-align: center;
    margin-top: 0;
    display: flex;
    justify-content: space-between;
}

.login-footer a {
    color: var(--gray-500);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 500;
    transition: color .15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.login-footer a svg { width: 12px; height: 12px; }

.login-footer a:hover {
    color: hsl(233deg 36% 38%);
    text-decoration: underline;
}

/* Login Footer link — oculto (movido al login-remember-row) */
.login-footer { display: none; }

/* Login Copyright */
.login-copyright {
    text-align: center;
    width: 100%;
}

.login-copyright p {
    color: hsl(225deg 20% 55%);
    font-size: var(--text-xs);
}

/* Loading State */
.btn-login.loading {
    pointer-events: none;
    opacity: 0.7;
}

.btn-login.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--text-inverse);
    animation: spin 0.6s linear infinite;
}

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

/* Icons — Bootstrap Icons */
.icon,
[class^="bi-"],
[class*=" bi-"] {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
    line-height: 1;
}

/* Botones con icono + texto */
.btn i.bi,
button i.bi {
    vertical-align: -0.125em;
    line-height: 1;
}

.icon-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Loading Screen */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    color: var(--gray-600);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ==========================================
   RESPONSIVE UTILITIES
   ========================================== */
@media (max-width: 640px) {
    .login-brand h1 {
        font-size: calc(var(--text-2xl) * 0.81);
    }

    .brand-icon {
        width: 44px;
        height: 44px;
        font-size: 2rem;
    }
}

/* Fade In Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ==========================================
   UTILITY CLASSES
   ========================================== */
.hidden {
    display: none !important;
}

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

.mt-4 {
    margin-top: var(--space-4);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

/* ==========================================
   DASHBOARD & APP LAYOUT
   ========================================== */

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
    background: var(--gray-50);
}

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--surface-card);
    border-bottom: 1px solid var(--gray-300);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 0 var(--space-4);
    z-index: var(--z-header);
    box-shadow: var(--shadow-sm);
}

/* Logo */
.app-logo {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--primary-600);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

.app-header-search {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 180px;
    padding: 0 var(--space-3);
}

.app-header-search .global-search {
    width: min(560px, 100%);
}

.app-logo-icon {
    display: none;
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: var(--text-2xl);
    cursor: pointer;
    padding: var(--space-2);
    color: var(--gray-700);
}

@media (max-width: 768px) {
    .menu-toggle {
        display: block;
    }
}

/* User Menu */
.user-menu {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-shrink: 0;
}

.user-info {
    text-align: right;
    display: none;
}

@media (min-width: 768px) {
    .user-info {
        display: block;
    }
}

@media (max-width: 920px) {
    .app-header-search {
        padding: 0;
    }
    .app-header-search .global-search {
        width: min(360px, 100%);
    }
    .app-header-search .gs-kbd {
        display: none;
    }
    .app-header-search .gs-input {
        padding-right: 12px !important;
    }
}

@media (max-width: 720px) {
    .app-header-search {
        display: none;
    }
}

.user-name {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--gray-900);
}

.user-role {
    font-size: var(--text-xs);
    color: var(--gray-500);
}

.btn-logout {
    padding: var(--space-2) var(--space-4);
    background: var(--primary-500);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
}

.btn-logout:hover {
    background: var(--primary-600);
}

/* Sidebar */
.app-sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    width: 260px;
    height: calc(100vh - 56px);
    background: var(--surface-card);
    border-right: 1px solid var(--gray-300);
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 350ms cubic-bezier(0.4, 0, 0.2, 1), transform var(--transition-base);
    z-index: var(--z-sidebar);
}

/* Mobile Sidebar */
@media (max-width: 768px) {
    .app-sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .app-sidebar.active {
        transform: translateX(0);
    }

    /* Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        top: 56px;
        background: rgba(0, 0, 0, 0.5);
        z-index: calc(var(--z-sidebar) - 1);
    }

    .sidebar-overlay.active {
        display: block;
    }
}

/* Navigation */
.nav-menu {
    padding: var(--space-4);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    color: var(--gray-700);
    text-decoration: none;
    font-size: var(--text-base);
    font-weight: 500;
    transition: all var(--transition-fast);
    margin-bottom: var(--space-1);
    cursor: pointer;
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--primary-600);
}

.nav-item.active {
    background: var(--primary-700); /* azul marino de marca */
    color: var(--text-inverse);
}

/* Icono de ítem de navegación */
.nav-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    line-height: 1;
    width: 20px;
    text-align: center;
}

/* Label de navegación: animación fade+slide al colapsar/expandir */
.nav-label {
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    opacity: 1;
    max-width: 200px;
    transform: translateX(0);
    transition:
        opacity 250ms ease,
        max-width 350ms cubic-bezier(0.4, 0, 0.2, 1),
        transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Nav Groups (submenús colapsables) ── */
.nav-group {
    margin-bottom: 2px;
}

/* Cabecera del grupo */
.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: none;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    color: var(--gray-400);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    transition: color 150ms ease, background 150ms ease;
    margin-top: var(--space-2);
}

.nav-group-header:hover {
    color: var(--gray-200);
    background: rgba(255,255,255,0.05);
}

.nav-group-left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Flecha del grupo */
.nav-chevron {
    font-size: 0.7rem;
    transition: transform 250ms ease;
    flex-shrink: 0;
}

.nav-group.open .nav-chevron {
    transform: rotate(0deg);
}

.nav-group:not(.open) .nav-chevron {
    transform: rotate(-90deg);
}

/* Contenedor de ítems del grupo */
.nav-group-items {
    overflow: hidden;
    max-height: 600px;
    transition: max-height 300ms ease, opacity 250ms ease;
    opacity: 1;
}

.nav-group:not(.open) .nav-group-items {
    max-height: 0;
    opacity: 0;
}

/* Sub-ítems: ligeramente indentados */
.nav-item.nav-sub {
    padding-left: calc(var(--space-3) + 10px);
    font-size: 0.9rem;
    font-weight: 500;
}

.nav-item.nav-sub .nav-icon {
    font-size: 0.95rem;
    width: 18px;
}

/* Sidebar colapsado (solo iconos) */
.app-sidebar.collapsed {
    width: 60px;
    overflow: visible;
}

.app-sidebar.collapsed .nav-label,
.app-sidebar.collapsed .nav-chevron {
    opacity: 0;
    max-width: 0;
    transform: translateX(-8px);
    pointer-events: none;
}

.app-sidebar.collapsed .nav-item {
    justify-content: center;
    padding: var(--space-3) 0;
    font-size: 1.3rem;
    gap: 0;
    position: relative;
}

.app-sidebar.collapsed .nav-item:hover::after {
    content: attr(data-module);
    position: absolute;
    left: 64px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--gray-800);
    color: var(--text-inverse);
    padding: 4px 10px;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    white-space: nowrap;
    z-index: 9999;
    pointer-events: none;
    text-transform: capitalize;
}

.app-sidebar.collapsed .badge {
    position: absolute;
    top: 4px;
    right: 4px;
    margin-left: 0;
}

.app-sidebar.collapsed .nav-group-header {
    justify-content: center;
    padding: var(--space-2) 0;
    gap: 0;
    overflow: hidden;
}

.app-sidebar.collapsed .nav-group-items {
    max-height: 0 !important;
    opacity: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
}

.app-main.sidebar-collapsed {
    margin-left: 60px;
}

@media (max-width: 768px) {
    .app-sidebar.collapsed {
        width: 260px;
    }
    .app-main.sidebar-collapsed {
        margin-left: 0;
    }
}

/* Main Content */
.app-main {
    flex: 1;
    margin-top: 56px;
    padding: var(--space-6);
    margin-left: 260px;
    transition: margin-left 350ms cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

#mainContent {
    overflow-x: hidden;
}

#mainContent.admin-mode {
    background: var(--surface-card);
    min-height: 100vh;
}

/* App Footer */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    height: var(--footer-height);
    margin-top: var(--space-6);
    border-top: 1px solid var(--footer-border);
    color: var(--footer-text);
    font-size: var(--text-xs);
    background: var(--footer-bg);
}

.app-footer__links {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.app-footer a {
    color: var(--footer-link);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    transition: color var(--transition-fast);
}

.app-footer a:hover {
    color: var(--footer-link-hover);
}

.app-footer svg {
    width: 14px;
    height: 14px;
}

@media (max-width: 768px) {
    .app-main {
        margin-left: 0;
        padding: var(--space-4);
    }
}

/* Page Header */
.page-header {
    margin-bottom: var(--space-6);
}

.page-title {
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: var(--space-2);
}

@media (max-width: 640px) {
    .page-title {
        font-size: var(--text-2xl);
    }
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-6);
    margin-bottom: var(--space-8);
}

@media (max-width: 640px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }
}

/* Stat Card */
.stat-card {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    border-left: 4px solid var(--primary-500);
    transition: all var(--transition-base);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-card-label {
    font-size: var(--text-sm);
    color: var(--gray-600);
    margin-bottom: var(--space-2);
    font-weight: 500;
}

.stat-card-value {
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--gray-900);
}

@media (max-width: 640px) {
    .stat-card-value {
        font-size: var(--text-2xl);
    }
}

/* Card */
.card {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
}

@media (max-width: 640px) {
    .card {
        padding: var(--space-4);
    }
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
    gap: var(--space-4);
}

.card-title {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--gray-900);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all var(--transition-base);
    white-space: nowrap;
}

/* Botón primario — acción principal */
.btn-primary,
.btn-success,
.btn-info,
.btn-outline-primary,
.btn-outline-success,
.btn-outline-info {
    background: var(--primary-500);
    color: var(--text-inverse);
    border: 1px solid var(--primary-500);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover,
.btn-success:hover,
.btn-info:hover,
.btn-outline-primary:hover,
.btn-outline-success:hover,
.btn-outline-info:hover {
    background: var(--primary-600);
    border-color: var(--primary-600);
    color: var(--text-inverse);
    box-shadow: var(--shadow-md);
}

/* Botón secundario — acción complementaria */
.btn-secondary,
.btn-warning,
.btn-outline-secondary,
.btn-outline-warning {
    background: var(--surface-card);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    box-shadow: none;
}

.btn-secondary:hover,
.btn-warning:hover,
.btn-outline-secondary:hover,
.btn-outline-warning:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
    color: var(--gray-900);
    box-shadow: var(--shadow-sm);
}

/* Botón destructivo */
.btn-danger,
.btn-outline-danger {
    background: var(--error);
    color: var(--text-inverse);
    border: 1px solid var(--error);
    box-shadow: var(--shadow-sm);
}

.btn-danger:hover,
.btn-outline-danger:hover {
    background: var(--primary-700);
    border-color: var(--primary-700);
    color: var(--text-inverse);
    box-shadow: var(--shadow-md);
}

/* Formal Action Buttons */
.action-buttons-formal {
    gap: var(--space-1);
}

.action-buttons-formal .btn-sm {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: var(--radius-md);
    letter-spacing: 0.3px;
    text-transform: capitalize;
    box-shadow: none;
    transition: all 0.2s ease;
}

.action-buttons-formal .btn-sm:hover {
    box-shadow: var(--shadow-sm);
}

.action-buttons-formal .btn-text {
    font-weight: 500;
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
}

.action-buttons {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    min-width: 200px;
}

.action-buttons .btn-sm {
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
}

/* Badges — fondo tenue, texto legible, borde sutil */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    line-height: 1.4;
}

.badge-success {
    background: var(--blue-100);
    color: #1e3a8a;
    border: 1px solid var(--blue-200);
}

.badge-warning {
    background: var(--blue-50);
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.badge-danger {
    background: #bfdbfe;
    color: #1e3a8a;
    border: 1px solid #60a5fa;
}

.badge-info {
    background: var(--blue-50);
    color: var(--primary-700);
    border: 1px solid #bfdbfe;
}

.badge-secondary,
.badge-gray {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.badge-primary {
    background: var(--blue-100);
    color: #1e3a8a;
    border: 1px solid var(--blue-200);
}

/* Sidebar badge counters */
.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin-left: auto;
    border-radius: var(--radius-md);
    background: var(--primary-500);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1;
}

/* Mobile: Full width buttons */
@media (max-width: 640px) {
    .btn {
        width: 100%;
        padding: var(--space-4);
    }
}

/* Mobile Table adjustments */
@media (max-width: 768px) {
    .table-container table {
        min-width: 700px;
    }
    
    .action-buttons .btn-sm {
        padding: var(--space-1);
        font-size: 11px;
    }
    
    .action-buttons-formal .btn-sm {
        padding: 4px 8px;
        font-size: 11px;
    }
}

/* Additional button styles for compact view */
.action-buttons .btn-sm {
    min-width: auto;
    white-space: nowrap;
}

.action-buttons-formal {
    min-width: auto;
}

/* Ensure table doesn't overflow its container */
#app .table-container {
    max-width: 100%;
    overflow-x: auto;
}

/* Table */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    width: 100%;
}

.table-container table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface-card);
    min-width: 900px;
}

th {
    padding: var(--space-4);
    text-align: left;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}

td {
    padding: var(--space-4);
    border-bottom: 1px solid var(--gray-200);
    font-size: var(--text-sm);
    white-space: nowrap;
}

/* Table column widths */
table th:nth-child(1), table td:nth-child(1) { width: 120px; }
table th:nth-child(2), table td:nth-child(2) { width: auto; min-width: 150px; }
table th:nth-child(3), table td:nth-child(3) { width: 100px; }
table th:nth-child(4), table td:nth-child(4) { width: 100px; }
table th:nth-child(5), table td:nth-child(5) { width: 110px; }
table th:nth-child(6), table td:nth-child(6) { width: 90px; }
table th:nth-child(7), table td:nth-child(7) { width: auto; min-width: 250px; }

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

thead {
    background: var(--surface-bg);
}

th {
    padding: 10px var(--space-4);
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

td {
    padding: 12px var(--space-4);
    border-bottom: 1px solid var(--table-border);
    font-size: var(--text-sm);
    color: var(--gray-800);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--surface-bg);
}

/* Mobile Table */
@media (max-width: 768px) {

    th,
    td {
        padding: var(--space-3);
        font-size: var(--text-xs);
    }
}

/* Forms */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-input,
.form-select {
    width: 100%;
}

/* Hint / ayuda bajo un input */
.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 3px;
}

.form-input--error,
.form-input--error:focus {
    border-color: var(--error) !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.10) !important;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-4);
    animation: fadeIn 0.15s;
}

/* Quotation Items Grid */
.item-row-grid {
    display: grid;
    grid-template-columns: minmax(200px, 3fr) minmax(70px, 80px) minmax(90px, 110px) minmax(100px, 120px) minmax(80px, 100px) 40px;
    gap: var(--space-3);
    align-items: center;
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: var(--space-3);
    margin-bottom: var(--space-3);
}

@media (max-width: 640px) {
    .item-row-grid {
        grid-template-columns: 1fr 1fr 40px;
        gap: var(--space-2);
    }

    /* Description spans full width on mobile */
    .item-row-grid>.form-group:first-child {
        grid-column: 1 / -1;
    }
}

.modal {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: fadeIn 0.15s ease-out;
}

@media (max-width: 640px) {
    .modal {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}

.modal-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--gray-50);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.modal-title {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.01em;
}

.modal-close {
    background: var(--white);
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-md);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    color: var(--gray-700);
    transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
    line-height: 1;
    padding: 0;
}

.modal-close:hover {
    color: var(--gray-900);
    border-color: var(--gray-500);
    background: var(--gray-100);
}

.modal-close:focus-visible {
    outline: 2px solid var(--accent-500);
    outline-offset: 2px;
}

.modal-close i {
    display: block;
    color: currentColor;
    pointer-events: none;
}

.modal-body {
    padding: var(--space-6);
}

.quote-view-modal {
    max-width: 840px;
    overflow: hidden;
}

.quote-view-modal .modal-header {
    align-items: flex-start;
}

.quote-modal-subtitle {
    margin: var(--space-1) 0 0;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 400;
}

.quote-view-body {
    max-height: calc(90vh - 148px);
    overflow-y: auto;
}

.quote-summary-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(120px, 1fr) minmax(120px, 1fr);
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.quote-summary-grid > div {
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    background: var(--surface-card);
    min-width: 0;
}

.quote-summary-label {
    display: block;
    margin-bottom: var(--space-1);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.quote-summary-grid strong,
.quote-status {
    display: block;
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-weight: 600;
    overflow-wrap: anywhere;
}

.quote-status {
    text-transform: capitalize;
}

.quote-portal-status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}

.quote-portal-status .badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.quote-portal-date {
    color: var(--text-secondary);
    font-size: var(--text-xs);
}

.quote-section-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--surface-border);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.quote-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
}

.quote-detail-table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
    table-layout: fixed;
}

.quote-detail-table th,
.quote-detail-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--table-border);
    vertical-align: top;
}

.quote-detail-table th {
    background: var(--table-header-bg);
    color: var(--table-header-text);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.quote-detail-table tbody tr:last-child td {
    border-bottom: 0;
}

.quote-detail-description {
    width: 38%;
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.45;
    overflow-wrap: anywhere;
    white-space: normal;
}

.quote-detail-muted {
    width: 16%;
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.quote-detail-number {
    width: 10%;
    text-align: right;
}

.quote-detail-price {
    width: 18%;
    text-align: right;
}

.quote-detail-total {
    width: 18%;
    color: var(--text-primary);
    font-weight: 600;
    text-align: right;
}

.quote-price-before {
    display: block;
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 400;
    text-decoration: line-through;
}

.quote-empty-row {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    text-align: center;
}

.quote-totals-card {
    width: min(100%, 360px);
    margin: var(--space-5) 0 0 auto;
}

.quote-total-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.quote-total-row strong {
    color: var(--text-primary);
    font-weight: 600;
    white-space: nowrap;
}

.quote-total-discount,
.quote-total-discount strong {
    color: var(--error);
}

.quote-total-final {
    margin-top: var(--space-2);
    padding-top: var(--space-3);
    border-top: 2px solid var(--surface-border-strong);
    color: var(--text-primary);
    font-size: var(--text-lg);
    font-weight: 700;
}

.quote-total-final strong {
    font-size: var(--text-xl);
    font-weight: 700;
}

.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    background: var(--gray-50);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.quote-view-footer {
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.quote-footer-secondary {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.quote-view-footer .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 38px;
    white-space: nowrap;
}

.quote-whatsapp-btn {
    background: var(--success);
    border-color: var(--success);
}

.quote-whatsapp-btn:hover {
    background: var(--success);
    border-color: var(--success);
}

@media (max-width: 640px) {
    .modal-footer {
        flex-direction: column-reverse;
    }

    .quote-view-modal {
        max-height: 100vh;
    }

    .quote-view-body {
        max-height: calc(100vh - 180px);
    }

    .quote-summary-grid {
        grid-template-columns: 1fr;
    }

    .quote-totals-card {
        width: 100%;
    }

    .quote-view-footer,
    .quote-footer-secondary {
        align-items: stretch;
        width: 100%;
    }

    .quote-footer-secondary {
        flex-direction: column-reverse;
    }

    .quote-view-footer .btn {
        width: 100%;
    }
}

/* ==========================================
   ITEM MODAL — Premium SaaS Redesign
   ========================================== */

/* Backdrop con blur */
.item-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-4);
    animation: fadeIn 0.15s ease;
}

/* Contenedor principal del modal */
.item-modal {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: min(92vw, 940px);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeIn 0.15s ease;
}

/* Header del modal */
.item-modal__header {
    padding: 20px 28px 18px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--surface-card);
}

.item-modal__title-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.item-modal__title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.02em;
    margin: 0;
}

.item-modal__badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 3px 10px;
    border-radius: var(--radius-md);
    background: var(--primary-50);
    color: var(--primary-500);
    border: 1px solid var(--primary-100);
    transition: all 0.2s;
}

.item-modal__badge.badge-servicio {
    background: var(--gray-100);
    color: var(--gray-800);
    border-color: var(--gray-300);
}

.item-modal__close {
    background: none;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--gray-400);
    font-size: 1.1rem;
    transition: all 0.15s;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
}

.item-modal__close:hover {
    background: var(--gray-100);
    color: var(--gray-700);
    border-color: var(--gray-300);
}

/* Body scrollable */
.item-modal__body {
    overflow-y: auto;
    padding: 24px 28px 8px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Secciones */
.im-section {
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 12px;
    transition: box-shadow 0.2s;
}

.im-section:focus-within {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.07);
    border-color: var(--gray-200);
}

.im-section__head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--gray-500);
    user-select: none;
}

.im-section__head svg,
.im-section__head i {
    font-size: 0.85rem;
    color: var(--gray-400);
}

.im-section__body {
    padding: 16px;
    background: var(--surface-card);
}

/* Grid de campos */
.im-grid {
    display: grid;
    gap: 12px 14px;
}

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

.im-col-span-2 { grid-column: span 2; }
.im-col-span-3 { grid-column: span 3; }
.im-col-span-4 { grid-column: span 4; }

@media (max-width: 720px) {
    .im-grid--3,
    .im-grid--4 { grid-template-columns: repeat(2, 1fr); }
    .im-col-span-2,
    .im-col-span-3,
    .im-col-span-4 { grid-column: span 2; }
}

@media (max-width: 480px) {
    .im-grid--3,
    .im-grid--4,
    .im-grid--2 { grid-template-columns: 1fr; }
    .im-col-span-2,
    .im-col-span-3,
    .im-col-span-4 { grid-column: span 1; }
    .item-modal { border-radius: 0; width: 100vw; max-height: 100dvh; }
    .item-modal-overlay { padding: 0; }
}

/* Labels e inputs */
.im-label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.73rem;
    font-weight: 600;
    color: var(--gray-600);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.im-label .im-required {
    color: var(--error);
    margin-left: 2px;
}

.im-label .im-hint-inline {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--gray-400);
    text-transform: none;
    letter-spacing: 0;
    margin-left: 5px;
}

.im-input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--gray-800);
    background: var(--surface-card);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.im-input:hover { border-color: var(--gray-300); }
.im-input:focus {
    border-color: var(--accent-500);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.10);
}

.im-input[readonly] {
    background: var(--gray-50);
    color: var(--gray-500);
    cursor: not-allowed;
}

textarea.im-input {
    height: auto;
    padding: 10px 12px;
    resize: vertical;
    min-height: 70px;
}

select.im-input {
    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 fill='%239CA3AF' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}

/* Input con prefijo */
.im-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.im-input-prefix {
    position: absolute;
    left: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-400);
    pointer-events: none;
    white-space: nowrap;
}

.im-input-wrap .im-input { padding-left: 46px !important; }
.im-input-wrap .im-input-prefix + .im-input--short { padding-left: 28px !important; }

.im-input--prefix-pct { padding-left: 28px !important; }
.im-pct-prefix { left: 11px; font-size: 0.78rem; }

/* Input hint */
.im-field-hint {
    display: block;
    font-size: 0.72rem;
    color: var(--gray-400);
    margin-top: 4px;
    line-height: 1.3;
}

/* Fila impuesto con botón + */
.im-tax-row {
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

.im-tax-row select.im-input { flex: 1; }

.im-btn-add-tax {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--gray-50);
    color: var(--gray-500);
    font-size: 1.15rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    line-height: 1;
}

.im-btn-add-tax:hover {
    background: var(--accent-500);
    color: var(--text-inverse);
    border-color: var(--accent-500);
}

/* Quick tax form */
.im-quick-tax {
    margin-top: 8px;
    padding: 12px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    display: none;
    flex-direction: column;
    gap: 8px;
}

.im-quick-tax.open { display: flex; }

.im-quick-tax__title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.im-quick-tax__actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

/* Toggle moderno */
.im-toggle-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    height: 42px;
    padding: 0 12px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-lg);
    background: var(--surface-card);
    cursor: pointer;
    transition: border-color 0.15s;
    user-select: none;
}

.im-toggle-group:hover { border-color: var(--gray-300); }

.im-toggle-group__label {
    font-size: 0.85rem;
    color: var(--gray-700);
    font-weight: 500;
}

.im-toggle-group__badge {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--gray-400);
    transition: color 0.2s;
}

.im-toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.im-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.im-toggle__slider {
    position: absolute;
    inset: 0;
    background: var(--gray-200);
    border-radius: var(--radius-lg);
    transition: background 0.2s;
    cursor: pointer;
}

.im-toggle__slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: var(--surface-card);
    border-radius: 50%;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: var(--shadow-sm);
}

.im-toggle input:checked + .im-toggle__slider { background: var(--success); }
.im-toggle input:checked + .im-toggle__slider::before { transform: translateX(18px); }
.im-toggle input:focus + .im-toggle__slider { box-shadow: 0 0 0 3px rgba(22,163,74,0.15); }

/* Estado toggle — color dinámico en badge */
.im-toggle-group:has(input:checked) .im-toggle-group__badge { color: var(--success); }
.im-toggle-group:has(input:checked) { border-color: #bbf7d0; background: #f0fdf4; }

/* Tipo de ítem — segmented control */
.im-type-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.im-type-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--surface-card);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    text-align: left;
    width: 100%;
}

.im-type-btn:hover { border-color: var(--gray-300); background: var(--gray-50); }

.im-type-btn.active {
    border-color: var(--accent-500);
    background: var(--blue-50);
    color: var(--accent-600);
}

.im-type-btn__icon {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-input);
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
    transition: background 0.15s;
}

.im-type-btn.active .im-type-btn__icon {
    background: rgba(37,99,235,0.12);
    color: var(--accent-500);
}

.im-type-btn__text strong {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-800);
    line-height: 1.2;
}

.im-type-btn.active .im-type-btn__text strong { color: var(--accent-600); }

.im-type-btn__text span {
    font-size: 0.72rem;
    color: var(--gray-400);
}

/* Footer sticky */
.item-modal__footer {
    padding: 14px 28px;
    border-top: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    background: var(--gray-50);
    flex-shrink: 0;
}

.item-modal__footer .im-btn-cancel {
    height: 40px;
    padding: 0 18px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--surface-card);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.item-modal__footer .im-btn-cancel:hover {
    background: var(--gray-100);
    color: var(--gray-800);
    border-color: var(--gray-300);
}

.item-modal__footer .im-btn-save {
    height: 40px;
    padding: 0 22px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary-500);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-inverse);
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 7px;
    font-family: inherit;
    box-shadow: var(--shadow-sm);
}

.item-modal__footer .im-btn-save:hover {
    background: var(--primary-600);
    box-shadow: 0 4px 12px rgba(30, 58, 95, 0.3);
}

.item-modal__footer .im-btn-save:active {
    box-shadow: none;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 80px;
    right: var(--space-4);
    z-index: calc(var(--z-modal) + 1);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

@media (max-width: 640px) {
    .toast-container {
        left: var(--space-4);
        right: var(--space-4);
    }
}

.toast {
    background: var(--surface-card);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 300px;
    animation: fadeIn 0.2s ease-out;
}

@media (max-width: 640px) {
    .toast {
        min-width: unset;
        width: 100%;
    }
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-error {
    border-left: 4px solid var(--error);
}

.toast-warning {
    border-left: 4px solid var(--warning);
}

.toast-info {
    border-left: 4px solid var(--info);
}

/* Responsive Helpers */
.hide-mobile {
    display: block;
}

.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none;
    }

    .show-mobile {
        display: block;
    }
}

/* Loading */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: calc(var(--z-modal) + 2);
}

/* Search Results Navigation */
.search-result-item {
    transition: background-color 0.2s;
}

.search-result-item.active {
    background-color: var(--primary-50) !important;
    border-left: 3px solid var(--primary-500);
}

/* Searchable Select Styles */
.search-container {
    position: relative;
    width: 100%;
}

.search-input {
    width: 100%;
    position: relative;
    z-index: 10;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-card);
    border: 1px solid var(--gray-300);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: var(--shadow-sm);
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.search-results.show {
    display: block;
}

.search-item {
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--gray-100);
}

.search-item:last-child {
    border-bottom: none;
}

.search-item:hover {
    background-color: var(--primary-50);
    color: var(--primary-700);
}

.search-item.selected {
    background-color: var(--primary-100);
    color: var(--primary-800);
    font-weight: 500;
}

/* Table Row Interactivity */
tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.05);
    /* Light gray for hover */
}

.app-logo-img {
    max-height: 48px;
    width: auto;
}

/* Client Search Module Styles */
.client-search-wrapper {
    position: relative;
    width: 100%;
}

.client-search-input:disabled {
    background-color: var(--gray-100);
    cursor: not-allowed;
    opacity: 0.7;
}

.client-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-card);
    border: 1px solid var(--gray-300);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: var(--shadow-md);
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.client-search-results.show {
    display: block;
}

.client-search-item {
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--gray-100);
}

.client-search-item:last-child {
    border-bottom: none;
}

.client-search-item:hover {
    background-color: var(--primary-50);
}

.client-search-item.selected {
    background-color: var(--primary-100);
    border-left: 3px solid var(--primary-500);
}

/* Service Search Module Styles */
.service-search-wrapper {
    position: relative;
    width: 100%;
}

.service-search-input:disabled {
    background-color: var(--gray-100);
    cursor: not-allowed;
    opacity: 0.7;
}

.service-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-card);
    border: 1px solid var(--gray-300);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: var(--shadow-md);
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.service-search-results.show {
    display: block;
}

.service-search-item {
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--gray-100);
}

.service-search-item:last-child {
    border-bottom: none;
}

.service-search-item:hover {
    background-color: var(--primary-50);
}

.service-search-item.selected {
    background-color: var(--primary-100);
    border-left: 3px solid var(--primary-500);
}

/* Proveedor Search Module Styles */
.proveedor-search-wrapper {
    position: relative;
    width: 100%;
}

.proveedor-search-input:disabled {
    background-color: var(--gray-100);
    cursor: not-allowed;
    opacity: 0.7;
}

.proveedor-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-card);
    border: 1px solid var(--gray-300);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: var(--shadow-md);
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.proveedor-search-results.show {
    display: block;
}

.proveedor-search-item {
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--gray-100);
}

.proveedor-search-item:last-child {
    border-bottom: none;
}

.proveedor-search-item:hover {
    background-color: var(--primary-50);
}

.proveedor-search-item.selected {
    background-color: var(--primary-100);
    border-left: 3px solid var(--primary-500);
}
/* ── Botones de filtro tipo pill ── */
.btn-filter-group {
    display: inline-flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-filter {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-300);
    background: var(--surface-card);
    color: var(--gray-600);
    cursor: pointer;
    transition: all 150ms ease;
    white-space: nowrap;
    line-height: 1.4;
}

.btn-filter:hover {
    border-color: var(--gray-400);
    color: var(--gray-800);
    background: var(--gray-50);
}

.btn-filter.active {
    background: var(--primary-500);
    color: var(--text-inverse);
    border-color: var(--primary-500);
}

/* ================================================================
   TABS DE ESTADO (Cotizaciones y reutilizable)
   ================================================================ */
.cot-tabs {
    display: flex;
    gap: 0;
    border: 1px solid var(--surface-border);
    border-bottom: none;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    background: var(--surface-bg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.cot-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    background: none;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
    width: auto;
}

.cot-tab:hover {
    color: var(--gray-800);
    background: var(--gray-100);
}

.cot-tab--active {
    color: var(--primary-500);
    border-bottom-color: var(--primary-500);
    background: var(--surface-card);
    font-weight: 600;
}

.cot-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 5px;
    background: var(--gray-200);
    color: var(--gray-600);
    border-radius: var(--radius-md);
    font-size: 0.72rem;
    font-weight: 700;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.cot-tab--active .cot-tab-count {
    background: var(--primary-500);
    color: var(--text-inverse);
}

/* ── Cotizaciones — botones de acción de fila (themeable claro/oscuro) ─────── */
.cot-act {
    padding: 5px 12px;
    border: 1px solid var(--surface-border);
    border-radius: 6px;
    background: var(--surface-card);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.cot-act:hover {
    background: var(--surface-hover);
    border-color: var(--surface-border-strong);
    color: var(--text-primary);
}
.cot-act--primary {
    color: var(--text-primary);
    border-color: var(--surface-border-strong);
}
.cot-act--accent {
    color: var(--text-link);
    border-color: var(--text-link);
    background: transparent;
}
.cot-act--accent:hover {
    background: var(--surface-hover);
    color: var(--text-link);
}

/* ── Modal Cliente — Tabs ────────────────────────────────────────────────── */
.mc-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 24px;
    background: var(--surface-card);
}

.mc-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 11px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--gray-500);
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    cursor: pointer;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.mc-tab:hover { color: var(--gray-700); }

.mc-tab.active {
    color: var(--primary-500);
    border-bottom-color: var(--primary-500);
}

.mc-tab svg { flex-shrink: 0; }

.mc-body {
    overflow-y: auto;
    max-height: 68vh;
    padding: 24px;
}

.mc-panel { display: none; }
.mc-panel.active { display: block; }

/* Sección header dentro del modal cliente */
.mc-section {
    margin-bottom: 24px;
}

.mc-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--gray-400);
    margin: 0 0 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-100);
}

/* Grid de campos */
.mc-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mc-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.mc-field { display: flex; flex-direction: column; gap: 5px; }
.mc-field label {
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.mc-field label .req { color: var(--error); margin-left: 2px; }

/* Bloque DGII readonly */
.mc-dgii-block {
    background: var(--gray-50);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
}
.mc-dgii-block .mc-section-title { color: var(--gray-400); }

/* Portal panel */
.mc-portal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

.mc-stat-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
}
.mc-stat-card .mc-stat-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--gray-400);
    margin-bottom: 6px;
}
.mc-stat-card .mc-stat-value {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--gray-700);
}
.mc-stat-card .mc-stat-sub {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 3px;
}

.mc-pass-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}
.mc-pass-row input { flex: 1; font-family: monospace; font-size: 0.82rem; }

@media (max-width: 640px) {
    .mc-grid-2, .mc-grid-3, .mc-portal-grid { grid-template-columns: 1fr; }
}

@keyframes padronAnim {
    from { transform: translateX(-60%); }
    to   { transform: translateX(160%); }
}

/* Grupos list cards — responsivo en móvil */
@media (max-width: 600px) {
    /* Colapsar la fila de grupo a layout vertical */
    #gruposList > div > div:not(:first-child) {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    #gruposList > div > div:not(:first-child) > div:nth-child(2),
    #gruposList > div > div:not(:first-child) > div:nth-child(3) {
        min-width: unset !important;
        text-align: left !important;
        display: flex;
        gap: 8px;
    }
    #gruposList > div > div:not(:first-child) > div:last-child {
        min-width: unset !important;
        justify-content: flex-start !important;
    }
    /* Ocultar header row en móvil */
    #gruposList > div > div:first-child {
        display: none !important;
    }
}

/* Global Search */
.global-search {
    position: relative;
    margin-bottom: 0;
}
.gs-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: .9rem;
    pointer-events: none;
}
.gs-input {
    padding-left: 36px !important;
    padding-right: 72px !important;
    border-radius: 8px !important;
    background: var(--surface-card) !important;
    border: 1px solid var(--surface-border) !important;
    color: var(--text-primary) !important;
    width: 100%;
}
.gs-input::placeholder { color: var(--gray-400); }
.gs-kbd {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    background: var(--surface-border);
    color: var(--gray-500);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--surface-border-strong);
    pointer-events: none;
}
.gs-results {
    position: absolute;
    left: 0; right: 0;
    top: 100%;
    margin-top: 4px;
    background: var(--surface-card);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 9999;
    box-shadow: 0 10px 25px rgba(0,0,0,.15);
}
.gs-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--surface-border);
    transition: background .15s;
}
.gs-item:hover, .gs-item.selected { background: var(--surface-hover); }
.gs-item:last-child { border-bottom: none; }
.gs-item-body { flex: 1; min-width: 0; }
.gs-item-label {
    color: var(--text-primary);
    font-size: .85rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gs-item-sub { color: var(--gray-500); font-size: .75rem; }
.gs-item-badge {
    font-size: .65rem;
    color: var(--gray-500);
    text-transform: uppercase;
    background: var(--surface-border);
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}
.gs-empty { padding: 1rem; color: var(--gray-500); text-align: center; }
.app-sidebar.gs-open { overflow: visible; }

/* ── Multi-empresa: selector al login ─────────────────────────────── */
.empresa-selector-overlay {
    position: fixed; inset: 0; z-index: 10000;
    background: rgba(15,23,42,.55); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity .2s;
}
.empresa-selector-overlay.visible { opacity: 1; }
.empresa-selector-modal {
    background: var(--surface); border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    width: 100%; max-width: 440px; overflow: hidden;
    transform: translateY(8px);
    transition: transform .2s;
}
.empresa-selector-overlay.visible .empresa-selector-modal { transform: none; }
.empresa-selector-header {
    display: flex; align-items: flex-start; gap: 14px;
    padding: 1.5rem 1.5rem 1rem; border-bottom: 1px solid var(--surface-border);
    background: linear-gradient(135deg, var(--blue-100) 0%, var(--blue-50) 100%);
}
.empresa-selector-header svg { flex-shrink: 0; color: var(--primary); margin-top: 2px; }
.empresa-selector-header h2 { margin: 0 0 3px; font-size: 1.1rem; }
.empresa-selector-header p { margin: 0; font-size: .85rem; color: var(--gray-500); }
.empresa-selector-list { padding: .75rem; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; background: #f8fafc; }
.empresa-selector-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px;
    background: #ffffff; border: 1px solid var(--surface-border);
    cursor: pointer; text-align: left; width: 100%;
    transition: background .15s, border-color .15s;
}
.empresa-selector-item:hover:not(:disabled) { background: var(--gray-50); border-color: var(--primary); }
.empresa-selector-item:disabled { opacity: .5; }
.empresa-selector-item.loading { opacity: .7; }
.empresa-logo-thumb {
    width: 38px; height: 38px; border-radius: 8px;
    background: var(--gray-100); display: flex; align-items: center;
    justify-content: center; overflow: hidden; flex-shrink: 0;
}
.empresa-logo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.empresa-logo-thumb span { font-size: 1.1rem; font-weight: 700; color: var(--gray-600); }
.empresa-item-info { flex: 1; min-width: 0; }
.empresa-item-nombre { font-weight: 600; font-size: .9rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empresa-item-rol { font-size: .75rem; color: var(--gray-500); }

/* ── Multi-empresa: badge/switcher en header ──────────────────────── */
/* Pill sin dropdown (1 sola empresa) */
.empresa-switcher-pill {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface-card); border: 1.5px solid var(--surface-border);
    border-radius: 8px; padding: 5px 14px 5px 6px;
    font-size: .82rem; color: var(--gray-700);
}

/* Avatar circular con iniciales */
.esw-pill-avatar {
    width: 30px; height: 30px; border-radius: 6px;
    background: var(--blue-100); color: var(--primary-500);
    font-size: .72rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; letter-spacing: .5px;
}

.esw-pill-nombre {
    max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-weight: 500;
}

.empresa-badge {
    font-size: .78rem; color: var(--gray-500); background: var(--gray-100);
    border-radius: 6px; padding: 4px 10px; max-width: 160px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.empresa-switcher { position: relative; }
.empresa-switcher-btn {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface-card); border: 1.5px solid var(--surface-border);
    border-radius: 8px; padding: 5px 14px 5px 6px; cursor: pointer;
    font-size: .82rem; color: var(--gray-700); font-weight: 500;
    transition: border-color .15s, box-shadow .15s;
}
.empresa-switcher-btn:hover {
    border-color: var(--blue-200);
    box-shadow: 0 0 0 3px rgba(59,130,246,.10);
}
.empresa-switcher-btn:focus-visible {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,.18);
}
.empresa-switcher-nombre { max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empresa-switcher-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0; z-index: 9999;
    background: #ffffff; border: 1px solid var(--surface-border);
    border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
    min-width: 220px; overflow: hidden;
}
.empresa-switcher-option {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; width: 100%; text-align: left;
    background: none; border: none; cursor: pointer;
    font-size: .85rem; transition: background .12s;
}
.empresa-switcher-option:hover { background: var(--gray-50); }
.empresa-switcher-option.active { background: var(--primary-10, #1e3a5f11); }
.esw-logo { width: 30px; height: 30px; border-radius: 6px; background: var(--gray-100); display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.esw-logo img { width: 100%; height: 100%; object-fit: cover; }
.esw-logo span { font-weight: 700; font-size: .85rem; color: var(--gray-600); }
.esw-info { flex: 1; min-width: 0; }
.esw-nombre { font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.esw-rol { font-size: .72rem; color: var(--gray-500); }

/* ══════════════════════════════════════════════════════
   DASHBOARD v2  —  preview/dashboard-redesign
══════════════════════════════════════════════════════ */
.dv2-header {
    display: flex; justify-content: space-between; align-items: center;
    gap: 1rem;
    margin-bottom: 1.15rem;
}
.dv2-title { margin: 0; font-size: 1.6rem; font-weight: 700; color: var(--gray-900); }
.dv2-header-meta { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-top: 4px; }
.dv2-subtitle { margin: 0; font-size: .82rem; color: var(--gray-500); display: flex; align-items: center; gap: 5px; text-transform: capitalize; }
.dv2-header-actions { display: flex; gap: .6rem; }
.dv2-btn-sm { padding: 8px 16px !important; font-size: .85rem !important; border-radius: var(--radius-md) !important; display: flex; align-items: center; gap: 6px; }
.dv2-period-tabs {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    background: var(--surface-card);
}
.dv2-period-tab {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--gray-500);
    cursor: pointer;
    font-size: .76rem;
    font-weight: 600;
    line-height: 1;
    min-height: 28px;
    padding: 0 9px;
}
.dv2-period-tab.active { background: var(--gray-900); color: #fff; }

/* Row 1 */
.dv2-row-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    align-items: start;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* KPI financieros */
.dv2-fin-kpis { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 1rem; align-items: start; }
.dv2-kpi-card {
    background: var(--surface-card); border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.05rem .85rem;
    display: flex; flex-direction: column; gap: 4px;
    border: 1px solid var(--surface-border);
    min-height: 160px;
}
.dv2-kpi-main { display: flex; align-items: flex-start; gap: .85rem; min-width: 0; }
.dv2-kpi-copy { min-width: 0; }
.dv2-kpi-icon { width: 38px; height: 38px; border-radius: var(--radius-xl); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.dv2-kpi-label { font-size: .78rem; color: var(--gray-500); font-weight: 500; }
.dv2-kpi-value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; overflow-wrap: anywhere; color: var(--gray-900); }
.dv2-kpi-sub { font-size: .74rem; color: var(--gray-400); margin-top: 2px; }
.dv2-spark { margin-top: auto; width: 100%; max-height: 42px; }
.dv2-trend { font-weight: 600; }
.dv2-trend.is-up { color: var(--success); }
.dv2-trend.is-down { color: var(--error); }
.dv2-tone-info .dv2-kpi-icon,
.dv2-tone-info .dv2-op-icon,
.dv2-tone-info .dv2-quick-icon,
.dv2-tone-info .dv2-sum-icon { background: var(--blue-50); color: var(--accent-500); }
.dv2-tone-info .dv2-kpi-value { color: var(--accent-500); }
.dv2-tone-success .dv2-kpi-icon,
.dv2-tone-success .dv2-op-icon,
.dv2-tone-success .dv2-quick-icon,
.dv2-tone-success .dv2-sum-icon { background: #f0fdf4; color: var(--success); }
.dv2-tone-success .dv2-kpi-value { color: var(--success); }
.dv2-tone-danger .dv2-kpi-icon,
.dv2-tone-danger .dv2-op-icon,
.dv2-tone-danger .dv2-quick-icon,
.dv2-tone-danger .dv2-sum-icon { background: #fef2f2; color: var(--error); }
.dv2-tone-danger .dv2-kpi-value { color: var(--error); }
.dv2-tone-warning .dv2-kpi-icon,
.dv2-tone-warning .dv2-op-icon,
.dv2-tone-warning .dv2-quick-icon,
.dv2-tone-warning .dv2-sum-icon { background: #fffbeb; color: var(--warning); }
.dv2-tone-warning .dv2-kpi-value { color: var(--warning); }
.dv2-tone-neutral .dv2-kpi-icon,
.dv2-tone-neutral .dv2-op-icon,
.dv2-tone-neutral .dv2-quick-icon,
.dv2-tone-neutral .dv2-sum-icon { background: #f1f5f9; color: #475569; }

/* KPI operativos */
.dv2-op-chips { display: flex; flex-direction: column; gap: .55rem; min-width: 0; }
.dv2-op-chip {
    background: var(--surface-card); border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--surface-border);
    padding: .65rem .75rem; cursor: pointer;
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
    transition: background-color .15s, border-color .15s, box-shadow .15s;
    min-height: 82px;
    width: 100%;
    text-align: left;
}
.dv2-op-chip:hover { background: var(--gray-50); border-color: var(--surface-border-strong); box-shadow: var(--shadow-md); }
.dv2-op-chip.dv2-op-alert { border-color: #fca5a5; }
.dv2-op-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; width: 100%; }
.dv2-op-icon { width: 30px; height: 30px; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; }
.dv2-op-val { font-size: 1.35rem; font-weight: 700; line-height: 1; }
.dv2-op-label { font-size: .72rem; color: var(--gray-500); line-height: 1.2; }
.dv2-op-action { display: flex; align-items: center; gap: 4px; margin-top: auto; color: var(--gray-700); font-size: .72rem; font-weight: 700; }

/* Row 2: chart */
.dv2-row-chart { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: 1rem; margin-bottom: 1rem; align-items: start; }
.dv2-chart-stack { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.dv2-card {
    background: var(--surface-card); border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--surface-border);
    overflow: hidden;
}
.dv2-card-body { padding: .75rem 1.1rem; min-height: 60px; }
.dv2-chart-card { padding: 1.05rem 1.2rem; }
.dv2-quick-card { padding: 1.05rem 1.1rem; }
.dv2-card-head {
    display: flex; justify-content: space-between; align-items: center;
    gap: .75rem;
    margin-bottom: .85rem;
}
.dv2-card-title { font-weight: 600; font-size: .9rem; color: var(--gray-800); display: flex; align-items: center; gap: 6px; }
.dv2-period-chip { background: var(--gray-100); border-radius: var(--radius-md); padding: 4px 11px; font-size: .77rem; color: var(--gray-600); display: flex; align-items: center; gap: 5px; }
.dv2-muted-chip { font-size: .78em; color: var(--gray-400); font-weight: 400; }
.dv2-link-btn { background: none; border: none; cursor: pointer; font-size: .8rem; color: var(--primary-500); display: flex; align-items: center; gap: 4px; padding: 0; }
.dv2-link-btn:hover { text-decoration: underline; }

/* Acceso rápido */
.dv2-quick-list { display: flex; flex-direction: column; gap: 6px; }
.dv2-quick-btn {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: var(--radius-xl);
    background: var(--gray-50); border: 1px solid var(--gray-200);
    cursor: pointer; text-align: left; width: 100%;
    transition: background .12s;
}
.dv2-quick-btn:hover { background: var(--gray-100); }
.dv2-quick-icon { width: 30px; height: 30px; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.dv2-quick-label { flex: 1; font-size: .85rem; font-weight: 500; color: var(--gray-700); }
.dv2-quick-arrow { color: var(--gray-400); font-size: .72rem; }

/* Row 3: resumen */
.dv2-row-summary { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 1rem; margin-bottom: 0; }
.dv2-summary-chip { padding: .9rem 1rem; display: flex; align-items: center; gap: .75rem; }
.dv2-sum-icon { width: 36px; height: 36px; border-radius: var(--radius-xl); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.dv2-sum-label { font-size: .74rem; color: var(--gray-500); }
.dv2-sum-val { font-size: 1rem; font-weight: 700; }

/* Tabla card */
.dv2-table-card { margin-bottom: 1rem; }
.dv2-table-body { padding: .75rem 1.1rem; min-height: 60px; }
.dv2-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2); padding: var(--space-6); color: var(--gray-400); text-align: center; }
.dv2-empty p { margin: 0; color: var(--gray-500); font-size: .88rem; }
.dv2-error { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-2); padding: var(--space-4); color: var(--error); font-size: .88rem; }
.dv2-progress-list { display: grid; gap: var(--space-3); }
.dv2-progress-row { min-width: 0; }
.dv2-progress-meta { display: flex; justify-content: space-between; gap: var(--space-3); font-size: .85rem; margin-bottom: 4px; }
.dv2-progress-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dv2-progress-track { background: var(--gray-100); border-radius: var(--radius-md); height: 6px; overflow: hidden; }
.dv2-progress-fill { background: var(--primary-500); border-radius: var(--radius-md); height: 6px; }
.dv2-progress-note { color: var(--gray-400); font-size: .75rem; margin-top: 3px; }
.dv2-pipeline-meta { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); flex-wrap: wrap; color: var(--text-secondary); font-size: .8rem; }
.dv2-pipeline-meta div:last-child { margin-left: auto; }
.dv2-pipeline-meta strong { color: var(--gray-800); }
.dv2-pipeline-bar { display: flex; height: 8px; border-radius: var(--radius-lg); overflow: hidden; margin-bottom: var(--space-3); gap: var(--space-1); }
.dv2-pipeline-legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.dv2-pipeline-item { display: flex; align-items: center; gap: var(--space-1); font-size: .8rem; color: var(--text-secondary); }
.dv2-pipeline-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dv2-pipeline-item small { color: var(--text-muted); }
.dv2-approval-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-2); border: 1px solid var(--surface-border); border-radius: var(--radius-xl); margin-bottom: var(--space-2); background: var(--surface-bg); cursor: pointer; width: 100%; text-align: left; }
.dv2-approval-row:hover { background: var(--gray-50); border-color: var(--surface-border-strong); }
.dv2-approval-main { display: flex; align-items: center; gap: var(--space-3); font-size: .875rem; font-weight: 500; color: var(--text-primary); }
.dv2-approval-icon { width: 32px; height: 32px; border-radius: var(--radius-xl); background: var(--gray-100); display: flex; align-items: center; justify-content: center; }
.dv2-approval-row strong { background: var(--gray-100); color: var(--gray-700); border-radius: var(--radius-md); padding: 2px 10px; font-size: .8rem; }

/* Row bottom: 2 columnas */
.dv2-row-bottom { display: grid; grid-template-columns: repeat(2,1fr); gap: 1rem; margin-bottom: 1rem; }
.dv2-row-bottom .dv2-card { padding: 1.1rem 1.2rem; }

/* ── DASHBOARD ALEGRA ── */
.dv2-header--alegra { align-items: flex-start; }
.dv2-greeting {
    margin: 0 0 2px;
    font-size: .85rem;
    font-weight: 500;
    color: var(--gray-500);
}
.dv2-header--alegra .dv2-title { font-size: 1.4rem; font-weight: 700; }
.dv2-header--alegra .dv2-subtitle { text-transform: none; }

/* KPI grid */
.dv2-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.dv2-kpi-alegra {
    background: var(--surface-card);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 120px;
    transition: box-shadow .15s, border-color .15s;
}
.dv2-kpi-alegra:hover { box-shadow: var(--shadow-md); border-color: var(--surface-border-strong); }
.dv2-kpi-alegra-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
}
.dv2-kpi-alegra-label {
    font-size: .78rem;
    font-weight: 500;
    color: var(--gray-500);
}
.dv2-kpi-alegra-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    color: var(--gray-500);
}
.dv2-kpi-alegra-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--gray-900);
    overflow-wrap: anywhere;
}
.dv2-kpi-alegra-sub { font-size: .75rem; color: var(--gray-400); margin-top: 2px; }

/* Tone overrides con colores semánticos reales para dashboard */
.dv2-tone-info .dv2-kpi-alegra-icon { background: var(--blue-50); color: var(--primary-600); }
.dv2-tone-success .dv2-kpi-alegra-icon { background: #f0fdf4; color: #16a34a; }
.dv2-tone-danger .dv2-kpi-alegra-icon { background: #fef2f2; color: #dc2626; }
.dv2-tone-warning .dv2-kpi-alegra-icon { background: #fffbeb; color: #d97706; }
.dv2-tone-neutral .dv2-kpi-alegra-icon { background: #f1f5f9; color: #475569; }
.dv2-tone-info .dv2-kpi-alegra-value { color: var(--primary-600); }
.dv2-tone-success .dv2-kpi-alegra-value { color: #16a34a; }
.dv2-tone-danger .dv2-kpi-alegra-value { color: #dc2626; }
.dv2-tone-warning .dv2-kpi-alegra-value { color: #d97706; }
.dv2-tone-neutral .dv2-kpi-alegra-value { color: #475569; }

/* Dashboard layout: main + sidebar */
.dv2-dashboard-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: start;
}
.dv2-dashboard-main { min-width: 0; }
.dv2-dashboard-side {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}
.dv2-signals-card { padding: 1.05rem 1.1rem; }
.dv2-signals-list {
    display: flex;
    flex-direction: column;
    gap: .55rem;
}

/* Lists grid */
.dv2-lists-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.dv2-lists-grid .dv2-card { padding: 1.05rem 1.1rem; }
.dv2-lists-grid .dv2-table-body { padding: 0; }

@media (max-width: 1280px) {
    .dv2-row-top,
    .dv2-row-chart,
    .dv2-dashboard-layout { grid-template-columns: 1fr; }
    .dv2-op-chips,
    .dv2-signals-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 900px) {
    .dv2-header { align-items: flex-start; flex-direction: column; }
    .dv2-header-actions { flex-wrap: wrap; }
    .dv2-fin-kpis,
    .dv2-op-chips,
    .dv2-row-summary,
    .dv2-row-bottom,
    .dv2-kpi-grid,
    .dv2-lists-grid { grid-template-columns: 1fr 1fr; }
    .dv2-dashboard-side { flex-direction: row; }
    .dv2-signals-card,
    .dv2-quick-card { flex: 1; }
}

@media (max-width: 640px) {
    .dv2-header-actions,
    .dv2-btn-sm { width: 100%; }
    .dv2-btn-sm { justify-content: center; }
    .dv2-fin-kpis,
    .dv2-op-chips,
    .dv2-row-summary,
    .dv2-row-bottom,
    .dv2-kpi-grid,
    .dv2-lists-grid,
    .dv2-signals-list { grid-template-columns: 1fr; }
    .dv2-card-head { align-items: flex-start; flex-direction: column; }
    .dv2-dashboard-side { flex-direction: column; }
}

/* Dark mode */
[data-theme="dark"] .dv2-kpi-card,
[data-theme="dark"] .dv2-op-chip,
[data-theme="dark"] .dv2-card { background: var(--surface-card); }
[data-theme="dark"] .dv2-quick-btn { background: var(--surface-hover); border-color: var(--surface-border); }
[data-theme="dark"] .dv2-quick-btn:hover { background: var(--gray-700); }
[data-theme="dark"] .dv2-period-chip { background: var(--gray-700); color: var(--gray-300); }
[data-theme="dark"] .dv2-period-tabs { background: var(--surface-card); }
[data-theme="dark"] .dv2-period-tab.active { background: var(--gray-100); color: var(--gray-900); }

/* Dark mode — sidebar y header: recuperar jerarquía/contraste (#15) */
[data-theme="dark"] .app-header,
[data-theme="dark"] .app-sidebar { border-color: var(--surface-border-strong); }
[data-theme="dark"] .app-logo { color: var(--gray-900); }
[data-theme="dark"] .nav-item { color: var(--gray-800); }
[data-theme="dark"] .nav-item:hover { background: var(--surface-hover); color: var(--gray-900); }
[data-theme="dark"] .nav-icon { color: inherit; }
[data-theme="dark"] .nav-group-header { color: var(--gray-500); }
[data-theme="dark"] .nav-group-header:hover { color: var(--gray-800); }
[data-theme="dark"] .user-name { color: var(--gray-900); }
[data-theme="dark"] .user-role { color: var(--gray-600); }

/* === Admin App Grid === */
.admin-apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
}

.admin-app-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.25rem 0.75rem;
    background: var(--surface-card, #fff);
    border: 1px solid var(--gray-200);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.18s ease;
    color: var(--gray-700);
    font-size: 0.8rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
}

.admin-app-card:hover {
    background: var(--primary-50, var(--blue-50));
    border-color: var(--primary-300, var(--blue-200));
    color: var(--primary-700, var(--primary-700));
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
}

.admin-app-card.active {
    background: var(--primary-600, var(--primary-600));
    border-color: var(--primary-600, var(--primary-600));
    color: #fff;
    box-shadow: 0 4px 14px rgba(37,99,235,.35);
}

.admin-app-icon {
    font-size: 1.6rem;
    line-height: 1;
}

[data-theme="dark"] .admin-app-card {
    background: var(--surface-card);
    border-color: var(--surface-border);
    color: var(--gray-300);
}
[data-theme="dark"] .admin-app-card:hover {
    background: var(--gray-700);
    border-color: var(--primary-400);
    color: var(--primary-300);
}
[data-theme="dark"] .admin-app-card.active {
    background: var(--primary-600);
    border-color: var(--primary-600);
    color: #fff;
}

@media (max-width: 600px) {
    .admin-apps-grid {
        grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
        gap: 0.5rem;
    }
    .admin-app-card { padding: 1rem 0.5rem; font-size: 0.75rem; }
    .admin-app-icon { font-size: 1.35rem; }
}
