/* ============================================ */
/* Bottom Sheet 컴포넌트 스타일 (표준 구조)      */
/* ============================================ */
/* 
 * ✅ 보강 기능 유지:
 * - iOS Safe Area (env(safe-area-inset-bottom))
 * - 100dvh 우선 사용 (fallback: 100vh)
 * - 접근성 포커스 아웃라인
 * - 드래그 애니메이션
 */

/* Overlay */
.bottom-sheet-overlay {
    position: fixed;
    top: 64px;  /* 상단 네비 높이만큼 아래로 */
    left: 0;
    right: 0;
    bottom: 64px;  /* 하단 네비 높이만큼 위로 */
    background: rgba(0, 0, 0, 0.45);
    z-index: 9990;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    opacity: 0;
    transition: opacity 200ms ease;
}

.bottom-sheet-overlay.active {
    opacity: 1;
}

.bottom-sheet-overlay.closing {
    opacity: 0;
}

/* Bottom Sheet */
.bottom-sheet {
    width: 100%;
    max-width: 720px;
    background: #fff;
    overflow: hidden;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 200ms ease;
    
    /* 상단바(64px)와 하단바(64px) 사이 공간 채우기 */
    height: calc(100vh - 128px);
    max-height: calc(100vh - 128px);
}

/* 100dvh 미지원 브라우저 fallback */
@supports (height: 100dvh) {
    .bottom-sheet {
        height: calc(100dvh - 128px);
        max-height: calc(100dvh - 128px);
    }
}

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

.bottom-sheet.closing {
    transform: translateY(100%);
}

/* Header (56px 고정) */
.bs-header {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid #eee;
    flex: 0 0 auto;
    position: relative;
    cursor: grab;
    user-select: none;
}

.bs-header:active {
    cursor: grabbing;
}

/* 드래그 핸들 (중앙 막대) */
.bs-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: #ddd;
}

/* 닫기 버튼 */
.bs-close-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 0;
    background: rgba(0, 0, 0, 0.06);
    font-size: 1.25rem;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bs-close-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.bs-close-btn:focus {
    outline: 2px solid var(--primary, #4F46E5);
    outline-offset: 2px;
}

/* Body (스크롤 영역) */
.bs-body {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    flex: 1;
    
    /* flex: 1로 남은 공간 자동 차지 */
    min-height: 0;
    
    /* iOS Safe Area 대응 - 보강 기능 유지 */
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

/* Body 스크롤 스타일링 */
.bs-body::-webkit-scrollbar {
    width: 6px;
}

.bs-body::-webkit-scrollbar-track {
    background: transparent;
}

.bs-body::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

.bs-body::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}

/* Footer (64px 고정) */
.bs-footer {
    height: 64px;
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #eee;
    flex: 0 0 auto;
    
    /* iOS Safe Area 대응 - 보강 기능 유지 */
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

/* 저장 버튼 */
.bs-save-btn {
    flex: 1;
    height: 44px;
    border: 0;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    background: var(--primary, #4F46E5);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.bs-save-btn:hover:not(:disabled) {
    background: var(--primary-dark, #4338CA);
}

.bs-save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.bs-save-btn:focus {
    outline: 2px solid var(--primary, #4F46E5);
    outline-offset: 2px;
}

/* 더보기 버튼 */
.bs-more-btn {
    width: 52px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.06);
    font-size: 1.5rem;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bs-more-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.bs-more-btn:focus {
    outline: 2px solid var(--primary, #4F46E5);
    outline-offset: 2px;
}

/* 삭제 버튼 */
.bs-delete-btn {
    height: 44px;
    padding: 0 1rem;
    border: 0;
    border-radius: 12px;
    background: #fee;
    color: #dc2626;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.bs-delete-btn:hover {
    background: #fcc;
    color: #b91c1c;
}

.bs-delete-btn:focus {
    outline: 2px solid #dc2626;
    outline-offset: 2px;
}

.bs-delete-btn i {
    font-size: 0.9rem;
}

/* ============================================ */
/* 모바일 최적화 (≤420px)                       */
/* ============================================ */

@media (max-width: 420px) {
    .bottom-sheet {
        border-top-left-radius: 12px;
        border-top-right-radius: 12px;
        max-width: 100%;
    }
    
    .bs-body {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
    
    .bs-footer {
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
}

/* ============================================ */
/* 섹션 스타일 (내용 구조화)                    */
/* ============================================ */

.bs-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #eee;
}

.bs-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.bs-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================ */
/* 폼 스타일 (Bottom Sheet 내부)               */
/* ============================================ */

.bs-body .form-group {
    margin-bottom: 1rem;
}

.bs-body .form-group:last-child {
    margin-bottom: 0;
}

.bs-body .form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #333;
}

.bs-body .form-control,
.bs-body .form-control-sm {
    width: 100%;
}

.bs-body textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

/* 폼 그리드 (PC에서 2열) */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 900px) {
    .form-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .form-grid .full-width {
        grid-column: 1 / -1;
    }
}

/* ============================================ */
/* 로딩/빈 상태                                 */
/* ============================================ */

.bs-body .loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #666;
}

.bs-body .spinner-small {
    width: 24px;
    height: 24px;
    border: 2px solid #eee;
    border-top-color: var(--primary, #4F46E5);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.bs-body .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #666;
    text-align: center;
}

.bs-body .empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.bs-body .empty-state p {
    margin: 0;
}

/* ============================================ */
/* 접근성 (보강 기능 유지)                      */
/* ============================================ */

/* 포커스 가시성 개선 */
.bs-body button:focus,
.bs-body a:focus,
.bs-body input:focus,
.bs-body textarea:focus,
.bs-body select:focus {
    outline: 2px solid var(--primary, #4F46E5);
    outline-offset: 2px;
}

/* 스크린리더 전용 텍스트 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ============================================ */
/* 기존 게시판 스타일과 통합                     */
/* ============================================ */

/* 첨부파일 그리드 */
.attachment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.75rem;
}

.attachment-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #ddd;
    cursor: pointer;
    transition: all 0.2s;
}

.attachment-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.attachment-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.attachment-date-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.25rem;
    font-size: 0.7rem;
    text-align: center;
}

.attachment-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(255,255,255,0.9);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.attachment-item:hover .attachment-delete {
    opacity: 1;
}

/* 연결된 소임 목록 */
.linked-work-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.linked-work-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.linked-work-item:hover {
    background: #f3f4f6;
}

.linked-work-category {
    padding: 0.25rem 0.5rem;
    background: white;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    flex-shrink: 0;
}

.linked-work-title {
    flex: 1;
    font-size: 0.9rem;
}

.linked-work-status {
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.linked-work-status.todo {
    background: #FEF3C7;
    color: #92400E;
}

.linked-work-status.doing {
    background: #DBEAFE;
    color: #1E40AF;
}

.linked-work-status.done {
    background: #D1FAE5;
    color: #065F46;
}

@media (max-width: 420px) {
    .attachment-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
