/* ============================================================
   FarmWorks - 스타일시트 (반응형)
   ============================================================ */

:root {
    --topbar-height: 3rem;
    --side-panel-width: min(360px, 85vw);
    --group-panel-width: min(300px, 80vw);
    --color-primary: #4a90d9;
    --color-primary-hover: #357abd;
    --color-danger: #e74c3c;
    --color-topbar: #2c3e50;
    --color-text: #333;
    --color-label: #888;
    --color-border: #eee;
    --radius: 0.375rem;
    --radius-lg: 0.75rem;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f5f5;
    color: var(--color-text);
    font-size: 100%;
}

.hidden {
    display: none;
}

/* 애니메이션 패널은 transform으로 숨김 */
.side-panel.hidden,
.group-panel.hidden {
    display: block;
}

/* ---- 인증 페이지 ---- */
.auth-container {
    max-width: 25rem;
    margin: 5rem auto;
    padding: 2.5rem;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 0.125rem 0.75rem rgba(0,0,0,0.1);
}

.auth-container h1 {
    text-align: center;
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
}

.auth-container h2 {
    text-align: center;
    font-size: 1.1rem;
    font-weight: normal;
    color: #666;
    margin-bottom: 1.5rem;
}

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

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #444;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(74,144,217,0.15);
}

.form-group input[type="checkbox"] {
    width: auto;
    padding: 0;
    margin: 0;
}

.form-group input[type="radio"] {
    width: auto;
    padding: 0;
    margin: 0;
}

.form-group input[type="color"] {
    width: 40px;
    height: 40px;
    padding: 2px;
    border: 2px solid #ddd;
    border-radius: var(--radius);
    cursor: pointer;
    vertical-align: middle;
}

.inline-edit-row input[type="color"] {
    width: 36px;
    height: 36px;
    padding: 2px;
    border: 2px solid #ddd;
    border-radius: var(--radius);
    cursor: pointer;
    vertical-align: middle;
}

.form-group label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: normal;
    cursor: pointer;
}

.auth-link {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: #666;
}

.auth-link a {
    color: var(--color-primary);
    text-decoration: none;
}

/* ---- 버튼 ---- */
.btn {
    display: inline-block;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: #e0e0e0;
    color: var(--color-text);
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.85rem;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

/* ---- 알림 ---- */
.alert {
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: #fde8e8;
    color: #c0392b;
    border: 1px solid #f5c6cb;
}

.alert-success {
    background: #e8f5e9;
    color: #27ae60;
    border: 1px solid #c3e6cb;
}

/* ---- 상단 바 ---- */
#topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--color-topbar);
    color: white;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    z-index: 1000;
    gap: 0.75rem;
}

.topbar-title {
    font-weight: 700;
    font-size: 1rem;
}

.topbar-user {
    font-size: 0.85rem;
    opacity: 0.8;
}

.btn-logout {
    background: rgba(255,255,255,0.15);
    color: white;
    border-radius: 0.25rem;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.25);
}

/* ---- 지도 ---- */
#map {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    transition: bottom 0.3s ease;
}

#map.map-half {
    bottom: 0;
}

@media (max-width: 480px) {
    #map.map-half {
        bottom: 50vh;
    }
}

/* ---- 필지 툴팁 ---- */
.field-tooltip.leaflet-tooltip {
    background: rgba(255,255,255,0.9) !important;
    border: 1px solid #999 !important;
    border-radius: 4px !important;
    padding: 4px 8px !important;
    font-size: 0.8rem !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15) !important;
}
.field-tooltip.leaflet-tooltip:before {
    border: none !important;
    display: none !important;
}
.gps-name-tooltip.leaflet-tooltip {
    background: rgba(50,50,50,0.85) !important;
    border: none !important;
    border-radius: 0.25rem !important;
    padding: 0.15rem 0.4rem !important;
    font-size: 0.7rem !important;
    color: #fff !important;
    white-space: nowrap !important;
}
.gps-name-tooltip.leaflet-tooltip:before {
    border: none !important;
    display: none !important;
}

/* ---- Leaflet.draw 편집 핸들 제거 (편집 모드만) ---- */
.leaflet-edit-resize .leaflet-editing-icon,
.leaflet-edit-move .leaflet-editing-icon {
    display: none !important;
}
.leaflet-edit-resize,
.leaflet-edit-move {
    display: none !important;
}
/* Leaflet.draw 꼭짓점(vertex) 마커 */
.leaflet-div-icon {
    background: #fff;
    border: 0.125rem solid #3388ff;
    border-radius: 0;
    width: 0.625rem !important;
    height: 0.625rem !important;
    margin-left: -0.3125rem !important;
    margin-top: -0.3125rem !important;
}
.leaflet-draw-guide-dash {
    display: none !important;
}
/* 폴리곤 선택 시 - JS에서 처리 */
.leaflet-interactive:focus {
    outline: none !important;
}
.leaflet-container svg path:focus {
    outline: none !important;
}
.leaflet-container svg:focus {
    outline: none !important;
}
.leaflet-container:focus {
    outline: none !important;
}

/* ---- 드래그 핸들 (데스크톱 숨김) ---- */
.panel-drag-handle {
    display: none;
}

/* ---- 사이드 패널 ---- */
.side-panel {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    width: var(--side-panel-width);
    bottom: 0;
    background: white;
    box-shadow: -2px 0 0.75rem rgba(0,0,0,0.15);
    z-index: 999;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.side-panel.hidden {
    transform: translateX(100%);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    background: white;
}

.panel-header h3 {
    font-size: 1.1rem;
}

#panel-content {
    padding: 1rem;
}

/* 패널 내 섹션 */
.panel-section {
    margin-bottom: 1.25rem;
}

.panel-section h4 {
    font-size: 0.95rem;
    color: #555;
    margin-bottom: 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    white-space: nowrap;
    gap: 0.5rem;
}

.panel-section h4 .btn {
    width: auto;
    flex-shrink: 0;
}

.info-row {
    display: flex;
    align-items: center;
    padding: 0.375rem 0;
    font-size: 0.9rem;
    gap: 0.5rem;
}

.info-row .label {
    color: var(--color-label);
    min-width: 4rem;
    flex-shrink: 0;
}

.info-row .value {
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow-wrap: break-word;
}

.info-row .btn-icon {
    font-size: 1rem;
    padding: 0.125rem 0.25rem;
    color: #999;
    flex-shrink: 0;
}

.info-row .btn-icon:hover {
    color: var(--color-primary);
}

/* 인라인 수정 폼 */
.inline-edit-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
    padding: 0.25rem 0 0.5rem 0;
    width: 100%;
}

.inline-edit-row input[type="text"],
.inline-edit-row select {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.375rem 0.5rem;
    border: 1px solid #ccc;
    border-radius: var(--radius);
    font-size: 0.85rem;
    height: 2rem;
}

.inline-edit-row input[type="color"] {
    width: 2rem;
    height: 2rem;
    padding: 0.125rem;
    border: 1px solid #ccc;
    border-radius: var(--radius);
    flex: 0 0 2rem;
}

.inline-edit-row .btn {
    padding: 0 0.5rem;
    font-size: 0.8rem;
    white-space: nowrap;
    height: 2rem;
    line-height: 2rem;
    flex: 0 0 auto;
    width: auto;
}

/* 작물/일지 카드 */
.card {
    background: #f9f9f9;
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.625rem;
    border-left: 3px solid var(--color-primary);
}

.card-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.card-meta {
    font-size: 0.8rem;
    color: var(--color-label);
}

.card-body {
    font-size: 0.9rem;
    margin-top: 0.375rem;
    color: #555;
}

/* 상태 뱃지 */
.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-growing { background: #e8f5e9; color: #27ae60; }
.badge-planned { background: #e3f2fd; color: #2196f3; }
.badge-harvested { background: #fff3e0; color: #f57c00; }
.badge-active { background: #e8f5e9; color: #27ae60; }
.badge-fallow { background: #f3e5f5; color: #9c27b0; }

/* ---- 모달 ---- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 1.75rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 26rem;
    box-shadow: 0 0.25rem 1.5rem rgba(0,0,0,0.2);
}

.modal-content h3 {
    margin-bottom: 1rem;
}

.modal-actions {
    display: flex;
    gap: 0.625rem;
    margin-top: 1.25rem;
}

.modal-actions .btn {
    flex: 1;
}

/* ---- 그룹 패널 ---- */
.group-panel {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: var(--group-panel-width);
    bottom: 0;
    background: white;
    box-shadow: 2px 0 0.75rem rgba(0,0,0,0.15);
    z-index: 999;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.group-panel.hidden {
    transform: translateX(-100%);
}

.group-item {
    display: flex;
    align-items: center;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--color-border);
    gap: 0.625rem;
}

.group-item:hover {
    background: #f9f9f9;
}

.group-color-dot {
    width: 0.875rem;
    height: 0.875rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.group-name {
    flex: 1;
    font-size: 0.95rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-count {
    font-size: 0.8rem;
    color: #999;
    flex-shrink: 0;
}

.group-visibility {
    cursor: pointer;
    font-size: 1.1rem;
    opacity: 0.6;
    flex-shrink: 0;
}

.group-visibility:hover {
    opacity: 1;
}

.group-actions {
    padding: 0.75rem 1rem;
}

.group-field-item:hover {
    background: #eef4ff;
}

/* ---- 검색 ---- */
#search-container {
    position: relative;
    flex: 0 1 16rem;
}

#search-input {
    width: 100%;
    padding: 0.375rem 0.75rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85rem;
    height: 2rem;
    background: rgba(255,255,255,0.15);
    color: white;
    outline: none;
}

#search-input::placeholder {
    color: rgba(255,255,255,0.5);
}

#search-input:focus {
    background: rgba(255,255,255,0.25);
}

#search-results {
    position: absolute;
    top: 2.25rem;
    left: 0;
    right: 0;
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 0.25rem 1rem rgba(0,0,0,0.2);
    max-height: 20rem;
    overflow-y: auto;
    z-index: 1001;
    color: var(--color-text);
}

#search-results.hidden {
    display: none;
}

.search-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.85rem;
}

.search-item:hover {
    background: #eef4ff;
}

.search-item:last-child {
    border-bottom: none;
}

.search-item-name {
    font-weight: 600;
}

.search-item-meta {
    font-size: 0.75rem;
    color: var(--color-label);
    margin-top: 0.125rem;
}

.search-no-result {
    padding: 0.75rem;
    color: var(--color-label);
    font-size: 0.85rem;
    text-align: center;
}

/* ---- 반응형 ---- */
/* ---- 햄버거 메뉴 ---- */
.topbar-mobile {
    display: none;
}

#hamburger-menu {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    width: 14rem;
    background: white;
    box-shadow: -2px 2px 8px rgba(0,0,0,0.15);
    border-radius: 0 0 0 var(--radius-lg);
    z-index: 999;
    overflow: hidden;
}

@media (max-width: 480px) {
    #hamburger-menu {
        width: 100%;
        left: 0;
        right: 0;
        border-radius: 0;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
}

.hamburger-item {
    display: block;
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    color: #333;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    text-decoration: none;
}

.hamburger-item:hover {
    background: #f5f5f5;
}

.hamburger-user {
    color: #888;
    font-size: 0.8rem;
}

.hamburger-logout {
    color: #c00;
}

@media (max-width: 480px) {
    :root {
        --side-panel-width: 100vw;
        --group-panel-width: 100vw;
        --topbar-height: 2.75rem;
    }

    #topbar {
        gap: 0.375rem;
        padding: 0 0.5rem;
    }

    .topbar-title {
        font-size: 0.85rem;
    }

    .topbar-desktop {
        display: none !important;
    }

    .topbar-mobile {
        display: inline-flex;
    }

    #search-container {
        flex: 1;
        min-width: 0;
    }

    #search-input {
        font-size: 0.8rem;
        padding: 0.25rem 0.5rem;
    }

    /* 햄버거 메뉴 - 전체 너비 */
    #hamburger-menu {
        width: 100%;
        left: 0;
        right: 0;
        border-radius: 0;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }

    /* 사이드 패널 - 하단 절반 */
    .side-panel {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 50vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .side-panel #panel-content {
        flex: 1;
        overflow-y: auto;
    }

    .side-panel.hidden {
        transform: translateY(100%);
    }

    /* 그룹 패널 - 하단 절반 */
    .group-panel {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 50vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .group-panel #group-content {
        flex: 1;
        overflow-y: auto;
    }

    .group-panel.hidden {
        transform: translateY(100%);
    }

    /* 드래그 핸들 */
    .panel-drag-handle {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 12px 0 8px 0;
        cursor: ns-resize;
        touch-action: none;
    }
    .panel-drag-handle::after {
        content: '';
        width: 48px;
        height: 5px;
        background: #bbb;
        border-radius: 3px;
    }

    /* 모달 - 하단에서 올라옴 */
    .modal {
        align-items: flex-end;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        padding: 1.25rem;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 80vh;
        overflow-y: auto;
    }

    /* 검색 결과 */
    #search-results {
        width: 100vw;
        left: 0;
        right: 0;
        position: fixed;
        top: var(--topbar-height);
    }

    .auth-container {
        margin: 1.25rem;
        padding: 1.5rem;
    }

    .info-row .label {
        min-width: 3.5rem;
        font-size: 0.8rem;
    }

    .info-row .value {
        font-size: 0.85rem;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    :root {
        --side-panel-width: min(360px, 90vw);
        --group-panel-width: min(300px, 85vw);
    }

    .auth-container {
        margin: 2rem auto;
        padding: 2rem;
    }
}

@media (min-width: 769px) {
    :root {
        --side-panel-width: 360px;
        --group-panel-width: 300px;
    }
}
