/* 공급가 관리 모달 — 어드민 디자인 시스템(common.css) 토큰만 사용.
   ⛔ 새 색·새 모서리값을 만들지 않는다. 표는 .ua-table 규격(머리행 sticky, 두 줄마다 옅은 회색).

   함정 — 표를 width:100% + table-layout:fixed 로 두면 열이 접힐 때 남는 폭을 남은 열이
     통째로 먹어 전환 애니메이션이 깨진다(선택 열이 88px→527px로 부풀었다). 그래서
     width:auto 로 두고 열 폭은 JS가 계산해 인라인으로 박으며, 남는 폭은 .sp-filler 가 받는다. */

.sp-overlay {
  position: fixed; inset: 0; z-index: 130;
  background: rgba(26,29,33,.42);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.sp-overlay[hidden] { display: none; }

.sp-modal {
  width: 100%; max-width: 1300px; max-height: 88vh;
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 20px 22px 18px;
  display: flex; flex-direction: column; min-height: 0;
}
.sp-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.sp-head h3 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.01em; color: var(--text); }
.sp-head .sp-chnew { margin-left: auto; }
.sp-x {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  cursor: pointer; font-size: 14px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.sp-x:hover { background: var(--surface-2); color: var(--text); }

.sp-sub { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
.sp-sub b { color: var(--text-2); }
.sp-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; min-height: 34px; }
.sp-bar > * { animation: spBarIn .26s cubic-bezier(.22,.61,.36,1); }
@keyframes spBarIn { from { opacity: 0; transform: translateY(-5px); } }

.sp-code { color: var(--text-2); background: var(--surface-2); font-weight: 600; font-size: 10.5px; }
.sp-back {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; font-weight: 700; font-family: inherit;
  color: var(--brand-ink); background: var(--sage-tint);
  border: 1px solid var(--sage-tint-2); border-radius: var(--radius-pill);
  padding: 7px 8px 7px 14px; cursor: pointer;
}
.sp-back:hover { background: var(--sage-tint-2); }
.sp-back .sp-x {
  width: 20px; height: 20px; border: 0; font-size: 13px;
  background: rgba(62,77,65,.14); color: inherit;
}

.sp-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-card); overflow: hidden;
  flex: 1 1 auto; min-height: 0; display: flex;
}
.sp-scroll { overflow: auto; width: 100%; }

/* width:100% + 모든 열 px 고정 + 맨 끝 filler(폭 미지정)가 남는 폭을 흡수.
   filler 가 없으면 열이 접힐 때 남은 열이 부풀고, filler 만 있고 열 폭이 안 박혀 있으면
   평소에 열이 늘어진다. 둘 다 있어야 한다. */
.sp-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.sp-table thead tr { background: var(--thead-bg); }
.sp-table thead th {
  position: sticky; top: 0; z-index: 2; background: var(--thead-bg); color: var(--text-2);
  font-weight: 700; text-align: left; white-space: nowrap;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
}
.sp-table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; color: var(--text); height: 47px; }
.sp-table tbody tr:nth-child(even) { background: rgba(243,244,246,.5); }
.sp-table tbody tr:last-child td { border-bottom: none; }
.sp-table tbody tr.sp-hasset td { height: 56px; }

/* 제품 열 */
.sp-table th.sp-prod, .sp-table td.sp-prod {
  position: sticky; left: 0; z-index: 1; background: var(--surface);
  width: 186px; max-width: 186px; padding: 10px 10px 10px 12px; font-weight: 600;
  box-shadow: 1px 0 0 var(--line);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sp-table thead th.sp-prod { z-index: 3; background: var(--thead-bg); }
.sp-table tbody tr:nth-child(even) td.sp-prod { background: #F7F8FA; }
.sp-parts { display: block; font-size: 10.5px; color: var(--muted); font-weight: 400; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; }
.sp-setbadge { color: var(--brand); background: var(--sage-tint-2); }

/* 채널 머리 — 누르면 펼쳐진다 */
.sp-table th.sp-chcol { text-align: right; padding: 0; }
.sp-table th.sp-chcol button {
  appearance: none; width: 100%; border: 0; background: transparent; font-family: inherit;
  padding: 9px 8px; text-align: right; cursor: pointer; color: var(--text-2);
  font-size: 11.5px; font-weight: 700; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: background-color .16s ease, color .16s ease;
}
.sp-table th.sp-chcol button:hover { background: var(--sage-tint); color: var(--brand-ink); }
.sp-code2 { display: block; font-size: 9.5px; color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.sp-table th.sp-chcol button:hover .sp-code2 { color: var(--brand); }

/* 날짜 열 — 폭 고정(열이 적을 때 하나가 남는 폭을 다 먹지 않게) */
.sp-table th.sp-datecol { width: 132px; text-align: right; font-variant-numeric: tabular-nums; padding: 9px 10px; }
.sp-tag { display: block; font-size: 10px; font-weight: 700; margin-top: 1px; }
.sp-tag.sp-now { color: var(--pos); }
.sp-tag.sp-future { color: var(--muted); }

/* 남는 폭을 흡수하는 빈 열 */
.sp-table th.sp-filler { background: var(--thead-bg); border-bottom: 1px solid var(--line); padding: 0; }
.sp-table td.sp-filler { padding: 0; border-bottom: 1px solid var(--line); }
.sp-table tbody tr:last-child td.sp-filler { border-bottom: none; }

.sp-table td.sp-cell { text-align: right; font-variant-numeric: tabular-nums; padding: 10px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-table td.sp-none { color: #C7CBD1; }
.sp-table td.sp-val { font-weight: 600; }
.sp-table td.sp-nowcell { background: var(--sage-tint) !important; color: var(--brand-ink); font-weight: 700; }
.sp-table td.sp-future { color: var(--muted); }
.sp-table tbody tr.sp-unset td.sp-prod { color: var(--muted); font-weight: 500; }
.sp-table td.sp-add { color: #C7CBD1; cursor: pointer; font-weight: 700; transition: background-color .15s ease, color .15s ease; }
.sp-table td.sp-add:hover { background: var(--sage-tint); color: var(--brand); }
.sp-table td.sp-acts, .sp-table th.sp-acts { width: 84px; text-align: right; white-space: nowrap; padding-left: 10px; }
.sp-empty { padding: 34px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* 열 접기/펴기 — 같은 표가 변형되는 것처럼 보이게 */
.sp-table th.sp-chcol, .sp-table td.sp-cell,
.sp-table th.sp-datecol, .sp-table td.sp-acts {
  max-width: 320px;
  transition: max-width .34s cubic-bezier(.22,.61,.36,1),
              min-width .34s cubic-bezier(.22,.61,.36,1),
              padding .34s cubic-bezier(.22,.61,.36,1),
              opacity .2s ease;
}
.sp-collapsed {
  max-width: 0 !important; min-width: 0 !important; width: 0 !important;
  padding-left: 0 !important; padding-right: 0 !important;
  opacity: 0 !important; overflow: hidden;
  background: transparent !important; border-bottom-color: transparent !important;
}
.sp-collapsed * { visibility: hidden; }
.sp-keeping { background: var(--sage-tint) !important; transition: background-color .22s ease; }
.sp-keeping button { color: var(--brand-ink) !important; }
@media (prefers-reduced-motion: reduce) {
  .sp-table th.sp-chcol, .sp-table td.sp-cell, .sp-table th.sp-datecol,
  .sp-table td.sp-acts, .sp-keeping, .sp-bar > * { transition: none !important; animation: none !important; }
}

.sp-legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 11.5px; margin: 10px 2px 0; }
.sp-legend b { color: var(--text-2); }
.sp-nowchip { color: var(--pos); background: var(--pos-bg); }

/* 작은 입력 창(값 변경·제품 추가·채널 추가) — 모달 위에 뜬다 */
.sp-sheet {
  position: fixed; inset: 0; z-index: 140;
  background: rgba(26,29,33,.42);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.sp-sheet[hidden] { display: none; }
.sp-sheet-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  padding: 22px 22px 20px;
}
.sp-sheet-title { font-size: 17px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; color: var(--text); }
.sp-field { margin-bottom: 14px; }
.sp-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.sp-field input, .sp-field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-md); font-size: 14px; font-family: inherit;
  color: var(--text); background: var(--surface);
}
.sp-field input:focus, .sp-field select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.sp-field input[inputmode="numeric"] { text-align: right; font-variant-numeric: tabular-nums; }
.sp-hint { font-size: 11.5px; color: var(--muted); font-weight: 400; margin-top: 5px; display: block; }
.sp-sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.sp-sheet-actions button { flex: 1 1 0; }
.sp-sheet-actions .btn-ghost { flex: 0 0 auto; padding-left: 18px; padding-right: 18px; }

/* 모달 전용 버튼(공용 .btn 계열이 이 안에서 안 잡힐 때 대비) */
.sp-overlay .btn-ghost, .sp-sheet .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 600; padding: 8px 14px; font-family: inherit;
  background: var(--surface); color: var(--charcoal); cursor: pointer;
}
.sp-overlay .btn-ghost:hover, .sp-sheet .btn-ghost:hover { background: var(--surface-2); }
.sp-sheet .btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand); border: 1px solid var(--brand); color: #fff;
  border-radius: var(--radius-pill); padding: 11px 16px; font-size: 14px;
  font-weight: 600; font-family: inherit; cursor: pointer;
}
.sp-sheet .btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); }

@media (max-width: 900px) {
  .sp-modal { max-width: 100%; padding: 16px 14px 14px; }
  .sp-table th.sp-prod, .sp-table td.sp-prod { width: 150px; max-width: 150px; }
}
