/* 주간 뷰 전용 스타일 */

.week-view {
    display: flex;
    height: 100vh;
    overflow: hidden;
    gap: 10px;
    margin: 20px 0;
}

/* 주간 뷰 사이드바 */
.week-view .diary-sidebar {
    width: 300px;
    background: var(--card-bg-color);
    border: 1px solid var(--card-border-color);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* 주간 달력 영역 */
.diary-week-calendar {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--card-bg-color);
    border: 1px solid var(--card-border-color);
    border-radius: 8px;
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 10px;
}

/* 주간 그리드 컨테이너 */
.week-grid-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    background: var(--card-bg-color, #fff);
}

/* 헤더 (요일) */
.week-header {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    border-bottom: 2px solid var(--card-border-color, #ddd);
    background: var(--card-bg-color, #fff);
    position: sticky;
    top: 0;
    z-index: 10;
}

.time-col-header {
    border-right: 1px solid var(--color-3, #ddd);
}

.day-col-header {
    text-align: center;
    padding: 15px 5px;
    border-right: 1px solid var(--color-3, #ddd);
}

.day-col-header.today {
    background: var(--primary-color-light, #dbeafe);
}

.day-col-header .day-name {
    font-size: 0.9em;
    color: var(--gray-400);
}

.day-col-header .day-num {
    font-size:1.4em;
    font-weight: bold;
}

.day-col-header.today .day-num {
    color: var(--primary-color, #3b82f6);
}

/* 종일 일정 영역 */
.all-day-events {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    min-height: 40px;
    max-height: 120px;
    overflow-y: auto;
    border-bottom: 1px solid var(--card-border-color, #ddd);
    background: var(--card-bg-color, #fff);
}

.time-col-label {
    padding: 10px 5px;
    text-align: center;
    font-size: 0.9em;
    color: var(--gray-400);
    border-right: 1px solid var(--color-3, #ddd);
}

.day-all-day-events {
    padding: 5px;
    border-right: 1px solid var(--color-3, #ddd);
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0; /* flex 축소 허용 */
}

.event-chip {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
    color: white;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.9;
    max-width: 100%; /* 부모 너비를 넘지 않도록 */
    box-sizing: border-box;
}

.event-chip:hover {
    opacity: 1;
}

/* 시간대별 그리드 */
.week-grid {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    position: relative;
}

.time-column {
    border-right: 1px solid var(--color-3, #ddd);
}

.time-slot {
    height: 60px;
    padding: 5px;
    text-align: right;
    font-size: 0.9em;
    color: var(--gray-400);
    border-bottom: 1px solid var(--color-e, #f5f5f5);
    position: relative;
    top: -10px;
}

.day-column {
    position: relative;
    border-right: 1px solid var(--color-3, #ddd);
}

.hour-slot {
    height: 60px;
    border-bottom: 1px solid var(--color-e, #f5f5f5);
}

.hour-slot:hover {
    background: var(--color-f-hover, #fafafa);
}

/* 드래그 선택 시 하이라이트 */
.hour-slot.selecting {
    background: rgba(59, 130, 246, 0.15) !important;
}

/* 편집 모드 - 드래그 오버 */
.hour-slot.drag-over {
    background: rgba(139, 92, 246, 0.2) !important;
    border: 2px dashed var(--accent-color, #8b5cf6) !important;
    box-sizing: border-box;
}

/* 시간대 이벤트 블록 */
.event-block {
    position: absolute;
    left: 2px;
    right: 2px;
    padding: 4px 6px;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    overflow: hidden;
    font-size: 0.9em;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    opacity: 0.9;
    z-index: 1;
}

.event-block:hover {
    opacity: 1;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.event-block .event-time {
    font-size: 10px;
    font-weight: bold;
    margin-bottom: 2px;
}

.event-block .event-title {
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 이벤트 타입별 스타일 */
.event-schedule {
    /* 색상은 인라인 스타일로 적용됨 */
}

.event-todo {
    /* 색상은 인라인 스타일로 적용됨 */
}

.event-anniversary {
    /* 색상은 인라인 스타일로 적용됨 */
}

/* ================== 반응형 디자인 ================== */

/* 태블릿 (768px ~ 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .week-header {
        grid-template-columns: 50px repeat(7, 1fr);
    }

    .week-grid {
        grid-template-columns: 50px repeat(7, 1fr);
    }

    .all-day-events {
        grid-template-columns: 50px repeat(7, 1fr);
    }

    .time-slot {
        font-size: 0.9em;
        padding: 3px;
    }

    .event-block {
        font-size: 0.9em;
    }
}

/* 모바일 (최대 768px) */
@media (max-width: 768px) {
    .week-view {
        flex-direction: column;
        height: auto;
    }

    .week-view .diary-sidebar {
        width: 100%;
        height: auto;
        min-height: 250px;
        max-height: 400px;
    }

    .sidebar-list {
        max-height: 200px;
    }

    .sidebar-detail {
        min-height: 120px;
    }

    /* 헤더 */
    .calendar-header {
        flex-direction: column;
        padding: 15px;
        gap: 10px;
    }

    .calendar-nav {
        width: 100%;
        justify-content: center;
    }

    .calendar-nav button {
        padding: 6px 12px;
        font-size:1em;
    }

    .view-switcher {
        justify-content: center;
        flex-wrap: wrap;
    }

    .btn-view {
        padding: 6px 12px;
        font-size:1em;
    }

    /* 주간 그리드 */
    .week-header {
        grid-template-columns: 45px repeat(7, 1fr);
        font-size: 0.9em;
    }

    .week-grid {
        grid-template-columns: 45px repeat(7, 1fr);
    }

    .all-day-events {
        grid-template-columns: 45px repeat(7, 1fr);
    }

    .day-col-header {
        padding: 10px 3px;
    }

    .day-col-header .day-name {
        font-size: 10px;
        margin-bottom: 3px;
    }

    .day-col-header .day-num {
        font-size:1.2em;
    }

    .time-slot {
        height: 50px;
        font-size: 10px;
        padding: 3px;
    }

    .hour-slot {
        height: 50px;
    }

    .event-chip {
        font-size: 10px;
        padding: 1px 4px;
    }

    .event-block {
        font-size: 10px;
        padding: 3px 4px;
        left: 1px;
        right: 1px;
    }

    .event-block .event-time {
        font-size: 0.8em;
    }

    .event-block .event-title {
        font-size: 10px;
    }
}

/* 작은 모바일 (최대 480px) */
@media (max-width: 480px) {
    .diary-sidebar {
        padding: 10px;
        min-height: 200px;
        max-height: 300px;
    }

    .sidebar-list {
        max-height: 150px;
    }

    .sidebar-detail {
        min-height: 100px;
    }

    .calendar-header {
        padding: 10px;
    }

    .calendar-nav button {
        padding: 5px 10px;
        font-size: 0.9em;
        margin: 0 2px;
    }

    .btn-view {
        padding: 5px 10px;
        font-size: 0.9em;
    }

    /* 주간 그리드 극축소 */
    .week-header {
        grid-template-columns: 35px repeat(7, 1fr);
        font-size: 0.9em;
    }

    .week-grid {
        grid-template-columns: 35px repeat(7, 1fr);
    }

    .all-day-events {
        grid-template-columns: 35px repeat(7, 1fr);
        min-height: 30px;
    }

    .time-col-header,
    .time-col-label {
        font-size: 0.8em;
        padding: 5px 2px;
    }

    .day-col-header {
        padding: 8px 2px;
    }

    .day-col-header .day-name {
        font-size: 0.8em;
        margin-bottom: 2px;
    }

    .day-col-header .day-num {
        font-size:1.1em;
    }

    .time-slot {
        height: 40px;
        font-size: 0.8em;
        padding: 2px;
    }

    .hour-slot {
        height: 40px;
    }

    .day-all-day-events {
        padding: 2px;
    }

    .event-chip {
        font-size: 0.8em;
        padding: 1px 2px;
    }

    .event-block {
        font-size: 0.8em;
        padding: 2px 3px;
        left: 0.5px;
        right: 0.5px;
    }

    .event-block .event-time {
        font-size: 8px;
        margin-bottom: 1px;
    }

    .event-block .event-title {
        font-size: 0.8em;
        line-height: 1.2;
    }

    /* 사이드바 */
    .sidebar-nav {
        margin-bottom: 10px;
    }

    .sidebar-tabs button {
        font-size:1.1em;
        padding: 6px;
    }

    .sidebar-add-btn a {
        padding: 6px;
        font-size:1.1em;
    }

    .list-item {
        padding: 8px;
    }

    .list-item-title {
        font-size: 0.9em;
    }

    .list-item-date {
        font-size: 10px;
    }

    .list-item-actions {
        flex-direction: column;
        gap: 3px;
    }

    .list-item-actions button {
        padding: 2px 6px;
        font-size: 10px;
        width: 100%;
    }

    .detail-title {
        font-size:1em;
    }

    .detail-meta,
    .detail-content {
        font-size: 0.9em;
    }
}

/* 가로 모드 최적화 (모바일 landscape) */
@media (max-width: 900px) and (orientation: landscape) {
    .week-view {
        flex-direction: row;
    }

    .diary-sidebar {
        width: 250px;
        height: 100vh;
        max-height: none;
    }

    .time-slot,
    .hour-slot {
        height: 35px;
    }

    .event-block {
        font-size: 0.8em;
    }
}

/* ============ 모바일 레이아웃 (768px 이하) ============ */
@media (max-width: 768px) {
    .week-view {
        flex-direction: column;
        height: auto;
        margin: 0;
        gap: 0;
    }

    /* 데스크톱 사이드바 숨김 */
    #desktop-sidebar {
        display: none !important;
    }

    /* 모바일 사이드바 (화면 최하단에서 올라옴) */
    #mobile-diary-sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 70vh;
        z-index: 800;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
        transition: transform 0.3s ease;
        transform: translateY(100%);
        display: flex;
        padding-bottom: 80px; /* 하단 버튼 공간 확보 */
    }

    #mobile-diary-sidebar.mobile-visible {
        transform: translateY(0);
    }

    /* 주간 달력 전체 화면 */
    .diary-week-calendar {
        width: 100%;
        border-radius: 0;
        border: none;
    }

    /* 주간 그리드 컨테이너 하단 여백 (모바일) */
    .week-grid-container {
        padding-bottom: 100px;
    }

    /* 헤더 크기 조정 */
    .week-header {
        grid-template-columns: 40px repeat(7, 1fr);
    }

    .time-col-header {
        width: 40px;
    }

    .day-col-header {
        padding: 8px 2px;
        font-size: 0.9em;
    }

    .day-col-header .day-name {
        font-size: 10px;
    }

    .day-col-header .day-num {
        font-size:1.2em;
    }

    /* 종일 일정 영역 */
    .all-day-events {
        grid-template-columns: 40px repeat(7, 1fr);
        min-height: 30px;
    }

    .time-col-label {
        padding: 5px 2px;
        font-size: 10px;
    }

    .day-all-day-events {
        padding: 2px;
    }

    /* 주간 그리드 */
    .week-grid {
        grid-template-columns: 40px repeat(7, 1fr);
    }

    .time-column {
        width: 40px;
    }

    .time-slot {
        padding: 2px;
        font-size: 10px;
        height: 40px;
    }

    .day-column {
        min-width: 0;
    }

    .hour-slot {
        height: 40px;
    }

    /* 이벤트 블록 크기 조정 */
    .event-block {
        font-size: 0.8em;
        padding: 2px;
        min-height: 25px;
    }

    .event-chip {
        font-size: 0.8em;
        padding: 1px 3px;
    }
}

/* ============ 아주 작은 모바일 (480px 이하) ============ */
@media (max-width: 480px) {
    .week-header {
        grid-template-columns: 35px repeat(7, 1fr);
    }

    .time-col-header {
        width: 35px;
    }

    .day-col-header {
        padding: 5px 1px;
        font-size: 10px;
    }

    .day-col-header .day-name {
        font-size: 0.8em;
    }

    .day-col-header .day-num {
        font-size:1.1em;
    }

    .all-day-events {
        grid-template-columns: 35px repeat(7, 1fr);
    }

    .week-grid {
        grid-template-columns: 35px repeat(7, 1fr);
    }

    .time-column {
        width: 35px;
    }

    .time-slot {
        font-size: 0.8em;
        height: 35px;
    }

    .hour-slot {
        height: 35px;
    }

    .event-block {
        font-size: 8px;
        padding: 1px;
        min-height: 20px;
    }
}
