/* =========================================
   LAYOUT: 대시보드 그리드 & 반응형
   ========================================= */

.view-transition {
  /* 효과 없음 */
}

.grabbing {
  cursor: grabbing !important;
  transition: none !important;
}

.snap-back {
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
}

.card,
.slim-scroll {
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

.order-scroll-area {
  overscroll-behavior-y: none;
  overscroll-behavior-x: contain !important;
  -webkit-overflow-scrolling: touch;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1.5fr 1fr 1.5fr;
  grid-template-areas: "order" "monthly" "chart";
  gap: 2px;
  width: 100%;
  height: calc(100vh - 48px);
  animation: fadeIn 0.6s ease-out;
}

.dashboard-grid.hide-order-panel .panel-order {
  display: none !important;
}

.dashboard-grid.perf-metrics-layout {
  grid-template-areas: "stats" "order" "history";
  grid-template-rows: 1.4fr 1.4fr 1.2fr !important;
}

.dashboard-grid.perf-metrics-layout .panel-order {
  display: flex !important;
  grid-area: order;
}

.dashboard-grid.perf-metrics-layout .panel-stats {
  display: flex !important;
  grid-area: stats;
}

.dashboard-grid.perf-metrics-layout .panel-history {
  display: flex !important;
  grid-area: history;
}

.dashboard-grid.perf-metrics-layout .panel-monthly,
.dashboard-grid.perf-metrics-layout .panel-chart {
  display: none !important;
}

.dashboard-grid.backtest-view-layout {
  grid-template-areas: "stats" "monthly" "chart";
}

.dashboard-grid.backtest-view-layout .panel-stats {
  display: flex !important;
  grid-area: stats;
}

.dashboard-grid.backtest-view-layout .panel-order,
.dashboard-grid.backtest-view-layout .panel-history {
  display: none !important;
}

.dashboard-grid.perf-tab-layout {
  grid-template-columns: 1fr !important;
  grid-template-areas: "stats" "monthly" "monthly-chart" "daily-chart" !important;
  grid-template-rows: 1fr 1fr 1fr 1fr !important;
}

.dashboard-grid.perf-tab-layout .panel-stats {
  display: flex !important;
  grid-area: stats;
  padding: 4px 8px !important;
}

#statsTable td, #statsTable th {
  white-space: nowrap !important;
}

.dashboard-grid.perf-tab-layout .panel-monthly {
  display: flex !important;
  grid-area: monthly;
}

.dashboard-grid.perf-tab-layout .panel-monthly-chart {
  display: flex !important;
  grid-area: monthly-chart;
}

.dashboard-grid.perf-tab-layout .panel-daily-chart {
  display: flex !important;
  grid-area: daily-chart;
}

.dashboard-grid.perf-tab-layout .panel-order,
.dashboard-grid.perf-tab-layout .panel-chart,
.dashboard-grid.perf-tab-layout .panel-history {
  display: none !important;
}

.dashboard-grid.perf-tab-layout #btnPeriodMode {
  display: none !important;
}

/* 성과 탭 패널 overflow 설정 */
.dashboard-grid.perf-tab-layout .panel-monthly,
.dashboard-grid.perf-tab-layout .panel-monthly-chart,
.dashboard-grid.perf-tab-layout .panel-daily-chart {
  overflow: hidden;
}

.dashboard-grid:not(.perf-metrics-layout) .panel-history {
  display: none !important;
}

.dashboard-grid.order-expanded {
  grid-template-areas: "order" !important;
  grid-template-rows: 1fr !important;
}

.dashboard-grid.force-3-col.order-expanded {
  grid-template-columns: 1fr !important;
  grid-template-areas: "order" !important;
  grid-template-rows: 1fr !important;
}

.dashboard-grid.order-expanded .panel-monthly,
.dashboard-grid.order-expanded .panel-chart,
.dashboard-grid.order-expanded .panel-settings {
  display: none !important;
}

.dashboard-grid.price-info-expanded {
  grid-template-areas: "priceinfo" !important;
  grid-template-rows: 1fr !important;
}

.dashboard-grid.force-3-col.price-info-expanded {
  grid-template-columns: 1fr !important;
  grid-template-areas: "priceinfo" !important;
  grid-template-rows: 1fr !important;
}

.dashboard-grid.price-info-expanded .panel-order,
.dashboard-grid.price-info-expanded .panel-monthly,
.dashboard-grid.price-info-expanded .panel-chart,
.dashboard-grid.price-info-expanded .panel-settings,
.dashboard-grid.price-info-expanded .panel-stats,
.dashboard-grid.price-info-expanded .panel-history {
  display: none !important;
}

.dashboard-grid.price-info-expanded .panel-price-info {
  display: flex !important;
  grid-area: priceinfo;
}

.dashboard-grid.analysis-expanded {
  grid-template-areas: "analysis" !important;
  grid-template-rows: 1fr !important;
}

.dashboard-grid.force-3-col.analysis-expanded {
  grid-template-columns: 1fr !important;
  grid-template-areas: "analysis" !important;
  grid-template-rows: 1fr !important;
}

.dashboard-grid.analysis-expanded .panel-order,
.dashboard-grid.analysis-expanded .panel-monthly,
.dashboard-grid.analysis-expanded .panel-monthly-chart,
.dashboard-grid.analysis-expanded .panel-daily-chart,
.dashboard-grid.analysis-expanded .panel-chart,
.dashboard-grid.analysis-expanded .panel-settings,
.dashboard-grid.analysis-expanded .panel-stats,
.dashboard-grid.analysis-expanded .panel-history,
.dashboard-grid.analysis-expanded .panel-price-info {
  display: none !important;
}

.dashboard-grid.analysis-expanded .panel-analysis {
  display: flex !important;
  grid-area: analysis;
}

.panel-analysis {
  flex-direction: column;
  gap: 5px;
  padding: 5px;
  overflow: hidden;
  margin: 0;
  box-sizing: border-box;
  min-height: 0;
}

.panel-analysis.hidden {
  display: none !important;
}

.dashboard-grid.monthly-expanded {
  grid-template-areas: "order" "monthly" "chart";
}

.panel-order {
  grid-area: order;
}

.panel-monthly {
  grid-area: monthly;
}

.panel-settings {
  grid-area: settings;
  overflow-y: auto;
}

.panel-stats {
  grid-area: stats;
  overflow-y: auto;
}

.panel-chart {
  grid-area: chart;
  border: 1px solid rgba(99, 102, 241, 0.2);
  position: relative;
}

#chartBox {
  flex: 1;
  width: 100%;
  min-height: 0;
  position: relative;
}

/* 동적 DOM 전용 스타일 클래스 */
.order-slot-container {
  flex: 1 1 110px;
  display: flex;
  flex-direction: column;
  min-width: 110px;
  display: none;
}

.order-slot-container.has-border-left {
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  padding-left: 4px;
}

.order-scroll-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.view-pane-active {
  display: block;
}

.view-pane-hidden {
  display: none;
}

/* 티어 푸터 기본 스타일 (display:flex로 시작, 나중에 display:none으로 덮어씌움) */
.tier-footer {
  margin-top: auto;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  font-size: calc(var(--app-font-size, 10.5px) - 2px) !important;
  font-weight: 700;
  display: flex;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  container-type: inline-size;
}

.tier-footer div {
  white-space: nowrap;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
}

.tier-footer span {
  color: #fff;
  margin-left: 1px;
}

@container (max-width: 250px) {
  .tier-footer {
    font-size: 10px;
    gap: 1px;
  }
}

@container (max-width: 200px) {
  .tier-footer {
    font-size: 9px;
    letter-spacing: -0.5px;
  }
}

@container (max-width: 160px) {
  .tier-footer {
    font-size: 8px;
    letter-spacing: -1px;
  }
}

.slot-title-sm {
  font-size: 0.8em;
  margin-bottom: 2px;
}

.tier-footer {
  display: none;
  margin-top: auto;
  flex-shrink: 0;
}

.tier-footer-val {
  color: var(--success);
}

.monthly-slot-0 {
  flex: 0;
  min-width: fit-content;
  width: fit-content;
  padding-right: 1px;
  display: none;
}

.monthly-slot-0 .slot-title {
  color: var(--text-muted);
  padding-left: 0;
  padding-right: 0;
}

.period-table-0 {
  border-spacing: 0 1px;
}

.period-table-0 th,
.period-table-0 td {
  padding: 0 !important;
  text-align: center;
  height: 16px;
}

.period-table-0 th {
  white-space: nowrap;
  width: 1%;
  vertical-align: middle;
}

.monthly-slot-item,
.monthly-slot-combined {
  flex: 1;
  min-width: 120px;
  display: none;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  padding-left: 4px;
}

.table-empty-cell {
  padding: 15px;
  color: #94a3b8;
  text-align: center;
}

/* 반응형 미디어쿼리 */
@media (max-width: 500px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1.5fr 1fr 1.5fr;
    grid-template-areas: "order" "monthly" "chart";
  }

  .dashboard-grid.backtest-view-layout {
    grid-template-areas: "stats" "monthly" "chart";
  }

  .dashboard-grid.order-expanded {
    grid-template-areas: "order" !important;
    grid-template-rows: 1fr !important;
  }

  .dashboard-grid.price-info-expanded {
    grid-template-areas: "priceinfo" !important;
    grid-template-rows: 1fr !important;
  }

  .dashboard-grid.hide-order-panel {
    grid-template-areas: "monthly" "monthly" "chart";
  }

  .panel-stats {
    display: none !important;
  }

  .dashboard-grid.perf-metrics-layout {
    grid-template-areas: "stats" "order" "history" !important;
    grid-template-rows: 1.4fr 1.4fr 1.2fr !important;
  }

  .dashboard-grid.perf-metrics-layout .panel-stats,
  .dashboard-grid.backtest-view-layout .panel-stats {
    display: flex !important;
  }

  .dashboard-grid.perf-tab-layout {
    grid-template-columns: 1fr !important;
    grid-template-areas: "stats" "monthly" "monthly-chart" "daily-chart" !important;
    grid-template-rows: 1fr 1fr 1fr 1fr !important;
  }

  .dashboard-grid.perf-tab-layout .panel-stats {
    display: flex !important;
  }

  .dashboard-grid.perf-tab-layout .panel-monthly {
    display: flex !important;
  }

  .dashboard-grid.perf-tab-layout .panel-monthly-chart {
    display: flex !important;
  }

  .dashboard-grid.perf-tab-layout .panel-daily-chart {
    display: flex !important;
  }
}

.dashboard-grid.force-3-col {
  grid-template-columns: minmax(210px, 230px) minmax(300px, 1fr) minmax(210px, 240px) !important;
  grid-template-rows: 1fr 1fr !important;
  grid-template-areas: "order monthly settings" "chart chart chart" !important;
  height: calc(100vh - 16px) !important;
}

.dashboard-grid.force-2-col {
  grid-template-columns: 1fr 1fr !important;
  grid-template-rows: minmax(0, 36fr) minmax(0, 32fr) minmax(0, 32fr) !important;
  grid-template-areas: "order settings" "monthly monthly" "chart chart" !important;
  height: auto !important;
}

.dashboard-grid.perf-metrics-layout.force-3-col,
.dashboard-grid.perf-metrics-layout.force-2-col {
  grid-template-columns: 1fr !important;
  grid-template-areas: "stats" "order" "history" !important;
  grid-template-rows: 1.4fr 1.4fr 1.2fr !important;
  height: calc(100vh - 48px) !important;
}

.dashboard-grid.perf-metrics-layout.force-3-col .panel-stats,
.dashboard-grid.perf-metrics-layout.force-2-col .panel-stats {
  display: flex !important;
  grid-area: stats !important;
}

.dashboard-grid.perf-metrics-layout.force-3-col .panel-order,
.dashboard-grid.perf-metrics-layout.force-2-col .panel-order {
  display: flex !important;
  grid-area: order !important;
}

.dashboard-grid.perf-metrics-layout.force-3-col .panel-history,
.dashboard-grid.perf-metrics-layout.force-2-col .panel-history {
  display: flex !important;
  grid-area: history !important;
}

.dashboard-grid.perf-metrics-layout.force-3-col .panel-monthly,
.dashboard-grid.perf-metrics-layout.force-2-col .panel-monthly,
.dashboard-grid.perf-metrics-layout.force-3-col .panel-chart,
.dashboard-grid.perf-metrics-layout.force-2-col .panel-chart,
.dashboard-grid.perf-metrics-layout.force-3-col .panel-settings,
.dashboard-grid.perf-metrics-layout.force-2-col .panel-settings {
  display: none !important;
}

@media (max-width: 1200px) {
  .panel-monthly.dual-active .hide-on-narrow {
    display: none;
  }
}

@media (max-width: 400px) {
  .period-metrics {
    flex-direction: column;
  }
}

/* 보유현황 보기 상태일 때 전체 보유현황 판이 한 번에 좌우 스크롤되도록 유지 */
.dashboard-grid:not(.perf-metrics-layout).holdings-view-active #dualOrderContainer {
  overflow-x: auto !important;
  overflow-y: hidden !important;
  min-width: 0 !important;
  touch-action: none !important;
  cursor: grab;
}

.dashboard-grid:not(.perf-metrics-layout).holdings-view-active #dualOrderContainer:active {
  cursor: grabbing;
}

.dashboard-grid:not(.perf-metrics-layout).holdings-view-active .order-scroll-area {
  overflow-x: visible !important;
  overflow-y: visible !important;
  touch-action: inherit !important;
}

.dashboard-grid:not(.perf-metrics-layout).holdings-view-active .order-slot-container {
  flex: 0 0 330px !important;
  min-width: 330px !important;
}

.dashboard-grid:not(.perf-metrics-layout).holdings-view-active #combinedOrderSlot {
  flex: 1 1 100% !important;
  min-width: 100% !important;
  width: 100% !important;
  max-width: none !important;
}

.dashboard-grid:not(.perf-metrics-layout).holdings-view-active #combinedHoldingsView {
  width: 100% !important;
}

.dashboard-grid:not(.perf-metrics-layout).holdings-view-active #combinedHoldingsView .data-table {
  width: 100% !important;
}

/* =========================================
   ANALYSIS GRID: 성과 분석 화면 레이아웃
   ========================================= */
.analysis-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 0;
  border: 1px solid rgba(148, 163, 184, 0.58);
  border-radius: 0;
  overflow: hidden;
  background: transparent;
  position: relative;
}

.analysis-grid::before {
  content: none;
}

.analysis-cell {
  min-height: 0;
  background: transparent;
  padding: 4px;
  overflow: hidden;
  position: relative;
  z-index: 1;
  border-right: 1px solid rgba(148, 163, 184, 0.9);
  border-bottom: 1px solid rgba(148, 163, 184, 0.9);
}

.analysis-cell-legend-panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  gap: 2px;
}

.analysis-cell-chart {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.analysis-chart-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 120px;
}

.analysis-chart-wrap canvas {
  max-width: 100%;
  height: 100%;
}

.analysis-grid > .analysis-cell:nth-child(2n) {
  border-right: none;
}

.analysis-grid > .analysis-cell:nth-last-child(-n+2) {
  border-bottom: none;
}

.analysis-section-title {
  color: var(--text-muted);
  font-size: var(--app-font-size, 10.5px);
  font-weight: 800;
  letter-spacing: 0.1px;
  line-height: 1;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 0 4px;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
}

.analysis-legend-list {
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 1px;
  flex: 1;
  width: 100%;
}

.analysis-legend-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 2px 4px;
  box-sizing: border-box;
  color: var(--text-muted);
  font-size: calc(var(--app-font-size, 10.5px) - 1px);
  font-weight: 700;
  line-height: 1;
}

.analysis-legend-models {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.analysis-legend-summary-row {
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  margin-top: 2px;
  padding-top: 3px !important;
}

.analysis-legend-summary-label {
  color: var(--text-muted) !important;
  font-weight: 800;
}

.analysis-legend-summary-value {
  color: var(--text-muted) !important;
  font-weight: 800;
}

.analysis-legend-left {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.analysis-legend-label {
  color: var(--text-muted);
  font-size: var(--app-font-size, 10.5px);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-asset-legend-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  min-width: 0;
  min-height: 14px;
  padding: 1px 4px;
  box-sizing: border-box;
  margin-bottom: 0;
}

.stats-asset-total {
  min-height: 16px;
}

.analysis-legend-value {
  color: var(--text-muted);
  font-size: var(--app-font-size, 10.5px);
  padding: 4px;
  text-align: center;
}
