/* ============================
   Holdings tab — KIS style 2-line rows
   ============================ */

.acct-group-title {
  margin: var(--spacing-lg) 0 var(--spacing-sm);
  padding-bottom: var(--spacing-xs);
  font-size: 13px;
  font-weight: 600;
  color: var(--color-muted);
  letter-spacing: 0.02em;
}
.acct-group-title:first-child { margin-top: 0; }

.holdings-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

.holdings-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  white-space: nowrap;
  table-layout: fixed;     /* 컬럼 폭 고정 — 데이터 변화에도 흔들리지 않음 */
  min-width: 880px;        /* 좁아져도 가로 스크롤로 유지 */
}

/* Column widths — fixed */
.holdings-table col.c-drag    { width: 28px; }
.holdings-table col.c-name    { width: 340px; }
.holdings-table col.c-pl      { width: 160px; }
.holdings-table col.c-value   { width: 140px; }
.holdings-table col.c-cost    { width: 140px; }
.holdings-table col.c-price   { width: 140px; }
.holdings-table col.c-actions { width: 82px; }

.holdings-table thead th {
  background: var(--color-surface-soft);
  font-size: 12px;
  font-weight: 500;
  color: var(--color-muted);
  text-align: right;
  padding: 8px var(--spacing-md);
  border-bottom: 1px solid var(--color-hairline);
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  z-index: 1;
  vertical-align: top;
  line-height: 1.3;
}
.holdings-table thead th:first-child { text-align: left; }
.holdings-table thead th.sortable { cursor: pointer; user-select: none; }
.holdings-table thead th.sortable:hover { color: var(--color-text); }
.holdings-table thead th .th-sub {
  display: block;
  font-size: 11px;
  color: var(--color-faint);
  font-weight: 400;
  margin-top: 2px;
}
.holdings-table thead th .sort-ind {
  color: var(--color-primary);
  margin-left: 4px;
  font-size: 10px;
}

/* Sticky first column */
.holdings-table th.col-name,
.holdings-table td.col-name {
  position: sticky;
  left: 0;
  background: var(--color-surface);
  z-index: 2;
}
.holdings-table thead th.col-name { background: var(--color-surface-soft); z-index: 3; }

/* Row body */
.holdings-table tbody td {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-hairline-soft);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
}
.holdings-table tbody td.col-name { text-align: left; }
.holdings-table tbody tr:last-child td { border-bottom: 0; }
.holdings-table tbody tr:hover td { background: var(--color-surface-soft); }
.cell-name-row {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  min-width: 0;
}
.cell-name-text {
  flex: 0 0 220px;     /* 종목명 영역 고정 폭 */
  min-width: 0;
  overflow: hidden;
}
.cell-name-text .cell-name-primary {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-name-spark {
  flex: 0 0 100px;     /* 스파크라인 폭 항상 100px */
}
.cell-name-spark svg { display: block; width: 100%; height: 30px; }
.sparkline { display: block; opacity: 0.85; }
.row-actions { display: flex; align-items: center; gap: 6px; }
.lot-table-wrap {
  max-height: 180px;     /* 헤더 ~30px + 5행 × 30px = 180px */
  overflow-y: auto;
  overflow-x: auto;
}
.lot-table thead th { position: sticky; top: 0; z-index: 1; }

.col-name.has-lots { cursor: pointer; }
.col-name.has-lots .cell-name-primary { text-decoration: underline dotted; text-underline-offset: 3px; }
.lot-detail td { padding: 0; background: var(--color-surface-soft); border-bottom: 1px solid var(--color-hairline); }
.lot-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.lot-table th, .lot-table td { padding: 6px 10px; text-align: right; font-family: var(--font-num); white-space: nowrap; }
.lot-table th { background: var(--color-surface); color: var(--color-muted); font-weight: 500; font-size: 11px; }
.lot-table th:first-child, .lot-table td:first-child { text-align: left; }
.lot-table tr.lot-row:hover td { background: var(--color-surface); }
@media (max-width: 640px) {
  .cell-name-text  { flex: 0 0 160px; }
  .cell-name-spark { flex: 0 0 80px; margin-left: auto; }
  .cell-name-spark svg { height: 26px; }
}
.holdings-table tbody tr:hover td.col-name { background: var(--color-surface-soft); }

/* 2-line cell content */
.cell-primary {
  font-family: var(--font-num);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}
.cell-secondary {
  font-family: var(--font-num);
  font-size: 12px;
  color: var(--color-faint);
  line-height: 1.2;
  margin-top: 2px;
}
/* 수익률에도 ± 색상 — specificity 강화 */
.cell-secondary.pos { color: var(--color-pos); }
.cell-secondary.neg { color: var(--color-neg); }

.cell-name-primary {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  font-family: var(--font-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-name-secondary {
  font-size: 12px;
  color: var(--color-faint);
  font-family: var(--font-num);
  margin-top: 2px;
}

/* Cash row */
.cash-row td {
  background: #f0fdf4;
  font-weight: 500;
}
.cash-row td.col-name { background: #f0fdf4; }
.cash-row .cell-name-primary { color: var(--color-cash); }

/* Subtotal row */
.subtotal-row td {
  background: var(--color-surface-soft);
  font-weight: 600;
  font-size: 13px;
}
.subtotal-row td.col-name { background: var(--color-surface-soft); }

/* PC: inline 버튼 숨김 */
.row-actions-inline { display: none; }

/* Actions column */
.col-actions { text-align: center !important; }
.row-actions {
  display: inline-flex;
  gap: 4px;
  opacity: 0.4;
  transition: opacity 0.1s;
}
tr:hover .row-actions { opacity: 1; }

/* Tick flash */
@keyframes tick-up {
  0%   { background-color: var(--color-pos-tick); }
  100% { background-color: transparent; }
}
@keyframes tick-down {
  0%   { background-color: var(--color-neg-tick); }
  100% { background-color: transparent; }
}
.tick-up   { animation: tick-up   0.9s ease-out; }
.tick-down { animation: tick-down 0.9s ease-out; }

/* ---- Mobile card layout ---- */
@media (max-width: 640px) {
  .holdings-wrap { background: transparent; border: 0; padding: 0; overflow: visible; }
  .holdings-table { min-width: 0; table-layout: auto; }
  .holdings-table colgroup { display: none; }
  .holdings-table > thead { display: none; }
  .holdings-table, .holdings-table > tbody { display: block; }
  .holdings-table > tbody > tr:not(.lot-detail) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm) var(--spacing-md);
    background: var(--color-surface);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
  }
  /* lot-detail 행은 그리드 카드 아닌 표 형태로 유지 + hidden 속성 존중 */
  .holdings-table > tbody > tr.lot-detail[hidden] { display: none !important; }
  .holdings-table > tbody > tr.lot-detail { display: block; margin-bottom: var(--spacing-sm); }
  .holdings-table > tbody > tr.lot-detail > td { display: block; padding: 0; overflow-x: auto; }
  .holdings-table > tbody > tr.lot-detail > td::before { display: none; }
  .lot-table { width: 100%; font-size: 10px; border-collapse: collapse; display: table; }
  .lot-table thead { display: table-header-group !important; }
  .lot-table tbody { display: table-row-group !important; }
  .lot-table tr { display: table-row !important; grid-template-columns: none !important; background: transparent !important; border: 0 !important; padding: 0 !important; margin: 0 !important; }
  .lot-table th, .lot-table td { display: table-cell !important; padding: 4px 5px !important; font-size: 10px; }
  .lot-table th::before, .lot-table td::before { display: none !important; }
  .holdings-table tbody tr:hover td { background: transparent; }
  .holdings-table tbody td {
    display: block;
    border: 0;
    padding: 0;
    text-align: left;
    position: static;
    background: transparent !important;
  }
  .holdings-table tbody td::before {
    content: attr(data-label);
    display: block;
    font-size: 12px;
    color: var(--color-faint);
    margin-bottom: 2px;
  }
  .holdings-table .cell-primary   { font-size: 16px; }
  .holdings-table .cell-secondary { font-size: 13px; }
  .holdings-table .cell-after     { font-size: 13px; }
  .holdings-table tbody td.col-name {
    grid-column: 1 / -1;
    grid-row: 1;
    border-bottom: 1px solid var(--color-hairline-soft);
    padding-bottom: var(--spacing-sm);
    margin-bottom: 0;
  }
  .holdings-table tbody td.col-name::before { display: none; }
  .holdings-table tbody td.col-actions { display: none; }  /* 모바일: 별도 셀 제거 */
  .holdings-table tbody td.col-drag { display: none; }    /* 모바일: 드래그 핸들 제거 */
  .row-actions-inline { display: flex; flex-shrink: 0; gap: 4px; margin-left: auto; opacity: 1; }
  .row-actions { opacity: 1; }
  .cash-row, .subtotal-row { grid-template-columns: 1fr; }
  .cash-row td.col-name, .subtotal-row td.col-name { border-bottom: 0; padding-bottom: 0; }
  /* PC 와 동일한 배경 */
  .holdings-table > tbody > tr.cash-row { background: #f0fdf4; }
  .holdings-table > tbody > tr.cash-row .cell-name-primary { color: var(--color-cash); }
  .holdings-table > tbody > tr.subtotal-row { background: var(--color-surface-soft); }
}

.session-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  border-radius: 999px;
  vertical-align: middle;
  background: var(--color-block, #fef3c7);
  color: #92400e;
}
.session-badge.sess-pre   { background: #dbeafe; color: #1e40af; }
.session-badge.sess-after { background: #fef3c7; color: #92400e; }
.session-badge.sess-day   { background: #dcfce7; color: #166534; }

.cell-after {
  margin-top: 2px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--color-muted);
}
.cell-after.pos { color: var(--color-pos); }
.cell-after.neg { color: var(--color-neg); }

/* 종목 액션 팝오버 */
.holding-action-pop {
  position: absolute;
  z-index: 1000;
  background: var(--color-surface);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  min-width: 120px;
  overflow: hidden;
}
.holding-action-pop.hidden { display: none; }
.hap-btn {
  padding: 11px 16px;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text);
}
.hap-btn:hover { background: var(--color-surface-soft); }
.hap-btn + .hap-btn { border-top: 1px solid var(--color-hairline-soft); }
.hap-sell { color: var(--color-neg); }
.hap-delete { color: var(--color-pos); }

/* ── 드래그 순서 변경 ── */
.col-drag {
  width: 28px;
  padding: 0 !important;
  text-align: center;
}
.drag-handle {
  display: inline-block;
  color: var(--color-faint);
  cursor: grab;
  user-select: none;
  font-size: 14px;
  line-height: 1;
  padding: 4px 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.holdings-table tbody tr[draggable]:hover .drag-handle { opacity: 1; }
.holdings-table.sorted .drag-handle { display: none; }
.holdings-table.sorted tr[draggable] { cursor: default; }

.holdings-table tr.row-dragging { opacity: 0.4; }
.holdings-table tr.drag-over-top td { box-shadow: inset 0 2px 0 var(--color-primary); }
.holdings-table tr.drag-over-bot td { box-shadow: inset 0 -2px 0 var(--color-primary); }
