/* Admin Layout Styles */
:root {
    --primary: #28a745;
    --primary-dark: #1e7e34;
    --primary-light: #48c774;
    --secondary: #2f3542;
    --dark: #1a1a1a;
    --light: #f8f9fa;
    --gray: #6c757d;
    --sidebar-width: 280px;
    --transition-speed: 0.3s;
}

/* Body and Layout */
body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--light);
    background-image: linear-gradient(rgba(240, 250, 240, 0.92), rgba(240, 250, 240, 0.92)), url('/images/logo_cnedd.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    color: var(--dark);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Sidebar Styles */
.sidebar {
    background: linear-gradient(180deg, var(--primary), var(--primary-dark));
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    z-index: 1100;
    padding: 20px 0;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.15);
    transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1), transform var(--transition-speed) ease;
    will-change: width, transform;
    overflow-y: auto;
    overflow-x: hidden;
    transform: none !important; /* Ensure it stays visible on desktop */
}

.sidebar.collapsed {
    width: 80px;
    transform: none !important;
}

/* Hide text when collapsed */
.sidebar.collapsed span,
.sidebar.collapsed .sidebar-header span,
.sidebar.collapsed nav p,
.sidebar.collapsed .mt-auto div > div {
    display: none !important;
}

.sidebar.collapsed .nav-link i,
.sidebar.collapsed .sidebar-brand img {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.sidebar.collapsed .nav-link {
    padding: 12px 0;
    justify-content: center;
    margin: 5px 10px;
    width: auto;
}

.sidebar.collapsed .nav-link i {
    margin: 0 auto;
    font-size: 1.4rem;
    display: block;
    text-align: center;
}

.sidebar.collapsed .sidebar-header {
    padding: 0;
    display: flex;
    justify-content: center;
    border-bottom: none;
    opacity: 1;
    pointer-events: auto;
}

.sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: 10px 0;
}

.sidebar.collapsed .sidebar-brand img {
    height: 32px;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
    z-index: 1050;
    display: none;
    transition: opacity var(--transition-speed) ease;
}

.sidebar-overlay.active {
    display: block;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}


.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 20px;
    transition: opacity var(--transition-speed) ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 15px;
    color: white;
    text-decoration: none;
    font-weight: 800;
    font-size: 1.2rem;
    transition: transform var(--transition-speed) ease;
}

.sidebar-brand img {
    height: 40px;
    width: auto;
    border-radius: 8px;
    transition: all var(--transition-speed) ease;
}

/* Navigation Links */
.nav-link {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    padding: 12px 20px;
    border-radius: 8px;
    margin: 5px 10px;
    transition: all var(--transition-speed) ease;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    position: relative;
    overflow: hidden;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transform: translateX(5px);
}

.nav-link i {
    font-size: 1.1rem;
    transition: transform var(--transition-speed) ease;
}

.nav-link:hover i {
    transform: translateX(2px);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: white;
    border-radius: 0 4px 4px 0;
}

/* Main Content */
.main-content {
    margin-left: 0;
    padding: 0;
    transition: margin-left var(--transition-speed) ease;
    will-change: margin-left;
}

.main-content.sidebar-collapsed {
    margin-left: 0;
}

/* Layout wrapper for sidebar + main content */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.admin-layout .sidebar {
    flex-shrink: 0;
}

.admin-layout .main-content {
    flex: 1;
    width: 100%;
    margin-left: 80px;
    transition: margin-left var(--transition-speed) ease;
}

@media (max-width: 767px) {
    .admin-layout .main-content {
        margin-left: 0;
    }
}

/* Header Section */
.header-section {
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    padding: 15px 40px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 0;
    transition: all var(--transition-speed) ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 999;
}

.header-section h1 {
    color: white !important;
}

.header-section #sidebarToggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
}

.header-section #sidebarToggle:hover {
    background: rgba(255, 255, 255, 0.3);
}

.header-section .btn-danger {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
}

.header-section .btn-danger:hover {
    background: rgba(220, 53, 69, 0.8);
    border-color: transparent;
}

.header-section span {
    color: rgba(255, 255, 255, 0.8) !important;
}

.content-body {
    padding: 30px 40px;
}

.breadcrumb-item.active {
    color: var(--gray);
}

/* Cards */
.card {
    border: none;
    border-radius: 16px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.card-header {
    background: white;
    border-bottom: 1px solid #e9ecef;
    border-radius: 16px 16px 0 0 !important;
    padding: 15px 20px;
    font-weight: 700;
    color: var(--dark);
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-weight: 600;
    transition: all var(--transition-speed) ease;
    position: relative;
    overflow: hidden;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.btn-primary::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255, 255, 255, 0.5);
    opacity: 0;
    border-radius: 100%;
    transform: scale(1, 1) translate(-50%);
    transform-origin: 50% 50%;
}

.btn-primary:active::after {
    animation: ripple 1s ease-out;
}

@keyframes ripple {
    0% {
        transform: scale(0, 0);
        opacity: 0.5;
    }

    100% {
        transform: scale(20, 20);
        opacity: 0;
    }
}

/* Forms */
.form-control,
.form-select {
    border-radius: 8px;
    border: 1px solid #e9ecef;
    padding: 10px 15px;
    font-size: 1rem;
    transition: all var(--transition-speed) ease;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
    transform: translateY(-1px);
}

/* Tables */
.table {
    font-size: 0.95rem;
}

.table th {
    background-color: #f8f9fa;
    border-top: none;
    font-weight: 700;
    color: var(--dark);
    border-bottom: 2px solid #e9ecef;
}

.table-hover tbody tr:hover {
    background-color: rgba(40, 167, 69, 0.05);
}

/* Alerts */
.alert {
    border: none;
    border-radius: 12px;
    padding: 15px 20px;
    font-weight: 600;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    animation: slideInDown 0.3s ease-out;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Toggle Button */
#sidebarToggle {
    position: relative;
    z-index: 1001;
}

#sidebarToggle[aria-expanded="true"] {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}

#sidebarToggle[aria-expanded="false"] {
    background: linear-gradient(135deg, var(--gray), var(--dark));
}

/* Responsive Design */
@media (max-width: 767px) {
    .sidebar {
        transform: translateX(-100%) !important;
        width: var(--sidebar-width) !important;
    }

    .sidebar.collapsed {
        transform: translateX(-100%) !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    .content-body {
        padding: 20px 15px;
    }

    .header-section {
        padding: 15px 20px;
    }
}

@media (max-width: 576px) {
    .content-body {
        padding: 15px 10px;
    }

    .card {
        border-radius: 12px;
    }

    .btn-primary {
        padding: 8px 16px;
        font-size: 0.9rem;
    }
    
    .header-section h1 {
        font-size: 16px !important;
    }
}

/* Print Styles */
@media print {
    .sidebar {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: 0;
    }

    .header-section {
        box-shadow: none;
        border: none;
    }

    .btn,
    .btn-primary {
        display: none;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .card {
        border: 2px solid var(--dark);
    }

    .form-control,
    .form-select {
        border: 2px solid var(--dark);
    }

    .btn-primary {
        border: 2px solid var(--dark);
        background: var(--dark) !important;
        color: white !important;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus Styles for Accessibility */
*:focus {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

/* Skip Link for Screen Readers */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary);
    color: white;
    padding: 8px;
    z-index: 100;
    text-decoration: none;
    border-radius: 4px;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 6px;
}

/* Global Responsive Fixes */
@media (max-width: 768px) {
    /* Make headers with buttons adapt to column on mobile */
    .content-body .d-flex.justify-content-between.align-items-center,
    .row .col-12.d-flex.justify-content-between.align-items-center {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 15px;
    }

    /* Make top level buttons full width on small screens */
    .content-body .d-flex.justify-content-between.align-items-center > a.btn,
    .content-body .d-flex.justify-content-between.align-items-center > button.btn {
        width: 100%;
        text-align: center !important;
        justify-content: center !important;
    }

    /* Fix table actions wrapping */
    td .btn-group {
        display: flex;
        flex-wrap: nowrap;
        gap: 4px; /* Slight gap between buttons */
    }
    
    td .btn-group .btn {
        flex: 1 1 auto;
        padding: 6px 10px !important;
        border-radius: 6px !important; /* fallback if radius circle causes layout issues */
    }

    /* Add responsiveness to any card body lacking table-responsive wrapper */
    .card-body {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Ensure sweetalerts/modals fit on screen */
    .modal-dialog {
        margin: 10px;
    }
}