:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --background: #f3f4f6;
    --surface: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e2e8f0;
    --radius: 0.5rem;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05);
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --primary-gradient: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);

    /* Glassmorphism Variables (Premium Layer) */
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-blur: blur(20px);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.05);
    --radius-premium: 20px;
}

body.dark-theme {
    --primary: #3b82f6;
    /* Lighter blue for dark mode */
    --primary-dark: #60a5fa;
    --background: #111827;
    /* Very dark gray */
    --surface: #1f2937;
    /* Dark gray */
    --text-main: #f9fafb;
    /* Off-white */
    --text-muted: #9ca3af;
    /* Light gray */
    --border: #374151;
    /* Darker border */
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.5);
    --secondary: #94a3b8;

    /* Dark Glass Variables */
    --glass-bg: rgba(17, 24, 39, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    /* Ultra-fine white border */
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}

body {
    transition: background-color 0.3s ease, color 0.3s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#sidebar-toggle {
    display: none;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}

.sidebar {
    width: 260px;
    background-color: var(--surface);
    border-right: 1px solid var(--border);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
}

/* Sidebar Collapsed State */
body.sidebar-collapsed .sidebar {
    width: 70px;
}

body.sidebar-collapsed .nav-brand span,
body.sidebar-collapsed .nav-link span,
body.sidebar-collapsed .nav-menu h4 {
    opacity: 0;
    visibility: hidden;
    width: 0;
    overflow: hidden;
}

body.sidebar-collapsed .nav-brand {
    justify-content: center;
    padding: 1.5rem 0;
}

body.sidebar-collapsed .nav-link {
    justify-content: center;
    padding: 0.875rem 0;
}

body.sidebar-collapsed .main-content {
    margin-left: 70px;
    width: calc(100% - 70px);
}

body.sidebar-collapsed .premium-topbar {
    margin-left: 70px;
    width: calc(100% - 70px);
}

body.sidebar-collapsed .premium-footer {
    margin-left: 70px;
}

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
    width: calc(100% - 260px);
    min-height: calc(100vh - 80px);
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

h1 {
    font-size: 1.875rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

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

a:hover {
    color: var(--primary-dark);
}

/* Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-size: 0.875rem;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    height: 32px;
    min-width: 32px;
}

.pagination-gap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Button Gradients & Shadows */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.4), 0 0 15px rgba(37, 99, 235, 0.3);
    /* Glow effect */
    transform: translateY(-1px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #dc2626);
    color: white;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    box-shadow: 0 4px 6px rgba(239, 68, 68, 0.4);
    transform: translateY(-1px);
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
    box-shadow: 0 4px 6px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: var(--background);
    border-color: var(--primary);
    color: var(--primary);
}

.card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border-radius: var(--radius-premium);
    box-shadow: var(--glass-shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--glass-border);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    /* Slightly rounded for modern feel */
    font-family: inherit;
    font-size: 0.925rem;
    background-color: rgba(0, 0, 0, 0.02);
    /* Very subtle tint instead of solid */
    color: var(--text-main);
    transition: all 0.2s;
}

body.dark-theme .form-control {
    background-color: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
    /* Modern ring */
}

/* Tables */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);

    /* Scroll Shadows (UX Indicator) */
    background:
        linear-gradient(to right, var(--surface) 30%, rgba(255, 255, 255, 0)),
        linear-gradient(to right, rgba(255, 255, 255, 0), var(--surface) 70%) 0 100%,
        radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)),
        radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)) 0 100%;
    background-repeat: no-repeat;
    background-color: var(--surface);
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-position: 0 0, 100% 0, 0 0, 100% 0;
    background-attachment: local, local, scroll, scroll;
}

/* Scroll Hint Animation */
.scroll-hint {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    animation: pulse-hint 2s infinite;
}

@keyframes pulse-hint {

    0%,
    100% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }
}

.scroll-hint.visible {
    display: flex;
}

.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    white-space: normal;
}

.table th {
    background-color: var(--background);
    white-space: nowrap;
    padding: 1rem 1.5rem;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    position: sticky;
    top: 0;
    border-bottom: 2px solid var(--border);
}

.table td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
    vertical-align: middle;
}

.table tbody tr {
    transition: background-color 0.15s;
}

.table tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
    /* Very subtle hover */
}

body.dark-theme .table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

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

/* Alerts & Badges */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border-left: 4px solid transparent;
}

.alert-success {
    background-color: rgba(16, 185, 129, 0.1);
    color: #065f46;
    border-left-color: var(--success);
}

/* Badges - High Contrast */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1;
    white-space: nowrap;
}

.badge-success {
    background-color: #10b981;
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.badge-danger {
    background-color: #ef4444;
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.badge-warning {
    background-color: #f59e0b;
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.badge-info {
    background-color: #3b82f6;
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Accessible Action Buttons */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: var(--radius);
    transition: all 0.2s;
    font-size: 1.1rem;
    color: var(--text-muted);
    border: 1px solid transparent;
}

.btn-icon:hover {
    background-color: var(--background);
    color: var(--primary);
    border-color: var(--border);
    transform: translateY(-1px);
}

/* Ensure contrast in Dark Mode */
body.dark-theme .badge {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark-theme .btn-icon {
    color: var(--text-muted);
}

body.dark-theme .btn-icon:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Sidebar Navigation */
.nav-brand {
    padding: 1.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.nav-brand i {
    font-size: 1.8rem;
    flex-shrink: 0;
}

.nav-brand span {
    transition: opacity 0.3s ease, width 0.3s ease;
}

.nav-menu {
    list-style: none;
    padding: 0 1rem;
}

.nav-item {
    margin-bottom: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    margin: 0.25rem 0.5rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
    gap: 0.75rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    white-space: nowrap;
}

.nav-link i {
    font-size: 1.2rem;
    flex-shrink: 0;
    min-width: 20px;
}

.nav-link span {
    transition: opacity 0.3s ease, width 0.3s ease;
}

.nav-link:hover {
    background-color: var(--background);
    color: var(--text-main);
}

.nav-link.active {
    background-color: rgba(37, 99, 235, 0.08);
    color: var(--primary);
    border-left-color: var(--primary);
}

body.dark-theme .nav-link.active {
    background-color: rgba(96, 165, 250, 0.15);
}

/* Sidebar Section Headers */
.nav-menu h4 {
    transition: opacity 0.3s ease, width 0.3s ease;
    white-space: nowrap;
}

/* Utilities */
.text-right {
    text-align: right;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.flex-row {
    flex-direction: row;
}

@media (min-width: 1024px) {
    .lg:flex-row {
        flex-direction: row;
    }
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

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

.gap-2 {
    gap: 0.5rem;
}

.gap-8 {
    gap: 2rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-6 {
    margin-bottom: 2rem !important;
    /* Aumentado para mejor separación vertical */
}

.gap-4 {
    gap: 1.5rem !important;
    /* Más espacio entre controles superiores */
}

/* Responsive */
.whitespace-nowrap {
    white-space: nowrap !important;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 100%;
        max-width: 300px;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.5);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        width: 100%;
    }

    /* Resetear estados de collapse en móvil */
    body.sidebar-collapsed .sidebar {
        width: 100%;
        max-width: 300px;
    }

    body.sidebar-collapsed .main-content,
    body.sidebar-collapsed .premium-topbar,
    body.sidebar-collapsed .premium-footer {
        margin-left: 0;
        width: 100%;
    }
}

/* Pagination Styles */
.pagination-container {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0 0.5rem;
}

.pagination-links {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    justify-content: center;
}

@media (min-width: 768px) {
    .pagination-container {
        flex-direction: row;
    }
}

/* Page & Section Headers Global Styling */
.page-header {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 2.5rem;
    width: 100%;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

@media (min-width: 768px) {
    .page-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

/* Asegurar que los inputs en cabeceras no se rompan */
.header-actions .form-control {
    min-width: 150px;
    height: 42px;
}

/* GLOBAL RESPONSIVE FIX FOR HEADERS (The "Magic" Bullet) */
@media (max-width: 768px) {

    /* Seleccionar el patrón exacto que se usa en todas las vistas */
    .main-content .flex.justify-between.items-center.mb-6,
    .main-content .flex.justify-between.items-center {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1.25rem !important;
        margin-bottom: 2rem !important;
    }

    .main-content h1,
    .main-content h2 {
        text-align: left;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Forzar botones a tomar ancho necesario o completo si están solos */
    .main-content .flex.gap-2 {
        width: 100%;
        flex-wrap: wrap;
    }

    .main-content .btn {
        flex: 1;
        justify-content: center;
        min-width: 120px;
    }
}

/* Premium Toolbar Components */
.premium-toolbar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: center;
    justify-content: center;
    margin-bottom: 3rem !important;
}

@media (min-width: 1024px) {
    .premium-toolbar {
        padding: 1rem 2rem;
        gap: 2rem;
    }
}

body.dark-theme .premium-toolbar {
    background: var(--glass-bg);
    border-color: var(--glass-border);
}

/* Desktop Layout (Default) */
.premium-toolbar form {
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 2rem !important;
}

/* Mobile Layout Overrides */
@media (max-width: 991px) {
    .premium-toolbar {
        padding: 1.25rem 1rem !important;
    }

    .premium-toolbar form {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1.25rem !important;
    }

    .premium-toolbar .flex:not(.segmented-control):not(.date-range-group) {
        flex-direction: column !important;
        width: 100% !important;
    }

    .toolbar-divider {
        display: none !important;
    }

    .segmented-control {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 4px !important;
    }

    .segmented-btn {
        padding: 0.6rem 0.75rem !important;
        font-size: 0.7rem !important;
        flex: 1 0 auto !important;
    }

    .date-range-group {
        flex-direction: row !important;
        width: 100% !important;
    }

    .filter-circle-btn {
        width: 100% !important;
    }
}

/* Segmented Control (Tabs) */
.segmented-control {
    background: rgba(0, 0, 0, 0.05);
    padding: 4px;
    border-radius: 14px;
    display: flex;
    gap: 2px;
    overflow-x: auto;
    /* Permitir scroll si es muy ancho en móvil */
    scrollbar-width: none;
    /* Ocultar scrollbar en Firefox */
    max-width: 100%;
}

.segmented-control::-webkit-scrollbar {
    display: none;
    /* Ocultar scrollbar en Chrome/Safari */
}

body.dark-theme .segmented-control {
    background: rgba(255, 255, 255, 0.05);
}

.segmented-btn {
    padding: 0.6rem 1rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    flex: 1 0 auto;
}

@media (min-width: 768px) {
    .segmented-btn {
        padding: 0.6rem 1.25rem;
        font-size: 0.8rem;
    }
}

.segmented-btn:hover {
    color: var(--text-main);
}

.segmented-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

body.dark-theme .segmented-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

/* Date Range Theme Integration */
.date-range-group {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 2px;
    width: 100%;
    /* Ancho completo en móvil */
    justify-content: space-between;
}

@media (min-width: 768px) {
    .date-range-group {
        width: auto;
    }
}

body.dark-theme .date-range-group {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--glass-border);
}

.date-input-wrapper {
    display: flex;
    flex-direction: column;
    padding: 0.4rem 0.75rem;
    border-radius: 10px;
    flex: 1;
}

@media (min-width: 768px) {
    .date-input-wrapper {
        padding: 0.4rem 1rem;
    }
}

.date-input-wrapper label {
    font-size: 0.55rem;
    text-transform: uppercase;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin-bottom: -2px;
}

.date-input-wrapper input {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-weight: 700;
    font-size: 0.8rem;
    outline: none;
    cursor: pointer;
    width: 100%;
}

@media (min-width: 768px) {
    .date-input-wrapper input {
        font-size: 0.85rem;
    }
}

.filter-circle-btn {
    height: 46px;
    padding: 0 1.5rem;
    border-radius: 14px;
    background: var(--primary-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 800;
    border: none;
    box-shadow: 0 8px 15px rgba(37, 99, 235, 0.25);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    white-space: nowrap;
    width: 100%;
    /* Ancho completo en móvil */
}

@media (min-width: 768px) {
    .filter-circle-btn {
        width: auto;
    }
}

.filter-circle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 20px rgba(37, 99, 235, 0.4);
    filter: brightness(1.1);
}

.toolbar-divider {
    width: 1px;
    height: 30px;
    background: var(--border);
    margin: 0 1rem;
    display: none;
}

@media (min-width: 1024px) {
    .toolbar-divider {
        display: block;
    }
}