/* Responsive Design CSS untuk Aplikasi Alkhawarizmi v1.1 */

/* ===== MOBILE FIRST APPROACH ===== */

/* Base mobile styles */
@media (max-width: 640px) {
    /* Container adjustments */
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* Typography adjustments */
    h1 {
        font-size: 1.5rem !important;
        line-height: 2rem !important;
    }
    
    h2 {
        font-size: 1.25rem !important;
        line-height: 1.75rem !important;
    }
    
    h3 {
        font-size: 1.125rem !important;
        line-height: 1.75rem !important;
    }
    
    /* Button adjustments */
    .btn, button {
        padding: 0.75rem 1rem !important;
        font-size: 0.875rem !important;
        min-height: 44px; /* Touch-friendly minimum */
    }
    
    /* Form adjustments */
    input, select, textarea {
        padding: 0.75rem !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 44px;
    }
    
    /* Card adjustments */
    .card, .bg-white {
        margin: 0.5rem 0 !important;
        padding: 1rem !important;
    }
    
    /* Grid adjustments */
    .grid {
        gap: 1rem !important;
    }
    
    /* Navigation adjustments */
    .nav-link {
        padding: 0.75rem 1rem !important;
        font-size: 1rem !important;
    }
}

/* ===== TABLET BREAKPOINT ===== */
@media (min-width: 641px) and (max-width: 1024px) {
    /* Container adjustments */
    .container {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    /* Typography adjustments */
    h1 {
        font-size: 1.875rem !important;
    }
    
    h2 {
        font-size: 1.5rem !important;
    }
    
    /* Grid adjustments */
    .grid-cols-1.md\:grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    
    .grid-cols-1.md\:grid-cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    
    .grid-cols-1.md\:grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* ===== DESKTOP BREAKPOINT ===== */
@media (min-width: 1025px) {
    /* Restore full desktop functionality */
    .grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
    /* Touch-friendly button sizes */
    button, .btn, a[role="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Touch-friendly form elements */
    input, select, textarea {
        min-height: 44px;
    }
    
    /* Touch-friendly navigation */
    .nav-link {
        padding: 0.75rem 1rem;
        margin: 0.25rem 0;
    }
    
    /* Touch-friendly table rows */
    tr {
        min-height: 44px;
    }
    
    /* Touch-friendly modal close buttons */
    .modal-close {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ===== RESPONSIVE TABLE ===== */
@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table-responsive table {
        min-width: 600px;
    }
    
    /* Stack table cells on very small screens */
    @media (max-width: 480px) {
        .table-responsive table {
            display: block;
        }
        
        .table-responsive thead {
            display: none;
        }
        
        .table-responsive tbody {
            display: block;
        }
        
        .table-responsive tr {
            display: block;
            margin-bottom: 1rem;
            border: 1px solid #e5e7eb;
            border-radius: 0.5rem;
            padding: 1rem;
        }
        
        .table-responsive td {
            display: block;
            text-align: left;
            padding: 0.5rem 0;
            border: none;
            border-bottom: 1px solid #f3f4f6;
        }
        
        .table-responsive td:last-child {
            border-bottom: none;
        }
        
        .table-responsive td::before {
            content: attr(data-label) ": ";
            font-weight: 600;
            color: #374151;
        }
    }
}

/* ===== RESPONSIVE FORMS ===== */
@media (max-width: 640px) {
    .form-grid {
        grid-template-columns: 1fr !important;
    }
    
    .form-row {
        flex-direction: column !important;
    }
    
    .form-row > * {
        margin-bottom: 1rem !important;
        margin-right: 0 !important;
    }
    
    /* Stack form buttons */
    .form-actions {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    .form-actions > * {
        width: 100% !important;
    }
}

/* ===== RESPONSIVE CARDS ===== */
@media (max-width: 640px) {
    .card-grid {
        grid-template-columns: 1fr !important;
    }
    
    .card {
        margin-bottom: 1rem !important;
    }
    
    .card-header {
        padding: 1rem !important;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    .card-footer {
        padding: 1rem !important;
    }
}

/* ===== RESPONSIVE MODALS ===== */
@media (max-width: 640px) {
    .modal-content {
        margin: 1rem !important;
        max-width: calc(100vw - 2rem) !important;
        max-height: calc(100vh - 2rem) !important;
    }
    
    .modal-header {
        padding: 1rem !important;
    }
    
    .modal-body {
        padding: 1rem !important;
    }
    
    .modal-footer {
        padding: 1rem !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    .modal-footer > * {
        width: 100% !important;
    }
}

/* ===== RESPONSIVE NAVIGATION ===== */
@media (max-width: 768px) {
    /* Mobile navigation improvements */
    .mobile-nav {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        display: none;
    }
    
    .mobile-nav.active {
        display: block;
    }
    
    .mobile-nav-content {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        background: white;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        z-index: 1001;
    }
    
    .mobile-nav.active .mobile-nav-content {
        transform: translateX(0);
    }
    
    /* Mobile menu items */
    .mobile-nav-item {
        display: block;
        padding: 1rem 1.5rem;
        border-bottom: 1px solid #f3f4f6;
        color: #374151;
        text-decoration: none;
        transition: background-color 0.2s;
    }
    
    .mobile-nav-item:hover {
        background-color: #f9fafb;
    }
    
    .mobile-nav-item.active {
        background-color: #ecfdf5;
        color: #059669;
        border-left: 4px solid #10b981;
    }
}

/* ===== RESPONSIVE SIDEBAR ===== */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        z-index: 1000 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease !important;
    }
    
    .sidebar.active {
        transform: translateX(0) !important;
    }
    
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
}

/* ===== RESPONSIVE UTILITIES ===== */
.hidden-mobile {
    display: none !important;
}

@media (min-width: 768px) {
    .hidden-mobile {
        display: block !important;
    }
}

.visible-mobile {
    display: block !important;
}

@media (min-width: 768px) {
    .visible-mobile {
        display: none !important;
    }
}

/* ===== RESPONSIVE SPACING ===== */
@media (max-width: 640px) {
    .p-mobile-4 {
        padding: 1rem !important;
    }
    
    .px-mobile-4 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .py-mobile-4 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
    
    .m-mobile-4 {
        margin: 1rem !important;
    }
    
    .mx-mobile-4 {
        margin-left: 1rem !important;
        margin-right: 1rem !important;
    }
    
    .my-mobile-4 {
        margin-top: 1rem !important;
        margin-bottom: 1rem !important;
    }
}

/* ===== RESPONSIVE TYPOGRAPHY ===== */
@media (max-width: 640px) {
    .text-mobile-sm {
        font-size: 0.875rem !important;
        line-height: 1.25rem !important;
    }
    
    .text-mobile-base {
        font-size: 1rem !important;
        line-height: 1.5rem !important;
    }
    
    .text-mobile-lg {
        font-size: 1.125rem !important;
        line-height: 1.75rem !important;
    }
    
    .text-mobile-xl {
        font-size: 1.25rem !important;
        line-height: 1.75rem !important;
    }
}

/* ===== RESPONSIVE FLEXBOX ===== */
@media (max-width: 640px) {
    .flex-mobile-col {
        flex-direction: column !important;
    }
    
    .flex-mobile-row {
        flex-direction: row !important;
    }
    
    .items-mobile-start {
        align-items: flex-start !important;
    }
    
    .items-mobile-center {
        align-items: center !important;
    }
    
    .justify-mobile-start {
        justify-content: flex-start !important;
    }
    
    .justify-mobile-center {
        justify-content: center !important;
    }
    
    .justify-mobile-between {
        justify-content: space-between !important;
    }
}

/* ===== RESPONSIVE GRID ===== */
@media (max-width: 640px) {
    .grid-mobile-1 {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }
    
    .grid-mobile-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    
    .gap-mobile-2 {
        gap: 0.5rem !important;
    }
    
    .gap-mobile-4 {
        gap: 1rem !important;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .no-print {
        display: none !important;
    }
    
    .print-break {
        page-break-before: always;
    }
    
    .print-break-after {
        page-break-after: always;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.4;
    }
    
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }
    
    table {
        page-break-inside: avoid;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: high) {
    .border {
        border-width: 2px !important;
    }
    
    .btn {
        border-width: 2px !important;
    }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
    /* Auto dark mode styles jika browser mendukung */
    .auto-dark {
        background-color: #1f2937 !important;
        color: #f9fafb !important;
    }
    
    .auto-dark .bg-white {
        background-color: #374151 !important;
    }
    
    .auto-dark .text-gray-900 {
        color: #f9fafb !important;
    }
    
    .auto-dark .text-gray-700 {
        color: #d1d5db !important;
    }
    
    .auto-dark .border-gray-200 {
        border-color: #4b5563 !important;
    }
}

/* ===== RESPONSIVE ANIMATIONS ===== */
@media (max-width: 640px) {
    .animate-mobile-fade-in {
        animation: fadeInMobile 0.3s ease-in-out;
    }
    
    .animate-mobile-slide-up {
        animation: slideUpMobile 0.3s ease-in-out;
    }
    
    .animate-mobile-slide-down {
        animation: slideDownMobile 0.3s ease-in-out;
    }
}

@keyframes fadeInMobile {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUpMobile {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideDownMobile {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ===== RESPONSIVE LOADING STATES ===== */
@media (max-width: 640px) {
    .loading-mobile {
        padding: 2rem 1rem;
        text-align: center;
    }
    
    .loading-mobile .spinner {
        width: 2rem;
        height: 2rem;
        border-width: 3px;
    }
    
    .loading-mobile .text {
        font-size: 0.875rem;
        margin-top: 1rem;
    }
}

/* ===== RESPONSIVE ERROR STATES ===== */
@media (max-width: 640px) {
    .error-mobile {
        padding: 1rem;
        margin: 1rem 0;
        border-radius: 0.5rem;
        border-left: 4px solid #ef4444;
    }
    
    .error-mobile .icon {
        font-size: 1.5rem;
        margin-right: 0.75rem;
    }
    
    .error-mobile .message {
        font-size: 0.875rem;
        line-height: 1.25rem;
    }
}

/* ===== RESPONSIVE SUCCESS STATES ===== */
@media (max-width: 640px) {
    .success-mobile {
        padding: 1rem;
        margin: 1rem 0;
        border-radius: 0.5rem;
        border-left: 4px solid #10b981;
    }
    
    .success-mobile .icon {
        font-size: 1.5rem;
        margin-right: 0.75rem;
    }
    
    .success-mobile .message {
        font-size: 0.875rem;
        line-height: 1.25rem;
    }
}
