/**
 * PreOrder Ijazah v3 - Custom Styles
 * Tailwind CSS overrides and custom utilities
 */

/* ============================================
 * Global Enhancements
 * ============================================ */

html {
    scroll-behavior: smooth;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Better focus styles for accessibility */
*:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ============================================
 * Loading States
 * ============================================ */

.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    border: 3px solid #f3f4f6;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* ============================================
 * Form Enhancements
 * ============================================ */

.form-input {
    @apply w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all;
}

.form-label {
    @apply block text-gray-700 font-medium mb-2;
}

.form-error {
    @apply text-red-600 text-sm mt-1;
}

.form-help {
    @apply text-gray-500 text-sm mt-1;
}

/* Enhanced input styles */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="tel"],
input[type="date"],
select,
textarea {
    transition: all 0.2s ease-in-out;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="tel"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

/* File input styling */
input[type="file"] {
    cursor: pointer;
}

input[type="file"]::-webkit-file-upload-button {
    padding: 0.5rem 1rem;
    margin-right: 1rem;
    background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

input[type="file"]::-webkit-file-upload-button:hover {
    background: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
}

/* Radio and checkbox enhancement */
input[type="radio"],
input[type="checkbox"] {
    cursor: pointer;
    transition: all 0.2s;
}

input[type="radio"]:checked,
input[type="checkbox"]:checked {
    transform: scale(1.1);
}

/* ============================================
 * Buttons
 * ============================================ */

.btn {
    @apply px-6 py-2 rounded-lg font-medium transition-all duration-200;
}

.btn-primary {
    @apply bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-700 hover:to-indigo-700 text-white shadow-md hover:shadow-lg;
}

.btn-secondary {
    @apply bg-gray-200 hover:bg-gray-300 text-gray-800;
}

.btn-danger {
    @apply bg-red-500 hover:bg-red-600 text-white;
}

/* ============================================
 * Cards
 * ============================================ */

.card {
    @apply bg-white rounded-xl shadow-md p-6;
}

.card-header {
    @apply border-b border-gray-200 pb-4 mb-4;
}

/* ============================================
 * Tables
 * ============================================ */

.table-container {
    @apply overflow-x-auto shadow-md rounded-lg;
}

.table {
    @apply min-w-full divide-y divide-gray-200;
}

.table thead {
    @apply bg-gray-50;
}

.table th {
    @apply px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider;
}

.table td {
    @apply px-6 py-4 whitespace-nowrap text-sm text-gray-900;
}

.table tbody tr:hover {
    @apply bg-gray-50;
}

/* ============================================
 * Utilities
 * ============================================ */

.gradient-bg {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.text-gradient {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
 * Print Styles
 * ============================================ */

@media print {
    nav, footer, .no-print {
        display: none !important;
    }

    body {
        background: white !important;
    }

    .print-page-break {
        page-break-after: always;
    }
}

/* ============================================
 * Animation
 * ============================================ */

.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
 * DataTables Custom Styling
 * ============================================ */

.dataTables_wrapper {
    @apply p-4;
}

.dataTables_filter input {
    @apply ml-2 px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500;
}

.dataTables_length select {
    @apply mx-2 px-3 py-1 border border-gray-300 rounded-lg;
}

.dataTables_paginate .paginate_button {
    @apply px-3 py-1 mx-1 border border-gray-300 rounded hover:bg-blue-500 hover:text-white hover:border-blue-500;
}

.dataTables_paginate .paginate_button.current {
    @apply bg-blue-500 text-white border-blue-500;
}

/* ============================================
 * Mobile Enhancements
 * ============================================ */

/* Better touch targets for mobile */
@media (max-width: 768px) {
    /* Minimum touch target size (44x44px recommended) */
    button,
    a,
    select {
        min-height: 20px;
        min-width: 20px;
    }

    /* Radio/checkbox: smaller visual, but label provides touch target */
    input[type="radio"],
    input[type="checkbox"] {
        min-height: unset;
        min-width: unset;
        width: 16px;
        height: 16px;
    }

    /* Larger tap areas for form inputs */
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.75rem 1rem;
    }

    /* Better spacing for mobile forms */
    .space-y-6 > * + * {
        margin-top: 2rem;
    }

    /* Improved mobile navigation */
    nav {
        position: sticky;
        top: 0;
        z-index: 1000;
        backdrop-filter: blur(10px);
    }

    /* Full-width buttons on mobile */
    button[type="submit"],
    .btn-primary {
        width: 100%;
    }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 1024px) {
    .container {
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

/* ============================================
 * Accessibility Enhancements
 * ============================================ */

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    button,
    input,
    select,
    textarea {
        border: 2px solid currentColor;
    }
}

/* ============================================
 * Performance Optimizations
 * ============================================ */

/* GPU acceleration for smooth animations */
.transform,
.transition-transform {
    transform: translateZ(0);
    will-change: transform;
}

/* Optimize images */
img {
    max-width: 100%;
    height: auto;
}

/* ============================================
 * Custom Scrollbar (Desktop)
 * ============================================ */

@media (min-width: 1024px) {
    ::-webkit-scrollbar {
        width: 10px;
        height: 10px;
    }

    ::-webkit-scrollbar-track {
        background: #f1f5f9;
        border-radius: 10px;
    }

    ::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
        border-radius: 10px;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
    }
}

/* ============================================
 * Additional Animations
 * ============================================ */

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.animate-slide-in-up {
    animation: slideInUp 0.4s ease-out;
}

.animate-slide-in-down {
    animation: slideInDown 0.4s ease-out;
}

.animate-scale-in {
    animation: scaleIn 0.3s ease-out;
}

/* ============================================
 * Utility Classes
 * ============================================ */

.backdrop-blur {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.glass-effect {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* ============================================
 * Bootstrap Datepicker Overrides
 * ============================================ */

/* Calendar icon inside datepicker input */
.datepicker-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%233b82f6' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.25rem;
    cursor: pointer;
}

/* CRITICAL: bootstrap-datepicker CSS expects Bootstrap framework to provide
   position:absolute + z-index for the dropdown. Since we don't load Bootstrap
   CSS (only Tailwind), we must add these here or the calendar won't float. */
.datepicker-dropdown {
    position: absolute !important;
    z-index: 9999 !important;
    top: 0;
    left: 0;
    display: block;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 0.5rem;
    min-width: 260px;
}

/* Datepicker inner container */
.datepicker {
    padding: 8px;
    border-radius: 0.5rem;
}

/* Calendar table cells */
.datepicker table {
    margin: 0;
    border-collapse: collapse;
    width: 100%;
}

.datepicker td,
.datepicker th {
    text-align: center;
    width: 30px;
    height: 30px;
    border-radius: 0.375rem;
    border: none;
    padding: 4px;
    font-size: 0.875rem;
}

.datepicker-days .day {
    border-radius: 0.375rem;
    padding: 4px;
    cursor: pointer;
}

.datepicker-days .day:hover {
    background: #eff6ff;
}

.datepicker-days .day.active,
.datepicker-months .month.active,
.datepicker-years .year.active {
    background: #2563eb !important;
    color: #fff !important;
    background-image: linear-gradient(to bottom, #3b82f6, #2563eb) !important;
}

.datepicker-days .day.today {
    background: #dbeafe;
    color: #2563eb;
    font-weight: 600;
}

.datepicker-days .day.disabled,
.datepicker-days .day.disabled:hover {
    color: #d1d5db;
    background: transparent;
    cursor: not-allowed;
}

.datepicker .datepicker-switch {
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}

.datepicker .prev,
.datepicker .next {
    cursor: pointer;
    border-radius: 0.375rem;
}

.datepicker .prev:hover,
.datepicker .next:hover {
    background: #f3f4f6;
}

.datepicker .dow {
    color: #6b7280;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
}

/* Month/year grid views */
.datepicker-months .month,
.datepicker-years .year {
    border-radius: 0.375rem;
    padding: 4px;
    cursor: pointer;
}

.datepicker-months .month:hover,
.datepicker-years .year:hover {
    background: #eff6ff;
}

/* Clear button */
.datepicker-dropdown .datepicker-days .clear {
    font-size: 0.75rem;
    color: #6b7280;
    cursor: pointer;
}
