/**
 * Airtable Form Widget - Custom Styles
 * Embeddable, responsive design for seamless integration
 */

/* Reset and base styles for embedding */
#airtable-form-widget {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    box-sizing: border-box;
    line-height: 1.6;
    color: #374151;
    max-width: 100%;
    margin: 0 auto;
}

#airtable-form-widget *,
#airtable-form-widget *::before,
#airtable-form-widget *::after {
    box-sizing: inherit;
}

/* Embedding styles for iframe compatibility */
.embeddable {
    width: 100%;
    height: 100vh;
    min-height: 600px;
    border: none;
    margin: 0;
    padding: 0;
}

/* Configuration panel animations */
#config-panel {
    transition: all 0.3s ease;
}

#config-form {
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 200px;
    opacity: 1;
    overflow: hidden;
}

#config-form.collapsed {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
}

#toggle-config {
    transition: transform 0.3s ease;
}

#toggle-config.rotated {
    transform: rotate(180deg);
}

/* Campaign list styling */
.campaign-type-group {
    margin-bottom: 24px;
}

.campaign-item {
    padding: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    margin-bottom: 8px;
}

.campaign-item:hover {
    border-color: #3b82f6;
    background: #f8faff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}

.campaign-item.selected {
    border-color: #3b82f6;
    background: linear-gradient(135deg, #dbeafe 0%, #ede9fe 100%);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.campaign-title {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 8px;
    font-size: 16px;
    line-height: 1.4;
}

.campaign-details {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.detail-item {
    display: inline-flex;
    align-items: center;
    font-size: 13px;
    color: #6b7280;
    font-weight: 500;
}

.campaign-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-top: 8px;
    border-top: 1px solid #f3f4f6;
}

/* Legacy record styles for backward compatibility */
.record-item {
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.record-item:hover {
    border-color: #3b82f6;
    background: #f8faff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.record-item.selected {
    border-color: #3b82f6;
    background: linear-gradient(135deg, #dbeafe 0%, #ede9fe 100%);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.record-title {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
    font-size: 14px;
}

.record-subtitle {
    color: #6b7280;
    font-size: 12px;
    line-height: 1.4;
}

.record-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.record-field-tag {
    background: #f3f4f6;
    color: #374151;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #e5e7eb;
}

/* Calendar customizations */
.interactive-calendar {
    width: 100%;
    max-width: 100%;
}

.interactive-calendar .day-cell {
    position: relative;
    border-radius: 6px;
    font-weight: 500;
}

.interactive-calendar .day-cell:hover {
    background: #dbeafe !important;
    color: #1e40af !important;
}

.interactive-calendar .day-cell.selected {
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%) !important;
    color: white !important;
    font-weight: 700;
}

/* Loading states */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.skeleton-loader {
    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; }
}

/* Form controls enhancement */
input:focus, select:focus, textarea:focus {
    outline: none;
    ring-width: 2px;
    ring-color: #3b82f6;
    border-color: #3b82f6;
}

button {
    transition: all 0.2s ease;
}

button:hover {
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

/* Status indicators */
.status-indicator {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

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

.status-indicator.error {
    background: #fef2f2;
    color: #dc2626;
}

.status-indicator.warning {
    background: #fef3c7;
    color: #d97706;
}

.status-indicator.info {
    background: var(--locale-lightest);
    color: var(--locale-medium);
}

/* Responsive design */
@media (max-width: 1024px) {
    #airtable-form-widget .flex.flex-col.lg\\:flex-row {
        flex-direction: column;
    }
    
    #airtable-form-widget .flex-1.p-6.border-r {
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .interactive-calendar {
        margin-top: 20px;
    }
}

@media (max-width: 768px) {
    #config-form {
        grid-template-columns: 1fr;
    }
    
    .record-item {
        padding: 10px 12px;
    }
    
    .interactive-calendar .calendar-header {
        padding: 12px;
    }
    
    .interactive-calendar .calendar-body {
        padding: 12px;
    }
    
    footer .flex {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
}

@media (max-width: 640px) {
    #airtable-form-widget {
        margin: 0;
        border-radius: 0;
    }
    
    header {
        padding: 16px !important;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .flex-1.p-6 {
        padding: 16px !important;
    }
    
    footer {
        padding: 16px !important;
    }
    
    .interactive-calendar .day-cell {
        height: 36px;
        font-size: 13px;
    }
}

/* Embedding specific styles */
body.embedded {
    margin: 0;
    padding: 0;
    background: transparent;
}

.embedded #airtable-form-widget {
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    box-shadow: none;
    border: none;
}

/* 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-width: 0;
}

/* Focus styles for keyboard navigation */
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--locale-medium);
    outline-offset: 2px;
}

.record-item:focus-visible {
    outline: 2px solid var(--locale-medium);
    outline-offset: 2px;
}

.interactive-calendar .day-cell:focus-visible {
    outline: 2px solid var(--locale-medium);
    outline-offset: 1px;
}

/* LOCALE Brand Colors */
:root {
    --locale-lightest: #B7D3F2;
    --locale-light: #AFAFDC;
    --locale-medium: #8A84E2;
    --locale-blue: #84AFE6;
    --locale-dark: #79BEEE;
}

/* Custom Tailwind-style LOCALE color utilities */
.text-locale-lightest { color: var(--locale-lightest) !important; }
.text-locale-light { color: var(--locale-light) !important; }
.text-locale-medium { color: var(--locale-medium) !important; }
.text-locale-blue { color: var(--locale-blue) !important; }
.text-locale-dark { color: var(--locale-dark) !important; }

.bg-locale-lightest { background-color: var(--locale-lightest) !important; }
.bg-locale-light { background-color: var(--locale-light) !important; }
.bg-locale-medium { background-color: var(--locale-medium) !important; }
.bg-locale-blue { background-color: var(--locale-blue) !important; }
.bg-locale-dark { background-color: var(--locale-dark) !important; }

.border-locale-lightest { border-color: var(--locale-lightest) !important; }
.border-locale-light { border-color: var(--locale-light) !important; }
.border-locale-medium { border-color: var(--locale-medium) !important; }
.border-locale-blue { border-color: var(--locale-blue) !important; }
.border-locale-dark { border-color: var(--locale-dark) !important; }

.focus\:ring-locale-medium:focus { 
    --tw-ring-color: var(--locale-medium) !important; 
}
.focus\:border-locale-medium:focus { 
    --tw-border-opacity: 1;
    border-color: var(--locale-medium) !important; 
}

.hover\:bg-locale-dark:hover { background-color: var(--locale-dark) !important; }
.hover\:text-locale-medium:hover { color: var(--locale-medium) !important; }
.hover\:from-locale-dark:hover { --tw-gradient-from: var(--locale-dark) !important; }
.hover\:to-locale-blue:hover { --tw-gradient-to: var(--locale-blue) !important; }

/* LOCALE Logo Header Styling */
.locale-logo-header {
    background: var(--locale-lightest);
    border-bottom: 1px solid rgba(138, 132, 226, 0.2);
}

/* Company Details Form Styling */
#company-details-section {
    background: linear-gradient(135deg, var(--locale-lightest) 0%, var(--locale-light) 50%, #f8faff 100%);
}

#company-details-form {
    animation: fadeIn 0.3s ease-in-out;
}

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

/* Form field enhancements */
#company-details-form input:focus,
#company-details-form textarea:focus,
#company-details-form select:focus {
    ring: 2px;
    ring-color: var(--locale-medium);
    border-color: var(--locale-medium);
    box-shadow: 0 0 0 3px rgba(138, 132, 226, 0.15);
}

#company-details-form input:invalid {
    border-color: #ef4444;
}

#company-details-form input:valid {
    border-color: #10b981;
}

/* Section headers */
#company-details-form h3 {
    position: relative;
    padding-left: 20px;
}

#company-details-form h3:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 20px;
    background: linear-gradient(135deg, var(--locale-medium), var(--locale-dark));
    border-radius: 2px;
}

/* Button enhancements */
#company-details-form button[type="submit"] {
    background: linear-gradient(135deg, var(--locale-medium) 0%, var(--locale-dark) 100%);
    transition: all 0.2s ease;
}

#company-details-form button[type="submit"]:hover {
    background: linear-gradient(135deg, var(--locale-dark) 0%, var(--locale-blue) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(138, 132, 226, 0.3);
}

#save-company-details:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Status styling */
#company-details-status {
    transition: all 0.3s ease;
    font-weight: 500;
}

/* Responsive adjustments for Company Details */
@media (max-width: 768px) {
    #company-details-form {
        grid-template-columns: 1fr;
    }
    
    #company-details-form .md\\:col-span-2 {
        grid-column: span 1;
    }
    
    #company-details-section .flex {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    #company-details-section .flex .flex {
        justify-content: stretch;
    }
}

/* Print styles */
@media print {
    #airtable-form-widget {
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    button {
        display: none;
    }
    
    .interactive-calendar .calendar-header button {
        display: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .record-item {
        border-width: 2px;
    }
    
    .record-item.selected {
        border-width: 3px;
    }
    
    .interactive-calendar .day-cell.selected {
        border: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Custom scrollbar */
.max-h-96::-webkit-scrollbar {
    width: 6px;
}

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

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

.max-h-96::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Error and success messages */
.message-banner {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    max-width: 400px;
    animation: slideIn 0.3s ease;
}

.message-banner.success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.message-banner.error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Tooltip styles */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 200px;
    background-color: #374151;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px;
    font-size: 12px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -100px;
    opacity: 0;
    transition: opacity 0.3s;
}

.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #374151 transparent transparent transparent;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}