/* Tailwind CSS directives */
@tailwind base;
@tailwind components;
@tailwind utilities;

/* Custom styles for zen.agency CRM */

/* Force scrollbar gutter to prevent layout shifts */
html {
    scrollbar-gutter: stable;
}

/* Alpine.js x-cloak - hide elements until Alpine is ready */
[x-cloak] {
    display: none !important;
}

/* GLOBAL MODAL/LIGHTBOX ANTI-GLITCH - Prevent all popups from spazzing */
[x-show].fixed,
.fixed[role="dialog"],
.fixed.z-50,
.fixed.z-\\[9999\\],
div[x-show^="show"],
div[x-show*="Modal"],
div[x-show*="modal"],
div[id*="modal"],
div[id*="Modal"] {
    transition: none !important;
    transform: none !important;
    animation: none !important;
}

/* Kill all transitions/transforms on modals and their children */
[x-show].fixed *,
.fixed[role="dialog"] *,
.fixed.z-50 *,
.fixed.z-\\[9999\\] *,
div[x-show^="show"] *,
div[x-show*="Modal"] *,
div[x-show*="modal"] *,
div[id*="modal"] *,
div[id*="Modal"] * {
    transition: none !important;
    transform: none !important;
    animation: none !important;
}

/* Override hover effects on modals */
[x-show].fixed:hover,
.fixed[role="dialog"]:hover,
.fixed.z-50:hover,
.fixed.z-\\[9999\\]:hover,
div[x-show^="show"]:hover,
div[x-show*="Modal"]:hover,
div[x-show*="modal"]:hover,
div[id*="modal"]:hover,
div[id*="Modal"]:hover {
    transition: none !important;
    transform: none !important;
    animation: none !important;
    box-shadow: none !important;
}

[x-show].fixed *:hover,
.fixed[role="dialog"] *:hover,
.fixed.z-50 *:hover,
.fixed.z-\\[9999\\] *:hover,
div[x-show^="show"] *:hover,
div[x-show*="Modal"] *:hover,
div[x-show*="modal"] *:hover,
div[id*="modal"] *:hover,
div[id*="Modal"] *:hover {
    transition: none !important;
    transform: none !important;
    animation: none !important;
}

/* Specific override for card-hover and btn-smooth classes inside modals */
[x-show].fixed .card-hover,
[x-show].fixed .card-hover:hover,
[x-show].fixed .btn-smooth,
[x-show].fixed .btn-smooth:hover,
.fixed[role="dialog"] .card-hover,
.fixed[role="dialog"] .card-hover:hover,
.fixed[role="dialog"] .btn-smooth,
.fixed[role="dialog"] .btn-smooth:hover {
    transition: none !important;
    transform: none !important;
    animation: none !important;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1) !important;
}

/* Modal backdrop - completely static */
.modal-anti-glitch,
[x-show].fixed.inset-0,
.fixed.inset-0[role="dialog"] {
    position: fixed !important;
    transition: none !important;
    transform: none !important;
    animation: none !important;
}

/* Custom scrollbar styles */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Ensure modals are hidden by default */
[x-show="false"] {
    display: none !important;
}

/* Fix for Alpine.js modal initialization */
[x-data] [x-show]:not([x-show="true"]) {
    display: none;
}

/* Stable Modal Positioning - Prevents jumping/erratic movement */
.zen-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

/* CRITICAL: Ensure hidden class works on modals - MAXIMUM OVERRIDE */
.zen-modal-overlay.hidden,
#projectActionsModal.hidden,
div[id*="modal"].hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    z-index: -9999 !important;
}

/* Force hide by default until explicitly shown */
#projectActionsModal {
    display: none;
}

#projectActionsModal:not(.hidden) {
    display: flex !important;
}

.zen-modal-content {
    position: relative;
    background-color: white;
    border-radius: 0.5rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 28rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.zen-modal-content-lg {
    max-width: 42rem;
}

.zen-modal-content-xl {
    max-width: 56rem;
}

/* CRITICAL: Override anti-glitch rules for zen-modal classes */
/* These modals use flexbox centering, NOT transform centering, so they need special treatment */
.zen-modal-overlay.zen-modal-overlay.zen-modal-overlay {
    position: fixed !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transform: none !important;
    transition: none !important;
    animation: none !important;
    pointer-events: auto !important;
    cursor: pointer;
}

.zen-modal-content.zen-modal-content.zen-modal-content {
    position: relative !important;
    transform: none !important;
    transition: none !important;
    animation: none !important;
    pointer-events: auto !important;
    cursor: default;
}

/* Prevent children from inheriting bad transform rules but allow pointer events */
.zen-modal-overlay *, 
.zen-modal-content * {
    transform: none !important;
    transition: none !important;
    animation: none !important;
    pointer-events: auto !important;
}

/* Ensure buttons and links inside modals are clickable - MAXIMUM SPECIFICITY */
button.px-4.py-2,
.zen-modal-content button,
.zen-modal-content a,
.zen-modal-content input,
.zen-modal-content select,
.zen-modal-content textarea,
#closeProjectActionsBtn,
#projectActionsModal button {
    pointer-events: auto !important;
    cursor: pointer !important;
    user-select: auto !important;
}

/* Force enable all interaction on zen-modal buttons */
div[id*="modal"] button {
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* Custom focus styles for zen.agency branding */
.zen-focus:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

/* Logo animations */
.zen-logo-dot {
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Custom button hover effects */
.zen-btn-primary {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    transition: all 0.2s ease;
}

.zen-btn-primary:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* Card hover effects */
.zen-card {
    transition: all 0.2s ease;
}

.zen-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

/* Progress bar animations */
.zen-progress-bar {
    background: linear-gradient(90deg, #ef4444 0%, #f87171 100%);
    transition: width 0.8s ease-in-out;
}

/* Status badge styles */
.status-badge {
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-active {
    background-color: #dcfce7;
    color: #166534;
}

.status-draft {
    background-color: #f1f5f9;
    color: #475569;
}

.status-ready {
    background-color: #dbeafe;
    color: #1e40af;
}

.status-in-progress {
    background-color: #fed7aa;
    color: #ea580c;
}

.status-internal-review {
    background-color: #e9d5ff;
    color: #6b21a8;
}

.status-testing {
    background-color: #fed7aa;
    color: #c2410c;
}

.status-uat {
    background-color: #ccfbf1;
    color: #115e59;
}

.status-ready-for-launch {
    background-color: #ddd6fe;
    color: #5b21b6;
}

.status-blocked {
    background-color: #fee2e2;
    color: #991b1b;
}

.status-completed {
    background-color: #dcfce7;
    color: #166534;
}

/* Priority indicators */
.priority-low {
    border-left: 4px solid #10b981;
}

.priority-medium {
    border-left: 4px solid #f59e0b;
}

.priority-high {
    border-left: 4px solid #f97316;
}

.priority-urgent {
    border-left: 4px solid #ef4444;
}

/* Custom form styles */
.zen-form-input {
    transition: all 0.2s ease;
    border: 1px solid #d1d5db;
}

.zen-form-input:focus {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.zen-form-label {
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.5rem;
    display: block;
}

/* Header navigation buttons styling */
.header-nav-button {
    padding: 0.375rem;
    color: #6b7280;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
}

.header-nav-button:hover {
    color: #ef4444;
    background-color: #f3f4f6;
}

/* Navigation active states */
.nav-link-active {
    border-bottom: 2px solid #ef4444;
    color: #111827;
}

.nav-link {
    border-bottom: 2px solid transparent;
    color: #6b7280;
    transition: all 0.2s ease;
}

.nav-link:hover {
    color: #374151;
    border-bottom-color: #d1d5db;
}

/* Kanban board styles */
.kanban-column {
    background: #f8fafc;
    border-radius: 8px;
    padding: 1rem;
    min-height: 600px;
    display: flex;
    flex-direction: column;
}

.kanban-card {
    background: white;
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    transition: all 0.2s ease;
}

.kanban-card:hover {
    border-color: #ef4444;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.1);
}

/* Time tracking styles */
.time-entry {
    border-left: 3px solid #ef4444;
    padding-left: 1rem;
    margin-bottom: 1rem;
}

.time-summary {
    background: linear-gradient(135deg, #fef2f2 0%, #fef7f7 100%);
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 1.5rem;
}

/* Avatar styles */
.zen-avatar {
    background: #ef4444;
    color: white;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

/* Dashboard stats cards */
.stats-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    border: 1px solid #e5e7eb;
    transition: all 0.2s ease;
}

.stats-card:hover {
    border-color: #ef4444;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.1);
}

.stats-icon {
    background: #fef2f2;
    border-radius: 8px;
    padding: 0.75rem;
    color: #ef4444;
}

/* Loading states */
.zen-loading {
    position: relative;
    overflow: hidden;
}

.zen-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.1), transparent);
    animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
    100% {
        left: 100%;
    }
}

/* Dark mode support (for future enhancement) */
@media (prefers-color-scheme: dark) {
    .zen-dark {
        background-color: #1f2937;
        color: #f9fafb;
    }

    .zen-dark .zen-card {
        background-color: #374151;
        border-color: #4b5563;
    }
}

/* Mobile responsive adjustments */
@media (max-width: 640px) {
    .zen-mobile-stack {
        flex-direction: column;
    }

    .zen-mobile-full {
        width: 100%;
        margin-bottom: 1rem;
    }

    .zen-mobile-text-sm {
        font-size: 0.875rem;
    }
}

/* Enhanced mobile touch targets and forms */
@media (max-width: 768px) {
    /* Touch-friendly button sizing */
    button, .btn, a.btn, input[type="button"], input[type="submit"] {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 16px; /* Prevents iOS zoom */
    }

    /* Form inputs mobile optimization */
    input[type="text"], input[type="email"], input[type="password"], 
    input[type="tel"], input[type="url"], input[type="search"], 
    input[type="number"], input[type="date"], input[type="datetime-local"],
    textarea, select {
        font-size: 16px; /* Prevents iOS zoom */
        min-height: 44px;
        padding: 12px;
        border-radius: 8px;
    }

    /* Card touch improvements */
    .zen-card {
        padding: 16px;
        margin-bottom: 12px;
    }

    /* Navigation touch targets */
    .nav-link, .sidebar-nav a {
        min-height: 48px;
        padding: 12px 16px;
        display: flex;
        align-items: center;
    }

    /* Modal improvements */
    .modal-content {
        margin: 20px;
        max-width: calc(100vw - 40px);
    }

    /* Table responsive improvements */
    .zen-table {
        font-size: 14px;
    }

    .zen-table th,
    .zen-table td {
        padding: 12px 8px;
        min-width: 100px;
    }

    /* Filter button improvements */
    .status-filter, .task-filter {
        font-size: 14px;
        padding: 10px 12px;
        margin: 2px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    /* Reduce padding on very small screens */
    .container, .max-w-7xl {
        padding-left: 16px;
        padding-right: 16px;
    }

    /* Stack statistics cards */
    .grid-cols-3 {
        grid-template-columns: 1fr;
    }

    /* Smaller text on mobile */
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.125rem; }
}

/* Print styles */
@media print {
    .zen-no-print {
        display: none !important;
    }

    .zen-print-break {
        page-break-before: always;
    }

    body {
        background: white !important;
        color: black !important;
    }
}

/* Accessibility improvements */
.zen-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.zen-focus-visible:focus {
    outline: 2px solid #ef4444;
    outline-offset: 2px;
}

/* HTMX specific styles */
.htmx-request {
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.htmx-request.htmx-indicator {
    opacity: 1;
}

/* Custom animations */
.zen-fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

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

.zen-slide-in {
    animation: slideIn 0.3s ease-out;
}

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

/* Error states */
.zen-error {
    border-color: #ef4444;
    background-color: #fef2f2;
}

.zen-error-text {
    color: #dc2626;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Success states */
.zen-success {
    border-color: #10b981;
    background-color: #f0fdf4;
}

.zen-success-text {
    color: #059669;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Custom dropdown styles */
.zen-dropdown {
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.zen-dropdown-item {
    padding: 0.75rem 1rem;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
}

.zen-dropdown-item:hover {
    background-color: #fef2f2;
    color: #ef4444;
}

/* Table styles */
.zen-table {
    border-collapse: collapse;
    width: 100%;
}

.zen-table th {
    background-color: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: #374151;
}

.zen-table td {
    border-bottom: 1px solid #f3f4f6;
    padding: 0.75rem;
    color: #6b7280;
}

.zen-table tr:hover {
    background-color: #fef2f2;
}

/* Comprehensive Dark Mode Hover States */
html.dark .hover\\:bg-gray-50:hover,
html.dark .hover\\:bg-zen-gray-50:hover,
html.dark .hover\\:bg-gray-100:hover,
html.dark .hover\\:bg-zen-gray-100:hover,
html.dark .hover\\:bg-white:hover {
    background-color: #374151 !important;
}

html.dark .hover\\:bg-gray-200:hover,
html.dark .hover\\:bg-zen-gray-200:hover {
    background-color: #4b5563 !important;
}

html.dark .hover\\:bg-red-50:hover,
html.dark .hover\\:bg-blue-50:hover,
html.dark .hover\\:bg-green-50:hover,
html.dark .hover\\:bg-yellow-50:hover {
    background-color: #374151 !important;
}

/* Dark mode table and row hover states */
html.dark .zen-table tr:hover,
html.dark tr:hover,
html.dark tr.hover\\:bg-zen-gray-50:hover,
html.dark tr.hover\\:bg-gray-50:hover {
    background-color: #374151 !important;
}

/* Dark mode contact/list item hover states (exclude form elements) */
html.dark .cursor-pointer:hover:not(input):not(select):not(textarea),
html.dark [role="button"]:hover:not(button[type="submit"]) {
    background-color: #374151 !important;
}

/* Dark mode card hover states (more specific to avoid form elements) */
html.dark .bg-white.card:hover,
html.dark .bg-white[role="button"]:hover {
    background-color: #374151 !important;
}

/* Dark mode button hover states (preserve specific button colors) */
html.dark .hover\\:bg-red-600:hover {
    background-color: #dc2626 !important;
}

html.dark .hover\\:bg-green-700:hover {
    background-color: #15803d !important;
}

html.dark .hover\\:bg-blue-600:hover {
    background-color: #2563eb !important;
}

/* CRM Navigation Tab Dark Mode Hover States */
html.dark button.hover\\:bg-gray-100:hover:not(.bg-zen-red),
html.dark a.hover\\:bg-gray-100:hover:not(.bg-zen-red),
html.dark .hover\\:text-gray-900:hover:not(.bg-zen-red) {
    background-color: #374151 !important;
    color: #f9fafb !important;
}

/* Force dark mode hover for all navigation elements (excluding active tabs) */
html.dark nav button:hover:not(.bg-zen-red),
html.dark nav a:hover:not(.bg-zen-red) {
    background-color: #374151 !important;
    color: #f9fafb !important;
}

/* Specific CRM tab hover overrides (excluding active tabs) */
html.dark .px-3.py-1\\.5:hover:not(.bg-zen-red) {
    background-color: #374151 !important;
    color: #f9fafb !important;
}

/* Dark mode text hover states (excluding active tabs) */
html.dark .text-gray-600:hover:not(.bg-zen-red) {
    color: #f9fafb !important;
}

/* Ensure active tabs maintain their styling in dark mode */
html.dark .bg-zen-red {
    background-color: #dc2626 !important;
    color: white !important;
}

html.dark .bg-zen-red:hover {
    background-color: #b91c1c !important;
    color: white !important;
}


/* Debug CSS for sentiment button visibility */
.bg-blue-50 button {
    z-index: 9999 !important;
    position: relative !important;
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    min-width: 30px !important;
    min-height: 30px !important;
    background-color: white !important;
    border: 1px solid #ccc !important;
}

.bg-blue-50 button [data-feather] {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 16px !important;
    height: 16px !important;
}

.bg-blue-50 button svg {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 16px !important;
    height: 16px !important;
}

/* Force visibility on edit modals */
.z-\\[9999\\] {
    z-index: 9999 !important;
}

/* Project card dropdown menu positioning fix */
.dropdown-menu {
    z-index: 9999 !important;
    position: absolute !important;
}

/* Ensure project cards don't clip dropdowns */
.grid > div {
    position: relative;
    overflow: visible !important;
}