/**
 * BAAL 아파트 실거래가 - 네이버 부동산 스타일 레이아웃
 * Map-centric layout with overlay search and slide panel
 */

/* ============================================
   CSS Variables
   ============================================ */
:root {
  /* Colors */
  --primary: #d4af37;
  --primary-dark: #b8941f;
  --primary-light: #ffd700;

  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --text-tertiary: #999;

  --gray-50: #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #eeeeee;
  --gray-300: #e0e0e0;
  --gray-600: #757575;

  --border-color: #e5e5e5;
  --error: #ef4444;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Typography */
  --font-sans: 'Noto Sans KR', -apple-system, sans-serif;
  --font-display: 'Playfair Display', serif;

  /* Layout */
  --header-height: 60px;
  --search-bar-height: 70px;
  --panel-width: 400px;

  /* Effects */
  --transition-base: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* ============================================
   Base Styles
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body.map-layout {
  font-family: var(--font-sans);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

/* ============================================
   Fixed Header
   ============================================ */
.header-fixed {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: white;
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.header-content-inline {
  max-width: none;
  height: 100%;
  padding: 0 var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-inline {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  font-size: 0;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.nav-inline {
  display: flex;
  gap: var(--space-md);
  align-items: center;
}

.nav-link {
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: color var(--transition-base);
}

.nav-link:hover {
  color: var(--primary);
}

/* ============================================
   Search Bar Overlay
   ============================================ */
.search-bar-overlay {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  height: var(--search-bar-height);
  background: white;
  border-bottom: 1px solid var(--border-color);
  z-index: 999;
  box-shadow: var(--shadow-sm);
}

.search-bar-container {
  height: 100%;
  padding: 0 var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.address-search-field {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.address-input {
  width: 220px;
  height: 36px;
  padding: 0 var(--space-sm);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-sans);
  transition: all var(--transition-base);
}

.address-input:focus {
  outline: none;
  border-color: var(--primary);
}

.address-input::placeholder {
  color: var(--text-tertiary);
  font-size: 12px;
}

.divider-or {
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 0 var(--space-xs);
}

.search-form-inline {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.form-field {
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-label-inline {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.form-select-inline {
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-sans);
  background: white;
  cursor: pointer;
  transition: border-color var(--transition-base);
  min-width: 90px;
}

.form-select-inline:hover {
  border-color: var(--primary);
}

.form-select-inline:disabled {
  background: var(--gray-100);
  cursor: not-allowed;
}

.btn-search {
  height: 36px;
  padding: 0 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--transition-base);
  white-space: nowrap;
}

.btn-search:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-search:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-reset {
  height: 36px;
  padding: 0 16px;
  background: white;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
}

.btn-reset:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

.button-group {
  display: flex;
  gap: 0;
}

.button-group .btn-search {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.button-group .btn-reset {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: none;
}

.btn-toggle-panel {
  height: 36px;
  width: 36px;
  background: white;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}

.btn-toggle-panel:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-toggle-panel.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ============================================
   Map Fullscreen
   ============================================ */
.map-fullscreen {
  position: fixed;
  top: calc(var(--header-height) + var(--search-bar-height));
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

/* ============================================
   Map Controls Overlay
   ============================================ */
.map-controls-overlay {
  position: fixed;
  bottom: var(--space-lg);
  left: var(--space-lg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.btn-control {
  height: 40px;
  padding: 0 var(--space-lg);
  background: white;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
}

.btn-control:hover {
  background: var(--gray-50);
  box-shadow: var(--shadow-md);
}

/* ============================================
   Right Slide Panel
   ============================================ */
.right-panel {
  position: fixed;
  top: calc(var(--header-height) + var(--search-bar-height));
  right: -400px; /* 처음엔 숨김 */
  width: var(--panel-width);
  height: calc(100vh - var(--header-height) - var(--search-bar-height));
  background: white;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.1);
  z-index: 500;
  transition: right var(--transition-base);
  display: flex;
  flex-direction: column;
  overflow-x: visible; /* X 버튼이 바깥에 보이도록 */
  overflow-y: hidden;
}

.right-panel.show {
  right: 0;
}

/* 패널 토글 버튼 (플로팅) */
.panel-toggle-floating {
  position: fixed;
  top: calc(var(--header-height) + var(--search-bar-height) + 16px);
  right: 8px; /* 패널 닫혔을 때: 화면 우측 */
  width: 44px;
  height: 44px;
  background: var(--primary);
  border: none;
  border-radius: 8px 0 0 8px; /* 왼쪽만 둥글게 */
  font-size: 28px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: -2px 2px 12px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  z-index: 501;
  line-height: 1;
}

.panel-toggle-floating .toggle-icon {
  transition: transform 0.3s ease;
}

/* 패널이 열렸을 때 */
.right-panel.show + .panel-toggle-floating {
  right: calc(var(--panel-width) + 8px); /* 패널 왼쪽 바깥 */
}

/* 패널이 열렸을 때 아이콘 방향 변경 (> 표시) */
.right-panel.show + .panel-toggle-floating .toggle-icon {
  transform: scaleX(1);
}

/* 패널이 닫혔을 때 아이콘 방향 (< 표시) */
.panel-toggle-floating .toggle-icon {
  transform: scaleX(-1);
}

.panel-toggle-floating:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
  box-shadow: -2px 2px 16px rgba(0, 114, 245, 0.4);
}

.tabs-section {
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  background: white;
}

.tabs-container {
  display: flex;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) var(--gray-100);
  scroll-behavior: smooth;
}

.tabs-container::-webkit-scrollbar {
  height: 6px;
}

.tabs-container::-webkit-scrollbar-track {
  background: var(--gray-100);
}

.tabs-container::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 3px;
}

.tabs-container::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
}

.tab-item {
  flex-shrink: 0;
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
}

.tab-item:hover {
  color: var(--text-primary);
  background: var(--gray-50);
}

.tab-item.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.tab-item .tab-close {
  margin-left: 6px;
  font-size: 16px;
  opacity: 0.6;
  transition: opacity var(--transition-base);
}

.tab-item .tab-close:hover {
  opacity: 1;
}

/* 새 탭 생성 알람 애니메이션 */
.tab-item.tab-new-alert {
  animation: tabAlert 1.5s ease-in-out;
}

@keyframes tabAlert {
  0%, 100% {
    box-shadow: none;
  }
  25% {
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.5),
                0 0 12px rgba(255, 59, 48, 0.3);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(255, 59, 48, 0.3),
                0 0 20px rgba(255, 59, 48, 0.2);
  }
  75% {
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.2),
                0 0 12px rgba(255, 59, 48, 0.1);
  }
}

.stats-section-panel {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.stats-grid-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
}

.stat-item {
  text-align: center;
}

.stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: var(--space-xs);
}

.stat-value-small {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}

.panel-controls {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.select-panel {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: var(--font-sans);
  background: white;
  cursor: pointer;
}

.result-list-panel {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
}

/* ============================================
   Result Cards
   ============================================ */
.result-card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  transition: all var(--transition-base);
  cursor: pointer;
}

.result-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.result-card.highlighted {
  border-color: var(--primary);
  background: linear-gradient(to right, rgba(212, 175, 55, 0.05), transparent);
  box-shadow: var(--shadow-md);
  animation: highlight-pulse 0.5s ease-in-out;
}

@keyframes highlight-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.result-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-md);
}

.result-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.result-card-address {
  font-size: 13px;
  color: var(--text-secondary);
}

.result-card-price {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.result-card-body {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
}

.result-card-info {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: var(--space-xs);
}

.result-card-label {
  color: var(--text-tertiary);
  min-width: 50px;
}

.result-card-warning {
  margin-top: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  background: rgba(239, 68, 68, 0.1);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--error);
  font-weight: 600;
  text-align: center;
}

/* ============================================
   Overlays (Loading, Empty, Error)
   ============================================ */
.loading-overlay,
.empty-overlay,
.error-overlay {
  position: fixed;
  top: calc(var(--header-height) + var(--search-bar-height));
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 900;
}

.error-close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--gray-200);
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.error-close-btn:hover {
  background: var(--gray-300);
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.empty-icon-text,
.error-icon-text {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: var(--space-md);
}

.empty-icon-text {
  color: var(--text-tertiary);
}

.error-icon-text {
  color: var(--error);
}

/* ============================================
   OpenLayers Popup
   ============================================ */
.ol-popup {
  position: absolute;
  background-color: white;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-lg);
  padding: 0;
  bottom: 12px;
  left: -50px;
  min-width: 250px;
  z-index: 1000;
}

.ol-popup:after {
  top: 100%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
  border-top-color: white;
  border-width: 10px;
  left: 48px;
  margin-left: -10px;
}

.ol-popup-content {
  padding: var(--space-lg);
}

.ol-popup-closer {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  border-radius: 50%;
  cursor: pointer;
  transition: background var(--transition-base);
  z-index: 1;
}

.ol-popup-closer:hover {
  background: var(--gray-200);
}

.ol-popup-closer:before {
  content: "×";
  font-size: 20px;
  color: var(--text-secondary);
  font-weight: 700;
  line-height: 1;
}

.popup-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.popup-address {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
}

.popup-price {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-md);
}

.popup-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.popup-info > div {
  font-size: 13px;
  color: var(--text-secondary);
}

.popup-show-all {
  width: 100%;
  margin-top: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-base);
}

.popup-show-all:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* ============================================
   Modal
   ============================================ */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: none;
}

.modal.show {
  display: block;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  max-width: 600px;
  margin: 80px auto;
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: var(--space-lg);
  right: var(--space-lg);
  background: none;
  border: none;
  font-size: 32px;
  color: var(--gray-600);
  cursor: pointer;
  transition: color var(--transition-base);
}

.modal-close:hover {
  color: var(--primary);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  margin-bottom: var(--space-xl);
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-body h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
}

.modal-body p {
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
  line-height: 1.8;
}

.modal-footer-text {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border-color);
}

/* ============================================
   Utility Classes
   ============================================ */
.hidden {
  display: none !important;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  :root {
    --panel-width: 100vw;
  }

  .search-bar-overlay {
    height: auto;
  }

  .search-form-inline {
    flex-direction: column;
    align-items: stretch;
    padding: var(--space-md);
  }

  .form-row {
    flex-direction: column;
  }

  .form-select-inline {
    width: 100%;
  }
}
