/* Modal Components */

/* --- Modal Overlay --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-overlay);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.show {
    opacity: 1;
}

.modal-overlay.show .modal-glass-card {
    animation: modalPopIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.modal-overlay.closing .modal-glass-card {
    animation: modalPopOut 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Edit modals should appear above other modals */
#daily-log-edit-modal,
#life-tracker-goals-modal {
    z-index: 1100;
}

/* Add time entry modal should appear above edit modals */
#add-time-entry-modal {
    z-index: 1200;
}

/* Download and upload confirmation modals should appear above their trigger modals */
#download-cloud-confirm-modal,
#upload-cloud-confirm-modal {
    z-index: 1100;
}

/* --- Modal Card --- */
.modal-glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-glass);
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    opacity: 0;
    transform: translateY(-3px) scale(0.92);
}

@keyframes modalPopIn {
    0% {
        opacity: 0;
        transform: translateY(-3px) scale(0.92);
    }
    60% {
        opacity: 1;
        transform: translateY(0) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes modalPopOut {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-3px) scale(0.92);
    }
}

/* --- Modal Header --- */
.modal-header {
    display: flex;
    flex-direction: column;
    padding: 0;
    border-bottom: 1px solid var(--border-glass);
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    min-height: 72px;
    flex-shrink: 0;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
    order: -1;
}

.modal-header h3 {
    flex: 1;
    margin: 0;
    padding: 0 20px 20px 20px;
    order: 1;
}

.modal-header h3.clickable-title {
    cursor: pointer;
}

/* --- Modal Body --- */
.modal-body {
    padding: 20px;
    box-sizing: border-box;
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 1;
    overflow-y: auto;
}

/* Lazy load content animation */
.modal-body > * {
    opacity: 0;
    animation: contentFadeIn 0.4s ease 0.15s forwards;
}

.modal-body > *:nth-child(1) { animation-delay: 0.15s; }
.modal-body > *:nth-child(2) { animation-delay: 0.2s; }
.modal-body > *:nth-child(3) { animation-delay: 0.25s; }
.modal-body > *:nth-child(4) { animation-delay: 0.3s; }
.modal-body > *:nth-child(5) { animation-delay: 0.35s; }
.modal-body > *:nth-child(n+6) { animation-delay: 0.4s; }

@keyframes contentFadeIn {
    from {
        opacity: 0;
        transform: translateY(5px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* --- Modal Footer --- */
.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border-glass);
    flex-shrink: 0;
}

/* --- Modal Tooltip --- */
.modal-tooltip {
    position: absolute;
    top: 60px;
    right: 20px;
    left: 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    border: 1px solid var(--border-glass-highlight);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow-glass);
    z-index: 1000;
    max-width: calc(100% - 40px);
    animation: tooltipFadeIn 0.3s ease;
    display: none;
}

.modal-tooltip.show {
    display: block;
}

.modal-tooltip h4 {
    color: var(--accent-primary);
    font-size: 1.1em;
    font-weight: 600;
    margin: 0 0 12px 0;
}

.modal-tooltip p {
    color: var(--text-main);
    font-size: 0.95em;
    line-height: 1.6;
    margin: 0 0 10px 0;
}

.modal-tooltip p:last-child {
    margin-bottom: 0;
}

.modal-tooltip .tooltip-score-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-glass);
}

.modal-tooltip .tooltip-score-section h5 {
    color: var(--accent-primary);
    font-size: 1em;
    font-weight: 600;
    margin: 0 0 10px 0;
}

.modal-tooltip .tooltip-score-text {
    color: var(--text-main);
    font-size: 0.9em;
    line-height: 1.6;
    margin: 0 0 12px 0;
}

.modal-tooltip .tooltip-score-list {
    margin: 0;
    padding-left: 20px;
    list-style: none;
}

.modal-tooltip .tooltip-score-list li {
    color: var(--text-main);
    font-size: 0.85em;
    line-height: 1.7;
    margin-bottom: 8px;
    position: relative;
    padding-left: 20px;
}

.modal-tooltip .tooltip-score-list li:last-child {
    margin-bottom: 0;
}

.modal-tooltip .tooltip-score-list li::before {
    content: '•';
    color: var(--accent-primary);
    font-weight: bold;
    position: absolute;
    left: 0;
}

.modal-tooltip .tooltip-score-list li strong {
    color: var(--accent-primary);
    font-weight: 600;
}

.modal-tooltip .tooltip-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--bg-glass-subtle);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border-glass);
    border-radius: 50%;
    color: var(--text-main);
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
}

.modal-tooltip .tooltip-close:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-glass-highlight);
    transform: scale(1.1);
}

.modal-tooltip .tooltip-close:active {
    transform: scale(0.9);
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Modal Responsive Styles --- */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 12px;
    }
    
    .modal-glass-card {
        max-width: calc(100vw - 24px);
        min-width: 240px;
        margin: 0;
        border-radius: 16px;
    }
}

@media (max-width: 400px) {
    .modal-overlay {
        padding: 12px;
    }
    
    .modal-glass-card {
        max-width: calc(100vw - 24px);
        min-width: 240px;
        margin: 0;
        border-radius: 16px;
    }
    
    .modal-body {
        padding: 15px;
    }
}

/* Compact modals for nutrition entries */
.nutrition-entry-modal-compact {
    max-width: 420px;
}

.nutrition-all-entries-modal-compact {
    max-width: 700px;
}

/* All graphs modal - responsive */
.all-graphs-modal-compact {
    max-width: 90vw;
    max-height: 90vh;
    width: 1000px;
}

.all-graphs-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    padding: 12px;
}

/* Mobile responsiveness for all modals */
@media (max-width: 480px) {
    .modal-overlay {
        padding: 10px;
    }
    
    .modal-glass-card {
        max-width: calc(100vw - 20px);
        border-radius: 16px;
    }
    
    .modal-header {
        min-height: 60px;
    }
    
    .modal-header h3 {
        font-size: 1.1em;
        padding: 0 16px 16px 16px;
    }
    
    .modal-header-actions {
        padding: 10px 16px;
    }
    
    .modal-body {
        padding: 16px;
    }
    
    .modal-footer {
        padding: 16px;
    }
    
    .nutrition-entry-modal-compact,
    .nutrition-all-entries-modal-compact {
        max-width: calc(100vw - 20px);
    }
    
    .all-graphs-modal-compact {
        max-width: calc(100vw - 20px);
        width: 100%;
    }
    
    .all-graphs-grid {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 8px;
    }
}

@media (max-width: 360px) {
    .modal-overlay {
        padding: 8px;
    }
    
    .modal-glass-card {
        max-width: calc(100vw - 16px);
        border-radius: 12px;
    }
    
    .modal-header h3 {
        font-size: 1em;
        padding: 0 12px 12px 12px;
    }
    
    .modal-header-actions {
        padding: 8px 12px;
    }
    
    .modal-body {
        padding: 12px;
    }
    
    .modal-footer {
        padding: 12px;
    }
    
    .nutrition-entry-modal-compact,
    .nutrition-all-entries-modal-compact {
        max-width: calc(100vw - 16px);
    }
    
    .all-graphs-modal-compact {
        max-width: calc(100vw - 16px);
    }
    
    .all-graphs-grid {
        gap: 12px;
        padding: 6px;
    }
}

@media (max-width: 320px) {
    .modal-overlay {
        padding: 6px;
    }
    
    .modal-glass-card {
        max-width: calc(100vw - 12px);
        min-width: 0;
        margin: 0;
        border-radius: 12px;
    }
    
    .modal-header {
        min-height: 56px;
    }
    
    .modal-header h3 {
        font-size: 0.95em;
        padding: 0 10px 10px 10px;
    }
    
    .modal-header-actions {
        padding: 6px 10px;
    }
    
    .modal-body {
        padding: 10px;
    }
    
    .modal-footer {
        padding: 10px;
    }
    
    .nutrition-entry-modal-compact,
    .nutrition-all-entries-modal-compact {
        max-width: calc(100vw - 12px);
    }
    
    .all-graphs-modal-compact {
        max-width: calc(100vw - 12px);
    }
    
    .all-graphs-grid {
        gap: 10px;
        padding: 4px;
    }
}

@media (max-width: 300px) {
    .modal-overlay {
        padding: 6px;
    }
    
    .modal-glass-card {
        max-width: calc(100vw - 12px);
        min-width: 0;
        margin: 0;
        border-radius: 10px;
    }
    
    .modal-header {
        min-height: 52px;
    }
    
    .modal-header h3 {
        font-size: 0.9em;
        padding: 0 8px 8px 8px;
    }
    
    .modal-header-actions {
        padding: 6px 8px;
    }
    
    .modal-body {
        padding: 8px;
    }
    
    .modal-footer {
        padding: 8px;
    }
    
    .nutrition-entry-modal-compact,
    .nutrition-all-entries-modal-compact {
        max-width: calc(100vw - 12px);
    }
    
    .all-graphs-modal-compact {
        max-width: calc(100vw - 12px);
    }
    
    .all-graphs-grid {
        gap: 8px;
        padding: 4px;
    }
}

