/* ============================================
   RESPONSIVE STYLES FOR CATTLE MANAGEMENT SYSTEM
   ============================================ */

/* Base responsive improvements */
* {
    box-sizing: border-box;
}

img {
    max-width: 100%;
    height: auto;
}

/* ============================================
   TABLET BREAKPOINT (768px - 1024px)
   ============================================ */
@media (max-width: 1024px) {
    .main-content {
        padding: 1.5rem;
    }
    
    .page-header h1 {
        font-size: 1.5rem;
    }
    
    /* KPI Cards - 2 columns on tablet */
    .kpi-card {
        margin-bottom: 1rem;
    }
    
    /* Tables - better scrolling */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        min-width: 700px;
    }
}

/* ============================================
   MOBILE BREAKPOINT (max-width: 990px)
   ============================================ */
@media (max-width: 990px) {
    /* Sidebar adjustments */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    /* Main content - full width on mobile */
    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 3.5rem; /* Space for mobile toggle on right */
    }
    
    /* Mobile toggle button */
    .mobile-toggle {
        display: block !important;
        position: fixed;
        top: 1rem;
        right: 1rem;
        z-index: 1001;
        background: var(--primary-color, #1a1a1a);
        color: white;
        border: none;
        padding: 0.5rem 0.75rem;
        border-radius: 6px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }
    
    /* Hide mobile toggle on pages without sidebar */
    body:not(:has(.sidebar)) .mobile-toggle {
        display: none !important;
    }
    
    /* Sidebar overlay */
    .sidebar-overlay.show {
        display: block;
    }
    
    /* ========================================
       CONSISTENT BUTTON SIZING
       ======================================== */
    
    /* Standard buttons - consistent sizing */
    .btn {
        min-height: 44px;
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
        line-height: 1.5;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Small buttons - consistent sizing */
    .btn-sm {
        min-height: 38px;
        padding: 0.5rem 0.875rem;
        font-size: 0.8rem;
        line-height: 1.5;
    }
    
    /* Table buttons - specific sizing */
    .table .btn-sm {
        min-height: 36px;
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }
    
    /* Page header - stack elements */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem;
    }
    
    .page-header > div {
        width: 100%;
    }
    
    .page-header h1 {
        font-size: 1.25rem;
    }
    
    .page-header p {
        font-size: 0.85rem;
    }
    
    /* Page header buttons - full width, consistent sizing */
    .page-header .btn {
        width: 100%;
        margin-bottom: 0.5rem;
        /* Size inherited from main .btn rule above */
    }
    
    .page-header > div:last-child {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }
    
    /* Remove bottom margin from last button */
    .page-header .btn:last-child {
        margin-bottom: 0;
    }
    
    /* Animal details page specific */
    .page-header .btn-secondary {
        width: 100%;
    }
    
    /* Card header buttons on animal details */
    .card-header .btn {
        margin-top: 0.5rem;
        /* width: 100%; */
        min-height: 44px;
        font-size: 0.875rem;
    }
    
    .card-header .d-flex {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem;
    }
    
    .card-header .d-flex > div {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .card-header .d-flex .btn {
        width: 100%;
        margin: 0;
    }
    
    .card-header .me-2 {
        margin-right: 0 !important;
    }
    
    /* Ensure h5 in card header doesn't break */
    .card-header h5 {
        margin-bottom: 0.5rem;
        font-size: 1rem;
    }
    
    /* Button container in card headers */
    .card-header > div:last-child {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 0.5rem;
    }
    
    /* Search and filter controls */
    .mb-3.d-flex {
        flex-direction: column !important;
        gap: 0.75rem;
    }
    
    .mb-3.d-flex .input-group {
        max-width: 100% !important;
    }
    
    .mb-3.d-flex .btn {
        width: 100%;
        min-height: 44px;
    }
    
    /* Button groups - ensure proper spacing */
    .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }
    
    .btn-group .btn {
        width: 100%;
        border-radius: 6px !important;
        margin: 0;
    }
    
    /* Offcanvas buttons */
    .offcanvas-body .btn {
        width: 100%;
        min-height: 44px;
        margin: 0.25rem 0;
    }
    
    .offcanvas-body .d-grid .btn {
        width: 100%;
    }
    
    /* KPI Cards - single column on mobile */
    .row > [class*='col-'] {
        margin-bottom: 1rem;
    }
    
    .kpi-card .card-body {
        padding: 1rem;
    }
    
    .kpi-number {
        font-size: 1.5rem !important;
    }
    
    .kpi-label {
        font-size: 0.75rem !important;
    }
    
    .kpi-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 18px !important;
    }
    
    /* Tables - responsive improvements */
    .table-responsive {
        margin: 0 -1rem;
        padding: 0 1rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        font-size: 0.8rem;
        min-width: 600px;
    }
    
    /* Borderless tables (info tables) - no min-width */
    .table-borderless {
        min-width: auto !important;
        width: 100%;
    }
    
    .table-borderless td {
        word-break: break-word;
        font-size: 0.85rem;
    }
    
    .table-borderless td:first-child {
        width: 40%;
        white-space: nowrap;
    }
    
    .table-borderless td:last-child {
        width: 60%;
    }
    
    .table thead th {
        font-size: 0.7rem;
        padding: 0.5rem 0.25rem;
        white-space: nowrap;
    }
    
    .table tbody td {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
        vertical-align: middle;
    }
    
    /* Better badge sizing in tables */
    .table .badge {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
        display: inline-block;
    }
    
    /* Action buttons in tables - stack */
    .table td:last-child {
        white-space: normal;
        min-width: 150px;
    }
    
    .table td:last-child .btn {
        display: block;
        width: 100%;
        margin: 0.25rem 0;
        font-size: 0.8rem;
        padding: 0.4rem 0.75rem;
        text-align: center;
    }
    
    .table td:last-child form {
        display: block;
        margin: 0.25rem 0;
    }
    
    .table td:last-child form .btn {
        width: 100%;
        margin: 0;
    }
    
    /* Make table buttons wrap nicely */
    .table .btn-sm {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
        white-space: nowrap;
        min-height: 36px;
    }
    
    /* Ensure proper button styling in tables */
    .table-responsive .table .btn {
        border-radius: 4px;
        font-weight: 500;
    }
    
    .table-responsive .table .btn-outline-primary {
        border-color: #007bff;
        color: #007bff;
    }
    
    .table-responsive .table .btn-outline-secondary {
        border-color: #6c757d;
        color: #6c757d;
    }
    
    .table-responsive .table .btn-outline-warning {
        border-color: #ffc107;
        color: #856404;
    }
    
    /* Cards */
    .card {
        margin-bottom: 1rem;
    }
    
    .card-header {
        padding: 0.75rem 1rem;
        font-size: 0.85rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    /* Category items */
    .category-item {
        padding: 0.5rem 0;
        font-size: 0.85rem;
    }
    
    /* Notifications */
    .alert {
        font-size: 0.8rem;
        padding: 0.5rem 0.75rem;
    }
    
    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }
    
    .pagination .page-item {
        margin: 0.125rem;
    }
    
    .pagination .page-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
        min-width: 40px;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 6px;
    }
    
    /* Hide some pagination items on very small screens */
    @media (max-width: 480px) {
        .pagination .page-item:not(.active):not(:first-child):not(:last-child):not(:nth-child(2)):not(:nth-last-child(2)) {
            display: none;
        }
    }
    
    /* Modals */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-dialog-lg {
        max-width: calc(100% - 1rem);
    }
    
    .modal-header {
        padding: 0.75rem 1rem;
    }
    
    .modal-title {
        font-size: 0.9rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem 1rem;
        display: flex;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
        /* Size inherited from main .btn rule */
    }
    
    /* Forms in modals */
    .modal .row {
        margin: 0;
    }
    
    .modal .row > [class*='col-'] {
        padding-left: 0;
        padding-right: 0;
        margin-bottom: 0.75rem;
    }
    
    .form-label {
        font-size: 0.85rem;
        margin-bottom: 0.375rem;
    }
    
    .form-control,
    .form-select {
        font-size: 0.85rem;
        padding: 0.5rem;
    }
    
    /* Offcanvas filters */
    .offcanvas {
        max-width: 85%;
    }
    
    .offcanvas-body {
        padding: 1rem;
    }
    
    .offcanvas-title {
        font-size: 1rem;
    }
    
    /* Dashboard specific */
    .stats-card {
        padding: 1rem;
    }
    
    .stats-card h3 {
        font-size: 1.5rem;
    }
    
    .stats-card p {
        font-size: 0.8rem;
    }
    
    /* Login page adjustments */
    .login-box {
        grid-template-columns: 1fr !important;
        max-width: 100%;
        margin: 1rem;
    }
    
    .brand-side {
        padding: 2rem 1.5rem;
        min-height: auto;
    }
    
    .brand-features {
        display: none;
    }
    
    .logo-circle {
        width: 100px;
        height: 100px;
        margin-bottom: 1.5rem;
    }
    
    .brand-title {
        font-size: 1.5rem;
    }
    
    .brand-subtitle {
        font-size: 0.9rem;
    }
    
    .form-side {
        padding: 2rem 1.5rem;
    }
    
    .form-header h2 {
        font-size: 1.25rem;
    }
    
    /* Badge adjustments */
    .badge {
        font-size: 0.7rem;
        padding: 0.25rem 0.4rem;
    }
    
    /* Utility classes for mobile */
    .mobile-hide {
        display: none !important;
    }
    
    .mobile-show {
        display: block !important;
    }
}

/* ============================================
   SMALL MOBILE BREAKPOINT (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    .main-content {
        padding: 0.75rem;
    }
    
    .page-header h1 {
        font-size: 1.1rem;
    }
    
    .page-header p {
        font-size: 0.8rem;
    }
    
    /* Even smaller KPI cards */
    .kpi-number {
        font-size: 1.25rem !important;
    }
    
    .kpi-label {
        font-size: 0.7rem !important;
    }
    
    .kpi-icon {
        width: 36px !important;
        height: 36px !important;
        font-size: 16px !important;
    }
    
    /* Buttons - maintain consistent sizing, only adjust font/padding */
    .btn {
        font-size: 0.8rem;
        padding: 0.5rem 0.75rem;
        /* min-height inherited from 990px breakpoint (44px) */
    }
    
    .btn-sm {
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
        /* min-height inherited from 990px breakpoint (38px) */
    }
    
    /* Tables - even more compact */
    .table {
        font-size: 0.7rem;
        min-width: 500px;
    }
    
    .table thead th {
        font-size: 0.65rem;
        padding: 0.4rem 0.2rem;
    }
    
    .table tbody td {
        padding: 0.4rem 0.2rem;
        font-size: 0.7rem;
    }
    
    /* Table action buttons - full width on very small screens */
    .table td:last-child .btn {
        font-size: 0.75rem;
        padding: 0.35rem 0.6rem;
        margin: 0.2rem 0;
    }
    
    /* Cards */
    .card-header {
        padding: 0.6rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    /* Modals */
    .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100% - 0.5rem);
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 0.75rem;
    }
    
    .modal-title {
        font-size: 0.85rem;
    }
    
    /* Forms */
    .form-label {
        font-size: 0.8rem;
    }
    
    .form-control,
    .form-select {
        font-size: 0.8rem;
        padding: 0.4rem;
    }
    
    /* Pagination - hide some page numbers */
    .pagination .page-item:not(.active):not(:first-child):not(:last-child) {
        display: none;
    }
    
    .pagination .page-item.active,
    .pagination .page-item:first-child,
    .pagination .page-item:last-child {
        display: block;
    }
    
    /* Login page */
    .login-box {
        margin: 0.5rem;
        border-radius: 12px;
    }
    
    .brand-side {
        padding: 1.5rem 1rem;
    }
    
    .logo-circle {
        width: 80px;
        height: 80px;
    }
    
    .brand-title {
        font-size: 1.25rem;
    }
    
    .brand-subtitle {
        font-size: 0.85rem;
    }
    
    .form-side {
        padding: 1.5rem 1rem;
    }
    
    .form-header h2 {
        font-size: 1.1rem;
    }
}

/* ============================================
   LANDSCAPE MOBILE ORIENTATION
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        overflow-y: auto;
    }
    
    .sidebar-footer {
        position: relative;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .modal-dialog {
        margin: 0.5rem auto;
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .sidebar,
    .mobile-toggle,
    .sidebar-overlay,
    .btn,
    .no-print,
    .page-header .btn,
    .offcanvas,
    .modal {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0;
        padding: 0;
    }
    
    .table {
        font-size: 10pt;
    }
    
    .card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border-width: 2px;
    }
    
    .card {
        border-width: 2px;
    }
    
    .table {
        border: 2px solid;
    }
}

/* ============================================
   TOUCH DEVICE IMPROVEMENTS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Touch targets already set in main mobile breakpoint */
    /* Just add touch-specific interactions */
    
    .nav-link {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }
    
    .form-control,
    .form-select {
        min-height: 44px;
        padding: 0.625rem 0.875rem;
        font-size: 0.9rem;
    }
    
    /* Remove hover effects on touch devices */
    .btn:hover,
    .nav-link:hover,
    .table tbody tr:hover {
        transform: none;
    }
    
    /* Add active state for touch feedback */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}
