/**
 * CRM Modal Styles
 * Styles for CRM system modal window
 * 
 * @version 1.0.0
 * @author CRM Integration System
 */

/* ===== MAIN MODAL WINDOW STYLES ===== */

.crm-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99990;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

/* Prevent page scrolling when modal is open */
body.crm-modal-open {
    overflow: hidden;
}

.crm-modal.show {
    opacity: 1;
    visibility: visible;
}

.crm-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.crm-modal-container {
    position: relative;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.crm-modal.show .crm-modal-container {
    transform: scale(1) translateY(0);
}

/* Modal window sizes */
.crm-modal-small {
    width: 400px;
    min-height: 300px;
}

.crm-modal-medium {
    width: 600px;
    min-height: 400px;
}

.crm-modal-large {
    width: 900px;
    min-height: 600px;
}

.crm-modal-fullscreen {
    width: 95vw;
    height: 95vh;
    max-width: none;
    max-height: none;
}

/* ===== MODAL WINDOW HEADER ===== */

.crm-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 12px 12px 0 0;
}

.crm-modal-title-section h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #111827;
    line-height: 1.2;
}

.crm-modal-subtitle {
    margin-top: 4px;
    font-size: 14px;
    color: #6b7280;
}

.crm-modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== NAVIGATION ===== */

.crm-modal-nav {
    display: flex;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    position: relative;
}

.crm-modal-nav::-webkit-scrollbar {
    display: none;
}

.crm-nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    transition: all 0.3s ease;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    min-width: 120px;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.crm-nav-item:hover {
    color: #374151;
    background: #f3f4f6;
}

.crm-nav-item.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    background: #eff6ff;
    transform: translateY(-1px);
}

.crm-nav-item.loading {
    opacity: 0.6;
    pointer-events: none;
}

.crm-nav-item.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 8px;
    width: 12px;
    height: 12px;
    border: 2px solid #2563eb;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: crm-spin 1s linear infinite;
    transform: translateY(-50%);
}

.crm-nav-item i {
    font-size: 16px;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== MODAL WINDOW CONTENT ===== */

.crm-modal-content {
    flex: 1;
    /* allow vertical scroll for long content */
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    background: #ffffff;
}

.crm-tab-content {
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
}

.crm-tab-content.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.crm-content {
    height: 100%;
    overflow-y: auto;
    padding: 24px;
    /* Extra bottom space so sticky actions don't overlap fields */
    padding-bottom: 96px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.crm-content.loading {
    opacity: 0.3;
    pointer-events: none;
}

.crm-content::-webkit-scrollbar {
    width: 6px;
}

.crm-content::-webkit-scrollbar-track {
    background: #f1f5f9;
}

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

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

/* ===== FORMS ===== */
.crm-form-actions {
    margin-top: 16px;
    padding: 12px 0 0 0;
    position: sticky;
    bottom: 0;
    z-index: 5;
}

/* ===== LOADING ===== */

.crm-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.crm-loading.show {
    opacity: 1;
    visibility: visible;
}

.crm-spinner {
    position: relative;
    width: 40px;
    height: 40px;
    margin-bottom: 16px;
}

.crm-spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-top: 3px solid #2563eb;
    border-radius: 50%;
    animation: crm-spin 1.2s linear infinite;
}

.crm-spinner-ring:nth-child(2) {
    animation-delay: -0.4s;
    border-top-color: #3b82f6;
}

.crm-spinner-ring:nth-child(3) {
    animation-delay: -0.8s;
    border-top-color: #60a5fa;
}

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

#crm-loading-text {
    margin: 0;
    font-size: 14px;
    color: #6b7280;
    font-weight: 500;
}

/* ===== ERRORS ===== */

.crm-error {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: #fef2f2;
    border: 2px solid #fecaca;
    border-radius: 8px;
    margin: 20px 0;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.15);
    position: relative;
}

.crm-error::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.05) 0%, rgba(239, 68, 68, 0.05) 100%);
    border-radius: 6px;
    pointer-events: none;
}

.crm-error-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    font-size: 14px;
    font-weight: bold;
    position: relative;
    z-index: 1;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

.crm-error-content {
    position: relative;
    z-index: 1;
}

.crm-error-content h4 {
    margin: 0 0 4px 0;
    font-size: 16px;
    font-weight: 600;
    color: #dc2626;
    text-shadow: 0 1px 2px rgba(220, 38, 38, 0.1);
}

.crm-error-content p {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #991b1b;
    line-height: 1.5;
}

/* ===== MODAL WINDOW FOOTER ===== */

.crm-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 0 0 12px 12px;
}

.crm-modal-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.crm-status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #6b7280;
}

.crm-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    animation: crm-pulse 2s infinite;
}

.crm-status-dot.error {
    background: #ef4444;
}

.crm-status-dot.warning {
    background: #f59e0b;
}

@keyframes crm-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== BUTTONS ===== */

.crm-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}

.crm-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.crm-btn-primary {
    background: #2563eb;
    color: white;
}

.crm-btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
    transform: translateY(-1px);
}

.crm-btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.crm-btn-secondary:hover:not(:disabled) {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.crm-btn-danger {
    background: #dc2626;
    color: white;
}

.crm-btn-danger:hover:not(:disabled) {
    background: #b91c1c;
    transform: translateY(-1px);
}

.crm-btn-close {
    background: none;
    color: #6b7280;
    padding: 8px;
    border-radius: 6px;
}

.crm-btn-close:hover:not(:disabled) {
    background: #f3f4f6;
    color: #374151;
}

.crm-btn-icon {
    padding: 8px;
    min-width: 36px;
    justify-content: center;
}

.crm-btn-full {
    width: 100%;
    justify-content: center;
}

/* ===== ICONS ===== */

.crm-icon-close::before { content: "×"; }
.crm-icon-refresh::before { content: "↻"; }
.crm-icon-fullscreen::before { content: "⛶"; }
.crm-icon-user::before { content: "👤"; }
.crm-icon-accounts::before { content: "💳"; }
.crm-icon-funds::before { content: "💰"; }
.crm-icon-support::before { content: "🎫"; }
.crm-icon-settings::before { content: "⚙️"; }
.crm-icon-help::before { content: "❓"; }
.crm-icon-logout::before { content: "🚪"; }
.crm-icon-login::before { content: "🔑"; }
.crm-icon-error::before { content: "⚠️"; }

/* ===== RESPONSIVENESS ===== */

@media (max-width: 768px) {
    .crm-modal-container {
        width: 95vw;
        height: 95vh;
        max-width: none;
        max-height: none;
        border-radius: 8px;
    }
    
    .crm-modal-large {
        width: 95vw;
        height: 95vh;
    }
    
    .crm-modal-header {
        padding: 16px 20px;
    }
    
    .crm-modal-title-section h3 {
        font-size: 18px;
    }
    
    .crm-modal-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
    }
    
    .crm-nav-item {
        min-width: 100px;
        padding: 12px 16px;
        font-size: 13px;
    }
    
    .crm-content {
        padding: 20px;
    }
    
    .crm-modal-footer {
        padding: 12px 20px;
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    .crm-modal-actions {
        justify-content: center;
    }
}

/* ===== NOTIFICATIONS ABOVE MODAL ===== */
#crm-notifications,
.crm-notifications {
    position: fixed;
    z-index: 100000; /* above modal */
}

@media (max-width: 480px) {
    .crm-modal-container {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
    
    .crm-modal-header {
        padding: 12px 16px;
    }
    
    .crm-content {
        padding: 16px;
    }
    
    .crm-modal-footer {
        padding: 12px 16px;
    }
    
    .crm-nav-item {
        min-width: 80px;
        padding: 10px 12px;
        font-size: 12px;
    }
    
    .crm-nav-item span {
        display: none;
    }
    
    .crm-nav-item i {
        font-size: 18px;
    }
}

/* ===== ANIMATIONS ===== */

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

@keyframes crm-fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

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

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

.crm-modal.fade-in {
    animation: crm-fadeIn 0.3s ease;
}

.crm-modal.fade-out {
    animation: crm-fadeOut 0.3s ease;
}

.crm-tab-content.slide-in {
    animation: crm-slideIn 0.3s ease;
}

.crm-tab-content.slide-out {
    animation: crm-slideOut 0.3s ease;
}

/* ===== DARK THEME ===== */

@media (prefers-color-scheme: dark) {
    .crm-modal-container {
        background: #1f2937;
        color: #f9fafb;
    }
    
    .crm-modal-header {
        background: #111827;
        border-bottom-color: #374151;
    }
    
    .crm-modal-title-section h3 {
        color: #f9fafb;
    }
    
    .crm-modal-subtitle {
        color: #9ca3af;
    }
    
    .crm-modal-nav {
        background: #1f2937;
        border-bottom-color: #374151;
    }
    
    .crm-nav-item {
        color: #9ca3af;
    }
    
    .crm-nav-item:hover {
        color: #d1d5db;
        background: #374151;
    }
    
    .crm-nav-item.active {
        color: #60a5fa;
        background: #1e3a8a;
    }
    
    .crm-modal-content {
        background: #1f2937;
    }
    
    .crm-modal-footer {
        background: #111827;
        border-top-color: #374151;
    }
    
    /* Sticky form actions bar in dark theme */
    .crm-form-actions {
        border-top-color: #374151;
    }
    
    .crm-status-indicator {
        color: #9ca3af;
    }
    
    .crm-btn-secondary {
        background: #374151;
        color: #d1d5db;
        border-color: #4b5563;
    }
    
    .crm-btn-secondary:hover:not(:disabled) {
        background: #4b5563;
        border-color: #6b7280;
    }
    
    .crm-btn-close {
        color: #9ca3af;
    }
    
    .crm-btn-close:hover:not(:disabled) {
        background: #374151;
        color: #d1d5db;
    }
    
    /* Dark theme loading styles */
    .crm-loading {
        background: rgba(31, 41, 55, 0.95);
    }
    
    #crm-loading-text {
        color: #d1d5db;
    }
    
    /* Dark theme error styles */
    .crm-error {
        background: #7f1d1d;
        border-color: #991b1b;
        box-shadow: 0 2px 8px rgba(127, 29, 29, 0.3);
    }
    
    .crm-error-content h4 {
        color: #fca5a5;
    }
    
    .crm-error-content p {
        color: #fecaca;
    }
}

/* ===== ADDITIONAL UTILITIES ===== */

.crm-hidden {
    display: none !important;
}

.crm-visible {
    display: block !important;
}

.crm-text-center {
    text-align: center;
}

.crm-text-left {
    text-align: left;
}

.crm-text-right {
    text-align: right;
}

.crm-mt-0 { margin-top: 0; }
.crm-mt-1 { margin-top: 4px; }
.crm-mt-2 { margin-top: 8px; }
.crm-mt-3 { margin-top: 12px; }
.crm-mt-4 { margin-top: 16px; }
.crm-mt-5 { margin-top: 20px; }

.crm-mb-0 { margin-bottom: 0; }
.crm-mb-1 { margin-bottom: 4px; }
.crm-mb-2 { margin-bottom: 8px; }
.crm-mb-3 { margin-bottom: 12px; }
.crm-mb-4 { margin-bottom: 16px; }
.crm-mb-5 { margin-bottom: 20px; }

.crm-p-0 { padding: 0; }
.crm-p-1 { padding: 4px; }
.crm-p-2 { padding: 8px; }
.crm-p-3 { padding: 12px; }
.crm-p-4 { padding: 16px; }
.crm-p-5 { padding: 20px; }
