/**
 * iOS-Style Modal System Styles
 * Native iOS alert, confirm, and action sheet styling
 */

.ios-modal-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 12000; /* iOS system modals - highest level */
    pointer-events: none;
    /* PWA Safe Area Support */
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
}

.ios-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: auto;
    z-index: 12000; /* iOS system modals - highest level */
}

/* Backdrop */
.ios-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ios-modal-active .ios-modal-backdrop {
    opacity: 1;
}

/* Alert Dialog */
.ios-modal-alert .ios-modal-dialog {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1.15);
    width: 270px;
    max-width: calc(100vw - 40px);
    background: var(--bg-elevated, rgba(255, 255, 255, 0.95));
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ios-modal-active.ios-modal-alert .ios-modal-dialog {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* Action Sheet */
.ios-modal-action-sheet .ios-modal-dialog {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: -400px;
    background: transparent;
    transition: bottom 0.4s cubic-bezier(0.36, 0.66, 0.04, 1);
    /* Account for tab bar (83px) + safe area + padding */
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
}

.ios-modal-active.ios-modal-action-sheet .ios-modal-dialog {
    /* Position above tab bar (83px typical height) */
    bottom: calc(83px + env(safe-area-inset-bottom, 0px) + 8px);
}

/* Modal Content */
.ios-modal-title {
    padding: 19px 16px 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.29412;
}

.ios-modal-message {
    padding: 16px;
    padding-top: 8px;
    font-size: 13px;
    font-weight: 400;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.38462;
}

.ios-modal-alert .ios-modal-message:first-child {
    padding-top: 19px;
}

/* Input Field */
.ios-modal-input-wrapper {
    padding: 0 16px 16px;
}

.ios-modal-input {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    border: 1px solid var(--border-primary, rgba(0, 0, 0, 0.1));
    border-radius: 8px;
    background: var(--bg-secondary, rgba(255, 255, 255, 0.8));
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', 'Helvetica Neue', sans-serif;
    outline: none;
    transition: border-color 0.2s;
}

.ios-modal-input:focus {
    border-color: var(--ios-blue, var(--color-blue));
    background: var(--bg-elevated, rgba(255, 255, 255, 0.95));
}

/* Buttons Container */
.ios-modal-alert .ios-modal-buttons {
    border-top: 0.5px solid rgba(60, 60, 67, 0.29);
    display: flex;
}

.ios-modal-action-sheet .ios-modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Button Base */
.ios-modal-btn {
    position: relative;
    flex: 1;
    padding: 12px 16px;
    font-size: 17px;
    font-weight: 400;
    text-align: center;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', 'Helvetica Neue', sans-serif;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* Alert Buttons */
.ios-modal-alert .ios-modal-btn {
    min-height: 44px;
}

.ios-modal-alert .ios-modal-btn:not(:first-child) {
    border-left: 0.5px solid rgba(60, 60, 67, 0.29);
}

.ios-modal-alert .ios-modal-buttons:has(.ios-modal-btn:nth-child(3)) {
    flex-direction: column;
}

.ios-modal-alert .ios-modal-buttons:has(.ios-modal-btn:nth-child(3)) .ios-modal-btn {
    border-left: none;
    border-top: 0.5px solid rgba(60, 60, 67, 0.29);
}

.ios-modal-alert .ios-modal-buttons:has(.ios-modal-btn:nth-child(3)) .ios-modal-btn:first-child {
    border-top: none;
}

/* Action Sheet Buttons */
.ios-modal-action-sheet .ios-modal-btn {
    background: var(--bg-elevated, rgba(255, 255, 255, 0.95));
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border-radius: 14px;
    min-height: 57px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Button Styles */
.ios-modal-btn-primary {
    color: var(--ios-blue, var(--color-blue));
    font-weight: 600;
}

.ios-modal-btn-cancel {
    color: var(--ios-blue, var(--color-blue));
    font-weight: 600; /* iOS Cancel buttons are bold */
}

/* Action Sheet Cancel button - separated from other actions (iOS native style) */
.ios-modal-action-sheet .ios-modal-btn-cancel {
    margin-top: 8px; /* Visual gap separating Cancel from action buttons */
}

.ios-modal-btn-destructive {
    color: var(--ios-red, var(--color-red));
}

.ios-modal-btn-default {
    color: var(--ios-blue, var(--color-blue));
}

/* Button Active State */
.ios-modal-btn:active {
    transform: scale(0.98);
}

.ios-modal-alert .ios-modal-btn:active {
    background: rgba(0, 0, 0, 0.05);
}

.ios-modal-action-sheet .ios-modal-btn:active {
    background: rgba(0, 0, 0, 0.05);
}

/* Button Icon */
.ios-modal-btn-icon {
    font-size: 20px;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .ios-modal-alert .ios-modal-dialog {
        background: rgba(28, 28, 30, 0.95);
    }

    .ios-modal-title,
    .ios-modal-message {
        color: #fff;
    }

    .ios-modal-input {
        background: rgba(44, 44, 46, 0.8);
        border-color: rgba(255, 255, 255, 0.1);
        color: #fff;
    }

    .ios-modal-input:focus {
        background: rgba(44, 44, 46, 0.95);
        border-color: var(--color-blue);
    }

    .ios-modal-alert .ios-modal-buttons {
        border-top-color: rgba(84, 84, 88, 0.6);
    }

    .ios-modal-alert .ios-modal-btn:not(:first-child) {
        border-left-color: rgba(84, 84, 88, 0.6);
    }

    .ios-modal-alert .ios-modal-buttons:has(.ios-modal-btn:nth-child(3)) .ios-modal-btn {
        border-top-color: rgba(84, 84, 88, 0.6);
    }

    .ios-modal-action-sheet .ios-modal-btn {
        background: rgba(44, 44, 46, 0.95);
    }

    .ios-modal-btn-primary {
        color: var(--color-blue);
    }

    .ios-modal-btn-cancel {
        color: var(--color-blue);
    }

    .ios-modal-btn-destructive {
        color: var(--color-red);
    }

    .ios-modal-btn-default {
        color: var(--color-blue);
    }

    .ios-modal-alert .ios-modal-btn:active,
    .ios-modal-action-sheet .ios-modal-btn:active {
        background: rgba(255, 255, 255, 0.1);
    }
}

/* Explicit dark mode class support */
.dark-mode .ios-modal-alert .ios-modal-dialog {
    background: rgba(28, 28, 30, 0.95);
}

.dark-mode .ios-modal-title,
.dark-mode .ios-modal-message {
    color: #fff;
}

.dark-mode .ios-modal-input {
    background: rgba(44, 44, 46, 0.8);
    border-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.dark-mode .ios-modal-input:focus {
    background: rgba(44, 44, 46, 0.95);
    border-color: var(--color-blue);
}

.dark-mode .ios-modal-alert .ios-modal-buttons {
    border-top-color: rgba(84, 84, 88, 0.6);
}

.dark-mode .ios-modal-alert .ios-modal-btn:not(:first-child) {
    border-left-color: rgba(84, 84, 88, 0.6);
}

.dark-mode .ios-modal-action-sheet .ios-modal-btn {
    background: rgba(44, 44, 46, 0.95);
}

.dark-mode .ios-modal-btn-primary {
    color: var(--color-blue);
}

.dark-mode .ios-modal-btn-cancel {
    color: var(--color-blue);
}

.dark-mode .ios-modal-btn-destructive {
    color: var(--color-red);
}

.dark-mode .ios-modal-btn-default {
    color: var(--color-blue);
}

.dark-mode .ios-modal-alert .ios-modal-btn:active,
.dark-mode .ios-modal-action-sheet .ios-modal-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Responsive adjustments for smaller screens */
@media only screen and (max-width: 374px) {
    .ios-modal-alert .ios-modal-dialog {
        width: 250px;
    }

    .ios-modal-title {
        font-size: 16px;
        padding: 16px 12px 0;
    }

    .ios-modal-message {
        font-size: 12px;
        padding: 12px;
    }

    .ios-modal-btn {
        font-size: 16px;
    }
}

/* Animation for action sheet cancel button */
.ios-modal-action-sheet .ios-modal-btn-cancel {
    margin-top: 0;
    font-weight: 600;
}

/* Prevent text selection */
.ios-modal-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Safe area support for action sheets */
.ios-modal-action-sheet .ios-modal-dialog {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}

/* ========================================
   iOS 17+ Sheet Modal (Half/Full Sheet)
   Modern presentation style for settings/forms
   ======================================== */

.ios-sheet {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 11000;
    pointer-events: none;
}

.ios-sheet-active {
    pointer-events: auto;
}

/* Sheet backdrop */
.ios-sheet-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

.ios-sheet-active .ios-sheet-backdrop {
    opacity: 1;
}

/* Sheet container */
.ios-sheet-container {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 90vh;
    background: rgba(28, 28, 30, 0.98);
    backdrop-filter: blur(60px) saturate(180%);
    -webkit-backdrop-filter: blur(60px) saturate(180%);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.3), 0 0 0 0.5px rgba(255, 255, 255, 0.1);
    transform: translateY(100%);
    transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1);
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
}

.ios-sheet-active .ios-sheet-container {
    transform: translateY(0);
}

/* Sheet handle (drag indicator) */
.ios-sheet-handle {
    width: 36px;
    height: 5px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    margin: 8px auto 0;
    flex-shrink: 0;
    cursor: grab;
}

.ios-sheet-handle:active {
    cursor: grabbing;
}

/* Sheet header */
.ios-sheet-header {
    padding: 16px 20px;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
}

.ios-sheet-title {
    font-size: 17px;
    font-weight: 600;
    color: #FFFFFF;
    flex: 1;
    text-align: center;
}

.ios-sheet-close {
    position: absolute;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(142, 142, 147, 0.2);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ios-sheet-close:hover {
    background: rgba(142, 142, 147, 0.3);
}

.ios-sheet-close:active {
    transform: scale(0.95);
    background: rgba(142, 142, 147, 0.4);
}

.ios-sheet-close::before,
.ios-sheet-close::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 2px;
    background: rgba(255, 255, 255, 0.7);
}

.ios-sheet-close::before {
    transform: rotate(45deg);
}

.ios-sheet-close::after {
    transform: rotate(-45deg);
}

/* Sheet content */
.ios-sheet-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
}

/* Sheet footer (for actions) */
.ios-sheet-footer {
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    border-top: 0.5px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.3);
}

.ios-sheet-footer-buttons {
    display: flex;
    gap: 12px;
}

.ios-sheet-footer-buttons button {
    flex: 1;
    min-height: 48px;
}

/* Half sheet variant */
.ios-sheet-half .ios-sheet-container {
    max-height: 50vh;
}

/* Full sheet variant */
.ios-sheet-full .ios-sheet-container {
    max-height: 100vh;
    border-radius: 0;
    padding-top: env(safe-area-inset-top);
}

.ios-sheet-full .ios-sheet-handle {
    display: none;
}

/* Sheet detent animations (size changes) */
.ios-sheet-container.transitioning {
    transition: max-height 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Sheet with scrollable content */
.ios-sheet-scrollable .ios-sheet-content {
    overscroll-behavior: contain;
}

/* iPad optimizations */
@media only screen and (min-width: 768px) {
    .ios-sheet-container {
        left: 50%;
        transform: translateX(-50%) translateY(100%);
        max-width: 500px;
        border-radius: 20px;
        margin-bottom: 20px;
        max-height: 85vh;
    }

    .ios-sheet-active .ios-sheet-container {
        transform: translateX(-50%) translateY(0);
    }

    .ios-sheet-full .ios-sheet-container {
        max-width: 700px;
        max-height: 90vh;
    }
}

/* Large iPad optimizations */
@media only screen and (min-width: 1024px) {
    .ios-sheet-container {
        max-width: 600px;
    }

    .ios-sheet-full .ios-sheet-container {
        max-width: 800px;
    }
}

/* ========================================
   iOS Settings-Style Sheet Content
   ======================================== */

.ios-sheet .ios-form-group {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 0;
    margin: 16px 0;
    overflow: hidden;
    border: 0.5px solid rgba(255, 255, 255, 0.08);
}

.ios-sheet .ios-form-row {
    padding: 14px 16px;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
}

.ios-sheet .ios-form-row:last-child {
    border-bottom: none;
}

.ios-sheet .ios-form-label {
    font-size: 17px;
    font-weight: 400;
    color: #FFFFFF;
}

.ios-sheet .ios-form-value {
    font-size: 17px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.6);
    margin-left: auto;
    padding-left: 16px;
}

.ios-sheet .ios-form-input {
    background: rgba(0, 0, 0, 0.25);
    border: 0.5px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 17px;
    color: #FFFFFF;
    width: 100%;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.ios-sheet .ios-form-input:focus {
    background: rgba(0, 0, 0, 0.35);
    border-color: rgba(10, 132, 255, 0.6);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 0 0 4px rgba(10, 132, 255, 0.1);
    outline: none;
}

/* Sheet section headers */
.ios-sheet-section-header {
    font-size: 13px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    padding: 16px 4px 8px;
    letter-spacing: -0.1px;
}

.ios-sheet-section-footer {
    font-size: 13px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.6);
    padding: 8px 4px 16px;
    line-height: 1.4;
}

/* ========================================
   iOS Card-Style Modal (For Billing)
   ======================================== */

.ios-modal-card {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 11500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.ios-modal-card-active {
    opacity: 1;
    pointer-events: auto;
}

.ios-modal-card-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.ios-modal-card-content {
    position: relative;
    background: rgba(28, 28, 30, 0.95);
    backdrop-filter: blur(60px) saturate(180%);
    -webkit-backdrop-filter: blur(60px) saturate(180%);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.1);
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.ios-modal-card-active .ios-modal-card-content {
    transform: scale(1);
}

/* Modal card header */
.ios-modal-card-header {
    padding: 24px 24px 16px;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ios-modal-card-title {
    font-size: 22px;
    font-weight: 700;
    color: #FFFFFF;
}

.ios-modal-card-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(142, 142, 147, 0.2);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ios-modal-card-close:hover {
    background: rgba(142, 142, 147, 0.3);
}

.ios-modal-card-close:active {
    transform: scale(0.95);
}

/* Modal card body */
.ios-modal-card-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* Modal card footer */
.ios-modal-card-footer {
    padding: 16px 24px 24px;
    border-top: 0.5px solid rgba(255, 255, 255, 0.08);
}

/* Responsive adjustments */
@media only screen and (max-width: 767px) {
    .ios-modal-card {
        padding: 0;
        align-items: flex-end;
    }

    .ios-modal-card-content {
        max-width: 100%;
        max-height: 95vh;
        border-radius: 20px 20px 0 0;
        margin-bottom: 0;
    }

    .ios-modal-card-header,
    .ios-modal-card-body,
    .ios-modal-card-footer {
        padding-left: 20px;
        padding-right: 20px;
    }
}
