/**
 * AppCustomDialogModal Styles
 *
 * Custom branded dialog modals matching Cocodraw marketing design.
 * Requires marketing.css CSS variables to be loaded.
 */

/* ==========================================================================
   Overlay
   ========================================================================== */
.app-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.app-dialog-overlay.app-dialog-visible {
    opacity: 1;
    visibility: visible;
}

/* Dark mode overlay */
[data-theme="dark"] .app-dialog-overlay {
    background: rgba(0, 0, 0, 0.7);
}

/* ==========================================================================
   Modal Container
   ========================================================================== */
.app-dialog-modal {
    background: var(--bg-secondary, #ffffff);
    border-radius: var(--radius-lg, 20px);
    box-shadow: var(--shadow-lg, 0 8px 40px rgba(0, 0, 0, 0.15));
    width: 100%;
    max-width: 420px;
    overflow: hidden;
    max-height: calc(100vh - 48px);
    transform: translateY(-20px) scale(0.95);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Prefer dynamic viewport units on mobile (prevents "jump/disappear" on scroll) */
@supports (height: 100dvh) {
    .app-dialog-modal {
        max-height: calc(100dvh - 48px);
    }
}

.app-dialog-visible .app-dialog-modal {
    transform: translateY(0) scale(1);
}

/* Dark mode modal */
[data-theme="dark"] .app-dialog-modal {
    background: var(--bg-secondary, #101821);
    border: 1px solid var(--border-light, rgba(255, 255, 255, 0.08));
}

/* ==========================================================================
   Accent Bar (top gradient stripe)
   ========================================================================== */
.app-dialog-accent {
    height: 4px;
    background: var(--gradient, linear-gradient(135deg, #2A00E5, #EC07D1));
}

/* Type-specific accent colors */
.app-dialog-success .app-dialog-accent {
    background: var(--success, #10b981);
}

.app-dialog-warning .app-dialog-accent {
    background: var(--warning, #f59e0b);
}

.app-dialog-error .app-dialog-accent {
    background: var(--error, #ef4444);
}

/* ==========================================================================
   Content Area
   ========================================================================== */
.app-dialog-content {
    padding: 28px 28px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* ==========================================================================
   Icon
   ========================================================================== */
.app-dialog-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.app-dialog-icon svg {
    width: 28px;
    height: 28px;
}

/* Icon type variants */
.app-dialog-icon-info {
    background: linear-gradient(135deg, rgba(42, 0, 229, 0.1), rgba(236, 7, 209, 0.1));
    color: var(--gradient-start, #2A00E5);
}

.app-dialog-icon-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success, #10b981);
}

.app-dialog-icon-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning, #f59e0b);
}

.app-dialog-icon-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error, #ef4444);
}

.app-dialog-icon-confirm {
    background: linear-gradient(135deg, rgba(42, 0, 229, 0.1), rgba(236, 7, 209, 0.1));
    color: var(--gradient-start, #2A00E5);
}

.app-dialog-icon-prompt {
    background: linear-gradient(135deg, rgba(42, 0, 229, 0.1), rgba(236, 7, 209, 0.1));
    color: var(--gradient-start, #2A00E5);
}

/* Dark mode icon backgrounds */
[data-theme="dark"] .app-dialog-icon-info,
[data-theme="dark"] .app-dialog-icon-confirm,
[data-theme="dark"] .app-dialog-icon-prompt {
    background: linear-gradient(135deg, rgba(42, 0, 229, 0.2), rgba(236, 7, 209, 0.2));
    color: var(--link-color, #f472b6);
}

[data-theme="dark"] .app-dialog-icon-success {
    background: rgba(16, 185, 129, 0.15);
}

[data-theme="dark"] .app-dialog-icon-warning {
    background: rgba(245, 158, 11, 0.15);
}

[data-theme="dark"] .app-dialog-icon-error {
    background: rgba(239, 68, 68, 0.15);
}

/* ==========================================================================
   Text Content
   ========================================================================== */
.app-dialog-text {
    margin-bottom: 4px;
}

.app-dialog-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary, #1a1a2e);
    margin: 0 0 8px 0;
    line-height: 1.3;
}

.app-dialog-message {
    font-size: 0.9375rem;
    color: var(--text-secondary, #4a4a68);
    margin: 0;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.app-dialog-countdown {
    margin-top: 10px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--warning, #f59e0b);
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.25);
    padding: 6px 10px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Text alignment variants */
.app-dialog-text-left,
.app-dialog-text-left .app-dialog-message {
    text-align: left;
}

.app-dialog-text-right,
.app-dialog-text-right .app-dialog-message {
    text-align: right;
}

/* ==========================================================================
   Input Field
   ========================================================================== */
.app-dialog-input-wrapper {
    width: 100%;
    margin-top: 16px;
}

.app-dialog-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-light, rgba(0, 0, 0, 0.1));
    border-radius: var(--radius-md, 12px);
    background: var(--bg-primary, #f8f9fc);
    color: var(--text-primary, #1a1a2e);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.app-dialog-input:focus {
    outline: none;
    border-color: var(--link-color, #2A00E5);
    box-shadow: 0 0 0 3px rgba(42, 0, 229, 0.1);
}

.app-dialog-input::placeholder {
    color: var(--text-muted, #8888a0);
}

/* Dark mode input */
[data-theme="dark"] .app-dialog-input {
    background: var(--bg-tertiary, #1a2332);
    border-color: var(--border-light, rgba(255, 255, 255, 0.08));
}

[data-theme="dark"] .app-dialog-input:focus {
    border-color: var(--link-color, #f472b6);
    box-shadow: 0 0 0 3px rgba(244, 114, 182, 0.15);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.app-dialog-buttons {
    display: flex;
    gap: 12px;
    padding: 20px 28px 28px;
    justify-content: center;
}

.app-dialog-btn {
    padding: 12px 24px;
    border-radius: var(--radius-md, 12px);
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    min-width: 100px;
}

.app-dialog-btn:focus {
    outline: none;
}

.app-dialog-btn:focus-visible {
    box-shadow: 0 0 0 3px rgba(42, 0, 229, 0.3);
}

/* Cancel button */
.app-dialog-btn-cancel {
    background: var(--bg-glass, rgba(255, 255, 255, 0.85));
    color: var(--text-primary, #1a1a2e);
    border: 1px solid var(--border-medium, rgba(0, 0, 0, 0.15));
}

.app-dialog-btn-cancel:hover {
    background: var(--bg-glass-hover, rgba(255, 255, 255, 0.95));
    border-color: var(--link-color, #2A00E5);
}

[data-theme="dark"] .app-dialog-btn-cancel {
    background: var(--bg-glass, rgba(255, 255, 255, 0.08));
    border-color: var(--border-medium, rgba(255, 255, 255, 0.15));
}

[data-theme="dark"] .app-dialog-btn-cancel:hover {
    background: var(--bg-glass-hover, rgba(255, 255, 255, 0.12));
    border-color: var(--link-color, #f472b6);
}

/* Confirm button - primary gradient */
.app-dialog-btn-confirm {
    background: var(--gradient, linear-gradient(135deg, #2A00E5, #EC07D1));
    color: white;
    box-shadow: 0 4px 20px rgba(42, 0, 229, 0.3);
}

.app-dialog-btn-confirm:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 25px rgba(42, 0, 229, 0.4);
}

.app-dialog-btn-confirm:active {
    transform: translateY(0);
}

/* Warning/Error confirm button variants */
.app-dialog-warning .app-dialog-btn-confirm {
    background: var(--warning, #f59e0b);
    box-shadow: 0 4px 20px rgba(245, 158, 11, 0.3);
}

.app-dialog-warning .app-dialog-btn-confirm:hover {
    box-shadow: 0 6px 25px rgba(245, 158, 11, 0.4);
}

.app-dialog-error .app-dialog-btn-confirm {
    background: var(--error, #ef4444);
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.3);
}

.app-dialog-error .app-dialog-btn-confirm:hover {
    box-shadow: 0 6px 25px rgba(239, 68, 68, 0.4);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 480px) {
    .app-dialog-overlay {
        padding: max(16px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
    }

    .app-dialog-modal {
        max-width: 100%;
    }

    .app-dialog-content {
        padding: 24px 20px 16px;
    }

    .app-dialog-buttons {
        padding: 16px 20px 24px;
        flex-direction: column-reverse;
    }

    .app-dialog-btn {
        width: 100%;
    }
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .app-dialog-overlay,
    .app-dialog-modal,
    .app-dialog-btn {
        transition: none;
    }

    .app-dialog-btn-confirm:hover {
        transform: none;
    }
}

/* ==========================================================================
   Select Dialog Options
   ========================================================================== */
.app-dialog-select .app-dialog-modal {
    max-width: 380px;
}

.app-dialog-options {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 4px;
}

/* Custom scrollbar for options */
.app-dialog-options::-webkit-scrollbar {
    width: 6px;
}

.app-dialog-options::-webkit-scrollbar-track {
    background: transparent;
}

.app-dialog-options::-webkit-scrollbar-thumb {
    background: var(--border-medium, rgba(0, 0, 0, 0.15));
    border-radius: 3px;
}

.app-dialog-options::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted, rgba(0, 0, 0, 0.25));
}

[data-theme="dark"] .app-dialog-options::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .app-dialog-options::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.app-dialog-option {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-primary, #f8f9fc);
    border: 1px solid var(--border-light, rgba(0, 0, 0, 0.08));
    border-radius: var(--radius-md, 12px);
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
    width: 100%;
    font-family: inherit;
}

.app-dialog-option:hover {
    background: var(--bg-secondary, #ffffff);
    border-color: var(--link-color, #2A00E5);
    box-shadow: 0 2px 8px rgba(42, 0, 229, 0.1);
}

.app-dialog-option:focus {
    outline: none;
    border-color: var(--link-color, #2A00E5);
    box-shadow: 0 0 0 3px rgba(42, 0, 229, 0.15);
}

.app-dialog-option-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(42, 0, 229, 0.1), rgba(236, 7, 209, 0.1));
    border-radius: 10px;
    font-size: 1.25rem;
    flex-shrink: 0;
    color: var(--gradient-start, #2A00E5);
}

.app-dialog-option-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.app-dialog-option-label {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary, #1a1a2e);
}

.app-dialog-option-desc {
    font-size: 0.8125rem;
    color: var(--text-muted, #8888a0);
    line-height: 1.4;
}

/* Dark mode select options */
[data-theme="dark"] .app-dialog-option {
    background: var(--bg-tertiary, #1a2332);
    border-color: var(--border-light, rgba(255, 255, 255, 0.08));
}

[data-theme="dark"] .app-dialog-option:hover {
    background: var(--bg-secondary, #101821);
    border-color: var(--link-color, #f472b6);
    box-shadow: 0 2px 8px rgba(244, 114, 182, 0.15);
}

[data-theme="dark"] .app-dialog-option:focus {
    border-color: var(--link-color, #f472b6);
    box-shadow: 0 0 0 3px rgba(244, 114, 182, 0.2);
}

[data-theme="dark"] .app-dialog-option-icon {
    background: linear-gradient(135deg, rgba(42, 0, 229, 0.2), rgba(236, 7, 209, 0.2));
    color: var(--link-color, #f472b6);
}

/* Ensure icons inside option buttons are visible in dark mode */
[data-theme="dark"] .app-dialog-option-icon i,
[data-theme="dark"] .app-dialog-option-icon svg {
    color: var(--link-color, #f472b6);
    fill: currentColor;
}

/* Select dialog icon */
.app-dialog-icon-select {
    background: linear-gradient(135deg, rgba(42, 0, 229, 0.1), rgba(236, 7, 209, 0.1));
    color: var(--gradient-start, #2A00E5);
}

[data-theme="dark"] .app-dialog-icon-select {
    background: linear-gradient(135deg, rgba(42, 0, 229, 0.2), rgba(236, 7, 209, 0.2));
    color: var(--link-color, #f472b6);
}

/* Single button variant (cancel only for select) */
.app-dialog-buttons-single {
    justify-content: center;
}

.app-dialog-buttons-single .app-dialog-btn-cancel {
    min-width: 120px;
}

/* ============================================
   Custom Dialog Content Styles
   ============================================ */

.app-dialog-custom {
    max-width: 480px;
}

.app-dialog-custom-content {
    width: 100%;
    margin-top: 16px;
    text-align: left;
}

/* File input styling */
.app-dialog-custom-content input[type="file"] {
    width: 100%;
    padding: 12px;
    border: 2px dashed var(--border-color, #e0e0e0);
    border-radius: 8px;
    background: var(--bg-secondary, #f8f9fa);
    color: var(--text-primary, #1a1a2e);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.app-dialog-custom-content input[type="file"]:hover {
    border-color: var(--gradient-start, #2A00E5);
    background: var(--bg-tertiary, #f0f1f3);
}

.app-dialog-custom-content input[type="file"]:focus {
    outline: none;
    border-color: var(--gradient-start, #2A00E5);
    box-shadow: 0 0 0 3px rgba(42, 0, 229, 0.1);
}

/* Info text */
.app-dialog-custom-content .import-info {
    font-size: 0.875rem;
    color: var(--text-secondary, #666);
    margin-bottom: 12px;
    line-height: 1.5;
}

/* Options section (radio buttons, checkboxes) */
.app-dialog-custom-content .import-options {
    margin-top: 16px;
    padding: 12px;
    background: var(--bg-secondary, #f8f9fa);
    border-radius: 8px;
}

.app-dialog-custom-content .import-options-title {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 8px;
    color: var(--text-primary, #1a1a2e);
}

.app-dialog-custom-content .import-option-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-dialog-custom-content .import-option-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary, #1a1a2e);
}

.app-dialog-custom-content .import-option-group input[type="radio"],
.app-dialog-custom-content .import-option-group input[type="checkbox"] {
    accent-color: var(--gradient-start, #2A00E5);
}

/* Progress section */
.app-dialog-custom-content .import-progress {
    margin-top: 16px;
    display: none;
}

.app-dialog-custom-content .import-progress.active {
    display: block;
}

.app-dialog-custom-content .progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-secondary, #e0e0e0);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.app-dialog-custom-content .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gradient-start, #2A00E5), var(--gradient-end, #EC07D1));
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.app-dialog-custom-content .progress-text {
    font-size: 0.75rem;
    color: var(--text-secondary, #666);
    text-align: center;
}

.app-dialog-custom-content .progress-text.error {
    color: #d32f2f;
}

/* Password input for encrypted files */
.app-dialog-custom-content .password-section {
    margin-top: 12px;
    display: none;
}

.app-dialog-custom-content .password-section.active {
    display: block;
}

.app-dialog-custom-content .password-section label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 4px;
    color: var(--text-secondary, #666);
}

.app-dialog-custom-content .password-section input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
    font-size: 0.875rem;
    background: var(--panel-bg, #fff);
    color: var(--text-primary, #1a1a2e);
}

/* Dark mode for custom content */
[data-theme="dark"] .app-dialog-custom-content input[type="file"] {
    background: var(--bg-secondary, #1a1f2e);
    border-color: var(--border-color, rgba(255, 255, 255, 0.15));
    color: var(--text-primary, #fff);
}

[data-theme="dark"] .app-dialog-custom-content input[type="file"]:hover {
    border-color: var(--link-color, #f472b6);
    background: var(--bg-tertiary, #151a26);
}

[data-theme="dark"] .app-dialog-custom-content input[type="file"]:focus {
    border-color: var(--link-color, #f472b6);
    box-shadow: 0 0 0 3px rgba(244, 114, 182, 0.2);
}

[data-theme="dark"] .app-dialog-custom-content .import-info {
    color: var(--text-secondary, #a0a0a0);
}

[data-theme="dark"] .app-dialog-custom-content .import-options {
    background: var(--bg-secondary, #1a1f2e);
}

[data-theme="dark"] .app-dialog-custom-content .import-options-title,
[data-theme="dark"] .app-dialog-custom-content .import-option-group label {
    color: var(--text-primary, #fff);
}

[data-theme="dark"] .app-dialog-custom-content .import-option-group input[type="radio"],
[data-theme="dark"] .app-dialog-custom-content .import-option-group input[type="checkbox"] {
    accent-color: var(--link-color, #f472b6);
}

[data-theme="dark"] .app-dialog-custom-content .progress-bar {
    background: var(--bg-tertiary, #151a26);
}

[data-theme="dark"] .app-dialog-custom-content .progress-text {
    color: var(--text-secondary, #a0a0a0);
}

[data-theme="dark"] .app-dialog-custom-content .password-section label {
    color: var(--text-secondary, #a0a0a0);
}

[data-theme="dark"] .app-dialog-custom-content .password-section input[type="password"] {
    background: var(--bg-secondary, #1a1f2e);
    border-color: var(--border-color, rgba(255, 255, 255, 0.15));
    color: var(--text-primary, #fff);
}

/* ==========================================================================
   Global Custom Content Theming
   Ensures all elements inside custom dialogs follow the theme
   ========================================================================== */

/* Base text color inheritance */
.app-dialog-custom-content,
.app-dialog-custom-content * {
    color: inherit;
}

.app-dialog-content {
    color: var(--text-primary, #1a1a2e);
}

[data-theme="dark"] .app-dialog-content {
    color: var(--text-primary, #ffffff);
}

/* Labels and descriptive text */
.app-dialog-custom-content label,
.app-dialog-custom-content span,
.app-dialog-custom-content p,
.app-dialog-custom-content div {
    color: var(--text-primary, #1a1a2e);
}

[data-theme="dark"] .app-dialog-custom-content label,
[data-theme="dark"] .app-dialog-custom-content span,
[data-theme="dark"] .app-dialog-custom-content p,
[data-theme="dark"] .app-dialog-custom-content div {
    color: var(--text-primary, #ffffff);
}

/* Muted text */
.app-dialog-custom-content [style*="text-muted"],
.app-dialog-custom-content .text-muted {
    color: var(--text-muted, #8888a0) !important;
}

[data-theme="dark"] .app-dialog-custom-content [style*="text-muted"],
[data-theme="dark"] .app-dialog-custom-content .text-muted {
    color: var(--text-muted, #a0a0b0) !important;
}

/* Input fields inside custom content */
.app-dialog-custom-content input[type="text"],
.app-dialog-custom-content input[type="number"],
.app-dialog-custom-content input[type="email"],
.app-dialog-custom-content input[type="datetime-local"],
.app-dialog-custom-content textarea,
.app-dialog-custom-content select {
    background: var(--bg-secondary, #f8f9fc);
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
    color: var(--text-primary, #1a1a2e);
}

[data-theme="dark"] .app-dialog-custom-content input[type="text"],
[data-theme="dark"] .app-dialog-custom-content input[type="number"],
[data-theme="dark"] .app-dialog-custom-content input[type="email"],
[data-theme="dark"] .app-dialog-custom-content input[type="datetime-local"],
[data-theme="dark"] .app-dialog-custom-content textarea,
[data-theme="dark"] .app-dialog-custom-content select {
    background: var(--bg-tertiary, #1a2332);
    border-color: var(--border-color, rgba(255, 255, 255, 0.15));
    color: var(--text-primary, #ffffff);
}

/* Buttons inside custom content */
.app-dialog-custom-content button {
    color: var(--text-primary, #1a1a2e);
}

[data-theme="dark"] .app-dialog-custom-content button {
    color: var(--text-primary, #ffffff);
}

/* Stat boxes and info sections */
.app-dialog-custom-content [style*="bg-secondary"] {
    background: var(--bg-secondary, #f8f9fc) !important;
}

[data-theme="dark"] .app-dialog-custom-content [style*="bg-secondary"] {
    background: var(--bg-tertiary, #1a2332) !important;
}
