/* ============================================================
 * common-modal.css — Phase M5-F 공통 모달 (PC/모바일 동일)
 * 디자인 토큰: --sage / --red / --text-* / --border-* / --radius-* / --shadow-* / --bg-*
 * 페어 파일: js/common-modal.js
 * ============================================================ */

/* body 스크롤 락 */
body.ow-modal-open {
    position: fixed;
    width: 100%;
    overflow: hidden;
}

/* 백드롭 */
.ow-modal {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.18s ease-out;
    -webkit-tap-highlight-color: transparent;
}
.ow-modal.is-open {
    opacity: 1;
}

/* 다이얼로그 박스 */
.ow-modal__dialog {
    background: var(--bg-white, #fff);
    border: 1px solid var(--border-light, #E5E4E0);
    border-radius: var(--radius-lg, 8px);
    box-shadow: var(--shadow-md, 0 4px 24px rgba(0, 0, 0, 0.12));
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: calc(100vh - 40px);
    transform: scale(0.96) translateY(8px);
    transition: transform 0.18s ease-out;
    overflow: hidden;
}
.ow-modal.is-open .ow-modal__dialog {
    transform: scale(1) translateY(0);
}

/* 사이즈 */
.ow-modal--sm .ow-modal__dialog { max-width: 420px; }
.ow-modal--md .ow-modal__dialog { max-width: 560px; }
.ow-modal--lg .ow-modal__dialog { max-width: 800px; }

/* 풀스크린 (모바일 자동 / 명시) */
.ow-modal--fullscreen {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
}
.ow-modal--fullscreen .ow-modal__dialog {
    max-width: none;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border: none;
    /* safe-area */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* 헤더 */
.ow-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light, #E5E4E0);
    flex-shrink: 0;
}
.ow-modal__title {
    margin: 0;
    font-family: var(--font-serif, 'Noto Serif KR', serif);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #2D2D2D);
    letter-spacing: -0.01em;
    line-height: 1.4;
    flex: 1;
    min-width: 0;
    /* 긴 제목 줄바꿈 허용 */
    word-break: keep-all;
    overflow-wrap: anywhere;
}
.ow-modal__close {
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: var(--text-secondary, #5A5A5A);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm, 4px);
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.ow-modal__close:hover {
    background: var(--bg-secondary, #F5F4F0);
    color: var(--text-primary, #2D2D2D);
}
.ow-modal__close:focus-visible {
    outline: 2px solid var(--sage, #6F8F72);
    outline-offset: 2px;
}

/* 바디 */
.ow-modal__body {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    color: var(--text-primary, #2D2D2D);
    font-size: 14px;
    line-height: 1.7;
}

/* 메시지 */
.ow-modal__message {
    margin: 0 0 12px 0;
    color: var(--text-primary, #2D2D2D);
    font-size: 14px;
    line-height: 1.7;
    word-break: keep-all;
    overflow-wrap: anywhere;
}
.ow-modal__message:last-child { margin-bottom: 0; }

/* 인풋 (prompt) */
.ow-modal__input {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light, #E5E4E0);
    border-radius: var(--radius-sm, 4px);
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary, #2D2D2D);
    background: var(--bg-white, #fff);
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}
.ow-modal__input:focus {
    outline: none;
    border-color: var(--sage, #6F8F72);
    box-shadow: 0 0 0 3px rgba(111, 143, 114, 0.18);
}
textarea.ow-modal__input {
    resize: vertical;
    min-height: 100px;
    font-family: var(--font-mono, 'IBM Plex Mono', monospace);
    line-height: 1.6;
}

/* 에러 메시지 */
.ow-modal__error {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--red-light, #FFF0F0);
    border: 1px solid var(--red, #E05252);
    color: var(--red, #E05252);
    border-radius: var(--radius-sm, 4px);
    font-size: 12px;
    line-height: 1.5;
}

/* 푸터 */
.ow-modal__footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 20px;
    border-top: 1px solid var(--border-light, #E5E4E0);
    background: var(--bg-secondary, #F9F8F4);
    flex-shrink: 0;
}

/* 버튼 */
.ow-modal__btn {
    padding: 9px 16px;
    border-radius: var(--radius-md, 6px);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    min-width: 72px;
    line-height: 1.2;
}
.ow-modal__btn:focus-visible {
    outline: 2px solid var(--sage, #6F8F72);
    outline-offset: 2px;
}

.ow-modal__btn--primary {
    background: var(--sage, #6F8F72);
    color: #fff;
    border-color: var(--sage, #6F8F72);
}
.ow-modal__btn--primary:hover {
    background: var(--sage-dark, #5F7F62);
    border-color: var(--sage-dark, #5F7F62);
}

.ow-modal__btn--danger {
    background: var(--red, #E05252);
    color: #fff;
    border-color: var(--red, #E05252);
}
.ow-modal__btn--danger:hover {
    background: #C04040;
    border-color: #C04040;
}

.ow-modal__btn--warning {
    background: #E0A040;
    color: #fff;
    border-color: #E0A040;
}
.ow-modal__btn--warning:hover {
    background: #C08030;
    border-color: #C08030;
}

.ow-modal__btn--ghost {
    background: var(--bg-white, #fff);
    color: var(--text-secondary, #5A5A5A);
    border-color: var(--border-light, #E5E4E0);
}
.ow-modal__btn--ghost:hover {
    background: var(--bg-secondary, #F5F4F0);
    color: var(--text-primary, #2D2D2D);
    border-color: var(--border-medium, #D5D4D0);
}

/* 모바일 (768px 이하) — 자동 풀스크린이지만 명시 size 지정 시 그대로 */
@media (max-width: 768px) {
    .ow-modal {
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
    }
    .ow-modal__dialog {
        max-width: none;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        border: none;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .ow-modal__header {
        padding: 14px 16px;
    }
    .ow-modal__title { font-size: 17px; }
    .ow-modal__body { padding: 16px; font-size: 15px; }
    .ow-modal__footer {
        padding: 10px 16px;
        /* 모바일에서 버튼 풀폭으로 */
        flex-direction: column-reverse;
        gap: 8px;
    }
    .ow-modal__btn {
        width: 100%;
        padding: 12px 16px;
        font-size: 15px;
        min-height: 44px;
    }
    .ow-modal__input {
        font-size: 16px; /* iOS 줌 방지 */
        padding: 12px 14px;
    }
    .ow-modal__close {
        font-size: 28px;
        padding: 6px 10px;
    }
}

/* 모션 감소 선호 */
@media (prefers-reduced-motion: reduce) {
    .ow-modal,
    .ow-modal__dialog {
        transition: none !important;
        transform: none !important;
    }
}
