/* Tailwind CSS Directives */
/* Note: When using Tailwind CDN, directives are handled automatically */
/* This file is for custom styles that extend Tailwind */

@tailwind base;
@tailwind components;
@tailwind utilities;

/* Custom Base Styles */
@layer base {
    html {
        scroll-behavior: smooth;
    }

    body {
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* WCAG AA compliant placeholder contrast */
    ::placeholder {
        color: #595959 !important;
        opacity: 1;
    }

    ::-webkit-input-placeholder {
        color: #595959 !important;
    }

    ::-moz-placeholder {
        color: #595959 !important;
    }

    :-ms-input-placeholder {
        color: #595959 !important;
    }
}

/* Custom Component Styles */
@layer components {
    /* Card hover effect */
    .card-hover {
        @apply transition-all duration-200 hover:shadow-md hover:-translate-y-0.5;
    }

    /* Button base styles */
    .btn-primary {
        @apply inline-flex items-center justify-center gap-2 bg-primary-600 text-white px-4 py-2 rounded-lg font-medium hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed;
    }

    .btn-secondary {
        @apply inline-flex items-center justify-center gap-2 bg-white text-gray-700 px-4 py-2 rounded-lg font-medium border border-gray-300 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 transition-colors;
    }

    /* Input styles */
    .input-field {
        @apply w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent transition-shadow;
    }

    /* Badge styles */
    .badge {
        @apply inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-medium;
    }

    .badge-success {
        @apply bg-green-100 text-green-800;
    }

    .badge-warning {
        @apply bg-yellow-100 text-yellow-800;
    }

    .badge-error {
        @apply bg-red-100 text-red-800;
    }

    .badge-info {
        @apply bg-blue-100 text-blue-800;
    }
}

/* Custom Utility Styles */
@layer utilities {
    /* Fade in animation */
    .fade-in {
        animation: fadeIn 0.3s ease-in-out;
    }

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

    /* Slide in animation */
    .slide-in {
        animation: slideIn 0.3s ease-out;
    }

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

    /* Pulse animation for loading states */
    .pulse-soft {
        animation: pulseSoft 2s infinite;
    }

    @keyframes pulseSoft {
        0%, 100% {
            opacity: 1;
        }
        50% {
            opacity: 0.5;
        }
    }

    /* Bounce once animation for success */
    .animate-bounce-once {
        animation: bounceOnce 0.6s ease-out;
    }

    @keyframes bounceOnce {
        0% {
            transform: scale(0);
            opacity: 0;
        }
        50% {
            transform: scale(1.2);
        }
        70% {
            transform: scale(0.9);
        }
        100% {
            transform: scale(1);
            opacity: 1;
        }
    }

    /* SSID 10-digit success flash */
    .ssid-success-flash {
        animation: ssidSuccessFlash 300ms ease-out;
    }

    @keyframes ssidSuccessFlash {
        0% {
            border-color: #8DC63F;
            box-shadow: 0 0 0 3px rgba(141, 198, 63, 0.3);
            background-color: rgba(141, 198, 63, 0.05);
        }
        100% {
            border-color: #8DC63F;
            box-shadow: 0 0 0 3px rgba(141, 198, 63, 0);
            background-color: transparent;
        }
    }

    /* SSID valid state (persistent green border) */
    .ssid-valid {
        border-color: #8DC63F !important;
    }

    /* Duplicate SSID warning state */
    .ssid-duplicate {
        border-color: #F59E0B !important;
        background-color: #FFFBEB !important;
    }

    /* Row duplicate warning highlight */
    .row-duplicate {
        background-color: #FFFBEB !important;
    }

    .row-duplicate td {
        background-color: #FFFBEB !important;
    }

    /* Duplicate warning badge */
    .duplicate-badge {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 2px 8px;
        background-color: #FEF3C7;
        border: 1px solid #F59E0B;
        border-radius: 9999px;
        font-size: 11px;
        font-weight: 600;
        color: #B45309;
    }

    /* Glass effect */
    .glass {
        backdrop-filter: blur(10px);
        background-color: rgba(255, 255, 255, 0.8);
    }

    /* Hide scrollbar but keep functionality */
    .scrollbar-hide {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .scrollbar-hide::-webkit-scrollbar {
        display: none;
    }
}

/* Medical/SaaS Theme Overrides */
:root {
    --color-primary: #2563eb;
    --color-medical-teal: #0d9488;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
}

/* Focus visible styles for accessibility */
*:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Selection color */
::selection {
    background-color: rgba(37, 99, 235, 0.2);
}

/* ============================================================
   MOBILE-FRIENDLY STYLES
   ============================================================ */

/* Larger touch targets on mobile */
@media (max-width: 768px) {
    /* Larger inputs for touch */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    select {
        font-size: 16px !important; /* Prevents iOS zoom */
        min-height: 48px;
        padding: 12px 14px;
    }

    /* Larger buttons */
    button {
        min-height: 44px;
        padding-left: 16px;
        padding-right: 16px;
    }

    /* Better spacing for mobile tables */
    .mobile-card-layout {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    /* Stack table cells on mobile */
    .mobile-stack td,
    .mobile-stack th {
        display: block;
        width: 100%;
        text-align: left;
        padding: 8px 12px;
    }

    /* Hide certain columns on mobile */
    .hide-on-mobile {
        display: none !important;
    }

    /* Full width dropdowns on mobile */
    .district-dropdown {
        position: fixed !important;
        left: 16px !important;
        right: 16px !important;
        width: auto !important;
        max-height: 50vh !important;
        bottom: 0 !important;
        top: auto !important;
        border-radius: 16px 16px 0 0 !important;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15) !important;
        z-index: 1000 !important;
    }

    /* Mobile dropdown overlay */
    .dropdown-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 999;
    }

    /* Better header on mobile */
    header .max-w-5xl {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Compact progress bar on mobile */
    .progress-container {
        padding: 12px;
    }

    /* Stack stats cards vertically */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    /* Mobile-friendly welcome guide */
    #welcome-guide {
        padding: 16px;
        margin: 8px;
        border-radius: 12px;
    }

    #welcome-guide .grid {
        grid-template-columns: 1fr !important;
        gap: 8px;
    }

    /* Full width buttons on mobile */
    .mobile-full-width {
        width: 100%;
    }

    /* Better table scrolling */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Compact admin table on mobile */
    #admin-clinician-table td {
        padding: 12px 8px;
        font-size: 14px;
    }

    /* Mobile entry row styling */
    .mobile-entry-row {
        background: white;
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        border: 1px solid #e5e7eb;
    }

    .mobile-entry-row .field-group {
        margin-bottom: 12px;
    }

    .mobile-entry-row .field-label {
        font-size: 12px;
        font-weight: 600;
        color: #6b7280;
        margin-bottom: 6px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    /* Tabs full width on mobile */
    .tab-button {
        flex: 1;
        justify-content: center;
    }
}

/* Small phone optimizations */
@media (max-width: 380px) {
    #welcome-guide h3 {
        font-size: 16px;
    }

    #welcome-guide p {
        font-size: 12px;
    }

    .stats-card {
        padding: 12px;
    }

    .stats-card .stat-number {
        font-size: 24px;
    }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding-left: 24px;
        padding-right: 24px;
    }

    #welcome-guide .grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Touch-friendly interactive elements */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .hover\:bg-gray-50:hover {
        background-color: inherit;
    }

    /* Add active state instead */
    .hover\:bg-gray-50:active {
        background-color: #f9fafb;
    }

    /* Larger click areas */
    .clickable-row {
        min-height: 56px;
    }

    /* Dropdown items */
    .dropdown-item {
        min-height: 48px;
        display: flex;
        align-items: center;
    }
}

/* Safe area padding for notched phones */
@supports (padding: max(0px)) {
    .safe-area-bottom {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .safe-area-top {
        padding-top: max(0px, env(safe-area-inset-top));
    }
}

/* Prevent body scroll when modal/dropdown open */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}
