/*
 * Layout System v1.0
 * Sistema base de tres zonas (header/body/footer) + densidad compacta global.
 */

:root {
    --layout-page-gap: 0;
    --layout-card-padding: 2rem;
    --layout-card-margin-bottom: 2rem;
    --layout-form-gap: 1rem;
    --layout-input-height: 38px;
    --layout-table-font-size: 0.875rem;
    --layout-table-cell-py: 0.75rem;
    --layout-table-cell-px: 1rem;
}

.is-compact {
    --layout-card-padding: 1.2rem;
    --layout-card-margin-bottom: 1rem;
    --layout-form-gap: 0.625rem;
    --layout-input-height: 32px;
    --layout-table-font-size: 0.8125rem;
    --layout-table-cell-py: 0.375rem;
    --layout-table-cell-px: 0.75rem;
}

.content-area.is-compact {
    padding: 0.875rem 1rem;
}

/* ==========================================================================
   VIEWPORT-LOCK: cuando content-area contiene un layout-page,
   el scroll se desactiva a nivel de content-area y se delega
   exclusivamente a layout-page__body.
   ========================================================================== */
.layout-page--viewport-lock {
    height: calc(100vh - 3.5rem);
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
}

.content-area:has(> .layout-page--viewport-lock) {
    overflow-y: hidden !important;
}

.layout-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: var(--layout-page-gap);
}

/* Header Estilo Google - Compacto */
.layout-page__header {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 1rem;
    background: var(--surface-header);
    border-bottom: 1px solid var(--gray-200);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    flex-shrink: 0;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.layout-page__header-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.layout-page__header-identity {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.layout-page__header-icon {
    width: 32px; /* Reducido de 40px */
    height: 32px;
    background: var(--primary-50);
    color: var(--primary-600);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem; /* Reducido de 1.5rem */
}

.layout-page__header-title {
    margin: 0;
    font-size: 1.125rem; /* Reducido de 1.25rem */
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.01em;
}

.layout-page__header-desc {
    margin: 0.125rem 0 0;
    font-size: 0.875rem;
    color: var(--gray-500);
}

.layout-page__header-stats {
    display: flex;
    gap: 1rem;
    margin-top: 0.25rem;
}

.layout-page__header-stat-item {
    display: flex;
    align-items: baseline;
    gap: 0.375rem;
    font-size: 0.8125rem;
}

.layout-page__header-stat-item .stat-label {
    color: var(--gray-500);
    font-weight: 500;
}

.layout-page__header-stat-item .stat-value {
    color: var(--gray-900);
    font-weight: 700;
}

.layout-page__header-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.layout-page__header-nav {
    display: flex;
    justify-content: flex-start; /* Nav a la izquierda debajo del título */
    align-items: center;
    width: 100%;
}

/* Tabs integradas en header apilado */
.layout-page__header .tabs-premium.grupo-tabs {
    margin-bottom: 0;
    background: transparent; /* Más limpio si va debajo */
    border: none;
    padding: 0;
    gap: 1.5rem; /* Estilo Material Tabs: espacio en lugar de cajas */
}

.layout-page__header .tab-item {
    padding: 0.5rem 0;
    font-size: 0.875rem;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    flex: none;
}

.layout-page__header .tab-item:hover {
    background: transparent;
    color: var(--primary-600);
}

.layout-page__header .tab-item.is-active {
    background: transparent;
    box-shadow: none;
    color: var(--primary-700);
    border-bottom-color: var(--primary-700);
}

/* Sección de Filtros */
.filters-section {
    margin: 1rem 0 !important; /* Forzamos override de estilos inline si existen */
    overflow: visible;
}

/* Body y Scroll Interno */
.layout-page__body {
    min-height: 0;
    overflow-y: auto;
    background: var(--surface-header);
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    gap: 0.75rem;
}

.layout-page__body > * {
    margin: 0;
}

/* Footer Fijo */
.layout-page__footer {
    flex-shrink: 0;
    padding: 0.75rem 1.5rem;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Scrollbar Estilo Google */
.layout-page__body::-webkit-scrollbar {
    width: var(--scrollbar-width);
}

.layout-page__body::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

.layout-page__body::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 10px;
    border: 2px solid var(--surface-header);
}

.layout-page__body::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Animación de entrada */
.layout-page {
    animation: google-fade-in 0.2s ease-out;
}

@keyframes google-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Dropdowns de Filtros (Estilo Google) */
.filters__menu {
    position: relative;
}

.filters__dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: #ffffff;
    border-radius: var(--radius-md);
    box-shadow: var(--google-shadow-2);
    border: 1px solid var(--gray-200);
    z-index: 100;
    min-width: 200px;
    padding: 0.5rem 0;
    overflow: hidden;
    animation: google-dropdown-in 0.15s ease-out;
}

@keyframes google-dropdown-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.filters__dropdown.hidden {
    display: none;
}

.filters__dropdown-panel {
    display: flex;
    flex-direction: column;
}

.filters__dropdown-header {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--gray-100);
    margin-bottom: 0.25rem;
}

.filters__dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--gray-700);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.1s ease;
}

.filters__dropdown-item:hover {
    background: var(--gray-50);
    color: var(--gray-900);
}

.filters__dropdown-item i {
    font-size: 1.125rem;
    color: var(--gray-400);
}

.filters__dropdown-item--checkbox {
    cursor: pointer;
    user-select: none;
}

.filters__dropdown-item--checkbox input {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.is-compact .filters__row,
.is-compact .form-grid,
.is-compact .general-card__grid,
.is-compact .grupo-general-stack,
.is-compact .grupo-form__body,
.is-compact .form-group {
    gap: var(--layout-form-gap);
}

.is-compact input,
.is-compact select,
.is-compact .form-control,
.is-compact .filters__search-input {
    min-height: var(--layout-input-height);
}

.is-compact .table,
.is-compact .table-interactive {
    font-size: var(--layout-table-font-size);
}

.is-compact .table th,
.is-compact .table td,
.is-compact .table-interactive th,
.is-compact .table-interactive td {
    padding: var(--layout-table-cell-py) var(--layout-table-cell-px);
}

/* ==========================================================================
   Tabs - Premium (Google Style)
   ========================================================================== */
.tabs-premium.grupo-tabs {
    display: flex;
    background: var(--gray-100);
    padding: 0.25rem;
    border-radius: var(--radius-lg);
    gap: 0.15rem;
    margin-bottom: 1.25rem;
    border: 1px solid var(--gray-200);
}

.tab-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: none;
    background: transparent;
    color: var(--gray-500);
    font-weight: 500;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-item i {
    font-size: 1.15rem;
    opacity: 0.7;
}

.tab-item:hover {
    color: var(--gray-700);
    background: rgba(255, 255, 255, 0.4);
}

.tab-item.is-active {
    background: white;
    color: var(--primary-700);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.tab-item.is-active i {
    color: var(--primary-600);
    opacity: 1;
}

/* Panel transitions */
.grupo-panel {
    display: none;
    animation: slideUp 0.3s ease-out;
}

.grupo-panel.is-active {
    display: block;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Layout Utilities Refinement */
.is-compact .general-card {
    padding: 1rem;
}

/* ==========================================================================
   Utilities - Grid & Flex (Estilo Tailwind/Premium)
   ========================================================================== */
.grid { display: grid; }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--12 { grid-template-columns: repeat(12, 1fr); }

.col-span-1 { grid-column: span 1 / span 1; }
.col-span-2 { grid-column: span 2 / span 2; }
.col-span-3 { grid-column: span 3 / span 3; }
.col-span-4 { grid-column: span 4 / span 4; }
.col-span-6 { grid-column: span 6 / span 6; }
.col-span-8 { grid-column: span 8 / span 8; }
.col-span-9 { grid-column: span 9 / span 9; }
.col-span-12 { grid-column: span 12 / span 12; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1 1 0%; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }

.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.p-3 { padding: 0.75rem; }

.w-full { width: 100%; }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.text-2xl { font-size: 1.5rem; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-black { font-weight: 900; }
.text-muted { color: var(--gray-500); }
.text-danger { color: var(--danger-600); }
.text-blue-700 { color: #1d4ed8; }
.bg-gray-50 { background-color: var(--gray-50); }
.bg-blue-50 { background-color: #eff6ff; }
.rounded-lg { border-radius: 0.5rem; }
.border { border: 1px solid var(--gray-200); }
.border-b { border-bottom: 1px solid var(--gray-200); }
.border-gray-50 { border-color: var(--gray-50); }
.border-gray-100 { border-color: var(--gray-100); }

/* ==========================================================================
   Animations
   ========================================================================== */
.animate-spin {
    animation: google-spin 1s linear infinite;
    display: inline-block;
}

@keyframes google-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Hero & Header - Compact (Google Style)
   ========================================================================== */
.grupo-form__hero {
    margin-bottom: 0.75rem !important;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--gray-100);
}

.grupo-form__intro h1 {
    font-size: 1.25rem !important;
    letter-spacing: -0.01em;
}

.grupo-form__intro p.grupo-form__eyebrow {
    font-size: 0.75rem !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.15rem !important;
}

.grupo-form__actions {
    gap: 0.35rem !important;
}

.grupo-form__actions .btn {
    padding: 0.5rem 0.875rem !important;
    font-size: 0.85rem !important;
    border-radius: var(--radius-md) !important;
}

.grupo-form__actions .btn--large {
    padding: 0.5rem 1rem !important;
}

.form-hero__icon {
    width: 42px;
    height: 42px;
    background: var(--gray-50);
    color: var(--primary-600);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
    border: 1px solid var(--gray-100);
}


/* Reducción de gaps en grid compacta */
.grid.is-compact {
    gap: 1rem !important;
}

.col-span-9.flex-col {
    gap: 0.75rem !important;
}

/* ==========================================================================
   Summary Stats (Premium / Google Analytics Style)
   ========================================================================== */
.summary-stats-container {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.summary-stats-bar {
    display: flex;
    flex-wrap: wrap;
    background: white;
}

.summary-stats-item {
    flex: 1;
    min-width: 200px;
    padding: 1.25rem 1.5rem;
    display: flex;
    gap: 1rem;
    border-right: 1px solid var(--gray-100);
    transition: background 0.2s ease;
}

.summary-stats-item:last-child {
    border-right: none;
}

.summary-stats-item:hover {
    background: var(--gray-50);
}

.summary-stats-item__icon {
    width: 42px;
    height: 42px;
    background: var(--primary-50);
    color: var(--primary-600);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.summary-stats-item--success .summary-stats-item__icon { background: var(--success-50); color: var(--success-600); }
.summary-stats-item--warning .summary-stats-item__icon { background: var(--warning-50); color: var(--warning-600); }
.summary-stats-item--danger .summary-stats-item__icon { background: var(--danger-50); color: var(--danger-600); }
.summary-stats-item--info .summary-stats-item__icon { background: var(--info-50); color: var(--info-600); }

.summary-stats-item__content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.summary-stats-item__label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.summary-stats-item__main-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.summary-stats-item__value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--gray-900);
    letter-spacing: -0.02em;
    line-height: 1;
}

.summary-stats-item__trend {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    font-size: 0.75rem;
    font-weight: 700;
}

.summary-stats-item__trend span.material-symbols-outlined {
    font-size: 1rem;
}

.summary-stats-item__secondary {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--gray-400);
}

.summary-stats-actions {
    padding: 0.75rem 1.5rem;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-100);
    display: flex;
    justify-content: flex-end;
}

/* Tipo Factura Cards */
.tipo-factura-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.tipo-factura-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    padding: 1rem 0.75rem;
    border: 2px solid var(--gray-200);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: white;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.tipo-factura-card:hover {
    border-color: var(--primary-300);
    background: var(--primary-50);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.tipo-factura-card.is-active {
    border-color: var(--primary-500);
    background: var(--primary-50);
    box-shadow: 0 0 0 3px var(--primary-100), 0 2px 4px rgba(0,0,0,0.05);
    transform: translateY(0);
}

.tipo-factura-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.tipo-factura-card__icon {
    font-size: 2rem;
    color: var(--gray-400);
    transition: color 0.2s ease;
}

.tipo-factura-card.is-active .tipo-factura-card__icon {
    color: var(--primary-600);
}

.tipo-factura-card__label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.tipo-factura-card.is-active .tipo-factura-card__label {
    color: var(--primary-700);
}

.tipo-factura-card__desc {
    font-size: 0.75rem;
    color: var(--gray-500);
    line-height: 1.2;
}

/* Cliente Seleccionado */
.cliente-seleccionado {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--primary-50);
    border: 1px solid var(--primary-200);
    border-radius: 0.375rem;
}

.cliente-seleccionado.is-visible {
    display: flex;
}

.cliente-seleccionado__info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.cliente-seleccionado__icon {
    color: var(--primary-600);
    font-size: 1.25rem;
}

.cliente-seleccionado__name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-800);
}

.cliente-seleccionado__change {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: 0.25rem;
    cursor: pointer;
    color: var(--gray-600);
    transition: all 0.2s ease;
}

.cliente-seleccionado__change:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}
