/* ===== 공용 날짜 필터 스타일 ===== */
/* date-filter fragment에서 사용하는 공용 스타일 */

.filter-section {
  background: linear-gradient(to bottom, #ffffff, #f8f9fa);
  padding: 12px 20px;
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid #e9ecef;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

/* 메인 필터 */
.main-filters {
  margin-bottom: 8px;
}

.filter-label-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  /* Align label text to bottom to match other labels */
  margin-bottom: 2px;
  width: 100%;
  height: 20px;
  /* Explicit height to match */
}

.split-btn {
  padding: 1px 6px;
  background: white;
  border: 1px solid #ddd;
  cursor: pointer;
  font-size: 11px;
  border-radius: 4px;
  color: #666;
  white-space: nowrap;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* transition: all 0.2s ease; */
  transition: all 0.2s ease;
  box-sizing: border-box;
  /* Ensure strict 20px height */
}

.split-btn:hover {
  background: #f0f0f0;
  color: #333;
}

.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

/* 날짜 필터 그룹 (PC/Mobile 공통 Flex) */
.date-range-group {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}


/* 필터 아이템 내부 요소 정렬 */
.filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* account-filter-single 정렬 조정 */
.filter-item.account-filter-single {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-item.account-filter-single .account-input-wrapper {
  margin-top: 0;
  margin-bottom: 0;
  display: flex;
  position: relative;
}

.filter-item.account-filter-single .account-input-wrapper input[type="text"] {
  min-width: 110px;
  width: 110px;
}

/* account-input-wrapper 내부 요소 정렬 */
.filter-item .account-input-wrapper .display-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-item label {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  white-space: nowrap;
  margin-bottom: 2px;
  letter-spacing: 0.3px;
  /* height: 20px; */
  /* line-height: 20px; */
  /* display: block; */
}

/* Label inside row (with button) should be centered without margin shift */
.filter-label-row label {
  margin-bottom: 0;
  position: relative;
  top: 1px;
}

.filter-item input[type="date"],
.filter-item input[type="month"],
.filter-item input[type="text"],
.filter-item input[type="number"] {
  padding: 8px 10px;
  border: 1.5px solid #dee2e6;
  border-radius: 6px;
  font-size: 14px;
  height: 32px;
  box-sizing: border-box;
  background: #ffffff;
  color: #333;
  transition: all 0.2s ease;
  font-family: inherit;
  line-height: 1.2;
}

.filter-item select {
  padding: 6px 10px;
  border: 1.5px solid #dee2e6;
  border-radius: 6px;
  font-size: 14px;
  height: 32px;
  box-sizing: border-box;
  background: #ffffff;
  color: #333;
  transition: all 0.2s ease;
  font-family: inherit;
  line-height: 1.5;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
  cursor: pointer;
}

/* 아이템 입력창 크기 */
.filter-item #itemFilter {
  min-width: 165px;
  width: 165px;
  padding-left: 10px !important;
  /* 아이콘이 없으므로 왼쪽 패딩 조정 */
}

/* account-input-wrapper 내부 input 스타일 통일 */
.filter-item .account-input-wrapper {
  height: 32px;
  display: flex;
  align-items: center;
  position: relative;
  margin-top: -1px;
}

.filter-item .account-input-wrapper input[type="text"] {
  height: 32px;
  box-sizing: border-box;
  padding: 8px 10px;
  padding-left: 28px;
  min-width: 110px;
  width: 110px;
  margin: 0;
  vertical-align: middle;
  border: 1.5px solid #dee2e6;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.filter-item input[type="text"]:hover,
.filter-item input[type="number"]:hover,
.filter-item select:hover,
.filter-item .account-input-wrapper input[type="text"]:hover {
  border-color: #adb5bd;
  background: #fafafa;
}

.filter-item input[type="text"]:focus,
.filter-item input[type="number"]:focus,
.filter-item select:focus,
.filter-item .account-input-wrapper input[type="text"]:focus {
  outline: none;
  border-color: #4a72a8;
  box-shadow: 0 0 0 3px rgba(74, 114, 168, 0.1);
  background: #ffffff;
}

/* 단위 필터는 작게 */
.filter-item #unitFilter {
  min-width: 70px;
  width: 70px;
}

.filter-item input[type="date"],
.filter-item input[type="month"] {
  padding: 8px 8px;
  border: 1.5px solid #e0e0e0;
  border-radius: 6px;
  font-size: 14px;
  min-width: 125px !important;
  width: 125px !important;
  height: 32px;
  box-sizing: border-box;
  background: #ffffff;
  color: #333;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
  line-height: 1.2;
  z-index: 2;
}

/* 날짜 입력 필드 호버 효과 */
.filter-item input[type="date"]:hover,
.filter-item input[type="month"]:hover {
  border-color: #b0b0b0;
  background: #fafafa;
}

/* 날짜 입력 필드 포커스 효과 */
.filter-item input[type="date"]:focus,
.filter-item input[type="month"]:focus {
  outline: none;
  border-color: #4a72a8;
  box-shadow: 0 0 0 3px rgba(74, 114, 168, 0.1);
  background: #ffffff;
}

/* 날짜 선택 아이콘 스타일 */
.filter-item input[type="date"]::-webkit-calendar-picker-indicator,
.filter-item input[type="month"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  padding: 4px;
  margin-left: 4px;
}

.filter-item input[type="date"]::-webkit-calendar-picker-indicator:hover,
.filter-item input[type="month"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

.filter-item input[type="number"] {
  min-width: 100px;
  width: 100px;
}

/* 기간 탐색 버튼 */
.period-nav-btn {
  padding: 0;
  background: #ffffff;
  border: 1.5px solid #dee2e6;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  min-width: 32px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #495057;
  box-sizing: border-box;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  margin-bottom: 0;
  position: relative;
  z-index: 0;
}

.period-nav-btn:hover {
  background: #f8f9fa;
  border-color: #4a72a8;
  color: #4a72a8;
}

.period-nav-btn:active {
  opacity: 0.7;
}

.search-btn {
  padding: 0;
  background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%);
  color: white;
  border: 1.5px solid #5a6268;
  cursor: pointer;
  font-size: 18px;
  border-radius: 6px;
  min-width: 32px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
  box-sizing: border-box;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.search-btn:hover {
  background: linear-gradient(135deg, #5a6268 0%, #495057 100%);
  border-color: #495057;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.search-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(74, 114, 168, 0.2);
}

.detail-btn {
  padding: 8px 12px;
  background: #ffffff;
  border: 1.5px solid #dee2e6;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
  box-sizing: border-box;
  transition: all 0.2s ease;
  color: #495057;
  white-space: nowrap;
  flex-shrink: 0;
}

.detail-btn:hover {
  background: #f8f9fa;
  border-color: #adb5bd;
  color: #212529;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.detail-btn.active {
  background: linear-gradient(135deg, #e9f2ff 0%, #dbe9ff 100%);
  border-color: #7aa7e0;
  color: #285b94;
}

.detail-filters {
  flex: 0 0 100%;
  width: 100%;
  box-sizing: border-box;
}

.detail-inner-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  align-items: flex-end;
}

.detail-inner-row .filter-item.amount-filter-from,
.detail-inner-row .filter-item.amount-filter-to {
  flex: 0 0 auto;
}

.detail-inner-row .filter-item.memo-filter-wrapper {
  flex: 1 1 180px;
  min-width: 180px;
}

.amount-separator {
  height: 32px;
  display: flex;
  align-items: center;
  align-self: flex-end;
  color: #868e96;
}

.view-options-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.view-btn {
  padding: 8px 12px;
  background: #ffffff;
  border: 1.5px solid #dee2e6;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
  box-sizing: border-box;
  transition: all 0.2s ease;
  color: #495057;
  white-space: nowrap;
}

.view-btn:hover {
  background: #f8f9fa;
  border-color: #adb5bd;
  color: #212529;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.view-btn.active {
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  color: white;
  border-color: #007bff;
  box-shadow: 0 2px 6px rgba(0, 123, 255, 0.3);
}

.view-btn.active:hover {
  background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
  border-color: #0056b3;
  box-shadow: 0 4px 8px rgba(0, 123, 255, 0.4);
}

.view-wrapper {
  position: relative;
}

.view-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  background: white;
  border: 1.5px solid #dee2e6;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  min-width: 140px;
  max-height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
}

.view-option {
  padding: 10px 14px;
  background: white;
  border: none;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  border-bottom: 1px solid #f0f0f0;
  transition: all 0.15s ease;
  color: #495057;
}

.view-option:last-child {
  border-bottom: none;
}

.view-option:hover {
  background: #f8f9fa;
  color: #212529;
  padding-left: 18px;
}

.view-option.active {
  background: linear-gradient(90deg, #e3f2fd 0%, #bbdefb 100%);
  color: #1976d2;
  font-weight: 600;
  border-left: 3px solid #1976d2;
}

.view-option.active:hover {
  background: linear-gradient(90deg, #bbdefb 0%, #90caf9 100%);
  padding-left: 18px;
}

.recent-wrapper {
  position: relative;
}

.recent-btn {
  padding: 8px 12px;
  background: #ffffff;
  border: 1.5px solid #dee2e6;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
  box-sizing: border-box;
  transition: all 0.2s ease;
  color: #495057;
  white-space: nowrap;
  flex-shrink: 0;
}

.recent-btn:hover {
  background: #f8f9fa;
  border-color: #adb5bd;
  color: #212529;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.recent-btn.active {
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  color: white;
  border-color: #007bff;
  box-shadow: 0 2px 6px rgba(0, 123, 255, 0.3);
}

.recent-btn.active:hover {
  background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
  border-color: #0056b3;
  box-shadow: 0 4px 8px rgba(0, 123, 255, 0.4);
}

.recent-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  background: white;
  border: 1.5px solid #dee2e6;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  min-width: 140px;
  max-height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
}

.recent-option {
  padding: 10px 14px;
  background: white;
  border: none;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  border-bottom: 1px solid #f0f0f0;
  transition: all 0.15s ease;
  color: #495057;
}

.recent-option:last-child {
  border-bottom: none;
}

.recent-option:hover {
  background: #f8f9fa;
  color: #212529;
  padding-left: 18px;
}

.recent-option.active {
  background: linear-gradient(90deg, #e3f2fd 0%, #bbdefb 100%);
  color: #1976d2;
  font-weight: 600;
  border-left: 3px solid #1976d2;
}

.recent-option.active:hover {
  background: linear-gradient(90deg, #bbdefb 0%, #90caf9 100%);
  padding-left: 18px;
}

.bottom-actions-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.bottom-btn {
  padding: 8px 16px;
  background: #ffffff;
  border: 1.5px solid #dee2e6;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  transition: all 0.2s ease;
  color: #495057;
}

.bottom-btn:hover {
  background: #f8f9fa;
  border-color: #adb5bd;
  color: #212529;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* 반응형 디자인 (Mobile) - 사용자 정의 레이아웃 */
@media (max-width: 768px) {
  .filter-section {
    padding: 12px 10px;
  }

  /*
   * 구조 평탄화 (Flattening) 완료
   * .filter-row 내부에 모든 요소가 포함되었으므로 display: flex로 직접 제어
   */
  .main-filters {
    display: block;
    /* 더 이상 Flex Container일 필요 없음 (내부가 함) */
    margin-bottom: 8px;
  }

  /* === Grid Layout System for Mobile === */
  .filter-row {
    display: grid;
    grid-template-columns: 1fr 40px;
    /* Left content, Right Search Btn */
    gap: 4px;
    /* Reduced gap */
    align-items: stretch;
  }

  /* Reset Order logic as we use Grid order/placement */
  .filter-row>* {
    order: unset !important;
  }

  /* === 1. Date Group (Row 1, Col 1) === */
  .date-range-group {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 4px;
    height: 36px;
    /* Explicit height enforcement */
  }

  /* Date Input 높이와 Button 높이 일치 (36px) 및 수직 중앙 정렬 보정 */
  .period-nav-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    margin: 0 !important;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
  }

  /* 모바일 날짜 입력창 정렬 보정 */
  .date-range-group .filter-item input {
    margin: 0 !important;
    vertical-align: middle;
    height: 36px;
    line-height: normal;
  }

  .date-filter-from label,
  .date-filter-to label {
    display: none;
  }

  .date-filter-from,
  .date-filter-to {
    flex: 1;
    min-width: 0;
  }

  .filter-item input[type="date"],
  .filter-item input[type="month"] {
    min-width: 0 !important;
    width: 100% !important;
    padding: 0 4px;
    text-align: center;
    font-size: 13px;
    height: 36px;
    letter-spacing: -0.5px;
  }

  /* === 2. Period Options (Row 2, Col 1) === */
  .view-options-inline {
    grid-column: 1;
    grid-row: 2;
    order: unset !important;
    width: 100%;
    margin: 0;
    padding-bottom: 4px;
    /* Slight padding for border */
    overflow-x: auto;
    white-space: nowrap;
    display: flex;
    gap: 6px;
    border-bottom: 1px solid #f0f0f0;
  }

  /* (Dropdown styles omitted/kept) */
  .view-menu,
  .recent-menu {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 80% !important;
    max-width: 300px;
    z-index: 10000 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3) !important;
    max-height: 80vh;
    overflow-y: auto;
    margin-top: 0 !important;
    border: 1px solid #ddd;
  }

  .view-options-inline::-webkit-scrollbar {
    display: none;
  }

  /* === 3. Account (Row 3, Col 1) === */
  .account-filter-wrapper {
    grid-column: 1;
    grid-row: 3;
    order: unset !important;
    width: 100%;
  }

  /* Mobile Single Alignment Fix */
  .filter-item.account-filter-single .filter-label-row {
    height: 20px !important;
    min-height: 20px !important;
    line-height: 20px !important;
    margin-bottom: 2px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
  }

  /* Universal Input Reset for Account */
  .account-input-wrapper {
    margin: 0 !important;
    padding: 0 !important;
  }

  .filter-item.account-filter-single .account-input-wrapper input[type="text"] {
    width: 100%;
    height: 32px;
    margin: 0 !important;
    /* Prevent sub-pixel shifts */
  }

  /* 분리 모드: 좌우 50%씩 배치 */
  .account-filter-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .account-filter-split .filter-item {
    width: 100%;
  }

  /* 분리 모드 Input Fix */
  .account-filter-split .account-input-wrapper input[type="text"] {
    width: 100% !important;
    min-width: 0;
    height: 32px;
    margin: 0 !important;
  }

  /* 분리 모드 라벨 정렬 - Single모드와 완전 일치시킴 */
  .account-filter-split .filter-item:first-child label {
    height: 20px !important;
    min-height: 20px !important;
    line-height: 20px !important;
    display: flex !important;
    align-items: center !important;
    margin-bottom: 2px !important;
    /* Removed 2px margin */
    margin-top: 0 !important;
  }

  /* 통합/분리 모드 간 높이 불일치 해결 */
  .filter-label-row,
  .account-filter-split .filter-item label {
    min-height: 20px;
    line-height: 20px;
  }

  .account-filter-split .filter-item .filter-label-row {
    height: 20px;
    margin-bottom: 2px;
  }

  .split-btn {
    height: 20px;
    font-size: 11px;
    padding: 0 8px;
    width: auto !important;
    /* Force auto width */
    max-width: 60px;
    /* Prevent stretching */
    display: inline-flex;
    justify-content: center;
    align-items: center;
  }

  /* === 4. Item (Row 4, Col 1) === */
  .item-filter-wrapper {
    grid-column: 1;
    grid-row: 4;
    order: unset !important;
    width: 100%;
  }

  .filter-item #itemFilter {
    width: 100%;
  }

  /* === 5. Search Button (Row 1-4, Col 2) - Tall Button === */
  .search-btn {
    grid-column: 2;
    grid-row: 1 / span 4;
    order: unset !important;
    width: 100% !important;
    height: auto !important;
    /* Stretch to grid area */
    margin: 0;
    border-radius: 6px;
    background: #6c757d;
    /* Standard Color */
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* === 6. Detail Toggle (Row 5, Col 1-2) - Bottom Center Triangle === */
  .detail-btn {
    grid-column: 1 / -1;
    grid-row: 5;
    order: unset !important;
    width: 100%;
    height: 32px;
    background: #ffffff;
    border: 1px dashed #dee2e6;
    color: #6c757d;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 6px;
    padding: 0 10px;
  }

  .detail-btn::before {
    content: none;
  }

  .detail-btn::after {
    content: "▼";
    font-size: 10px;
    color: inherit;
    line-height: 1;
  }

  .detail-btn.active::after {
    content: "▲";
  }

  .detail-btn:hover {
    background: #f8f9fa;
    color: #495057;
    border-color: #adb5bd;
  }

  .bottom-actions-right {
    display: none;
  }

  /* Detail Filters Content Layout */
  .detail-filters {
    margin-top: 4px;
    /* Reduced from default */
  }

  .detail-filters .detail-inner-row {
    gap: 4px !important;
    /* Reduced vertical gap */
  }

  .detail-filters .detail-inner-row .filter-item.amount-filter-from,
  .detail-filters .detail-inner-row .filter-item.amount-filter-to {
    width: calc(50% - 15px) !important;
    flex: unset !important;
    /* Disable flex-grow if set previously */
  }

  .detail-filters .detail-inner-row .amount-separator {
    width: 10px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .detail-filters .detail-inner-row .filter-item.memo-filter-wrapper {
    width: 100% !important;
    margin-top: 0 !important;
    /* Reduced from 4px to 0 */
    margin-bottom: 0 !important;
    /* Reduce bottom margin */
    flex: unset !important;
  }

  /* Detail Filters Panel Integration */
  .detail-filters {
    grid-column: 1 / -1;
    grid-row: 6;
    order: unset !important;
    margin-top: 4px;
    border-top: 1px dashed #eee;
    padding-top: 8px;
    background: transparent;
    /* Remove background to look integrated */
    border-radius: 0;
  }
}

/* PC Specific Fixes */
@media (min-width: 769px) {

  /* PC Item Label Alignment */
  .filter-label-row {
    height: 20px;
    margin-bottom: 2px;
  }

  .filter-item label {
    line-height: 20px;
    margin-bottom: 2px;
  }

  /* PC Detail integration */
  .detail-filters {
    background: transparent;
    border: none;
    border-top: 1px dashed #e0e0e0;
    /* Internal divider only */
    padding: 8px 0 0 0;
    margin-top: 8px;
  }
}
