/**
 * Custom Modal Dialog System
 * Branded modal dialogs to replace native confirm/alert dialogs
 *
 * FILE PURPOSE: Styled modal dialog components matching brand design
 * LOAD ORDER: After components.css
 * DEPENDENCIES: variables.css, themes.css
 * USED BY: modal-dialog.js
 *
 * FEATURES:
 * - Confirm/Alert/Warning dialogs with consistent styling
 * - Brand-themed buttons and colors
 * - Smooth animations and transitions
 * - Dark mode support
 * - Accessibility features (ARIA labels, focus management)
 * - Responsive design for mobile devices
 */

/* ============================================================================
   MODAL BACKDROP & CONTAINER
   ============================================================================ */

.gdo-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1090;
    opacity: 0;
    transition: opacity var(--transition-normal);
    pointer-events: none;
}

.gdo-modal-backdrop.show {
    opacity: 1;
    pointer-events: all;
}

/* ============================================================================
   MODAL DIALOG BOX
   ============================================================================ */

.gdo-modal-dialog {
    position: relative;
    width: 90%;
    max-width: 450px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-brand);
    transform: scale(0.95) translateY(20px);
    transition: transform var(--transition-normal);
    opacity: 0;
    overflow: hidden;
}

.gdo-modal-backdrop.show .gdo-modal-dialog {
    transform: scale(1) translateY(0);
    opacity: 1;
}

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

.gdo-modal-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    background: linear-gradient(135deg, rgba(157, 90, 109, 0.08) 0%, rgba(89, 61, 108, 0.05) 100%);
}

.gdo-modal-icon {
    font-size: 1.75rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
}

/* Icon colors by type */
.gdo-modal-icon.success {
    background: rgba(40, 167, 69, 0.1);
    color: #28a745;
}

.gdo-modal-icon.warning {
    background: rgba(255, 193, 7, 0.1);
    color: #ffc107;
}

.gdo-modal-icon.danger {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

.gdo-modal-icon.info {
    background: rgba(23, 162, 184, 0.1);
    color: #17a2b8;
}

.gdo-modal-icon.question {
    background: rgba(157, 90, 109, 0.1);
    color: var(--gdo-purple);
}

.gdo-modal-title-wrapper {
    flex: 1;
    min-width: 0;
}

.gdo-modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    word-wrap: break-word;
}

.gdo-modal-subtitle {
    margin: 0.25rem 0 0 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ============================================================================
   MODAL BODY
   ============================================================================ */

.gdo-modal-body {
    padding: var(--spacing-lg);
    color: var(--text-primary);
    line-height: 1.6;
    word-wrap: break-word;
    word-break: break-word;
    max-height: 60vh;
    overflow-y: auto;
}

/* Scrollbar styling for modal body */
.gdo-modal-body::-webkit-scrollbar {
    width: 8px;
}

.gdo-modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.gdo-modal-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.gdo-modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Support for longer messages and HTML content */
.gdo-modal-message {
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
}

/* Support rich HTML content in messages */
.gdo-modal-message p {
    margin: 0.5rem 0;
}

.gdo-modal-message ul,
.gdo-modal-message ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.gdo-modal-message li {
    margin: 0.25rem 0;
}

.gdo-modal-message strong,
.gdo-modal-message b {
    font-weight: 600;
    color: inherit;
}

.gdo-modal-message code {
    background: var(--bg-hover);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.gdo-modal-message table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
}

.gdo-modal-message table th,
.gdo-modal-message table td {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.gdo-modal-message table th {
    background: var(--bg-hover);
    font-weight: 600;
}

/* ============================================================================
   MODAL FOOTER / BUTTONS
   ============================================================================ */

.gdo-modal-footer {
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-end;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0%, rgba(0, 0, 0, 0.01) 100%);
}

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

.gdo-modal-btn {
    padding: 0.625rem 1.5rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    white-space: nowrap;
    min-height: 38px;
    outline: none;
}

.gdo-modal-btn:focus {
    outline: 2px solid var(--gdo-purple);
    outline-offset: 2px;
}

.gdo-modal-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Primary button (confirm/ok) */
.gdo-modal-btn.primary {
    background: linear-gradient(135deg, var(--gdo-mauve) 0%, var(--gdo-purple) 100%);
    color: white;
    border-color: var(--gdo-purple-border);
}

.gdo-modal-btn.primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-brand-hover);
}

.gdo-modal-btn.primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: var(--shadow-brand);
}

/* Secondary button (cancel/close) */
.gdo-modal-btn.secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.gdo-modal-btn.secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

.gdo-modal-btn.secondary:active:not(:disabled) {
    background: var(--bg-secondary);
}

/* Danger button (for destructive actions) */
.gdo-modal-btn.danger {
    background: #dc3545;
    color: white;
    border-color: #c82333;
}

.gdo-modal-btn.danger:hover:not(:disabled) {
    background: #c82333;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3);
}

.gdo-modal-btn.danger:active:not(:disabled) {
    background: #bd2130;
    transform: translateY(0);
}

/* Success button */
.gdo-modal-btn.success {
    background: #28a745;
    color: white;
    border-color: #1e7e34;
}

.gdo-modal-btn.success:hover:not(:disabled) {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

.gdo-modal-btn.success:active:not(:disabled) {
    background: #1e7e34;
    transform: translateY(0);
}

/* Loading state */
.gdo-modal-btn.loading {
    position: relative;
    pointer-events: none;
}

.gdo-modal-btn.loading::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    top: 50%;
    right: 10px;
    margin-top: -6px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: gdo-modal-spin 0.8s linear infinite;
}

@keyframes gdo-modal-spin {
    to { transform: rotate(360deg); }
}

/* Single button layout (full width when only one button) */
.gdo-modal-footer .gdo-modal-btn:only-child {
    width: 100%;
    justify-content: center;
}

/* ============================================================================
   SPECIAL DIALOG TYPES
   ============================================================================ */

/* Confirmation dialog - usually has confirm + cancel buttons */
.gdo-modal-dialog.confirm-dialog .gdo-modal-icon {
    /* Question icon styling */
}

/* Warning/Alert dialog - usually has warning color */
.gdo-modal-dialog.warning-dialog .gdo-modal-header {
    background: linear-gradient(135deg, rgba(255, 193, 7, 0.08) 0%, rgba(255, 193, 7, 0.05) 100%);
}

.gdo-modal-dialog.warning-dialog .gdo-modal-title {
    color: #ff8c00;
}

/* Danger/Error dialog - destructive action confirmation */
.gdo-modal-dialog.danger-dialog .gdo-modal-header {
    background: linear-gradient(135deg, rgba(220, 53, 69, 0.08) 0%, rgba(220, 53, 69, 0.05) 100%);
}

.gdo-modal-dialog.danger-dialog .gdo-modal-title {
    color: #dc3545;
}

/* Success dialog - operation completed */
.gdo-modal-dialog.success-dialog .gdo-modal-header {
    background: linear-gradient(135deg, rgba(40, 167, 69, 0.08) 0%, rgba(40, 167, 69, 0.05) 100%);
}

.gdo-modal-dialog.success-dialog .gdo-modal-title {
    color: #28a745;
}

/* ============================================================================
   DARK MODE SUPPORT
   ============================================================================ */

[data-theme="dark"] .gdo-modal-btn.secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .gdo-modal-btn.secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .gdo-modal-dialog.warning-dialog .gdo-modal-header {
    background: linear-gradient(135deg, rgba(255, 193, 7, 0.12) 0%, rgba(255, 193, 7, 0.08) 100%);
}

[data-theme="dark"] .gdo-modal-dialog.danger-dialog .gdo-modal-header {
    background: linear-gradient(135deg, rgba(220, 53, 69, 0.12) 0%, rgba(220, 53, 69, 0.08) 100%);
}

[data-theme="dark"] .gdo-modal-dialog.success-dialog .gdo-modal-header {
    background: linear-gradient(135deg, rgba(40, 167, 69, 0.12) 0%, rgba(40, 167, 69, 0.08) 100%);
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .gdo-modal-dialog {
        border-width: 2px;
    }

    .gdo-modal-btn {
        border-width: 2px;
        font-weight: bold;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .gdo-modal-backdrop,
    .gdo-modal-dialog,
    .gdo-modal-btn {
        transition: none;
    }

    .gdo-modal-btn.loading::after {
        animation: none;
        border-top-color: currentColor;
    }
}

/* Focus visible for keyboard navigation */
.gdo-modal-btn:focus-visible {
    outline: 2px solid var(--gdo-purple);
    outline-offset: 2px;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 576px) {
    .gdo-modal-dialog {
        max-width: 90%;
        width: 100%;
        margin: 1rem;
    }

    .gdo-modal-header {
        padding: var(--spacing-md);
        flex-direction: column;
        text-align: center;
    }

    .gdo-modal-icon {
        margin-bottom: var(--spacing-sm);
    }

    .gdo-modal-title {
        font-size: 1.1rem;
    }

    .gdo-modal-body {
        padding: var(--spacing-md);
        max-height: 50vh;
    }

    .gdo-modal-footer {
        padding: var(--spacing-md);
        flex-direction: column-reverse;
    }

    .gdo-modal-footer .gdo-modal-btn {
        width: 100%;
        justify-content: center;
    }

    .gdo-modal-footer .gdo-modal-btn.primary {
        margin-top: var(--spacing-sm);
    }
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

/* Text content with proper wrapping */
.gdo-modal-text {
    word-break: break-word;
    white-space: pre-wrap;
}

/* List styling in modals */
.gdo-modal-list {
    list-style: none;
    padding-left: 0;
    margin: var(--spacing-md) 0;
}

.gdo-modal-list li {
    padding: var(--spacing-sm) 0;
    padding-left: var(--spacing-lg);
    position: relative;
}

.gdo-modal-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--gdo-purple);
}

/* Code blocks in modals */
.gdo-modal-code {
    background: var(--code-bg);
    color: var(--code-text);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    margin: var(--spacing-md) 0;
}
