/* Admin Panel Custom Styles - Responsive Layout Fixes */

/* Reset và base styles */
* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f8f9fa;
    overflow-x: hidden;
}

/* Header styles */
.navbar-brand {
    font-weight: 600;
}
.navbar{
    z-index: 5000 !important;
}
/* Sidebar styles */
.sidebar-custom {
    width: 250px;
    min-height: 100vh;
    background: #fff;
    border-right: 1px solid #e9ecef;
    position: fixed;
    top: 56px; /* Account for fixed header height */
    left: 0;
    bottom: 0;
    z-index: 1030;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}

.sidebar-header {
    letter-spacing: 1px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom: none !important;
}

.sidebar-header span {
    color: white !important;
}

.nav-section {
    font-size: 0.75rem;
    letter-spacing: 1px;
    font-weight: 600;
}

.sidebar-custom .nav-link {
    color: #495057;
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    margin: 0 0.5rem 0.25rem 0.5rem;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.sidebar-custom .nav-link i {
    font-size: 1.1rem;
    width: 1.5rem;
    text-align: center;
}

.sidebar-custom .nav-link:hover {
    background: #e3f2fd;
    color: #1976d2;
    border-color: #bbdefb;
    transform: translateX(3px);
}

.sidebar-custom .nav-link.active {
    background: #1976d2;
    color: white;
    font-weight: 500;
    border-color: #1976d2;
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.3);
}

.sidebar-profile {
    background: #f8f9fa;
    border-radius: 0.75rem;
    margin: 0 0.5rem 0.5rem 0.5rem;
    border: 1px solid #e9ecef !important;
}

/* Main content area */
.admin-main-content {
    margin-left: 250px; /* Match sidebar width */
    padding: 2rem;
    padding-top: 2rem; /* Add space for fixed header */
    min-height: calc(100vh - 56px);
    background: #f8f9fa;
    overflow-x: auto;
}

/* Container adjustments */
.container-fluid {
    padding-left: 0;
    padding-right: 0;
}

/* Card improvements */
.card {
    border: none;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    transition: all 0.3s ease;
    border-radius: 12px;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
}

.card-body {
    padding: 1.5rem;
}

/* Table improvements */
.table {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.table thead th {
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    color: #495057;
}

/* Form improvements */
.form-control, .form-select {
    border-radius: 8px;
    border: 1px solid #ced4da;
    transition: all 0.2s ease;
}

.form-control:focus, .form-select:focus {
    border-color: #1976d2;
    box-shadow: 0 0 0 0.2rem rgba(25, 118, 210, 0.25);
}

/* Button improvements */
.btn {
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

/* Responsive breakpoints */
@media (max-width: 1199.98px) {
    .sidebar-custom {
        width: 220px;
    }
    
    .admin-main-content {
        margin-left: 220px;
        padding: 1.5rem;
        padding-top: 5.5rem; /* Add space for fixed header */
    }
}

@media (max-width: 991.98px) {
    .sidebar-custom {
        position: static;
        width: 100%;
        min-height: auto;
        border-right: none;
        border-bottom: 1px solid #e9ecef;
        top: auto;
        box-shadow: none;
    }
    
    .admin-main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 5rem; /* Add space for fixed header */
    }
    
    .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }
}

@media (max-width: 767.98px) {
    .admin-main-content {
        padding: 0.75rem;
        padding-top: 4.5rem; /* Add space for fixed header */
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .table-responsive {
        font-size: 0.9rem;
    }
}

@media (max-width: 575.98px) {
    .sidebar-custom .nav-link {
        padding: 0.5rem 1rem;
        margin: 0 0.25rem 0.125rem 0.25rem;
        font-size: 0.9rem;
    }
    
    .admin-main-content {
        padding: 0.5rem;
    }
}

/* Utility classes */
.shadow-custom {
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.rounded-custom {
    border-radius: 12px;
}

/* Scrollbar styling */
.sidebar-custom::-webkit-scrollbar {
    width: 6px;
}

.sidebar-custom::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.sidebar-custom::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.sidebar-custom::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Animation classes */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Fix for content overflow */
.admin-main-content .row {
    margin-left: 0;
    margin-right: 0;
}

.admin-main-content .col-md-9,
.admin-main-content .col-lg-10 {
    padding-left: 0;
    padding-right: 0;
}

/* Ensure tables don't overflow */
.table-responsive {
    border-radius: 8px;
    overflow: hidden;
}

/* Fix for form elements */
.form-row {
    margin-left: 0;
    margin-right: 0;
}

/* Image handling */
img {
    max-width: 100%;
    height: auto;
}

/* Fix for Bootstrap grid conflicts */
.row > * {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.row > *:first-child {
    padding-left: 0;
}

.row > *:last-child {
    padding-right: 0;
}

/* Additional responsive fixes */
@media (max-width: 1400px) {
    .admin-main-content {
        margin-left: 250px;
        padding: 1.5rem;
    }
}

@media (max-width: 1200px) {
    .admin-main-content {
        margin-left: 220px;
        padding: 1.25rem;
    }
}

@media (max-width: 992px) {
    .sidebar-custom {
        position: static;
        width: 100%;
        min-height: auto;
        border-right: none;
        border-bottom: 1px solid #e9ecef;
        top: auto;
        box-shadow: none;
        z-index: auto;
    }
    
    .admin-main-content {
        margin-left: 0;
        padding: 1rem;
    }
    
    .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }
}

@media (max-width: 768px) {
    .admin-main-content {
        padding: 0.75rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .table-responsive {
        font-size: 0.9rem;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .btn-group .btn {
        border-radius: 4px !important;
    }
}

@media (max-width: 576px) {
    .sidebar-custom .nav-link {
        padding: 0.5rem 1rem;
        margin: 0 0.25rem 0.125rem 0.25rem;
        font-size: 0.9rem;
    }
    
    .admin-main-content {
        padding: 0.5rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    .table th,
    .table td {
        padding: 0.5rem;
        font-size: 0.875rem;
    }
    
    .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
    }
}

/* Specific fixes for common issues */
.admin-main-content .container-fluid {
    padding-left: 0;
    padding-right: 0;
}

.admin-main-content .row {
    margin-left: 0;
    margin-right: 0;
}

.admin-main-content .col-md-9,
.admin-main-content .col-lg-10 {
    padding-left: 0;
    padding-right: 0;
}

/* Fix for modal positioning */
.modal {
    z-index: 1055;
}

.modal-backdrop {
    z-index: 1050;
}

/* Fix for dropdown menus */
.dropdown-menu {
    z-index: 1060;
}

/* Fix for tooltips */
.tooltip {
    z-index: 1070;
}

/* Fix for popovers */
.popover {
    z-index: 1070;
}

/* Fix for alerts */
.alert {
    border-radius: 8px;
    border: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Fix for badges */
.badge {
    font-weight: 500;
    padding: 0.5em 0.75em;
}

/* Fix for code elements */
code {
    background-color: #f8f9fa;
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.875em;
}

/* Fix for pagination */
.pagination .page-link {
    border-radius: 6px;
    margin: 0 2px;
}

/* Fix for form validation */
.was-validated .form-control:valid,
.was-validated .form-select:valid {
    border-color: #198754;
    box-shadow: 0 0 0 0.2rem rgba(25, 135, 84, 0.25);
}

.was-validated .form-control:invalid,
.was-validated .form-select:invalid {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* Fix for loading states */
.btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

/* Fix for focus states */
.btn:focus,
.form-control:focus,
.form-select:focus {
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(25, 118, 210, 0.25);
}

/* Fix for hover states */
.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

/* Fix for active states */
.btn:active {
    transform: translateY(0);
}

/* Fix for disabled states */
.btn:disabled:hover {
    transform: none;
}

/* Fix for table responsiveness */
@media (max-width: 768px) {
    .table-responsive {
        font-size: 0.875rem;
    }
    
    .table th,
    .table td {
        padding: 0.5rem;
    }
    
    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
}

/* Fix for card responsiveness */
@media (max-width: 576px) {
    .card-body {
        padding: 1rem;
    }
    
    .card-title {
        font-size: 1.1rem;
    }
    
    .card-text {
        font-size: 0.9rem;
    }
}

/* Fix for form responsiveness */
@media (max-width: 768px) {
    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    .form-control,
    .form-select {
        font-size: 0.9rem;
        padding: 0.5rem 0.75rem;
    }
    
    .btn {
        font-size: 0.9rem;
        padding: 0.5rem 1rem;
    }
}

/* Fix for sidebar responsiveness */
@media (max-width: 992px) {
    .sidebar-custom {
        position: static;
        width: 100%;
        min-height: auto;
        border-right: none;
        border-bottom: 1px solid #e9ecef;
        top: auto;
        box-shadow: none;
        z-index: auto;
    }
    
    .sidebar-custom .nav-link {
        padding: 0.5rem 1rem;
        margin: 0.25rem 0;
        border-radius: 6px;
    }
    
    .sidebar-custom .nav-link:hover {
        transform: none;
    }
    
    .sidebar-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border-radius: 8px;
        margin: 0.5rem;
    }
    
    .sidebar-profile {
        margin: 0.5rem;
        border-radius: 8px;
    }
}

/* Fix for header responsiveness */
@media (max-width: 768px) {
    .navbar-brand {
        font-size: 1rem;
    }
    
    .navbar .text-white {
        font-size: 0.9rem;
    }
}

/* Fix for main content responsiveness */
@media (max-width: 992px) {
    .admin-main-content {
        margin-left: 0;
        padding: 1rem;
    }
}

@media (max-width: 768px) {
    .admin-main-content {
        padding: 0.75rem;
    }
}

@media (max-width: 576px) {
    .admin-main-content {
        padding: 0.5rem;
    }
}

/* Enhanced Mobile Off-Canvas Navigation */
.offcanvas {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.offcanvas-header {
    background: rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.offcanvas-title {
    color: white;
    font-weight: 600;
    font-size: 1.25rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.offcanvas .btn-close {
    filter: invert(1);
    opacity: 0.8;
    transition: all 0.3s ease;
}

.offcanvas .btn-close:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Mobile Navigation Links */
.offcanvas .nav-link {
    color: rgba(255, 255, 255, 0.9);
    padding: 1rem 1.5rem;
    margin: 0.25rem 1rem;
    border-radius: 12px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.offcanvas .nav-link::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.offcanvas .nav-link:hover::before {
    left: 100%;
}

.offcanvas .nav-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    transform: translateX(8px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

.offcanvas .nav-link.active {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-weight: 600;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.4);
}

.offcanvas .nav-link i {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
    margin-right: 16px;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.offcanvas .nav-link span {
    flex: 1;
    font-weight: 500;
}

.offcanvas .nav-link:hover i {
    transform: scale(1.1);
}

.offcanvas .nav-section {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin: 1.5rem 1rem 0.5rem 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Enhanced Mobile Header */
.navbar {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 600;
    color: white !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.navbar-brand i {
    color: #4a90e2;
    text-shadow: 0 0 10px rgba(74, 144, 226, 0.5);
}

/* Custom Hamburger Menu */
.hamburger-btn {
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.05);
}

.hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.hamburger-icon {
    width: 20px;
    height: 16px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.hamburger-icon span {
    display: block;
    height: 2px;
    width: 100%;
    background: white;
    border-radius: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

.hamburger-btn:hover .hamburger-icon span:nth-child(1) {
    transform: translateY(2px) rotate(45deg);
}

.hamburger-btn:hover .hamburger-icon span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.hamburger-btn:hover .hamburger-icon span:nth-child(3) {
    transform: translateY(-2px) rotate(-45deg);
}

/* Active hamburger state */
.hamburger-icon.active span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}

.hamburger-icon.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.hamburger-icon.active span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

/* Body class for offcanvas open */
body.offcanvas-open {
    overflow: hidden;
}

/* Header Dropdown */
.navbar .dropdown-toggle {
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 0.5rem 0.75rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.05);
}

.navbar .dropdown-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.navbar .dropdown-toggle i {
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}

.navbar .dropdown-toggle:hover i {
    transform: scale(1.1);
}

.navbar .dropdown-menu {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    margin-top: 0.5rem;
}

.navbar .dropdown-item {
    padding: 0.75rem 1rem;
    transition: all 0.3s ease;
    border-radius: 8px;
    margin: 0.25rem;
}

.navbar .dropdown-item:hover {
    background: rgba(74, 144, 226, 0.1);
    transform: translateX(5px);
}

.navbar .dropdown-item i {
    width: 16px;
    text-align: center;
}

/* Backdrop Overlay */
.offcanvas-backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    transition: all 0.3s ease;
}

/* Mobile Profile Section */
.offcanvas .sidebar-profile {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    margin: 1rem;
    padding: 1rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.offcanvas .sidebar-profile img {
    border: 2px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
}

.offcanvas .sidebar-profile:hover img {
    transform: scale(1.05);
    border-color: rgba(255, 255, 255, 0.5);
}

.offcanvas .sidebar-profile .fw-bold {
    color: white;
    font-weight: 600;
}

.offcanvas .sidebar-profile .text-muted {
    color: rgba(255, 255, 255, 0.7) !important;
}

/* Animation for menu items */
@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.offcanvas .nav-link {
    animation: slideInFromLeft 0.3s ease forwards;
}

.offcanvas .nav-link:nth-child(1) { animation-delay: 0.1s; }
.offcanvas .nav-link:nth-child(2) { animation-delay: 0.15s; }
.offcanvas .nav-link:nth-child(3) { animation-delay: 0.2s; }
.offcanvas .nav-link:nth-child(4) { animation-delay: 0.25s; }
.offcanvas .nav-link:nth-child(5) { animation-delay: 0.3s; }
.offcanvas .nav-link:nth-child(6) { animation-delay: 0.35s; }
.offcanvas .nav-link:nth-child(7) { animation-delay: 0.4s; }
.offcanvas .nav-link:nth-child(8) { animation-delay: 0.45s; }
.offcanvas .nav-link:nth-child(9) { animation-delay: 0.5s; }
.offcanvas .nav-link:nth-child(10) { animation-delay: 0.55s; }

/* Offcanvas + responsive adjustments for sidebar */
@media (max-width: 991.98px) {
    .admin-main-content {
        margin-left: 0 !important;
    }

    .sidebar-custom {
        display: none;
    }
}

/* Posts table responsive: only show title on mobile */
@media (max-width: 575.98px) {
    .posts-table thead th:nth-child(1),
    .posts-table thead th:nth-child(3),
    .posts-table thead th:nth-child(4),
    .posts-table thead th:nth-child(5),
    .posts-table thead th:nth-child(6),
    .posts-table tbody td:nth-child(1),
    .posts-table tbody td:nth-child(3),
    .posts-table tbody td:nth-child(4),
    .posts-table tbody td:nth-child(5),
    .posts-table tbody td:nth-child(6) {
        display: none;
    }

    .posts-table tbody td:nth-child(2) {
        display: table-cell;
        width: 100%;
    }

    .posts-actions {
        display: none !important;
    }
}
