/**
 * DonationKit - Public Styles
 */

/* CSS Variables */
:root {
    --dk-primary: #2563eb;
    --dk-primary-hover: #1d4ed8;
    --dk-success: #16a34a;
    --dk-error: #dc2626;
    --dk-text: #1f2937;
    --dk-text-light: #6b7280;
    --dk-border: #d1d5db;
    --dk-bg: #ffffff;
    --dk-bg-light: #f9fafb;
    --dk-radius: 8px;
    --dk-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Dark theme */
.dk-theme-dark {
    --dk-text: #f9fafb;
    --dk-text-light: #9ca3af;
    --dk-border: #4b5563;
    --dk-bg: #1f2937;
    --dk-bg-light: #374151;
}

/* Container */
.dk-donation-form {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--dk-text);
    max-width: 480px;
    margin: 0 auto;
}

.dk-layout-card {
    background: var(--dk-bg);
    border: 1px solid var(--dk-border);
    border-radius: var(--dk-radius);
    padding: 24px;
    box-shadow: var(--dk-shadow);
}

.dk-layout-inline {
    background: transparent;
    padding: 0;
}

/* Title */
.dk-form-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 20px 0;
    color: var(--dk-text);
    text-align: center;
}

/* Type Toggle */
.dk-type-toggle {
    display: flex;
    background: var(--dk-bg-light);
    border-radius: var(--dk-radius);
    padding: 4px;
    margin-bottom: 20px;
}

.dk-type-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--dk-text-light);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: calc(var(--dk-radius) - 2px);
    transition: all 0.2s ease;
}

.dk-type-btn:hover {
    color: var(--dk-text);
}

.dk-type-btn.active {
    background: var(--dk-bg);
    color: var(--dk-primary);
    box-shadow: var(--dk-shadow);
}

/* Amount Section */
.dk-amount-section {
    margin-bottom: 20px;
}

.dk-amount-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}

.dk-amount-btn {
    padding: 14px 12px;
    border: 2px solid var(--dk-border);
    background: var(--dk-bg);
    color: var(--dk-text);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--dk-radius);
    transition: all 0.2s ease;
}

.dk-amount-btn:hover {
    border-color: var(--dk-primary);
    color: var(--dk-primary);
}

.dk-amount-btn.active {
    border-color: var(--dk-primary);
    background: var(--dk-primary);
    color: #ffffff;
}

.dk-amount-other-btn {
    font-weight: 500;
}

/* Other Amount Input */
.dk-other-amount {
    margin-top: 12px;
}

.dk-input-group {
    display: flex;
    align-items: center;
    border: 2px solid var(--dk-border);
    border-radius: var(--dk-radius);
    overflow: hidden;
    transition: border-color 0.2s ease;
}

.dk-input-group:focus-within {
    border-color: var(--dk-primary);
}

.dk-input-prefix {
    padding: 12px 14px;
    background: var(--dk-bg-light);
    color: var(--dk-text-light);
    font-weight: 500;
    font-size: 1rem;
}

.dk-other-amount-input {
    flex: 1;
    padding: 12px 14px;
    border: none;
    font-size: 1rem;
    background: var(--dk-bg);
    color: var(--dk-text);
    outline: none;
    -moz-appearance: textfield;
}

.dk-other-amount-input::-webkit-outer-spin-button,
.dk-other-amount-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.dk-amount-hint {
    font-size: 0.8125rem;
    color: var(--dk-text-light);
    margin: 8px 0 0;
}

/* Donor Section */
.dk-donor-section {
    margin-bottom: 20px;
}

.dk-field {
    margin-bottom: 14px;
}

.dk-field:last-child {
    margin-bottom: 0;
}

.dk-field-row {
    display: flex;
    gap: 12px;
}

.dk-field-row-2 .dk-field {
    flex: 1;
    margin-bottom: 14px;
}

.dk-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--dk-text);
    margin-bottom: 6px;
}

.dk-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--dk-border);
    border-radius: var(--dk-radius);
    font-size: 1rem;
    background: var(--dk-bg);
    color: var(--dk-text);
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.dk-input:focus {
    outline: none;
    border-color: var(--dk-primary);
}

.dk-input::placeholder {
    color: var(--dk-text-light);
}

/* Payment Section */
.dk-payment-section {
    margin-bottom: 20px;
}

.dk-card-element {
    padding: 14px;
    border: 2px solid var(--dk-border);
    border-radius: var(--dk-radius);
    background: var(--dk-bg);
    transition: border-color 0.2s ease;
}

.dk-card-element.StripeElement--focus {
    border-color: var(--dk-primary);
}

.dk-card-element.StripeElement--invalid {
    border-color: var(--dk-error);
}

.dk-card-errors {
    color: var(--dk-error);
    font-size: 0.875rem;
    margin-top: 8px;
    display: none;
}

/* Consent Section */
.dk-consent-section {
    margin-bottom: 20px;
    padding: 14px;
    background: var(--dk-bg-light);
    border-radius: var(--dk-radius);
}

.dk-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
}

.dk-checkbox {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    flex-shrink: 0;
    accent-color: var(--dk-primary);
}

.dk-checkbox-text {
    font-size: 0.9375rem;
    color: var(--dk-text);
    line-height: 1.4;
}

.dk-consent-helper {
    font-size: 0.8125rem;
    color: var(--dk-text-light);
    margin: 6px 0 0 28px;
}

/* Submit Section */
.dk-submit-section {
    margin-bottom: 16px;
}

.dk-submit-btn {
    width: 100%;
    padding: 16px 24px;
    border: none;
    border-radius: var(--dk-radius);
    background: var(--dk-primary);
    color: #ffffff;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.dk-submit-btn:hover:not(:disabled) {
    background: var(--dk-primary-hover);
}

.dk-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.dk-btn-interval {
    font-weight: 400;
    opacity: 0.9;
}

.dk-btn-processing {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dk-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: dk-spin 0.8s linear infinite;
}

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

/* Messages */
.dk-messages {
    min-height: 24px;
}

.dk-error-message {
    padding: 12px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--dk-radius);
    color: var(--dk-error);
    font-size: 0.9375rem;
}

.dk-success-message {
    padding: 12px 14px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--dk-radius);
    color: var(--dk-success);
    font-size: 0.9375rem;
}

/* Thank You State */
.dk-thank-you {
    text-align: center;
    padding: 40px 20px;
}

.dk-thank-you-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    background: var(--dk-success);
    color: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.dk-thank-you-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 12px;
    color: var(--dk-text);
}

.dk-thank-you-message {
    font-size: 1rem;
    color: var(--dk-text-light);
    margin: 0;
    line-height: 1.5;
}

/* Error State */
.dk-error {
    padding: 20px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--dk-radius);
    color: var(--dk-error);
    text-align: center;
}

/* Submit button stays inline on all devices for now */

/* Abandonment Banner (Toast-style, bottom-right) */
.dk-abandonment-banner {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #ffffff;
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    z-index: 9999;
    max-width: 380px;
    width: calc(100vw - 40px);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.dk-abandonment-banner.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dk-abandonment-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease, color 0.2s ease;
}

.dk-abandonment-close:hover {
    background: #f3f4f6;
    color: #6b7280;
}

.dk-abandonment-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

.dk-abandonment-text {
    flex: 1;
    min-width: 0;
}

.dk-abandonment-title {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0 0 4px;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dk-abandonment-emoji {
    font-size: 1rem;
}

.dk-abandonment-body {
    font-size: 0.8125rem;
    color: #6b7280;
    margin: 0;
    line-height: 1.4;
}

.dk-abandonment-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    background: var(--dk-primary);
    color: #ffffff;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.dk-abandonment-btn:hover {
    background: var(--dk-primary-hover);
}

/* Mobile: same layout, just full width */
@media (max-width: 480px) {
    .dk-abandonment-banner {
        bottom: 16px;
        right: 16px;
        left: 16px;
        width: auto;
        max-width: none;
    }
    
    .dk-abandonment-content {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .dk-abandonment-btn {
        width: 100%;
        text-align: center;
    }
}

/* ===========================================
   Donation Popup Modal (for trigger buttons)
   =========================================== */
.dk-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: 20px;
}

.dk-popup-overlay.active {
    opacity: 1;
    visibility: visible;
}

.dk-popup-container {
    background: var(--dk-bg);
    border-radius: var(--dk-radius);
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    transform: scale(0.95) translateY(10px);
    transition: transform 0.3s ease;
}

.dk-popup-overlay.active .dk-popup-container {
    transform: scale(1) translateY(0);
}

.dk-popup-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease, color 0.2s ease;
    z-index: 10;
}

.dk-popup-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #1f2937;
}

.dk-popup-content {
    padding: 24px;
}

.dk-popup-content .dk-donation-form {
    max-width: none;
}

.dk-popup-content .dk-layout-card {
    border: none;
    box-shadow: none;
    padding: 0;
}

/* Mobile popup */
@media (max-width: 640px) {
    .dk-popup-overlay {
        padding: 0;
        align-items: flex-end;
    }
    
    .dk-popup-container {
        max-width: none;
        max-height: 85vh;
        max-height: 85dvh;
        border-radius: 16px 16px 0 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .dk-popup-close {
        position: absolute;
        top: 12px;
        right: 12px;
        background: rgba(255, 255, 255, 0.9);
        z-index: 10;
    }
    
    .dk-popup-content {
        padding: 16px;
        padding-top: 48px; /* Space for close button */
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    }
    
    /* Keep submit button inline, just ensure it's visible */
    .dk-popup-content .dk-submit-btn {
        margin-bottom: 8px;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .dk-layout-card {
        padding: 20px 16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    
    .dk-amount-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .dk-field-row {
        flex-direction: column;
        gap: 0;
    }
    
    .dk-field-row-2 .dk-field {
        flex: none;
    }
}
