/* Dark mode toggle styles */

/* Force dark mode colors regardless of .dark class */
body {
    background: #111827 !important;
    color: #e5e7eb !important;
}

.bg-white, [class*="bg-white "] {
    background-color: #1f2937 !important;
}

[class*="bg-white/"] {
    background-color: rgba(31, 41, 55, 0.8) !important;
}

.bg-gray-50, [class*="bg-gray-50 "] {
    background-color: #111827 !important;
}

.text-gray-900, [class*="text-gray-900 "] {
    color: #f9fafb !important;
}

.text-gray-800, [class*="text-gray-800 "] {
    color: #f3f4f6 !important;
}

.text-gray-700, [class*="text-gray-700 "] {
    color: #d1d5db !important;
}

.text-gray-600, [class*="text-gray-600 "] {
    color: #9ca3af !important;
}

.text-gray-500, [class*="text-gray-500 "] {
    color: #9ca3af !important;
}

.border-gray-200, [class*="border-gray-200 "] {
    border-color: #374151 !important;
}

.border-gray-100, [class*="border-gray-100 "] {
    border-color: #374151 !important;
}

.bg-gray-100, [class*="bg-gray-100 "] {
    background-color: #1f2937 !important;
}

.shadow-lg, .shadow-xl, .shadow-md, .shadow-sm, .shadow {
    box-shadow: 0 1px 3px 0 rgba(0,0,0,0.3) !important;
}

/* Gradient backgrounds override */
[class*="from-gray-50"], [class*="to-gray-100"] {
    background: #111827 !important;
}

/* Modal/dropdown overrides */
.modal, [class*="modal"] {
    background-color: rgba(0,0,0,0.7) !important;
}

/* Card-specific overrides */
.dashboard-card, .metric-card, .modern-card {
    background: #1e293b !important;
    border-color: #334155 !important;
}

:root {
    --z-critical: 999999;
}

.header-card {
    z-index: 100;
    position: relative;
}

.user-menu-container {
    position: relative !important;
    overflow: visible !important;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #2196F3;
}

input:checked + .slider:before {
    transform: translateX(24px);
}

/* Status badge styling for appointments and repair orders */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* Card hover effects */
.appointment-card:hover,
.ro-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Dark mode specific hover effects */
.dark .appointment-card:hover,
.dark .ro-card:hover {
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

/* Dropdown menu animations */
.appointment-dropdown,
.status-dropdown {
    transition: opacity 0.15s ease-out, transform 0.15s ease-out;
}

.appointment-dropdown.hidden,
.status-dropdown.hidden {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

/* Menu button hover effects */
.appointment-menu-btn:hover,
.hamburger-menu-btn:hover {
    background-color: rgba(107, 114, 128, 0.1);
}

.dark .appointment-menu-btn:hover,
.dark .hamburger-menu-btn:hover {
    background-color: rgba(156, 163, 175, 0.1);
}

/* Custom scrollbar for modal */
.max-h-\[90vh\]::-webkit-scrollbar {
    width: 6px;
}

.max-h-\[90vh\]::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.max-h-\[90vh\]::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.max-h-\[90vh\]::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.dark .max-h-\[90vh\]::-webkit-scrollbar-track {
    background: #374151;
}

.dark .max-h-\[90vh\]::-webkit-scrollbar-thumb {
    background: #6b7280;
}

.dark .max-h-\[90vh\]::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Notification animations */
#notification-root .transform {
    transition: all 0.3s ease-in-out;
}

/* Tab styles */
.tab-active {
    border-color: #3b82f6;
    color: #3b82f6;
}

.tab-inactive {
    border-color: transparent;
    color: #6b7280;
}

.tab-inactive:hover {
    color: #374151;
    border-color: #d1d5db;
}

.dark .tab-inactive:hover {
    color: #d1d5db;
    border-color: #4b5563;
}

/* Button loading states */
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Form focus states */
input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 1px #3b82f6;
}

.dark input:focus,
.dark textarea:focus,
.dark select:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 1px #60a5fa;
}

/* Custom animations for cards */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.appointment-card,
.ro-card {
    animation: slideInUp 0.3s ease-out;
}

/* Status-specific styling */
.border-l-red-500 {
    border-left-color: #ef4444;
}

.border-l-blue-500 {
    border-left-color: #3b82f6;
}

.border-l-orange-500 {
    border-left-color: #f97316;
}

.border-l-green-500 {
    border-left-color: #22c55e;
}

.border-l-purple-500 {
    border-left-color: #a855f7;
}

/* Overdue styling */
.bg-red-50 {
    background-color: #fef2f2;
}

.dark .bg-red-900\/10 {
    background-color: rgba(127, 29, 29, 0.1);
}

.border-red-200 {
    border-color: #fecaca;
}

.dark .border-red-800 {
    border-color: #991b1b;
}

/* Turn into RO button styling */
.turn-into-ro-btn {
    transition: all 0.2s ease-in-out;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.turn-into-ro-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.turn-into-ro-btn:active {
    transform: translateY(0);
}

/* Pulsing animation for urgent turn-into-RO buttons */
.turn-into-ro-btn.pulse {
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
        transform: scale(1.02);
    }
}

/* Print styles */
@media print {
    .appointment-menu-container,
    .status-menu-container,
    .hamburger-menu-btn,
    .appointment-menu-btn {
        display: none !important;
    }
}

/* Mobile responsiveness */
@media (max-width: 640px) {
    .appointment-card,
    .ro-card {
        padding: 1rem;
    }
    
    .status-badge {
        font-size: 0.625rem;
        padding: 0.125rem 0.375rem;
    }
    
    .appointment-dropdown,
    .status-dropdown {
        width: 180px;
        right: -20px;
    }
}

/* Collapsible Day Sections Styling */
.day-section {
    transition: all 0.3s ease-in-out;
}

.day-header {
    user-select: none;
    transition: all 0.2s ease-in-out;
}

.day-header:hover {
    transform: translateY(-1px);
}

.day-header:active {
    transform: translateY(0);
}

.chevron-icon {
    transition: transform 0.2s ease-in-out;
}

.day-appointments {
    transition: all 0.3s ease-in-out;
    overflow: hidden;
}

.day-appointments.hidden {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

.day-appointments:not(.hidden) {
    max-height: 2000px;
    opacity: 1;
}

/* Day header gradient animations */
.day-header.from-blue-600:hover {
    background: linear-gradient(to right, #2563eb, #1d4ed8);
}

.day-header.from-green-600:hover {
    background: linear-gradient(to right, #059669, #047857);
}

.day-header.from-gray-500:hover {
    background: linear-gradient(to right, #6b7280, #4b5563);
}

/* Responsive adjustments for day sections */
@media (max-width: 640px) {
    .day-header .text-lg {
        font-size: 1rem;
    }
    
    .day-header .text-sm {
        font-size: 0.75rem;
    }
    
    .day-header .px-3 {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* Dark mode specific adjustments */
.dark .day-header {
    border: 1px solid rgba(75, 85, 99, 0.3);
}

.dark .day-appointments {
    border-left: 2px solid rgba(75, 85, 99, 0.3);
    padding-left: 1rem;
    margin-left: 1rem;
}

/* Animation for appointment cards within day sections */
.day-appointments .appointment-card {
    animation: slideInFromLeft 0.3s ease-out;
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Staggered animation for multiple appointments */
.day-appointments .appointment-card:nth-child(1) { animation-delay: 0.1s; }
.day-appointments .appointment-card:nth-child(2) { animation-delay: 0.2s; }
.day-appointments .appointment-card:nth-child(3) { animation-delay: 0.3s; }
.day-appointments .appointment-card:nth-child(4) { animation-delay: 0.4s; }
.day-appointments .appointment-card:nth-child(5) { animation-delay: 0.5s; }

/* Expand/collapse button styling */
.expand-all-btn,
.collapse-all-btn {
    transition: all 0.2s ease-in-out;
}

.expand-all-btn:hover,
.collapse-all-btn:hover {
    transform: scale(1.05);
}
/* Add this to your style.css file */

/* RO Origin Indicator Styling */
.ro-origin-indicator {
    animation: slideInFromTop 0.5s ease-out;
    transition: all 0.3s ease-in-out;
}

.ro-origin-indicator:hover {
    background-color: rgb(239 246 255 / 0.8);
}

.dark .ro-origin-indicator:hover {
    background-color: rgb(30 58 138 / 0.3);
}

/* Animation for the indicator */
@keyframes slideInFromTop {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Close button styling */
.ro-origin-indicator button {
    transition: all 0.2s ease-in-out;
    padding: 0.25rem;
    border-radius: 0.25rem;
}

.ro-origin-indicator button:hover {
    background-color: rgba(59, 130, 246, 0.1);
    transform: scale(1.1);
}

/* Responsive design for the indicator */
@media (max-width: 640px) {
    .ro-origin-indicator {
        padding: 0.75rem;
        margin-bottom: 1rem;
    }
    
    .ro-origin-indicator .text-sm {
        font-size: 0.875rem;
    }
    
    .ro-origin-indicator .text-xs {
        font-size: 0.75rem;
    }
}

/* Integration with existing quote form styling */
.quote-form .ro-origin-indicator {
    margin-top: 0;
    margin-bottom: 1.5rem;
}

/* Dark mode specific adjustments */
.dark .ro-origin-indicator {
    border-left-color: #60a5fa;
    background-color: rgba(30, 58, 138, 0.1);
}

/* === PHASE 1 ENHANCEMENTS === */

/* Customer Lookup Components */
.customer-lookup-dropdown {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border: 1px solid #e5e7eb;
    max-height: 400px;
    overflow-y: auto;
}

.dark .customer-lookup-dropdown {
    border-color: #374151;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.customer-result-item {
    transition: all 0.2s ease;
}

.customer-result-item:hover {
    transform: translateY(-1px);
}

.customer-lookup-btn {
    transition: all 0.2s ease;
    font-size: 0.875rem;
    white-space: nowrap;
}

.customer-lookup-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Customer Suggestions */
.customer-suggestion {
    animation: slideIn 0.3s ease-out;
}

.active-ro-suggestion {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Customer History Widget */
.customer-history-widget {
    border: 1px solid #e5e7eb;
    transition: all 0.2s ease;
}

.dark .customer-history-widget {
    border-color: #374151;
}

.customer-history-widget:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Quick Customer Lookup Modal */
.customer-quick-result {
    transition: all 0.2s ease;
}

.customer-quick-result:hover {
    transform: translateX(4px);
}

/* Navigation Loading Overlay */
#nav-loading-overlay {
    backdrop-filter: blur(2px);
}

/* Customer Highlighting */
.highlight-customer {
    animation: highlightPulse 2s ease-in-out;
}

@keyframes highlightPulse {
    0%, 100% {
        background-color: #fef3c7;
        border-color: #f59e0b;
    }
    50% {
        background-color: #fde68a;
        border-color: #d97706;
    }
}

.dark .highlight-customer {
    animation: highlightPulseDark 2s ease-in-out;
}

@keyframes highlightPulseDark {
    0%, 100% {
        background-color: #451a03;
        border-color: #d97706;
    }
    50% {
        background-color: #78350f;
        border-color: #f59e0b;
    }
}

/* Enhanced Form Styling */
.enhanced-form-field {
    position: relative;
}

.enhanced-form-field .field-enhancement {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 4px;
}

/* Search Results Styling */
.search-result-item {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    transition: all 0.2s ease;
}

.search-result-item:hover {
    background-color: #f3f4f6;
    padding-left: 20px;
}

.dark .search-result-item {
    border-color: #374151;
}

.dark .search-result-item:hover {
    background-color: #374151;
}

.search-result-item:last-child {
    border-bottom: none;
}

/* Modal Enhancements */
.modal-backdrop {
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    animation: slideUp 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Quick Action Buttons */
.quick-action-btn {
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.quick-action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.quick-action-btn:hover::before {
    left: 100%;
}

/* Data Transfer Indicators */
.data-transfer-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #3b82f6;
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    z-index: var(--z-notification);
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Enhanced Metric Cards */
.metric-card-clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

/* ===== Z-INDEX HIERARCHY ===== */
/* Standardized z-index system to prevent conflicts
 *
 * IMPORTANT: Always use these CSS variables instead of hardcoded z-index values
 * to maintain consistency and prevent specificity conflicts.
 *
 * Layer hierarchy (lowest to highest):
 * 1. Base content: 1-99 (--z-base)
 * 2. Dropdowns/menus: 1000-1999 (--z-dropdown)
 * 3. Modals: 5000-5999 (--z-modal)
 * 4. Notifications: 9000-9999 (--z-notification)
 * 5. Critical overlays: 9999+ (--z-critical)
 * 6. Priority modals: 10000+ (--z-modal-priority)
 */
:root {
    /* Base content */
    --z-base: 1;

    /* Dropdowns and menus */
    --z-dropdown: 1000;

    /* Modals and overlays */
    --z-modal: 5000;

    /* Priority modals (account settings, site settings) */
    --z-modal-priority: 10000;

    /* Notifications and toasts */
    --z-notification: 9000;

    /* Critical overlays (tooltips, etc.) */
    --z-critical: 9999;
}

/* Apply standardized z-index values */
.appointment-dropdown,
.status-dropdown,
.ro-dropdown {
    z-index: var(--z-dropdown) !important;
}

/* User dropdown - highest priority to beat notifications */
#user-dropdown {
    z-index: var(--z-critical) !important;
    /* Preserve CSS positioning - don't let JavaScript override these */
    position: absolute !important;
    right: 0 !important;
    margin-top: 0.5rem !important; /* mt-2 equivalent */
}

/* ===== PORTAL SYSTEM MODAL STYLES ===== */
/* General modal styles for all modals using the portal system */
.modal {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: var(--z-modal);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

/* Hide by default */
.modal.hidden {
    display: none;
}

/* Modal content animations */
.modal > div {
    animation: slideUp 0.3s ease-out;
}

/* Portal-based dropdown styles */
.dropdown-portal {
    position: fixed !important;
    z-index: var(--z-dropdown) !important;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    min-width: 200px;
    animation: dropdownSlideIn 0.2s ease-out;
}

.dark .dropdown-portal {
    background: #1f2937;
    border-color: #374151;
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Ensure dropdown portal items have proper styling */
.dropdown-portal .dropdown-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.dropdown-portal .dropdown-item:hover {
    background-color: #f3f4f6;
}

.dark .dropdown-portal .dropdown-item:hover {
    background-color: #374151;
}

/* Standard modals */
[id*="-modal"] {
    z-index: var(--z-modal) !important;
}

/* Priority modals (account settings, site settings) - consolidated */
.z-modal-priority,
#account-settings-modal,
#site-configuration-modal,
#site-settings-modal {
    z-index: var(--z-modal-priority) !important;
    position: fixed !important;
}

#notification-toast {
    z-index: var(--z-notification) !important;
}

/* Dropdown parent cards get elevated z-index when dropdown is open */
.appointment-card.dropdown-open,
.ro-card.dropdown-open {
    z-index: calc(var(--z-dropdown) + 1) !important;
}

/* Mobile navigation */
#mobile-navigation {
    z-index: calc(var(--z-dropdown) - 1) !important;
}

.metric-card-clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

/* Loading States */
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.dark .loading-skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
}

/* Responsive Enhancements */
@media (max-width: 768px) {
    .customer-lookup-dropdown {
        max-height: 300px;
    }

    .customer-lookup-btn {
        padding: 8px 12px;
        font-size: 0.75rem;
    }

    .quick-action-btn {
        padding: 12px;
        font-size: 0.875rem;
    }
}

/* Layout Stability - Prevent layout shifts during page load */
.container {
    min-height: 0; /* Prevent container from causing layout shifts */
}

body {
    overflow-x: hidden; /* Prevent horizontal scrolling during layout shifts */
}

/* Ensure main content containers have stable positioning */
.container.mx-auto {
    position: relative;
    width: 100%;
    max-width: 100%;
}

/* Accessibility Improvements */
.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;
}

.focus\:not-sr-only:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .customer-lookup-dropdown {
        border-width: 2px;
    }

    .customer-result-item:hover {
        outline: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .customer-suggestion,
    .active-ro-suggestion,
    .modal-content,
    .customer-quick-result,
    .quick-action-btn,
    .metric-card-clickable {
        animation: none;
        transition: none;
    }

    .customer-quick-result:hover,
    .metric-card-clickable:hover {
        transform: none;
    }
}

/* ===== SERVICE EDIT MODAL Z-INDEX FIX ===== */
/* Force service edit modal to use portal system z-index */
#service-edit-modal-quote {
    z-index: var(--z-modal-priority) !important;
    position: fixed !important;
}

#service-edit-modal-quote > div {
    z-index: var(--z-modal-priority) !important;
    position: relative !important;
}

/* Ensure all quote-related modals use priority z-index */
[id*="service-edit-modal"],
[id*="add-service-modal"],
[id*="custom-service-modal"] {
    z-index: var(--z-modal-priority) !important;
    position: fixed !important;
}

/* Force custom service modal to top */
#add-custom-service-modal {
    z-index: var(--z-modal-priority) !important;
    position: fixed !important;
}

#add-custom-service-modal > div {
    z-index: var(--z-modal-priority) !important;
    position: relative !important;
}
