/**
 * 모드별 스타일 정의
 * 클릭 모드, 검색 모드, 손 모드별 UI 스타일
 */

/* ============= 모드별 기본 스타일 ============= */

:root {
    --mode-accent-rgb: 147, 197, 253;
}

/* 클릭 모드 */
body.mode-click {
    --primary-color: #424242;
    --mode-indicator-bg: #F5F5F5;
    --mode-accent-rgb: 148, 163, 184;
}

body.mode-click .search-only,
body.mode-click .hand-only {
    display: none !important;
}

body.mode-click .click-only {
    display: block;
}

/* 클릭 모드 - 기본 커서 */
body.mode-click #map,
body.mode-click #map-click,
body.mode-click #map-click * {
    cursor: default !important;
}

/* 클릭 모드에서 기본 커서 */
body.mode-click .map-instance {
    cursor: default !important;
}

body.mode-click .map-instance * {
    cursor: default !important;
}

/* 검색 모드 */
body.mode-search {
    --primary-color: #9B59B6;
    --mode-indicator-bg: #F3E5F5;
    --mode-accent-rgb: 176, 156, 255;
}

body.mode-search .click-only,
body.mode-search .hand-only {
    display: none !important;
}

body.mode-search .search-only {
    display: block;
}

/* 검색 모드 - 기본 커서 */
body.mode-search #map,
body.mode-search #map-search,
body.mode-search #map-search * {
    cursor: default !important;
}

body.mode-search .map-instance {
    cursor: default !important;
}

/* 검색 모드에서도 사이드바 유지 */
body.mode-search .sidebar {
    display: flex;
}

/* 검색 모드에서도 기본 레이아웃 유지 */
body.mode-search .map-container {
    flex: 1;
}

/* 검색 모드에서는 색상 팔레트 비활성화 */
body.mode-search #colorPanelContent {
    opacity: 0.35;
    pointer-events: none;
}

body.mode-search .color-panel-placeholder {
    opacity: 1;
    pointer-events: auto;
}

/* 손 모드 */
body.mode-hand {
    --primary-color: #2196F3;
    --mode-indicator-bg: #E3F2FD;
    --mode-accent-rgb: 120, 194, 204;
}

body.mode-hand .click-only,
body.mode-hand .search-only {
    display: none !important;
}

body.mode-hand .hand-only {
    display: block;
}

/* 손 모드 - 강화된 손 커서 (3-지도 시스템 호환) */
body.mode-hand #map,
body.mode-hand #map-hand,
body.mode-hand #map-hand *,
body.mode-hand .map-instance,
body.mode-hand .map-instance * {
    cursor: default !important;
}

body.mode-hand #map:active,
body.mode-hand #map-hand:active,
body.mode-hand #map-hand:active *,
body.mode-hand .map-instance:active,
body.mode-hand .map-instance:active * {
    cursor: default !important;
}

body.mode-hand .interactive-elements {
    pointer-events: none;
    opacity: 0.5;
}

/* 손 모드에서도 헤더 버튼들은 정상적인 포인터 커서 유지 - 강화 */
body.mode-hand .header .map-type-btn,
body.mode-hand .header .map-type-btn:hover,
body.mode-hand .header .map-type-btn.active,
body.mode-hand .header .header-calendar-btn,
body.mode-hand .header .header-calendar-btn:hover,
body.mode-hand .header .header-backup-btn,
body.mode-hand .header .header-backup-btn:hover,
body.mode-hand .mode-switcher .mode-button,
body.mode-hand .mode-switcher .mode-button:hover {
    cursor: pointer !important;
}

/* 🎯 캘린더 인터랙션 완전 비활성화 - 최종 강화 */
#calendarIframe,
#calendarIframe *,
#calendarModal iframe,
#calendarModal iframe * {
    pointer-events: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    cursor: default !important;
    touch-action: none !important;
    -webkit-touch-callout: none !important;
}

/* JavaScript 오버레이를 위한 iframe 컨테이너 스타일 */
.iframe-interaction-blocker {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 999999 !important;
    background: transparent !important;
    pointer-events: auto !important;
    cursor: default !important;
}

/* 캘린더 모달 전체에서도 과도한 인터랙션 제거 */
#calendarModal .modal-content {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

/* ================= 공통 사이드바 레이아웃 ================= */
:root {
    --sidebar-width-desktop: 360px;
}

@media (min-width: 1025px) {
    .main-container {
        align-items: stretch;
    }

    .sidebar {
        flex: 0 0 var(--sidebar-width-desktop);
        width: var(--sidebar-width-desktop);
        max-width: var(--sidebar-width-desktop);
        padding: 1rem 1.2rem 1.1rem;
        gap: 0.9rem;
        background: transparent;
        overflow: hidden;
        box-sizing: border-box;
    }

    .sidebar > .color-panel,
    .sidebar > .parcel-info {
        background: #ffffff;
        border-radius: 14px;
        border: 1px solid rgba(148, 163, 184, 0.16);
        box-shadow: 0 14px 34px -26px rgba(15, 23, 42, 0.32);
        padding: 0.9rem 1rem;
        width: 100%;
        box-sizing: border-box;
    }

    .color-panel {
        min-height: 220px;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .color-panel-content,
    .color-panel-placeholder {
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    .color-panel-content {
        justify-content: flex-start;
    }

    .color-panel-placeholder {
        justify-content: center;
    }

    .color-panel-placeholder {
        border-radius: 12px;
        border: 1px dashed rgba(148, 163, 184, 0.4);
        background: rgba(241, 245, 249, 0.65);
        padding: 1rem;
        align-items: center;
        text-align: center;
        min-height: auto;
    }

    .color-panel h3,
    .parcel-info h3 {
        font-size: 0.84rem;
        letter-spacing: 0.05em;
        text-transform: uppercase;
        color: rgba(51, 65, 85, 0.8);
        margin-bottom: 0.55rem;
    }

    .color-palette {
        display: grid;
        grid-template-columns: repeat(4, minmax(48px, 1fr));
        gap: 0.5rem;
    }

    .color-item {
        height: 34px;
        border-radius: 8px;
        border: 1px solid rgba(148, 163, 184, 0.45);
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
    }

    .color-item.active {
        border-width: 2px;
        box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
    }

    .current-color {
        display: flex;
        align-items: center;
        gap: 0.7rem;
        font-size: 0.82rem;
        font-weight: 600;
        color: rgba(30, 41, 59, 0.85);
    }

    .current-color #currentColor {
        width: 30px;
        height: 30px;
        border-radius: 8px;
        border: 2px solid rgba(148, 163, 184, 0.45);
        box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.9);
    }

    .color-stats {
        font-size: 0.8rem;
        color: rgba(71, 85, 105, 0.75);
        font-weight: 500;
    }

    .parcel-info form {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.6rem 0.5rem;
    }

    .parcel-info .form-group {
        margin-bottom: 0;
        gap: 0.35rem;
    }

    .parcel-info .form-group-wide {
        grid-column: 1 / -1;
    }

    .parcel-info .form-group label {
        font-size: 0.78rem;
        font-weight: 600;
        color: rgba(51, 65, 85, 0.85);
    }

    .parcel-info .form-group input,
    .parcel-info .form-group textarea {
        width: 100%;
        padding: 0.5rem 0.68rem;
        border-radius: 9px;
        border: 1px solid rgba(148, 163, 184, 0.4);
        font-size: 0.86rem;
        background: rgba(255, 255, 255, 0.98);
        box-shadow: inset 0 1px 2px rgba(148, 163, 184, 0.14);
        transition: border-color 0.2s ease, box-shadow 0.2s ease;
        box-sizing: border-box;
    }

    .parcel-info .form-group input:focus,
    .parcel-info .form-group textarea:focus {
        border-color: rgba(59, 130, 246, 0.55);
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
    }

    .parcel-info .form-actions {
        margin-top: 0.2rem;
        padding-top: 0.6rem;
        border-top: 1px solid rgba(148, 163, 184, 0.22);
    }

    .parcel-info .form-actions-wide {
        grid-column: 1 / -1;
    }

    .parcel-info .form-actions-primary {
        display: flex;
        gap: 0.55rem;
        flex-wrap: nowrap;
    }

    .parcel-info .form-actions-primary button {
        flex: 1 1 auto;
        min-width: 0;
        padding: 0.58rem 0.68rem;
        border-radius: 10px;
        font-size: 0.84rem;
        border: 1px solid rgba(148, 163, 184, 0.35);
        background: linear-gradient(135deg, rgba(248, 250, 252, 0.96), rgba(237, 242, 247, 0.94));
        box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
    }

    .parcel-info .form-actions-primary button:hover {
        transform: translateY(-1px);
        border-color: rgba(37, 99, 235, 0.35);
    }
}

/* 캘린더 iframe 호버 효과 완전 제거 */
#calendarIframe:hover,
#calendarIframe:hover *,
#calendarModal iframe:hover,
#calendarModal iframe:hover * {
    pointer-events: none !important;
    cursor: default !important;
}

/* 캘린더 iframe 내부 모든 버튼과 링크 비활성화 */
#calendarIframe button,
#calendarIframe a,
#calendarIframe [role="button"],
#calendarModal iframe button,
#calendarModal iframe a,
#calendarModal iframe [role="button"] {
    pointer-events: none !important;
    cursor: default !important;
    user-select: none !important;
}

/* 캘린더 최상위 컨테이너에서 모든 이벤트 차단 */
#calendarModal {
    user-select: none !important;
}

#calendarModal * {
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    -khtml-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
}

/* 손 모드에서 헤더 전체 포인터 커서 강제 적용 */
body.mode-hand .header {
    cursor: pointer !important;
}

body.mode-hand .header * {
    cursor: pointer !important;
}

/* 지도 영역은 여전히 grab 커서 */
body.mode-hand #map,
body.mode-hand #map * {
    cursor: grab !important;
}

body.mode-hand #map:active,
body.mode-hand #map:active * {
    cursor: grabbing !important;
}

/* 손 모드에서 거리뷰(파노라마)도 손 커서 유지 */
body.mode-hand #pano {
    cursor: grab !important;
}

body.mode-hand #pano:active {
    cursor: grabbing !important;
}

body.mode-hand #pano * {
    cursor: grab !important;
}

/* ============= 색상 팔레트 스타일 ============= */

.color-palette-container {
    /* 사이드바 내부에 위치하도록 변경 */
    background: white;
    border-radius: 8px;
    padding: 10px;
    margin: 10px 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.color-button {
    width: 40px;
    height: 40px;
    border: 3px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    outline: none;
}

.color-button:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.color-button.selected {
    border-color: #333;
    box-shadow: 0 0 0 2px white, 0 0 0 4px #333;
}

.color-button .usage-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #333;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
}

.color-reset-button {
    width: 40px;
    height: 40px;
    border: 2px dashed #999;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.3s ease;
    outline: none;
}

.color-reset-button:hover {
    background: #f5f5f5;
    transform: rotate(180deg);
}

/* ============= 모드 전환 버튼 스타일 ============= */

.mode-switcher {
    position: fixed;
    top: 10px;
    right: 20px;
    background: white;
    border-radius: 12px;
    padding: 5px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 5px;
    z-index: 1001;
}

.mode-button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: #f0f0f0;
    color: #333;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
}

.mode-button:hover {
    background: #e0e0e0;
}

.mode-button.active {
    background: var(--primary-color);
    color: white;
}

/* 버튼 텍스트에 포함된 이모지를 그대로 사용한다. */

/* ============= 모드 인디케이터 ============= */

.mode-indicator {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--mode-indicator-bg);
    color: var(--primary-color);
    padding: 8px 24px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: all 0.3s ease;
}

/* ============= 검색 결과 스타일 ============= */

.search-results-container {
    position: fixed;
    left: 20px;
    top: 100px;
    bottom: 20px;
    width: 300px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 999;
}

.search-results-header {
    padding: 15px;
    background: #9B59B6;
    color: white;
    font-weight: bold;
}

.search-results-body {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.search-result-item {
    padding: 12px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: #f5f5f5;
}

.search-result-item .result-name {
    font-weight: bold;
    color: #333;
    margin-bottom: 4px;
}

.search-result-item .result-owner {
    font-size: 12px;
    color: #666;
}

.search-result-item .result-address {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
}

.no-results {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

/* ============= 검색 입력 스타일 ============= */

.search-input-container {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    max-width: calc(100vw - 40px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    padding: 8px 12px;
    z-index: 1000;
}

body.mode-search .search-input-container {
    display: flex;
}

body:not(.mode-search) .search-input-container {
    display: none;
}

.search-input-container input {
    flex: 1;
    border: none;
    outline: none;
    padding: 8px;
    font-size: 14px;
}

.search-input-container button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: #9B59B6;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.search-input-container button:hover {
    background: #8E44AD;
}

#clearSearchButton {
    background: #e74c3c;
    margin-left: 8px;
}

#clearSearchButton:hover {
    background: #c0392b;
}

/* ============= 모드 전환 애니메이션 ============= */

@keyframes modeSwitch {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

body[class*="mode-"] .mode-indicator {
    animation: modeSwitch 0.3s ease-out;
}

/* ============= 반응형 디자인 ============= */

@media (max-width: 768px) {
    .color-palette-container {
        top: auto;
        bottom: 20px;
        right: 10px;
        flex-direction: row;
    }

    .mode-switcher {
        top: auto;
        bottom: 80px;
        right: 10px;
    }

    .search-results-container {
        left: 10px;
        right: 10px;
        width: auto;
        height: 200px;
        top: auto;
        bottom: 140px;
    }

    .search-input-container {
        left: 50%;
        transform: translateX(-50%);
        top: 60px;
        width: calc(100vw - 20px);
    }
}

/* ============= 다크 모드 지원 ============= */

@media (prefers-color-scheme: dark) {
    .color-palette-container,
    .mode-switcher,
    .search-results-container,
    .search-input-container {
        background: #2c3e50;
        color: #ecf0f1;
    }

    .color-button {
        border-color: #34495e;
    }

    .color-button.selected {
        border-color: #ecf0f1;
        box-shadow: 0 0 0 2px #2c3e50, 0 0 0 4px #ecf0f1;
    }

    .mode-button {
        background: #34495e;
        color: #ecf0f1;
    }

    .mode-button:hover {
        background: #4a5f7e;
    }

    .search-result-item:hover {
        background: #34495e;
    }

    .search-result-item .result-name {
        color: #ecf0f1;
    }
}

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

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
