/* =============================================
   MODAL BASE - BEM Naming, Zero !important
   Clean flex-based layout for fullscreen modals
   ============================================= */

/* Overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    animation: modal-fade-in 0.2s ease;
}

/* Modal Container */
.modal {
    position: fixed;
    bottom: 6px;
    left: 9px;
    right: 9px;
    max-height: 90dvh;
    background: var(--bg-primary);
    border-radius: 16px;
    z-index: 101;
    animation: modal-slide-up 0.3s ease;

    /* Flex Layout - KEY! */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Modifier: Fullscreen */
.modal--fullscreen {
    top: 0;
    max-height: 100dvh;
    border-radius: 0;
}

/* =============================================
   HEADER - Fixed at top
   ============================================= */
.modal__header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.modal__title {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal__close,
.modal__action {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.modal__close {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.modal__close:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.modal__action--save {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.3);
}

.modal__action--save:hover {
    background: var(--primary-dark);
}

/* =============================================
   TABS - Fixed below header
   ============================================= */
.modal__tabs {
    flex: 0 0 auto;
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.modal__tab {
    flex: 1;
    min-width: 80px;
    padding: 12px 8px;
    border: none;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.modal__tab i {
    font-size: 1.1rem;
}

.modal__tab:hover {
    color: var(--text-primary);
}

.modal__tab--active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* =============================================
   BODY - Scrollable, expands to fill space
   ============================================= */
.modal__body {
    flex: 1 1 auto;
    min-height: 0;           /* Critical for flex scroll! */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Tab Panels - Now enabled with plan-modal.css */
.modal__panel {
    display: none;
    padding: 16px;
}

.modal__panel--active {
    display: block;
}

/* Panel that needs to fill height - keeping for future */
/*
.modal__panel--flex {
    display: none;
    flex-direction: column;
}

.modal__panel--flex.modal__panel--active {
    display: flex;
}
*/

/* =============================================
   FOOTER - Fixed at bottom (inside flex, NOT position:fixed)
   ============================================= */
.modal__footer {
    flex: 0 0 auto;
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.modal__footer .btn {
    flex: 1;
}

/* =============================================
   SECTION - Content blocks inside panels
   ============================================= */
.modal__section {
    margin-bottom: 16px;
}

.modal__section:last-child {
    margin-bottom: 0;
}

.modal__section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* =============================================
   BODY SCROLL LOCK
   ============================================= */
body.modal-open {
    overflow: hidden;
}

/* =============================================
   ACCESSIBILITY
   ============================================= */
.modal:focus {
    outline: none;
}

.modal__close:focus-visible,
.modal__action:focus-visible,
.modal__tab:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (min-width: 768px) {
    .modal:not(.modal--fullscreen) {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: 600px;
        max-width: 90vw;
        border-radius: 16px;
        bottom: auto;
        top: 50%;
        transform: translate(-50%, -50%);
        max-height: 85vh;
        animation: modal-fade-in 0.2s ease;
    }
}
