/* Mobile Responsive CSS untuk Sistem Manajemen Proyek */

/* Base styles for all devices */
html,
body {
    overflow-x: hidden;
    max-width: 100%;
}

/* Prevent body scroll when sidebar is open on mobile */
body.sidebar-open {
    overflow: hidden;
}

@media (min-width: 1024px) {
    body.sidebar-open {
        overflow: auto;
    }
}

/* Base Mobile Styles */
@media (max-width: 640px) {

    /* Typography */
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 1.5rem !important;
    }

    h2 {
        font-size: 1.25rem !important;
    }

    h3 {
        font-size: 1.125rem !important;
    }

    /* Buttons */
    button,
    .btn,
    a[class*="bg-"] {
        font-size: 0.875rem;
        padding: 0.5rem 1rem;
    }

    /* Form Inputs */
    input,
    select,
    textarea {
        font-size: 14px !important;
    }

    /* Tables - Force to card layout on mobile */
    table {
        font-size: 0.75rem;
    }

    /* Modal adjustments */
    .modal {
        padding: 1rem;
    }

    /* Cards */
    .card {
        margin-bottom: 1rem;
    }

    /* Spacing */
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Prevent content from being hidden under fixed mobile header */
    main {
        padding-top: 5rem !important;
        /* Space for mobile header (64px) + extra spacing */
        min-height: 100vh;
    }

    /* Page headers in content area */
    main>div:first-child,
    main>.bg-white:first-child,
    main>.rounded-lg:first-child {
        margin-top: 0.5rem;
    }

    /* Prevent content overflow */
    main>* {
        max-width: 100%;
        overflow-x: auto;
    }

    /* Cards and containers */
    .bg-white,
    .rounded-lg,
    .shadow {
        max-width: 100%;
    }

    /* Page header with actions */
    .flex.justify-between.items-center.mb-6,
    .flex.justify-between.items-center.mb-8 {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
    }

    .flex.justify-between.items-center.mb-6>*,
    .flex.justify-between.items-center.mb-8>* {
        width: 100%;
    }

    /* Action button groups */
    .flex.gap-2,
    .flex.gap-3,
    .flex.gap-4,
    .flex.space-x-2,
    .flex.space-x-3,
    .flex.space-x-4 {
        flex-wrap: wrap;
        width: 100%;
    }

    .flex.gap-2>a,
    .flex.gap-2>button,
    .flex.gap-3>a,
    .flex.gap-3>button {
        flex: 1;
        min-width: calc(50% - 0.5rem);
        text-align: center;
        justify-content: center;
    }

    /* Single full-width buttons */
    .w-full-mobile {
        width: 100% !important;
    }
}

/* Tablet Styles */
@media (min-width: 641px) and (max-width: 1024px) {

    /* Adjust spacing for tablet */
    .container {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }

    /* Table adjustments */
    table {
        font-size: 0.875rem;
    }

    /* Content padding for tablet mobile header */
    main {
        padding-top: 5rem !important;
    }
}

/* For devices between mobile and desktop (tablets in portrait) */
@media (min-width: 641px) and (max-width: 1023px) {

    /* Show mobile header on tablets too */
    header.lg\:hidden {
        display: flex !important;
    }

    /* Adjust main content */
    main {
        margin-left: 0 !important;
        padding-top: 5rem !important;
    }
}

/* Landscape orientation specific */
@media (max-width: 896px) and (orientation: landscape) {

    /* Reduce vertical spacing in landscape */
    .py-8 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    .my-8 {
        margin-top: 1rem !important;
        margin-bottom: 1rem !important;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {

    /* Make buttons and links more touch-friendly */
    button,
    a,
    .clickable {
        min-height: 44px;
        min-width: 44px;
    }

    /* Increase tap target size for icons */
    i.fas,
    i.far {
        padding: 0.5rem;
    }
}

/* Print styles */
@media print {

    /* Hide sidebar and navigation */
    aside,
    .sidebar,
    nav,
    .no-print {
        display: none !important;
    }

    /* Adjust main content */
    main {
        margin-left: 0 !important;
        padding-top: 0 !important;
    }

    /* Full width for print */
    .container {
        max-width: 100% !important;
    }

    /* Remove shadows and borders */
    .shadow,
    .shadow-lg,
    .shadow-xl {
        box-shadow: none !important;
    }

    /* Adjust colors for print */
    body {
        background: white !important;
    }
}

/* Specific component improvements */

/* Sidebar mobile improvements */
@media (max-width: 1023px) {
    .sidebar-transition {
        transition: transform 0.3s ease-in-out;
    }

    aside {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Ensure sidebar can scroll */
        height: 100vh;
        height: 100dvh;
        /* Dynamic viewport height for mobile browsers */
    }

    /* Sidebar content wrapper with proper padding for scroll */
    aside>div:first-child {
        padding-bottom: 8rem;
        /* Space for footer */
        min-height: 100%;
    }

    /* Make sure navigation can scroll */
    aside nav {
        max-height: calc(100vh - 250px);
        max-height: calc(100dvh - 250px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Stats cards on mobile */
@media (max-width: 640px) {
    .stats-card {
        padding: 1rem;
    }

    .stats-card h3 {
        font-size: 1.5rem !important;
    }

    .stats-card p {
        font-size: 0.75rem;
    }
}

/* Table responsive wrapper */
@media (max-width: 1023px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-responsive table {
        min-width: 800px;
    }

    /* Horizontal scroll indicator */
    .table-responsive {
        position: relative;
    }

    .table-responsive::after {
        content: '← Geser untuk melihat lebih →';
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.7);
        color: white;
        padding: 0.25rem 0.75rem;
        border-radius: 0.25rem;
        font-size: 0.75rem;
        pointer-events: none;
        opacity: 0.8;
    }

    /* Hide scroll indicator when not needed */
    .table-responsive.no-scroll::after {
        display: none;
    }
}

/* Form improvements on mobile */
@media (max-width: 640px) {
    form .grid {
        grid-template-columns: 1fr !important;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions button {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Better spacing for form groups */
    .mb-4 {
        margin-bottom: 1rem;
    }

    /* Labels and inputs full width */
    label {
        display: block;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea {
        width: 100% !important;
        max-width: 100%;
    }
}

/* Card grid responsive */
@media (max-width: 640px) {
    .card-grid {
        grid-template-columns: 1fr !important;
    }

    /* Stats cards better spacing */
    .grid>div {
        margin-bottom: 1rem;
    }

    /* Action buttons in cards */
    .card .flex.gap-2,
    .card .flex.space-x-2 {
        flex-wrap: wrap;
        gap: 0.5rem !important;
    }

    .card .flex.gap-2>*,
    .card .flex.space-x-2>* {
        flex: 1;
        min-width: calc(50% - 0.25rem);
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .card-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* Utility classes for mobile */
.mobile-hidden {
    display: block;
}

@media (max-width: 1023px) {
    .mobile-hidden {
        display: none !important;
    }
}

.mobile-only {
    display: none;
}

@media (max-width: 1023px) {
    .mobile-only {
        display: block !important;
    }
}

/* Flexbox utilities for mobile */
@media (max-width: 640px) {
    .flex-wrap-mobile {
        flex-wrap: wrap;
    }

    .flex-col-mobile {
        flex-direction: column;
    }

    /* Better spacing for flex containers */
    .flex.justify-between {
        gap: 1rem;
    }

    .flex.items-center {
        align-items: flex-start !important;
        flex-direction: column;
    }

    /* Keep specific flex containers horizontal */
    .flex.items-center.keep-horizontal {
        flex-direction: row !important;
        align-items: center !important;
    }
}

/* Padding utilities for mobile */
@media (max-width: 640px) {

    .p-8,
    .p-6 {
        padding: 1rem !important;
    }

    .px-8,
    .px-6 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .py-8,
    .py-6 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    /* Margin adjustments */
    .mb-8,
    .mb-6 {
        margin-bottom: 1.5rem !important;
    }

    .mt-8,
    .mt-6 {
        margin-top: 1.5rem !important;
    }
}

/* Text utilities */
@media (max-width: 640px) {
    .text-truncate-mobile {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* Safe area padding for notched devices */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    header {
        padding-top: max(1rem, env(safe-area-inset-top));
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    /* Add dark mode styles if needed */
}

/* High contrast mode support */
@media (prefers-contrast: high) {

    button,
    a {
        border: 2px solid currentColor;
    }
}