/**
 * Custom CSS for Cattle Farm Management System
 * AdminLTE Theme Customization
 */

/* ============================================
   Variables & Overrides
   ============================================ */

:root {
    --primary-color: #28a745;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --info-color: #17a2b8;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --sidebar-dark-bg: #1a1d21;
    --sidebar-light-bg: #ffffff;
}

/* ============================================
   General Customizations
   ============================================ */

body {
    font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.main-header {
    border-bottom: 1px solid #e9ecef;
}

.content-header {
    padding: 15px 0;
}

.card {
    border: none;
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.125), 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.125), 0 4px 8px rgba(0, 0, 0, 0.15);
}

.card-header {
    background-color: #fff;
    border-bottom: 1px solid #e9ecef;
}

/* ============================================
   Sidebar Customizations
   ============================================ */

.main-sidebar {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.nav-sidebar .nav-item > .nav-link {
    margin: 3px 5px;
    border-radius: 5px;
}

.nav-sidebar .nav-item > .nav-link.active {
    background-color: var(--primary-color);
}

.nav-sidebar .nav-item > .nav-link:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.nav-treeview > .nav-item > .nav-link {
    padding-left: 30px;
}

/* ============================================
   Button Customizations
   ============================================ */

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

.btn-primary:hover {
    background-color: #218838;
    border-color: #1e7e34;
}

.btn-success {
    background-color: var(--success-color);
    border-color: var(--success-color);
}

.btn-info {
    background-color: var(--info-color);
    border-color: var(--info-color);
}

.btn-warning {
    background-color: var(--warning-color);
    border-color: var(--warning-color);
    color: #212529;
}

.btn-danger {
    background-color: var(--danger-color);
    border-color: var(--danger-color);
}

/* ============================================
   Badge Customizations
   ============================================ */

.badge.bg-success {
    background-color: var(--success-color) !important;
}

.badge.bg-info {
    background-color: var(--info-color) !important;
}

.badge.bg-warning {
    background-color: var(--warning-color) !important;
    color: #212529;
}

.badge.bg-danger {
    background-color: var(--danger-color) !important;
}

/* ============================================
   Table Customizations
   ============================================ */

.table {
    background-color: #fff;
}

.table thead th {
    border-top: none;
    font-weight: 600;
    color: #495057;
    text-transform: uppercase;
    font-size: 0.85rem;
}

.table tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.table td {
    vertical-align: middle;
}

/* ============================================
   Form Customizations
   ============================================ */

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}

.form-control {
    border-radius: 4px;
}

.custom-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}

/* ============================================
   Small Box Customizations
   ============================================ */

.small-box {
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.small-box .icon {
    top: 10px;
    right: 15px;
    font-size: 60px;
    color: rgba(255, 255, 255, 0.2);
}

.small-box:hover .icon {
    font-size: 70px;
}

/* ============================================
   Modal Customizations
   ============================================ */

.modal-header {
    border-bottom: 1px solid #e9ecef;
}

.modal-footer {
    border-top: 1px solid #e9ecef;
}

/* ============================================
   Info Box Customizations
   ============================================ */

.info-box {
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.info-box-content {
    padding: 10px;
}

/* ============================================
   Dashboard Specific
   ============================================ */

.dashboard-stats {
    padding: 20px;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary-color) 0%, #20c997 100%);
    border-radius: 10px;
    padding: 20px;
    color: white;
    margin-bottom: 20px;
}

.stat-card.danger {
    background: linear-gradient(135deg, #dc3545 0%, #e83e8c 100%);
}

.stat-card.warning {
    background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
    color: #212529;
}

.stat-card.info {
    background: linear-gradient(135deg, #17a2b8 0%, #6610f2 100%);
}

/* ============================================
   Activity Feed
   ============================================ */

.activity-feed {
    max-height: 400px;
    overflow-y: auto;
}

.activity-item {
    padding: 10px 0;
    border-bottom: 1px solid #e9ecef;
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-icon {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
}

/* ============================================
   Profile Page
   ============================================ */

.profile-user-img {
    width: 100px;
    height: 100px;
    object-fit: cover;
}

.profile-username {
    font-size: 1.5rem;
    font-weight: 600;
}

.list-group-unbordered > .list-group-item {
    border-left: none;
    border-right: none;
    padding-left: 0;
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 768px) {
    .main-header {
        position: relative;
    }
    
    .small-box .icon {
        display: none;
    }
    
    .card-tools {
        float: none;
        margin-top: 10px;
    }
    
    .card-tools .btn {
        margin-bottom: 5px;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .main-sidebar,
    .main-header,
    .content-header,
    .card-tools,
    .btn,
    .no-print {
        display: none !important;
    }
    
    .content-wrapper {
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd;
    }
}

/* ============================================
   Animations
   ============================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

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

.slide-in {
    animation: slideIn 0.3s ease;
}

/* ============================================
   Utility Classes
   ============================================ */

.text-cattle {
    color: var(--primary-color);
}

.bg-cattle {
    background-color: var(--primary-color) !important;
}

.cursor-pointer {
    cursor: pointer;
}

.truncate {
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   Loading States
   ============================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   Notification Styles
   ============================================ */

.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger-color);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Progress Bar Styles
   ============================================ */

.progress-sm {
    height: 6px;
}

.progress-lg {
    height: 25px;
}

/* ============================================
   Chart Container Styles
   ============================================ */

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

/* ============================================
   Timeline Styles
   ============================================ */

.timeline {
    position: relative;
    padding: 20px 0;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 30px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #dee2e6;
}

.timeline-item {
    position: relative;
    padding-left: 60px;
    margin-bottom: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: 24px;
    top: 5px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary-color);
    border: 2px solid white;
}

.timeline-icon {
    position: absolute;
    left: 15px;
    top: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
Sidebar Toggle Fixes
============================================ */

/* Fix for sidebar toggle animation and flash */
.main-sidebar {
    transition: transform 0.3s ease-in-out;
    will-change: transform;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

/* Fix for content wrapper transition */
.content-wrapper {
    transition: margin-left 0.3s ease-in-out;
    min-height: calc(100vh - 56px);
}

/* Fix for collapsed sidebar state */
.sidebar-collapse .main-sidebar {
    transform: translateX(-250px);
}

.sidebar-open .main-sidebar {
    transform: translateX(0);
}

.sidebar-collapse .content-wrapper {
    margin-left: 0 !important;
}

.sidebar-open .content-wrapper {
    margin-left: 250px !important;
}

/* Fix for mobile devices */
@media (max-width: 767.98px) {
    .main-sidebar {
        transform: translateX(-250px);
        box-shadow: none;
    }
    
    .sidebar-open .main-sidebar {
        transform: translateX(0);
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
    }
    
    .content-wrapper {
        margin-left: 0 !important;
    }
    
    .sidebar-open .content-wrapper {
        margin-left: 0 !important;
    }
    
    /* Overlay for mobile */
    .sidebar-open .main-sidebar::after {
        content: '';
        position: fixed;
        top: 0;
        left: 250px;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1029;
    }
}

/* Fix for pushmenu button */
[data-widget="pushmenu"] {
    cursor: pointer;
    outline: none;
}

[data-widget="pushmenu"]:focus {
    outline: none;
}

/* Prevent body scroll when sidebar is open on mobile */
@media (max-width: 767.98px) {
    .sidebar-open {
        overflow: hidden;
    }
    
    .sidebar-open body {
        overflow: hidden;
    }
}

/* Fix for navbar when sidebar is open on desktop */
@media (min-width: 768px) {
    .sidebar-open .main-header .navbar {
        margin-left: 250px;
        width: calc(100% - 250px);
    }
    
    .sidebar-collapse .main-header .navbar {
        margin-left: 0;
        width: 100%;
    }
}

/* Fix for sidebar z-index */
.main-sidebar {
    z-index: 1030;
}

/* Fix for overlay scrollbars */
.overlay-scrollbars-enabled .main-sidebar {
    overflow: hidden;
}

/* Smooth transition for all sidebar elements */
.nav-sidebar,
.sidebar .user-panel,
.sidebar .brand-link {
    transition: all 0.3s ease-in-out;
}

/* Fix for sidebar menu animation */
.nav-sidebar > .nav-item > .nav-link {
    transition: all 0.2s ease-in-out;
}

/* Prevent flash during transition */
body {
    overflow-x: hidden;
}

/* Ensure proper stacking context */
.wrapper {
    position: relative;
    overflow-x: hidden;
}

/* Fix for AdminLTE's default behavior */
.layout-fixed .main-sidebar {
    position: fixed;
}

/* Responsive fixes */
@media (max-width: 991.98px) {
    .main-sidebar {
        transform: translateX(-250px);
    }
    
    .sidebar-open .main-sidebar {
        transform: translateX(0);
    }
    
    .main-header .navbar {
        margin-left: 0;
        width: 100%;
    }
}

/* High priority fix - add at the very end of custom.css */
body.sidebar-open .main-sidebar {
    display: block !important;
    transform: translateX(0) !important;
}

body:not(.sidebar-open) .main-sidebar {
    transform: translateX(-250px) !important;
}

/* Force proper transitions */
.main-sidebar,
.content-wrapper,
.main-header .navbar {
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
}