@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-color: #ffffff;
    --sidebar-bg: #4D6F85;
    --text-main: #1f2937;
    --text-muted: #5A74A0;
    --primary-color: #4D6F85;
    --primary-hover: #5A74A0;
    --accent-color: #8CACAF;
    --card-bg: #ffffff;
    --border-color: #cbd5e1; /* Gris más definido para dar estructura sólida */
    --shadow-soft: none; /* Quitamos las sombras */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --border-radius: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

html {
    font-size: 14.5px; /* Scales down all rem-based typography and spacing slightly */
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar Styling */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    z-index: 100;
    border-right: 1px solid var(--border-color);
}

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

.sidebar-logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 20px;
}

.sidebar-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.5px;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 10px;
    color: #D8E2ED;
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
    border-left: 4px solid transparent;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
    transform: translateX(5px);
}

.nav-link.active {
    background: var(--primary-hover);
    color: white;
    border-left: 4px solid var(--accent-color);
    box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.1);
}

.nav-icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Main Content Area */
.main-wrapper {
    flex: 1;
    margin-left: 280px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: calc(100vw - 280px);
}

/* Top Header */
.top-header {
    height: 80px;
    background: rgba(216, 226, 237, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 99;
    width: 100%;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
}

.btn-icon:hover {
    background: #e2e8f0;
    color: var(--text-main);
}

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

.sidebar-collapsed .sidebar-title,
.sidebar-collapsed .nav-link span {
    display: none;
}

.sidebar-collapsed .sidebar-logo {
    margin-right: 0;
}

.sidebar-collapsed .sidebar-header {
    justify-content: center;
    padding: 2rem 0;
}

.sidebar-collapsed .nav-item {
    display: flex;
    justify-content: center;
}

.sidebar-collapsed .nav-link {
    padding: 1rem;
    justify-content: center;
}

.sidebar-collapsed .nav-icon {
    margin-right: 0;
}

.sidebar-collapsed .main-wrapper {
    margin-left: 80px;
    width: calc(100% - 80px);
}

.header-search {
    display: flex;
    align-items: center;
    background: white;
    padding: 10px 20px;
    border-radius: 30px;
    border: 1px solid var(--border-color);
    width: 300px;
    min-width: 300px;
    flex-shrink: 0;
}

.header-search input {
    border: none;
    outline: none;
    background: transparent;
    margin-left: 10px;
    width: 100%;
    color: var(--text-main);
}

.header-profile {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-shrink: 0;
}

.profile-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
}

.header-profile:hover .profile-avatar {
    transform: scale(1.05);
    box-shadow: 0 4px 10px rgba(77, 111, 133, 0.3);
}

.user-profile-container {
    position: relative;
    cursor: pointer;
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: var(--card-bg);
    min-width: 260px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition);
    z-index: 1000;
    padding: 0.5rem;
}

.user-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 8px;
    transition: var(--transition);
}

.dropdown-link:hover {
    background: #f1f5f9;
    color: #ef4444; /* Rojo para destacar el cierre de sesión */
}

.dropdown-link i {
    width: 18px;
    height: 18px;
    color: #ef4444;
}

/* Content Container */
.content-container {
    padding: 2rem;
    flex: 1;
}

/* Page Title Section */
.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.page-breadcrumb {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Footer */
.main-footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    background: transparent;
    font-size: 0.875rem;
}

/* Enhancing Existing Table & Forms generic */
.table-container {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: 480px;
}

.form-wrapper {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* Modern Forms */
.modern-form fieldset {
    border: none;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.modern-form legend {
    grid-column: 1 / -1;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    width: 100%;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #f8fafc;
    color: var(--text-main);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    background: white;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(77, 111, 133, 0.15);
}

.btn {
    padding: 12px 24px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.95rem;
    text-align: center;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(16, 185, 129, 0.3);
}

.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #f1f5f9;
    color: var(--primary-color);
    transition: var(--transition);
}

.btn-action:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: auto;
    padding: 1rem 0;
}

/* Elegant specific styling for pagination buttons */
.pagination .btn {
    padding: 0;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px; /* Slightly rounded square */
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
    background: transparent;
    border: 1px solid var(--border-color); /* Flat outline style */
    box-shadow: none;
    text-decoration: none;
    transition: var(--transition);
}

.pagination .btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    transform: none; /* Disable the generic btn hover jump */
    box-shadow: none;
}

.pagination .btn.btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

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

.btn-icon-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
}

/* Table Responsive Wrapper */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    flex: 1;
}

/* Empty State (No Data) */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    background: #f9fafb;
    border-radius: 12px;
    border: 2px dashed var(--border-color);
    margin: 10px 0;
}

.empty-state .empty-icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.empty-state h3 {
    color: var(--text-main);
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Modern Tables */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 10px 0;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

table tr {
    text-align: left;
    transition: var(--transition);
}

table tr:hover td {
    background-color: #f9fafb;
}

table th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    padding: 10px 14px;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--primary-hover);
}

table th:first-child {
    border-top-left-radius: 8px;
}

table th:last-child {
    border-top-right-radius: 8px;
}

table td {
    padding: 10px 14px;
    font-size: 12.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

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

/* Action buttons in tables (links generated by PHP) */
table td a {
    padding: 4px 10px;
    font-size: 12.5px;
    border-radius: 6px;
    background-color: white;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

table td a:hover {
    background-color: var(--primary-color);
    color: white;
}

/* Main action button (Crear) outside tables */
.table-container > a {
    display: inline-block;
    margin-top: 15px;
    padding: 10px 20px;
    border-radius: 8px;
    background-color: var(--primary-color);
    color: white;
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

.table-container > a:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

/* Modern Table Toolbar (Search, Filter, Create) */
.table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 1.5rem;
    padding: 0 4px;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 250px;
    max-width: 400px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 18px;
    height: 18px;
}

.search-box input {
    width: 100%;
    padding: 10px 15px 10px 42px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: #f8fafc;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

.search-box input:focus {
    background: white;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(77, 111, 133, 0.15);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-group select {
    padding: 10px 15px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: #f8fafc;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
    transition: var(--transition);
}

.filter-group select:focus {
    border-color: var(--primary-color);
    background: white;
}

.btn-filter {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background-color: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    border-radius: 10px;
    font-weight: 600;
    transition: var(--transition);
}

.btn-filter:hover {
    background-color: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(77, 111, 133, 0.2);
}

.toolbar-actions {
    margin-left: auto;
}

/* Form Layout Grids */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

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


/* =========================================
   Responsive Design (Laptops & Tablets)
========================================= */

@media (max-width: 1200px) {
    /* Smaller laptops */
    .sidebar {
        width: 240px;
        padding: 2rem 1rem;
    }
    .main-wrapper {
        margin-left: 240px;
        width: calc(100vw - 240px);
    }
    .header-search {
        min-width: 220px;
        width: 260px;
    }
}

@media (max-width: 992px) {
    /* Tablets and very small laptops */
    .sidebar {
        width: 80px;
        padding: 1.5rem 0.5rem;
        transform: translateX(0);
    }
    .sidebar-title, .nav-link span {
        display: none; /* Hide text, keep icons */
    }
    .sidebar-header {
        justify-content: center;
        padding-bottom: 1.5rem;
    }
    .nav-link {
        justify-content: center;
        padding: 12px;
    }
    .main-wrapper {
        margin-left: 80px;
        width: calc(100vw - 80px);
    }
    .header-search {
        display: none; /* Hide search bar to save space */
    }
    .top-header {
        padding: 0 1.5rem;
    }
    .content-container {
        padding: 1.5rem;
    }
}

@media (max-width: 768px) {
    /* Mobile screens - Sidebar Off-Canvas */
    .sidebar {
        width: 260px;
        transform: translateX(0); /* Shows when NOT collapsed */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 2rem 1.5rem;
    }
    
    .sidebar-title, .nav-link span {
        display: inline; /* Restore text inside sidebar */
    }
    
    .sidebar-header {
        justify-content: flex-start;
        padding-bottom: 2rem;
    }

    .nav-link {
        justify-content: flex-start;
        padding: 12px 16px;
    }

    .main-wrapper {
        margin-left: 0 !important;
        width: 100vw !important;
    }

    /* By default body has .sidebar-collapsed */
    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }
    
    /* Overlay effect when sidebar is OPEN (meaning NOT collapsed) */
    body:not(.sidebar-collapsed):not(.login-body)::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99; /* Below sidebar (100) */
        backdrop-filter: blur(2px);
    }
    
    .page-title {
        font-size: 1.5rem;
    }
    .content-container {
        padding: 1rem;
    }
    .top-header {
        height: 60px;
        padding: 0 1rem;
    }
    
    /* Clean pagination on mobile (only show arrows and active page) */
    .pagination > a:not(.btn-icon-only):not(.btn-primary) {
        display: none;
    }
}

@media (max-width: 768px) {
    .modern-form fieldset {
        grid-template-columns: 1fr;
    }
    .form-actions {
        justify-content: center;
        flex-direction: column-reverse;
    }
    .form-actions .btn {
        width: 100%;
    }
}
