:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #0f172a;
    --light: #f8fafc;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 80px;
    --header-height: 70px;
    --sidebar-bg: #1e293b;
    --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --card-radius: 12px;
}

* {
    box-sizing: border-box;
}

body {
    background-color: var(--light);
    color: var(--dark);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    margin: 0;
    overflow-x: hidden;
}

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

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: white;
    height: 100vh;
    position: fixed;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

/* Sidebar Collapsed State */
.app-container.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

.app-container.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

.app-container.sidebar-collapsed .sidebar-header {
    justify-content: center;
    padding: 1.5rem 0;
}

.app-container.sidebar-collapsed .sidebar-header .logo-text,
.app-container.sidebar-collapsed .sidebar-menu,
.app-container.sidebar-collapsed .sidebar-footer {
    display: none !important;
}

.sidebar-toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    position: absolute;
    right: 1rem;
}

.sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.app-container.sidebar-collapsed .sidebar-toggle-btn {
    position: static;
    margin-top: 10px;
}

.mobile-close-btn {
    display: none;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.header-user {
    position: relative;
    padding: 4px;
    border-radius: 12px;
    transition: background 0.2s;
}

.header-user:hover {
    background: #f8fafc;
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 220px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    padding: 8px;
    display: none;
    flex-direction: column;
    z-index: 1000;
}

.profile-dropdown.active {
    display: flex;
}

.dropdown-header {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
}

.dropdown-header strong {
    font-size: 0.9rem;
    color: var(--dark);
    display: block;
}

.dropdown-header span {
    font-size: 0.75rem;
    color: var(--secondary);
}

.dropdown-divider {
    height: 1px;
    background: #f1f5f9;
    margin: 8px 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.875rem;
    color: #475569;
    font-weight: 500;
    transition: all 0.2s;
}

.dropdown-item:hover {
    background: #f1f5f9;
    color: var(--primary);
}

.logout-item {
    color: var(--danger);
}

.logout-item:hover {
    background: #fee2e2;
    color: var(--danger);
}

.header {
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 900;
}

.content-padding {
    padding: 2rem;
}

/* Sidebar Elements */
.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header .logo-text {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #60a5fa, #2563eb);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-menu {
    flex: 1;
    padding: 1rem 0.75rem;
    list-style: none;
    margin: 0;
    overflow-y: auto;
    scrollbar-width: thin;
}

.sidebar-menu::-webkit-scrollbar {
    width: 4px;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.menu-item {
    margin-bottom: 4px;
}

.menu-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem 1rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.menu-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.menu-link.active {
    background: var(--primary);
    color: white;
}

.menu-link svg {
    width: 20px;
    height: 20px;
}

.sidebar-footer {
    display: none;
}

/* UI Components */
.card {
    background: white;
    border-radius: var(--card-radius);
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    border: 1px solid #f1f5f9;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.icon-bg {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-bg-primary {
    background: #dbeafe;
    color: var(--primary);
}

.icon-bg-success {
    background: #dcfce7;
    color: var(--success);
}

.icon-bg-warning {
    background: #fef9c3;
    color: var(--warning);
}

.icon-bg-danger {
    background: #fee2e2;
    color: var(--danger);
}

.stat-info h3 {
    margin: 0;
    font-size: 0.875rem;
    color: var(--secondary);
    font-weight: 500;
}

.stat-info p {
    margin: 4px 0 0;
    font-size: 1.5rem;
    font-weight: 700;
}

/* Dashboard Grid v2 */
.dashboard-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-rows: auto auto;
    gap: 1.5rem;
}

.dashboard-main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.dashboard-side {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Calendar Styles */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 10px;
    margin-top: 1rem;
}

.calendar-day {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    min-height: 100px;
    transition: all 0.2s;
}

.calendar-day.is-today {
    background: #dbeafe;
    border-color: var(--primary);
}

.day-name {
    display: block;
    font-size: 0.75rem;
    color: var(--secondary);
    font-weight: 600;
    text-transform: uppercase;
}

.day-number {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    margin: 4px 0;
}

.day-events {
    font-size: 0.7rem;
    color: var(--primary);
    margin-top: 5px;
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* Alert List */
.alert-item {
    padding: 12px;
    border-left: 4px solid var(--warning);
    background: #fffbeb;
    border-radius: 4px;
    margin-bottom: 10px;
}

.alert-item.danger {
    border-left-color: var(--danger);
    background: #fef2e2;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background-color: white;
    color: var(--dark);
    font-size: 0.95rem;
    transition: all 0.2s;
    outline: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
    background-color: white;
}

.form-control::placeholder {
    color: #94a3b8;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20fill%3D%22none%22%20stroke%3D%22%2364748b%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22m6%209%206%206%206-6%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.1rem;
    padding-right: 2.5rem;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

/* Form Errors */
.form-group ul {
    list-style: none;
    padding: 0;
    margin: 8px 0 0;
    color: var(--danger);
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group ul li {
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-group ul li::before {
    content: "•";
    color: var(--danger);
    font-weight: 900;
}

/* Invalid State Highlighting */
.form-group:has(ul) .form-control {
    border-color: var(--danger);
    background-color: #fffcfc;
}

.form-group:has(ul) .form-control:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1);
}

.form-group:has(ul) .form-label {
    color: var(--danger);
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-secondary {
    background: white;
    color: #475569;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.9rem;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: var(--dark);
}

.btn-danger {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fee2e2;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.btn-danger:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    transform: translateY(-1px);
}

/* Client Selection Checkboxes */
.client-selection-container {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0.5rem;
    background: #f8fafc;
}

/* Widget Container */
.client-selection-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
}

/* Cada fila (Contenedor de Checkbox + Label) */
.client-selection-grid>div,
.client-selection-grid .form-check {
    display: flex !important;
    flex-direction: row !important;
    /* FORZAR HORIZONTAL */
    align-items: center !important;
    gap: 12px !important;
    background: white;
    padding: 8px 12px !important;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
    cursor: pointer;
}

/* En caso de que el Label envuelva al Input */
.client-selection-grid label {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 10px !important;
    margin: 0 !important;
    width: 100%;
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
}

.client-selection-grid>div:hover,
.client-selection-grid .form-check:hover {
    border-color: var(--primary);
    background: #f0f9ff;
}

/* Estilo del Checkbox */
.client-selection-grid input[type="checkbox"] {
    width: 15px !important;
    height: 15px !important;
    border-radius: 3px;
    margin: 0 !important;
    cursor: pointer;
    flex-shrink: 0;
}

/* --- Responsive Design --- */

@media (max-width: 801px) {
    :root {
        --header-height: 50px;
    }

    body {
        font-size: 14px;
        /* Slightly smaller base font */
    }

    .sidebar {
        transform: translateX(-100%);
        visibility: hidden;
        width: 260px !important;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 2000;
        box-shadow: 10px 0 25px rgba(0, 0, 0, 0.1);
        display: flex;
        flex-direction: column;
    }

    .mobile-close-btn {
        display: flex !important;
        position: absolute;
        right: 1rem;
    }

    .sidebar.active {
        transform: translateX(0);
        visibility: visible;
    }

    .main-content {
        margin-left: 0 !important;
    }

    /* Hide desktop toggle icon on mobile */
    .sidebar-toggle-btn,
    .toggle-icon {
        display: none !important;
    }

    .header {
        padding: 0 0.75rem;
    }

    .header-search {
        display: none;
    }

    .content-padding {
        padding: 1rem;
        /* Compact padding */
    }

    /* Dashboard Grid Mobile */
    .dashboard-container {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .card {
        padding: 1rem;
    }

    /* Responsive Tables */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    table {
        min-width: 500px;
    }

    /* Sidebar Toggle - Hamburger */
    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        background: #f1f5f9;
        border: none;
        border-radius: 8px;
        color: var(--dark);
        cursor: pointer;
    }

    /* Overlay */
    .mobile-overlay {
        display: none;
        position: fixed;
        inset: 0px !important;
        width: 100vw !important;
        height: 100vh !important;
        background: rgba(15, 23, 42, 0.5);
        backdrop-filter: blur(2px);
        z-index: 1500;
    }

    .mobile-overlay.active {
        display: block !important;
    }

    .header-user {
        position: static;
        /* Let the dropdown position relative to the header on mobile */
    }

    .profile-dropdown {
        top: var(--header-height);
        right: 1rem;
        width: calc(100% - 2rem);
        max-width: 250px;
        z-index: 3000;
        /* Above everything */
    }

    /* Forms on Mobile */
    .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: 0.6rem 1rem;
        margin-bottom: 0.5rem;
    }

    /* Calendar Mobile */
    .calendar-grid {
        display: flex !important;
        overflow-x: auto;
        gap: 8px;
        padding: 5px 5px 12px;
        margin: 0 -0.75rem;
        -webkit-overflow-scrolling: touch;
    }

    .calendar-day {
        min-width: 90px;
        flex-shrink: 0;
        min-height: 80px;
    }
}

@media (min-width: 802px) {
    .mobile-menu-btn {
        display: none !important;
    }
}