/* ========================================
   SISTEMA DE DISEÑO - CRM PREMIUM
   ======================================== */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800&family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700&family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap');
/* @import for Material Symbols eliminat - es carrega al header.php */

/* ========================================
   UI FIXES: TOGGLE & ICONS
   ======================================== */
.switch-container {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.switch-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 22px;
}

.switch input {
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    position: absolute !important;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--danger-color);
    /* Inactive: Red */
    border-radius: 34px;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

input:checked+.slider {
    background-color: var(--success-color);
    /* Active: Green */
}

input:checked+.slider:before {
    transform: translateX(22px);
}

.input-with-icon {
    position: relative;
    width: 100%;
}

.input-with-icon .material-symbols-outlined {
    position: absolute !important;
    left: 12px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    color: var(--gray-400) !important;
    font-size: 20px !important;
    pointer-events: none;
    z-index: 5 !important;
}

.input-with-icon input,
.input-with-icon select {
    padding-left: 44px !important;
}


:root {
    /* Colores principales */
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #3b82f6;

    --secondary-color: #8b5cf6;
    --accent-color: #06b6d4;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;

    /* Grises */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Tipografia */
    --font-sans: 'Plus Jakarta Sans', 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
    --font-general: 'Plus Jakarta Sans', sans-serif;
    /* Monospace-first for general UI */

    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);

    /* Espaciado - Compact Mode (~80-85% scale) */
    --spacing-xs: 0.2rem;
    --spacing-sm: 0.4rem;
    --spacing-md: 0.85rem;
    --spacing-lg: 1.25rem;
    --spacing-xl: 1.75rem;
    --spacing-2xl: 2.5rem;

    /* Bordes */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

    /* Layout - Compact Mode */
    --sidebar-width: 300px;
    --sidebar-collapsed-width: 64px;
    --header-height: 56px;
    --transition-speed: 0.25s;
}

/* Reset y base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-general);
    font-size: 13px;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-50);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.material-symbols-outlined {
    font-family: 'Material Symbols Outlined' !important;
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'liga';
}

/* Icon Colors - Android/Apple style */
.icon-blue {
    color: #3b82f6 !important;
}

/* Standard Vertical Alignment for Icons */
.icon-aligned {
    display: inline-flex !important;
    align-items: center !important;
    vertical-align: middle !important;
    gap: 0.5rem;
}

/* 1. Page Transitions & Auto-fade alerts */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

.alert-autodismiss {
    animation: fadeIn 0.4s ease-out, fadeOut 0.5s ease-in 4.5s forwards;
}

.main-content,
.container,
.login-card {
    animation: fadeIn 0.4s ease-out forwards;
}

/* 2. Custom Scrollbars (WebKit) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
    transition: background 0.2s;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

/* 3. Floating Labels */
.floating-group {
    position: relative;
    margin-bottom: 1rem;
}

.floating-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 14px;
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    outline: none;
    transition: all 0.2s ease;
}

.floating-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.floating-label {
    position: absolute;
    left: 14px;
    top: 12px;
    font-size: 14px;
    color: var(--gray-500);
    pointer-events: none;
    transition: all 0.2s ease;
    background: white;
    padding: 0 4px;
}

.floating-input:focus~.floating-label,
.floating-input:not(:placeholder-shown)~.floating-label {
    top: -8px;
    font-size: 12px;
    color: var(--primary-color);
    font-weight: 500;
}

.icon-blue {
    color: var(--primary-color) !important;
}

.icon-green {
    color: #10b981 !important;
}

.icon-orange {
    color: #f59e0b !important;
}

.icon-red {
    color: #ef4444 !important;
}

.icon-purple {
    color: #8b5cf6 !important;
}

.icon-teal {
    color: #14b8a6 !important;
}

.icon-gray {
    color: #64748b !important;
}

.icon-indigo {
    color: #6366f1 !important;
}

/* Subtle backgrounds for icons in cards */
.icon-bg-blue {
    background-color: rgba(59, 130, 246, 0.1);
}

.icon-bg-green {
    background-color: rgba(16, 185, 129, 0.1);
}

.icon-bg-orange {
    background-color: rgba(245, 158, 11, 0.1);
}

.icon-bg-red {
    background-color: rgba(239, 68, 68, 0.1);
}

.icon-bg-purple {
    background-color: rgba(139, 92, 246, 0.1);
}

.icon-bg-teal {
    background-color: rgba(20, 184, 166, 0.1);
}

.icon-bg-indigo {
    background-color: rgba(99, 102, 241, 0.1);
}

/* ========================================
   HEADER
   ======================================== */

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    z-index: 1001;
    display: flex;
    align-items: center;
    padding: 0 var(--spacing-lg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

@media (max-width: 768px) {
    .header {
        padding: 0 var(--spacing-sm);
    }
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 20px;
}

/* Botones toggle */
.menu-toggle,
.sidebar-toggle-desktop {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: var(--spacing-sm);
    color: var(--gray-700);
    border-radius: var(--radius-md);
    transition: all 0.2s;
    line-height: 1;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
}

.menu-toggle:hover,
.sidebar-toggle-desktop:hover {
    background: var(--gray-100);
    color: var(--primary-color);
}

/* Mostrar hamburguesa en móvil */
@media (max-width: 768px) {
    .menu-toggle {
        display: flex;
    }
}

/* Toggle sidebar en desktop - Oculto por petición del usuario */
@media (min-width: 769px) {
    .sidebar-toggle-desktop {
        display: none;
    }
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-self: start;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-900);
    text-decoration: none;
}

@media (max-width: 768px) {
    .logo span:last-child {
        display: block !important;
        font-size: 14px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 200px;
    }
}

.logo-icon {
    width: auto;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    font-size: 18px;
}

.header-search {
    position: relative;
    flex: 1;
    max-width: 800px;
    min-width: 250px;
    margin: 0 20px;
    transition: all 0.3s ease;
}

@media (max-width: 768px) {
    .header-search {
        display: none;
    }
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 16px;
    color: var(--gray-400);
    font-size: 16px;
    pointer-events: none;
}

/* Unified Filter Reset - Force Absolute Parity */
#globalSearchInput,
.search-input:not(textarea),
button.search-input,
select.search-input,
input.search-input,
.btn-premium {
    height: 48px !important;
    min-height: 48px !important;
    max-height: 48px !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    font-size: 16px !important;
    font-weight: 500 !important;
    border-radius: 12px !important;
    border: 1px solid var(--gray-200) !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02) !important;
}

/* Specific background and colors for non-primary filter elements */
#globalSearchInput,
.search-input,
button.search-input,
select.search-input,
input.search-input,
.btn-premium-outline {
    background-color: var(--gray-50) !important;
    color: var(--gray-800) !important;
}

/* Ensure centering for buttons */
button.search-input,
.btn-premium {
    display: inline-flex !important;
    align-items: center !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    line-height: normal !important;
}

/* Mimic select appearance for button.search-input */
select.search-input,
button.search-input {
    cursor: pointer !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    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='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 16px center !important;
    padding-right: 40px !important;
    text-align: left !important;
    justify-content: flex-start !important;
}

/* Search input with icons adjustments */
#globalSearchInput {
    padding-left: 48px !important;
}

.search-input:not(#globalSearchInput) {
    padding-left: 16px !important;
}

#globalSearchInput:focus,
.search-input:focus {
    background-color: white !important;
    border-color: var(--primary-color) !important;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1), 0 10px 15px -3px rgba(0, 0, 0, 0.05) !important;
    outline: none !important;
    transform: translateY(-1px) !important;
}


/* Grid Layouts */
/* Grid Layouts - FIXED: Using minmax(0, 1fr) to prevent overflow */
.grid-3-cols {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
}

.grid-2x2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

@media (max-width: 1400px) {
    /* Increased breakpoint for better readability on laptops */

    .grid-3-cols,
    .charts-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {

    .grid-3-cols,
    .charts-grid,
    .grid-2x2 {
        grid-template-columns: 1fr !important;
    }
}

@media (min-width: 769px) {
    .grid-2x2 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* Unified Form Control Styles - Inherit from reset */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="search"],
select,
textarea {
    width: 100%;
    height: auto;
    padding: 14px 16px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    color: var(--gray-800);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
    font-family: inherit;
    box-sizing: border-box;
}

/* Dashboard Stats Cards */
.stat-card {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
}

.stat-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-500);
    margin-top: 2px;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
    background: white;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1), 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    outline: none;
    transform: translateY(-1px);
}

input::placeholder,
textarea::placeholder {
    color: var(--gray-400);
    font-weight: 400;
    font-size: 15px;
}

/* Base Select specific styling (overridden by .search-input rules if applicable) */
select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

/* Date input specific styling - normalize appearance */
input[type="date"],
input[type="datetime-local"],
input[type="time"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

/* Ensure date inputs have consistent internal spacing */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.6;
    padding-left: 8px;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

/* Textarea specific */
textarea {
    resize: vertical;
    min-height: 100px;
}

/* Hide internal card borders and content when parent is collapsed */
.collapsed-container {
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.collapsed-container[style*="max-height: 0px"] {
    overflow: hidden !important;
}

.collapsed-container[style*="max-height: 0px"] .dashboard-card {
    border-top-color: transparent !important;
    opacity: 0;
}

.search-loader {
    position: absolute;
    right: 12px;
    width: 16px;
    height: 16px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.late-item--tasca {
    border: 1px solid #fecaca;
    background: rgba(239, 68, 68, 0.02);
}

.late-item--tasca:hover {
    background: rgba(239, 68, 68, 0.05);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.search-results-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--gray-200);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    padding: 8px;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--gray-700);
    transition: background 0.2s ease;
}

.search-result-item:hover {
    background: var(--gray-50);
}

.search-result-icon {
    font-size: 18px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    border-radius: 6px;
    overflow: hidden;
}

.search-result-info {
    display: flex;
    flex-direction: column;
}

.search-result-type {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--gray-400);
    letter-spacing: 0.05em;
}

.search-result-title {
    font-size: 13px;
    font-weight: 500;
}

.search-no-results {
    padding: 16px;
    text-align: center;
    color: var(--gray-500);
    font-size: 14px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.header-user {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
}

.header-user:hover {
    background: var(--gray-100);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gray-400), var(--gray-600));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 16px;
    /* Increased for emoji */
}

.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--gray-900);
}

.user-role {
    font-size: 10px;
    color: var(--gray-600);
    text-transform: capitalize;
    background: var(--gray-100);
    padding: 1px 6px;
    border-radius: 4px;
    width: fit-content;
    font-weight: 500;
}

/* Ocultar user info en móvil */
@media (max-width: 768px) {
    .user-info {
        display: none;
    }
}

/* SESSION CLOCK */
.session-clock {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    transition: all 0.3s ease;
    cursor: help;
}

.session-clock:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

.session-clock.warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}

.session-clock.critical {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #dc3545;
    animation: pulse 1s infinite;
}

.clock-icon {
    font-size: 16px;
}

.clock-time {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    min-width: 45px;
}

/* ========================================
   SIDEBAR
   ======================================== */

.sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    bottom: 0;
    width: var(--sidebar-width);
    background: white;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-right: 1px solid var(--glass-border);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    /* Removed padding to allow edge-to-edge links */
    z-index: 1002;
    transition: width var(--transition-speed);
}

/* Sidebar colapsado en desktop */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    padding: 0;
}

.sidebar.collapsed .sidebar-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-link,
.sidebar.collapsed .sidebar-nav a {
    justify-content: center;
    padding: 0.75rem var(--spacing-sm);
}

.sidebar.collapsed .sidebar-icon,
.sidebar.collapsed .nav-icon {
    margin-right: 0;
}

/* Sidebar oculto en móvil por defecto */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
        width: var(--sidebar-width);
        /* Asegurar ancho fijo al abrir */
    }

    /* Ocultar texto inicialmente en móvil para que no 'baile' */
    .sidebar .sidebar-text {
        opacity: 0;
        transition: opacity 0.2s;
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.active .sidebar-text {
        opacity: 1;
    }
}

/* Sidebar en Desktop: Modo Hover Expandible */
@media (min-width: 769px) {

    /* Estado inicial: Colapsado (solo iconos) */
    .sidebar {
        width: var(--sidebar-collapsed-width);
        overflow-y: auto;
        overflow-x: hidden;
        white-space: nowrap;
        transition: width 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        scrollbar-width: none;
        z-index: 1001;
        /* Above header if expanding */
    }

    /* Chrome/Safari/Edge: Ocultar scrollbar cuando colapsado */
    .sidebar:not(:hover)::-webkit-scrollbar {
        display: none;
    }

    .sidebar .sidebar-text,
    .sidebar .logo-text,
    .sidebar .nav-text,
    .sidebar .sidebar-category {
        opacity: 0;
        visibility: hidden;
        max-width: 0;
        white-space: nowrap;
        overflow: hidden;
        transition: opacity 0.2s, max-width 0.3s;
    }

    .sidebar .header-search {
        display: none;
    }

    /* Estado Expandido Bloqueado */
    .sidebar.expanded {
        width: var(--sidebar-width);
    }

    .sidebar.expanded .sidebar-text,
    .sidebar.expanded .nav-text,
    .sidebar.expanded .sidebar-category {
        opacity: 1;
        visibility: visible;
        max-width: 200px;
    }

    /* Hover solo cuando no está forzado expandido */
    .sidebar:not(.expanded):hover {
        width: var(--sidebar-width);
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.1);
    }

    .sidebar.expanded .sidebar-text,
    .sidebar.expanded .nav-text,
    .sidebar.expanded .sidebar-category,
    .sidebar:hover .sidebar-text,
    .sidebar:hover .nav-text,
    .sidebar:hover .sidebar-category {
        opacity: 1;
        visibility: visible;
        max-width: 250px;
        transition-delay: 0.05s;
    }

    /* Ajustar enlaces */
    .sidebar:not(.expanded) .sidebar-link,
    .sidebar:not(.expanded) .sidebar-nav a {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    .sidebar:not(.expanded) .sidebar-icon {
        margin-right: 0;
    }

    .sidebar .sidebar-text {
        margin-left: 0;
    }

    .sidebar .sidebar-link,
    .sidebar .sidebar-nav a {
        padding: 0.8rem 0;
        gap: 0;
    }

    .sidebar.expanded .sidebar-link,
    .sidebar.expanded .sidebar-nav a,
    .sidebar:hover .sidebar-link,
    .sidebar:hover .sidebar-nav a {
        padding-right: var(--spacing-md);
        justify-content: flex-start;
    }

    /* Main content ajustado al ancho dinámico */
    .main-content {
        margin-left: var(--sidebar-collapsed-width);
        padding-top: var(--header-height);
        transition: margin-left 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        min-height: calc(100vh - var(--header-height));
        display: flex;
        flex-direction: column;
    }

    .main-content.expanded {
        margin-left: var(--sidebar-width);
    }

    .container-fluid-max {
        max-width: 100%;
        width: 100%;
        padding: var(--spacing-lg);
    }
}

.sidebar.active {
    transform: translateX(0);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}


/* Overlay para cerrar sidebar en móvil */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: 100%;
    height: calc(100vh - var(--header-height));
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    padding: var(--spacing-md) 0;
}

.sidebar-nav a,
.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: 0.8rem var(--spacing-lg);
    color: var(--gray-600);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
    width: 100%;
}

.sidebar-nav a:hover,
.sidebar-link:hover {
    background: var(--gray-50);
    color: var(--primary-color);
}

.sidebar-nav a.active,
.sidebar-link.active {
    background: rgba(37, 99, 235, 0.05);
    color: var(--primary-color);
    font-weight: 700;
}

.sidebar-nav a.active::before,
.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary-color);
    z-index: 10;
}

.sidebar-icon,
.nav-icon {
    font-size: 1.2rem;
    width: var(--sidebar-collapsed-width);
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    color: var(--gray-500);
}

.sidebar-link.active .sidebar-icon,
.sidebar-nav a.active .sidebar-icon {
    color: var(--primary-color);
    transform: scale(1.1);
}

.sidebar-text {
    transition: opacity var(--transition-speed) ease, width var(--transition-speed) ease;
    white-space: nowrap;
}

/* Separador */
.sidebar-separator {
    height: 1px;
    background: var(--gray-100);
    margin: var(--spacing-sm) var(--spacing-md);
}

/* Scrollbar personalizado */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

/* ========================================
   MAIN CONTENT
   ======================================== */

.main-content {
    margin-left: var(--sidebar-collapsed-width);
    margin-top: var(--header-height);
    padding: var(--spacing-md);
    min-height: calc(100vh - var(--header-height));
    transition: margin-left var(--transition-speed) ease;
}

@media (max-width: 768px) {
    .main-content {
        padding: var(--spacing-md);
    }
}

/* Main content con sidebar colapsado */
.main-content.expanded {
    margin-left: var(--sidebar-collapsed-width);
}

/* Main content en móvil */
/* Main content en móvil */
@media (max-width: 768px) {
    .main-content {
        margin-left: 0;
        padding: var(--spacing-sm);
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }
}

.container {
    width: 100%;
    max-width: 100%;
    /* Full width */
    margin: 0 auto;
    padding: 0 var(--spacing-md);
    /* Add horizontal padding for breathing room */
}

/* Remove restrictive max-width media query */
@media (max-width: 1800px) {
    .container {
        max-width: 100%;
    }
}

@media (min-width: 1801px) {
    .container {
        max-width: 100%;
        padding: 0 var(--spacing-2xl);
    }
}

/* ========================================
   RESPONSIVE UTILITIES
   ======================================== */

.grid-2-cols {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-lg);
}

.grid-responsive {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--spacing-lg);
}

.grid-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
}

.grid-stats-reforc {
    display: grid !important;
    grid-template-columns: repeat(6, 1fr) !important;
    gap: var(--spacing-md);
    width: 100% !important;
}

.grid-stats-reforc .stat-card {
    justify-content: center;
    /* Centra el contingut horitzontalment dins la targeta */
    min-width: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.grid-stats-reforc .stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color-light);
    background-color: var(--gray-50);
}

.grid-stats-reforc .stat-card:active {
    transform: translateY(0);
}

@media (max-width: 1200px) {
    .grid-stats-reforc {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

@media (max-width: 768px) {

    .grid-2-cols,
    .grid-responsive {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }

    .grid-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-sm);
    }

    .container {
        padding: 0 var(--spacing-sm) !important;
    }

    .stat-card {
        padding: var(--spacing-md);
        gap: var(--spacing-sm);
    }

    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: block !important;
    }

    /* Ajustos per a les targetes de reforç a mòbil */
    .grid-stats-reforc .stat-card {
        flex-direction: column;
        text-align: center;
        padding: var(--spacing-sm);
        gap: var(--spacing-xs);
        min-width: 0;
        /* Evita que creixin més del 1fr del grid */
    }

    .grid-stats-reforc .stat-icon {
        width: 32px;
        height: 32px;
        margin: 0 auto;
    }

    .grid-stats-reforc .stat-icon span {
        font-size: 18px !important;
    }

    .grid-stats-reforc .stat-value {
        font-size: 16px;
    }

    .grid-stats-reforc .stat-label {
        font-size: 9px;
        line-height: 1.1;
        white-space: normal;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 13px;
        /* Compact view as requested (simulates ~90%) */
    }

}

.show-mobile {
    display: none;
}

.grid-stack-mobile {
    display: grid;
    gap: var(--spacing-md);
}

@media (max-width: 768px) {
    .grid-stack-mobile {
        grid-template-columns: 1fr !important;
    }
}

/* ========================================
   PAGE HEADER
   ======================================== */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
}

.page-header p {
    color: var(--gray-600);
    margin-top: var(--spacing-xs);
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header h1 {
        font-size: 24px;
    }

    .page-header>div:last-child {
        display: flex;
        gap: var(--spacing-sm);
        flex-wrap: wrap;
    }
}

/* ========================================
   STATS GRID
   ======================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: var(--spacing-md);
    }
}


.stat-card {
    background: white;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--gray-100);
    text-decoration: none;
    color: inherit;
}

.stat-card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border-color: rgba(37, 99, 235, 0.2);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1;
}

.stat-label {
    font-size: 13px;
    color: var(--gray-600);
    margin-top: var(--spacing-xs);
    font-weight: 500;
}

/* ========================================
   PREMIUM ACTION BAR & BUTTONS
   ======================================== */
.action-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.status-group-premium {
    display: flex;
    align-items: center;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 2px;
    height: 42px;
}

.status-group-label {
    padding: 0 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    border-right: 1px solid var(--gray-200);
    height: 100%;
    display: flex;
    align-items: center;
}

.status-group-premium select {
    background: transparent;
    border: none;
    font-weight: 700;
    padding: 0 10px;
    height: 100%;
    cursor: pointer;
    font-size: 14px;
    outline: none;
}

.status-group-value {
    padding: 0 16px;
    font-size: 14px;
    font-weight: 700;
}

.status-group-value.status-pendent {
    color: #f59e0b;
}

.status-group-value.status-en-proces {
    color: #2563eb;
}

.status-group-value.status-completat {
    color: #10b981;
}

.status-group-value.status-cancellat {
    color: #ef4444;
}

.btn-premium {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px;
    padding: 0 24px;
    height: 48px;
    /* Unified weight for filter bar buttons */
    min-width: 140px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 14px;
    line-height: 1 !important;
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    white-space: nowrap;
    box-sizing: border-box;
    vertical-align: middle;
}

.btn-premium-sm {
    padding: 0 16px;
    height: 36px;
    min-width: 100px;
    font-size: 13px;
    border-radius: 8px;
}

.btn-premium:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn-premium:active {
    transform: translateY(0);
}

.btn-premium-blue {
    background: #2563eb;
    color: white !important;
}

.btn-premium-orange {
    background: #f59e0b;
    color: white !important;
}

.btn-premium-orange:hover {
    background: #d97706;
}

.btn-premium-purple {
    background: #9333ea;
    color: white !important;
}

.btn-premium-purple:hover {
    background: #7e22ce;
}

.btn-premium-indigo {
    background: #4f46e5;
    color: white !important;
}

.btn-premium-indigo:hover {
    background: #4338ca;
}

.btn-premium-teal {
    background: #0d9488;
    color: white !important;
}

.btn-premium-teal:hover {
    background: #0f766e;
}

.btn-premium-blue:hover {
    background: #1d4ed8;
}

.btn-premium-red {
    background: #ef4444;
    color: white !important;
}

.btn-premium-red:hover {
    background: #dc2626;
}

.btn-premium-soft-red {
    background: #fecaca !important;
    /* Rojo claro pastel */
    color: #991b1b !important;
    /* Rojo oscuro para contraste */
    border: 1px solid #f87171 !important;
}

.btn-premium-soft-red:hover {
    background: #fee2e2 !important;
    color: #7f1d1d !important;
}

.btn-premium-gray {
    background: #f1f5f9;
    color: #475569 !important;
}

.btn-premium-gray:hover {
    background: #e2e8f0;
}

.btn-premium-vibrant-blue {
    background: #0070c1;
    color: white !important;
}

.btn-premium-vibrant-blue:hover {
    background: #005a9e;
}

.btn-premium-excel {
    background-color: #217346 !important;
    color: white !important;
    white-space: nowrap !important;
}

.btn-premium-excel:hover {
    background-color: #1a5c38 !important;
}

.btn-premium-outline {
    background: white;
    border: 1px solid var(--gray-200);
    color: var(--gray-700);
}

.btn-premium-outline:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

.btn-premium .material-symbols-outlined,
.btn-premium .ms-Icon,
.btn .material-symbols-outlined,
.btn .ms-Icon {
    font-size: 20px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    vertical-align: middle;
    min-width: 1em;
    min-height: 1em;
}

.ms-Icon {
    font-style: normal;
    font-weight: normal;
}

/* ========================================
   BADGES
   ======================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.badge-info {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.badge--admin {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.badge--referent {
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
}

.badge--oficina {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

/* Blue/Indigo */

/* ========================================
   BUTTONS
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    border: 1px solid transparent;
    white-space: nowrap;
}

.btn:hover {
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: scale(0.98);
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.4);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    /* transform: translateY(-1px); */
    /* Removed as new .btn:hover handles transform */
    /* box-shadow: var(--shadow-md); */
    /* Removed as new .btn:hover handles box-shadow */
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-200);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}

.btn-outline:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.btn-sm {
    padding: 0.5rem var(--spacing-md);
    font-size: 13px;
}

@media (max-width: 768px) {
    .btn {
        font-size: 13px;
        padding: 0.5rem var(--spacing-md);
    }
}

/* ========================================
   FILTROS (Single Row)
   ======================================== */
.filters-form {
    display: flex;
    flex-wrap: nowrap;
    /* Force single row on desktop */
    align-items: center;
    gap: var(--spacing-md);
    width: 100%;
}

.filters-form .search-input,
.filters-form select.search-input {
    flex: 1;
    /* Distribute space evenly */
    margin: 0;
    min-width: 150px;
    /* Prevent too narrow inputs */
}

.filters-form .btn {
    white-space: nowrap;
    flex-shrink: 0;
    /* Keep buttons from shrinking */
}

@media (max-width: 1200px) {
    .filters-form {
        flex-wrap: wrap;
        /* Allow wrapping on smaller desktop/tablets if needed */
    }
}

@media (max-width: 768px) {
    .filters-form {
        flex-direction: column;
        /* Stack on mobile */
        align-items: stretch;
    }

    .filters-form .search-input,
    .filters-form select.search-input {
        width: 100%;
    }
}

/* ========================================
   CARDS Y DASHBOARD
   ======================================== */

.dashboard-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--gray-100);
}

.dashboard-card:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
    border-color: rgba(37, 99, 235, 0.1);
}

.card-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-900);
}

.card-body {
    padding: var(--spacing-lg);
}

@media (max-width: 768px) {

    .card-header,
    .card-body {
        padding: var(--spacing-md);
    }
}

/* ========================================
   TABLES
   ======================================== */

.table-responsive {
    /* overflow: visible is required to allow position: sticky to reach the viewport */
    overflow: visible !important;
}

@media (max-width: 1024px) {
    .table-responsive {
        /* On smaller screens, allow horizontal scroll even if it breaks vertical stickiness */
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
    border-radius: var(--radius-lg);
    /* overflow: hidden removed to allow sticky headers to work */
    box-shadow: var(--shadow-sm);
}

/* Explicitly hide the incorrect property if needed, but better to remove it */
.table {
    /* Fixed typo: changed from border-hidden: hidden; */
    border-style: hidden;
}

.table thead th {
    background: var(--gray-50);
    padding: 0.75rem var(--spacing-md);
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    z-index: 20;
    /* Evitar que el header desaparezca al hacer scroll rápido */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    /* Prevent background from bleeding into borders */
    background-clip: padding-box;
    /* Consistent border for sticky header */
    border-bottom: 2px solid var(--gray-200);
}

/* Fix for table overlap: Ensure container has enough top margin or the table has breathing room */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 1px;
    /* Help with sticky positioning edge cases */
}

.table td {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
    /* Force single line */
    vertical-align: middle;
}

/* Ensure actions column buttons stay inline */
.table td:last-child {
    width: 1%;
    /* Shrink to fit content */
    white-space: nowrap;
}

/* Target the div inside the last column to force row */
.table td:last-child>div {
    display: flex !important;
    flex-wrap: nowrap !important;
    justify-content: flex-end;
    gap: var(--spacing-sm);
}

.table tbody tr:hover {
    background: var(--gray-50);
}

@media (max-width: 768px) {
    .table {
        font-size: 13px;
    }

    .table th,
    .table td {
        padding: var(--spacing-sm);
    }

    .table .hide-mobile {
        display: none;
    }
}

/* ========================================
   FORMS
   ======================================== */

.form-group {
    margin-bottom: var(--spacing-lg);
}

/* Formulario de filtros responsivo
   Desktop: Flex horizontal (como antes)
   Mobile: Stack vertical */
.filters-form {
    display: flex;
    gap: var(--spacing-md);
    align-items: center;
    flex-wrap: wrap;
}

.filters-form .search-input,
.filters-form .form-control,
.filters-form select,
.filters-form input {
    margin: 0;
    min-width: 150px;
    /* Ancho base razonable para PC */
}

/* Specific preference for search bar to be wider on PC if possible, but not forced */
.filters-form input[name="search"] {
    flex: 1;
    min-width: 250px;
}

@media (max-width: 768px) {
    .filters-form {
        display: grid;
        grid-template-columns: 1fr;
        align-items: stretch;
        gap: var(--spacing-md);
    }

    .filters-form .search-input,
    .filters-form input,
    .filters-form select {
        width: 100% !important;
        min-width: 0;
        flex: none;
    }
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    color: var(--gray-900);
    font-size: 13px;
}

.form-control,
.form-input,
select.search-input,
textarea.search-input {
    width: 100%;
    padding: 0.625rem var(--spacing-md);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 14px;
    transition: all 0.2s;
    font-family: var(--font-sans);
}

.form-control:focus,
.form-input:focus,
.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea.form-control,
textarea.search-input {
    resize: vertical;
    min-height: 100px;
}

/* Grids de formularios responsive */
@media (max-width: 768px) {
    [style*="grid-template-columns: repeat(2"] {
        grid-template-columns: 1fr !important;
    }
}

/* ========================================
   PROGRESS BAR
   ======================================== */

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--gray-200);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 999px;
    transition: width 0.5s ease;
}

/* Badges y Status */
.print-info {
    display: none;
}

/* Badges y Status */
.print-info {
    display: none;
}

.badge,
.status {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

/* Variants d'estat (Badges lleugers corregits) */
.badge-primary,
.status--info {
    background: rgba(59, 130, 246, 0.1);
    /* Blau clar */
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.4);
}

.badge-danger,
.status--danger {
    background: rgba(239, 68, 68, 0.1);
    /* Vermell */
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-success,
.status--success {
    background: rgba(16, 185, 129, 0.1);
    /* Verd */
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.badge-warning,
.status--warning {
    background: rgba(245, 158, 11, 0.1);
    /* Groc/Taronja */
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.4);
}

.badge-info,
.status--accent {
    background: rgba(6, 182, 212, 0.1);
    color: var(--accent-color);
    border: 1px solid rgba(6, 182, 212, 0.4);
}

.badge-purple,
.status--purple {
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
    border: 1px solid rgba(139, 92, 246, 0.4);
}

.badge-secondary,
.status--neutral {
    background: rgba(107, 114, 128, 0.1);
    color: var(--gray-600);
    border: 1px solid rgba(107, 114, 128, 0.4);
}

/* Rols d'usuari */
.badge--admin {
    background: rgba(239, 68, 68, 0.1);
    color: #b91c1c;
    /* Red 700 for better contrast on light bg */
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge--referent {
    background: rgba(59, 130, 246, 0.1);
    color: #1d4ed8;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.badge--oficina {
    background: rgba(107, 114, 128, 0.1);
    color: #374151;
    border: 1px solid rgba(107, 114, 128, 0.2);
}

/* Categories de Log */
.badge--log-acces {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.badge--log-sistema {
    background: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.badge--log-dades {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge--log-seguretat {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge--log-error {
    background: rgba(244, 63, 94, 0.1);
    color: #e11d48;
    border: 1px solid rgba(244, 63, 94, 0.2);
}

/* ========================================
   GRIDS RESPONSIVE
   ======================================== */

/* Grids de 2 columnas → 1 columna en móvil */
@media (max-width: 768px) {

    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns: repeat(2, 1fr)"] {
        grid-template-columns: 1fr !important;
    }
}

/* ========================================
   UTILITIES
   ======================================== */

.text-muted {
    color: var(--gray-600);
}

.mt-4 {
    margin-top: var(--spacing-lg);
}

/* Ocultar en móvil */
.hide-on-mobile {
    display: block;
}

@media (max-width: 768px) {
    .hide-on-mobile {
        display: none !important;
    }
}

/* Mostrar solo en móvil */
.show-on-mobile {
    display: none;
}

@media (max-width: 768px) {
    .show-on-mobile {
        display: block !important;
    }
}

/* ========================================
   ANIMACIONES
   ======================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

.fade-out {
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {

    .sidebar,
    .header,
    .btn,
    .sidebar-overlay {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* UI GRID FOR MOBILE (2 COLS) AND DESKTOP (FLEX ROW) */
.grid-mobile-2col {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
}

.status-selector-group {
    display: flex;
    align-items: center;
    height: 38px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    overflow: hidden;
    background: white;
}

.status-selector-group label {
    font-weight: 600;
    color: var(--gray-700);
    white-space: nowrap;
    padding: 0 12px;
    background: var(--gray-50);
    border-right: 1px solid var(--gray-200);
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 14px;
}

.status-selector-group select {
    margin: 0 !important;
    padding: 0 12px !important;
    height: 100% !important;
    font-weight: 500;
    border: none !important;
    font-size: 14px !important;
    color: var(--gray-900);
    background: transparent;
    cursor: pointer;
}

@media (max-width: 768px) {

    /* PREVENT iOS ZOOM on focus */
    .form-control,
    .search-input,
    .form-input,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* IMPROVE TOUCH TARGETS */
    .btn,
    .sidebar-link,
    button,
    select {
        min-height: 44px;
        /* Apple Interface Guidelines */
    }

    .w-mobile-100 {
        width: 100% !important;
    }

    .flex-mobile-wrap {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
    }

    .grid-mobile-2col {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        width: 100%;
        margin-top: 8px;
    }

    .grid-mobile-2col>* {
        width: 100% !important;
        margin: 0 !important;
    }

    .status-selector-group {
        height: 44px !important;
        /* Match buttons on mobile */
    }

    /* MOBILE ORDERING: 
       HTML Order: 1.Status, 2.Editar, 3.Eliminar, 4.Imprimir, 5.Reenviar, 6.Tornar
       Mobile Order: Row 1: Status(1), Tornar(6) | Row 2: Editar(2), Eliminar(3) | Row 3: Imprimir(4), Reenviar(5)
    */
    .grid-mobile-2col>*:nth-child(1) {
        order: 1;
    }

    /* Status */
    .grid-mobile-2col>*:nth-child(2) {
        order: 3;
    }

    /* Editar */
    .grid-mobile-2col>*:nth-child(3) {
        order: 4;
    }

    /* Eliminar */
    .grid-mobile-2col>*:nth-child(4) {
        order: 5;
    }

    /* Imprimir */
    .grid-mobile-2col>*:nth-child(5) {
        order: 6;
    }

    /* Reenviar */
    .grid-mobile-2col>*:nth-child(6) {
        order: 2;
    }

    /* Tornar (moves to row 1, col 2) */

    .flex-mobile-wrap>* {
        width: 100% !important;
        margin: 0 !important;
        justify-content: center !important;
    }

    /* TABLE ADJUSTMENTS */
    .table td {
        white-space: normal;
        /* Allow text wrapping in cells if needed */
        min-width: 120px;
        /* Minimum width for readability */
    }

    /* STATUS BADGES */
    .badge,
    .status {
        white-space: nowrap;
    }

    /* Ocultar text dels botons d'acció a les taules i dashboard */
    .table .btn .btn-text,
    .late-item-actions .btn .btn-text,
    .late-item-header .btn .btn-text {
        display: none;
    }

    .table .btn {
        padding: 6px 10px !important;
        min-width: unset !important;
    }

    /* DETAILS VIEW RESPONSIVENESS */
    .details-header-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px;
    }

    .details-header-row>div {
        width: 100%;
    }

    /* Ensure status badge aligns left on mobile if needed */
    .details-header-row span {
        align-self: flex-start;
        margin-top: 4px;
    }

    .details-info-grid,
    .details-info-grid-small {
        grid-template-columns: 1fr !important;
        /* Force single column on mobile */
    }

    /* OVERFLOW PREVENTION */
    .details-description-box,
    .details-info-grid div,
    .details-info-grid-small div,
    .details-header-row div {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        word-break: break-word !important;
        max-width: 100% !important;
    }

    .details-description-box {
        background: var(--gray-50);
        padding: 12px !important;
        /* Slightly less padding on mobile */
        border-radius: 8px;
        border-left: 4px solid var(--primary-color);
        font-size: 14px !important;
        line-height: 1.6;
    }
}

/* Default Desktop Styles (Defined outside media query) */
.details-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--gray-200);
}

.details-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.details-info-grid-small {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* Help Modal Styles */
.help-section {
    padding: 24px;
    border-bottom: 1px solid var(--gray-200);
}

.help-section:last-child {
    border-bottom: none;
}

.help-title {
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    margin-bottom: 16px;
}

.help-content h4 {
    color: var(--gray-800);
    margin-top: 16px;
    margin-bottom: 8px;
    font-size: 1rem;
}

.help-content ul {
    padding-left: 20px;
    color: var(--gray-600);
    line-height: 1.6;
    margin-bottom: 16px;
}

.help-content li {
    margin-bottom: 4px;
}

.badge-help {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

details summary {
    padding: 12px;
    background: var(--gray-50);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    color: var(--gray-800);
    transition: background 0.2s;
}

details summary:hover {
    background: var(--gray-100);
}

details[open] summary {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-bottom: 0;
}

details .content {
    padding: 16px;
    border: 1px solid var(--gray-100);
    border-top: none;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

/* ========================================
   MOBILE HEADER OVERRIDES (Critial)
   ======================================== */
@media (max-width: 768px) {

    /* Amagar text del logo */
    .logo span {
        display: none !important;
    }

    /* Botó de sortir: Mostrar botó, amagar text */
    .header-actions .btn[href*="logout.php"] {
        display: inline-flex !important;
        /* Restore display */
    }

    .header-actions .btn[href*="logout.php"] .btn-text {
        display: none !important;
        /* Hide text only */
    }

    /* Reduir espaiat */
    .header-actions {
        gap: 6px !important;
        justify-self: end !important;
        /* Even tighter gap */
    }
}

/* ========================================
   MOBILE AVATAR VISIBILITY (Critical)
   ======================================== */
@media (max-width: 768px) {
    .user-avatar {
        width: 34px !important;
        height: 34px !important;
        font-size: 18px !important;
        /* Larger for mobile emoji */
        font-weight: normal !important;
        line-height: 1 !important;
        color: #ffffff !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        overflow: visible !important;
        flex-shrink: 0 !important;
        background: linear-gradient(135deg, var(--gray-400), var(--gray-600)) !important;
        -webkit-text-fill-color: #ffffff !important;
        /* Force safari text fill */
    }
}

/* ========================================
   MOBILE SESSION CLOCK VISIBILITY
   ======================================== */
@media (max-width: 768px) {
    #sessionClock {
        display: none !important;
    }
}

/* ========================================
   MOBILE HEADER GRID FIX (Critical)
   ======================================== */
@media (max-width: 768px) {

    /* Override inline grid from headers.php */
    .header-container {
        display: grid !important;
        grid-template-columns: auto 1fr auto !important;
    }

    .header-left {
        justify-self: start !important;
    }

    .header-search {
        display: none !important;
    }

    .header-actions {
        justify-self: end !important;
    }
}

/* ========================================
   MOBILE TABLE STICKY HEADER FIX
   ======================================== */
@media (max-width: 768px) {}

.servei-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.servei-card-icon {
    font-size: 32px;
}

.servei-card-title {
    font-size: 16px;
    color: var(--gray-900);
    margin: 0;
    line-height: 1.2;
}

.servei-card-subtitle {
    font-size: 12px;
    color: var(--gray-500);
    font-weight: 400;
    font-style: italic;
    margin-left: 4px;
}

.stat-item {
    padding: 12px;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-item--success {
    background: rgba(16, 185, 129, 0.05);
    border-left: 3px solid #10b981;
}

.stat-item--danger {
    background: rgba(239, 68, 68, 0.05);
    border-left: 3px solid #ef4444;
}

.stat-item--total {
    background: var(--gray-50);
    padding: 8px 12px;
}

.stat-item-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
}

.stat-item-label--total {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-600);
}

.stat-item-value {
    font-size: 20px;
    font-weight: 600;
}

.stat-item-value--success {
    color: #10b981;
}

.stat-item-value--danger {
    color: #ef4444;
}

.stat-item-value--total {
    font-size: 16px;
    color: var(--gray-900);
}

.late-item {
    padding: 16px;
    border-radius: 8px;
    display: grid;
    gap: 8px;
    transition: all 0.2s ease;
}

.late-item--recordatori {
    border: 1px solid #fecaca;
    background: rgba(239, 68, 68, 0.02);
}

.late-item--recordatori:hover {
    background: rgba(239, 68, 68, 0.05);
}

.late-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.late-item-ref {
    font-family: var(--font-family-mono);
    font-weight: 600;
    font-size: 14px;
}

.late-item-ref--danger {
    color: #ef4444;
}

.late-item-date {
    font-size: 13px;
    color: var(--gray-600);
}

.late-badge {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
}

.late-badge--danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.late-badge--info {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.late-item-details {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 13px;
    color: var(--gray-700);
}

.late-item-actions {
    display: flex;
    gap: 8px;
    padding-top: 8px;
}

.late-item-actions--bordered {
    border-top: 1px solid #fecaca;
}

.pending-item {
    padding: 16px;
    border-radius: 8px;
    display: grid;
    gap: 8px;
    transition: all 0.2s ease;
}

.pending-item:hover {
    background: var(--gray-50);
}

.pending-item--orange {
    border: 1px solid #fde68a;
    background: rgba(245, 158, 11, 0.02);
}

.pending-item--orange:hover {
    background: rgba(245, 158, 11, 0.05);
}

@keyframes pulse-light-error {
    0% {
        border-color: #fecaca;
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.1);
    }

    50% {
        border-color: #ef4444;
        box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.05);
    }

    100% {
        border-color: #fecaca;
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.1);
    }
}

.pending-item--danger {
    border: 1px solid #fecaca;
    background: rgba(239, 68, 68, 0.02);
    animation: pulse-light-error 3s infinite ease-in-out;
}

.pending-item--danger:hover {
    background: rgba(239, 68, 68, 0.05);
    animation: none;
    /* Se detiene al pasar el ratón para facilitar la lectura/clic */
}

.pending-item-desc {
    font-size: 13px;
    color: var(--gray-600);
    padding-top: 8px;
    border-top: 1px solid var(--gray-200);
}

.pending-item--today {
    border: 1px solid #f59e0b;
    background: rgba(245, 158, 11, 0.15);
    border-left: 4px solid #f59e0b;
}

.pending-item--today:hover {
    background: rgba(245, 158, 11, 0.25);
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    width: 320px;
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 16px;
    border-left: 4px solid var(--primary-color);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.toast--entering {
    transform: translateX(120%);
    opacity: 0;
}

.toast--leaving {
    transform: translateX(120%);
    opacity: 0;
}

.toast--success {
    border-left-color: var(--success-color);
}

.toast--error {
    border-left-color: var(--danger-color);
}

.toast--warning {
    border-left-color: var(--warning-color);
}

.toast--info {
    border-left-color: var(--primary-color);
}

.toast__icon {
    font-size: 20px;
    flex-shrink: 0;
}

.toast__content {
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-800);
    flex-grow: 1;
    line-height: 1.4;
}

.toast__close {
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    color: var(--gray-400);
    transition: color 0.2s;
    line-height: 1;
}

.toast__close:hover {
    color: var(--gray-700);
}

@media (max-width: 480px) {
    .toast-container {
        top: auto;
        bottom: 24px;
        left: 24px;
        right: 24px;
    }

    .toast {
        width: 100%;
    }
}

/* SEARCH RESULTS ENHANCEMENTS */
.search-group-header {
    padding: 8px 12px;
    background-color: var(--gray-50);
    color: var(--gray-500);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--gray-100);
}

.search-result-item.selected {
    background-color: var(--primary-color) !important;
    color: white !important;
}

.search-result-item.selected .search-result-title,
.search-result-item.selected .search-result-icon {
    color: white !important;
}

/* ========================================
   MICRO-ANIMACIONES Y POLISH
   ======================================== */

.stat-card,
.dashboard-card,
.btn,
.sidebar-link {
    transition: all var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
    border-color: var(--primary-light);
}

.btn:active {
    transform: scale(0.95);
}

/* Glass effect for cards */
.dashboard-card,
.stat-card {
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

/* Skeleton Loading */
.skeleton {
    position: relative;
    overflow: hidden;
    background-color: var(--gray-200);
    border-radius: var(--radius-sm);
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}

.skeleton::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    background-image: linear-gradient(90deg,
            rgba(255, 255, 255, 0) 0,
            rgba(255, 255, 255, 0.2) 20%,
            rgba(255, 255, 255, 0.5) 60%,
            rgba(255, 255, 255, 0));
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    100% {
        transform: translateX(100%);
    }
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5rem;
    width: 80%;
}

.skeleton-value {
    height: 2rem;
    width: 50%;
    margin-bottom: 0.25rem;
}

/* ========================================
   AUDIT / SYSTEM INFO FOOTER
   ======================================== */
.audit-footer {
    margin-top: 24px;
    padding: 12px 16px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #64748b;
    flex-wrap: wrap;
    gap: 12px;
}

.audit-footer div,
.audit-footer span,
.audit-footer strong {
    font-size: 11.5px;
    line-height: 1.4;
}

.audit-footer strong {
    color: #475569;
}

.audit-footer-left {
    text-align: left;
    display: flex;
    align-items: center;
}

.audit-footer-right {
    text-align: right;
    display: flex;
    align-items: center;
    gap: 12px;
}

.audit-footer-separator {
    width: 1px;
    height: 14px;
    background: #e2e8f0;
}

@media (max-width: 768px) {
    .audit-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 14px;
    }

    .audit-footer-left,
    .audit-footer-right {
        text-align: left;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .audit-footer-separator {
        display: none;
    }
}

/* Badge Styles for Email Types */
.badge-purple {
    background-color: #f3e8ff;
    color: #7e22ce;
    border: 1px solid #d8b4fe;
}

.badge-blue {
    background-color: #dbeafe;
    color: #1d4ed8;
    border: 1px solid #93c5fd;
}

/* Utilitats */
@media (max-width: 768px) {
    .hide-on-mobile {
        display: none !important;
    }
}