/* ==========================================================================
   조작 요소 — 버튼 · 입력 · 표 · 모달 · 토스트

   크기는 전부 tokens.css 에서 옵니다. 여기에 날 px 를 쓰지 않습니다.
   그래야 어느 화면에서 쓰든 같은 크기로 보입니다.
   ========================================================================== */

/* ------------------------------------------------------------------ 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-3);
  height: var(--ctl-h); padding: 0 var(--ctl-px);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: var(--fs-md); font-weight: var(--fw-mid); white-space: nowrap;
  cursor: pointer; transition: border-color .12s, background .12s;
}
.btn:hover:not(:disabled) { border-color: var(--text-3); background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: var(--icon-sm); height: var(--icon-sm); flex: 0 0 var(--icon-sm); }

.btn--primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  font-weight: var(--fw-bold);
}
.btn--primary:hover:not(:disabled) {
  filter: brightness(1.07); border-color: var(--accent); background: var(--accent);
}

.btn--danger { color: var(--danger); }
.btn--danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-bg); }

.btn--ghost { background: none; border-color: transparent; color: var(--text-2); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); border-color: transparent; }

.btn--ghostdanger { color: var(--text-3); border-color: transparent; background: none; }
.btn--ghostdanger:hover:not(:disabled) {
  color: var(--danger); background: var(--danger-bg); border-color: transparent;
}

.btn--sm { height: var(--ctl-h-sm); padding: 0 var(--ctl-px-sm); font-size: var(--fs-sm); }
.btn--block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--ctl-h); height: var(--ctl-h); padding: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: var(--icon); height: var(--icon); }
.icon-btn--ghost { background: none; border-color: transparent; }

.link-btn {
  background: none; border: 0; padding: 0;
  color: var(--accent); font-size: inherit; cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

/* -------------------------------------------------------------- 입력 요소 */
.formrow { display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; }
.formrow__label {
  font-size: var(--fs-sm); font-weight: var(--fw-mid); color: var(--text-2);
}
.formrow__hint { font-size: var(--fs-xs); color: var(--text-3); line-height: var(--lh-body); }
.field__label { font-size: var(--fs-sm); font-weight: var(--fw-mid); color: var(--text-2); }

.input,
.select {
  width: 100%; height: var(--ctl-h); padding: 0 var(--sp-4);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: var(--fs-md);
}
/* background 는 단축속성이라 background-image 까지 초기화합니다.
   그러면 controls.css 가 그린 셀렉트의 드롭다운 화살표가 포커스 순간 사라집니다.
   색만 바꿉니다. */
.input:focus, .select:focus {
  background-color: var(--surface); border-color: var(--accent); outline: none;
}
.input--area {
  height: auto; min-height: calc(var(--ctl-h) * 2);
  padding: var(--sp-4); resize: vertical; line-height: var(--lh-body);
}
.input--file { padding: var(--sp-2) var(--sp-4); height: auto; }
/* 사용자가 실제로 건드린 뒤에만 오류로 표시합니다 (:invalid 는 빈 필수칸도 잡습니다) */
.input:user-invalid { border-color: var(--danger); }

.select--full { width: 100%; max-width: none; }

.readonly {
  height: var(--ctl-h); display: flex; align-items: center; padding: 0 var(--sp-4);
  background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: var(--radius); color: var(--text-2); font-size: var(--fs-md);
}

.formgrid { display: grid; gap: var(--sp-5); }
.formgrid--2 { grid-template-columns: 1fr 1fr; }
.formgrid--3 { grid-template-columns: repeat(3, 1fr); }

.checkgroup { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-6); }

/* 모달 맨 위의 한 줄 안내. 스타일이 없어서 본문과 구분이 안 됐습니다 —
   자금 담당자 지정 · 롤플레이 고르기 · 근무표 휴무 충돌 · 예외 네 곳입니다. */
.formnote {
  margin: 0 0 var(--sp-4);
  color: var(--text-3);
  font-size: var(--fs-sm); line-height: var(--lh-body);
}

/* 사람을 골라 체크하는 목록 — 한 줄에 하나씩, 길어지면 스스로 스크롤합니다.
   지점 인원이 스무 명이 넘으면 모달이 화면 밖으로 나갑니다. */
.checklist {
  display: flex; flex-direction: column;
  max-height: 44vh; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.checklist .checkbox {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.checklist .checkbox:last-child { border-bottom: 0; }
.checklist .checkbox:hover { background: var(--surface-2); }
.checkbox {
  display: inline-flex; align-items: center; gap: var(--sp-3);
  font-size: var(--fs-sm); color: var(--text); cursor: pointer; min-width: 0;
}
.checkbox input {
  width: var(--icon-sm); height: var(--icon-sm); flex: 0 0 var(--icon-sm);
  accent-color: var(--accent); cursor: pointer;
}
.checkbox--sub { color: var(--text-3); }

.details {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
}
.details__summary {
  padding: var(--sp-4) var(--sp-5);
  font-size: var(--fs-sm); color: var(--text-2);
  cursor: pointer; list-style: none;
}
.details__summary::before { content: '▸ '; color: var(--text-3); }
.details[open] .details__summary::before { content: '▾ '; }
.details__body {
  padding: 0 var(--sp-5) var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-4);
}

.capsrow { display: flex; align-items: center; gap: var(--sp-5); flex-wrap: wrap; }
.capsrow__role {
  font-size: var(--fs-sm); font-weight: var(--fw-mid); color: var(--text-2);
  flex: 0 0 96px; min-width: 0;
}

.grants {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--sp-5); background: var(--surface-2);
  display: flex; flex-direction: column; gap: var(--sp-3);
}
.grants__head { font-size: var(--fs-sm); font-weight: var(--fw-bold); }
.grantrow {
  display: flex; align-items: center; gap: var(--sp-6);
  padding: var(--sp-2) 0; border-top: 1px solid var(--border-2); min-width: 0;
}
.grantrow:first-of-type { border-top: 0; }
.grantrow .checkbox:first-child { flex: 1 1 auto; min-width: 0; }

.idcard {
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding: var(--sp-5); margin-bottom: var(--sp-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: var(--fs-sm);
}
.idcard__row { display: flex; justify-content: space-between; gap: var(--sp-5); }
.idcard__row span { color: var(--text-3); }

/* ---------------------------------------------------------------- 모달 */
body.is-modal-open { overflow: hidden; }

.modal { position: fixed; inset: 0; z-index: var(--z-overlay); }
.modal__backdrop { position: absolute; inset: 0; background: rgba(16, 20, 26, .55); }
.modal__panel {
  position: relative;
  width: min(var(--modal-w), calc(100vw - var(--sp-8)));
  max-height: calc(100vh - var(--sp-8) * 2);
  margin: var(--sp-8) auto;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-l);
  box-shadow: var(--shadow-xl);
}
/* 표가 들어가는 창은 넓어야 합니다.
   ui.js 가 opts.wide 일 때 --wide 를 붙이는데 정의가 없어 여태 아무 효과가 없었습니다. */
.modal__panel--wide { width: min(var(--modal-w-wide), calc(100vw - var(--sp-8))); }

.modal__head {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--border);
}
.modal__title {
  font-size: var(--fs-lg); font-weight: var(--fw-bold); flex: 1 1 auto; min-width: 0;
}
.modal__body {
  padding: var(--sp-6); overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--sp-5);
}
.modal__foot {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6); border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-l) var(--radius-l);
}
.modal__msg {
  flex: 1 1 auto; min-width: 0; font-size: var(--fs-sm); color: var(--text-3);
  overflow-wrap: break-word;
}
.modal__msg--error { color: var(--danger); }

/* -------------------------------------------------------------- 토스트 */
.toast {
  position: fixed; left: 50%; bottom: var(--sp-7); z-index: var(--z-toast);
  transform: translate(-50%, var(--sp-4));
  max-width: min(520px, calc(100vw - var(--sp-8)));
  padding: var(--sp-4) var(--sp-6);
  background: var(--text); color: var(--surface);
  border-radius: var(--radius);
  font-size: var(--fs-md); box-shadow: var(--shadow-h);
  opacity: 0; visibility: hidden;
  transition: opacity .15s, transform .15s, visibility .15s;
}
.toast.is-visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.toast--error { background: var(--danger); color: #fff; }

/* -------------------------------------------------------------- 신원 칩 */
.identity {
  display: flex; flex-direction: column; align-items: flex-start;
  height: var(--ctl-h); padding: 0 var(--sp-4); max-width: 190px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  justify-content: center; min-width: 0;
}
.identity:hover { border-color: var(--text-3); }
.identity__name {
  font-size: var(--fs-sm); font-weight: var(--fw-bold); line-height: 1.15;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.identity__meta {
  font-size: var(--fs-xs); color: var(--text-3); line-height: 1.2;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------------------------------------------------------------- 표
   표는 사이트에 하나뿐입니다. 줄 높이도 머리줄도 어느 화면에서나 같습니다. */
.tablewrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
}

/* 머리줄이 진짜로 붙게 하려면 상자에 높이 제한이 있어야 합니다.

   .tablewrap 은 가로 스크롤 상자입니다. 그러면 세로도 스크롤 상자로 계산되는데,
   높이 제한이 없어 세로 스크롤이 아예 생기지 않습니다 —
   붙을 자리가 없으니 머리줄 고정이 하는 일이 없었습니다.

   화면 높이에서 상단바·페이지 머리·여백을 뺀 만큼으로 제한하면
   목록이 길 때 상자 안에서 스크롤되고 머리줄이 위에 붙습니다.
   행이 적으면 제한에 닿지 않으므로 평소에는 아무 차이가 없습니다. */
.tablewrap { max-height: calc(100vh - var(--top-h) - 220px); overflow-y: auto; }

/* 표가 패널 안에 있으면 테두리가 두 겹이 되고, 패널 여백만큼 표가 좁아집니다.
   안쪽 테두리를 지우고 패널 모서리까지 채워 좌우 --card-p 두 번을 되찾습니다. */
.panel > .tablewrap {
  margin-left: calc(var(--card-p) * -1);
  margin-right: calc(var(--card-p) * -1);
  border-left: 0; border-right: 0; border-radius: 0;
  background: none;
}
.panel > .tablewrap:first-child {
  margin-top: calc(var(--card-p) * -1);
  border-top: 0;
}
.panel > .tablewrap:last-child {
  margin-bottom: calc(var(--card-p) * -1);
  border-bottom: 0;
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.table th {
  position: sticky; top: 0; z-index: var(--z-thead);
  height: var(--th-h); padding: 0 var(--row-px);
  text-align: left; white-space: nowrap;
  background: var(--surface-2); color: var(--text-3);
  font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: .03em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.table td {
  height: var(--row-h); padding: var(--sp-3) var(--row-px);
  border-top: 1px solid var(--border-2);
  vertical-align: middle; min-width: 0;
}
.table tbody tr:hover { background: var(--surface-2); }
.table tr.row--off { opacity: .55; }
.table tbody tr.is-selected { background: var(--accent-bg); }

.cellmain { font-weight: var(--fw-mid); color: var(--text); }
.cellsub {
  font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--sp-1);
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cellurl { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--accent); }
.cellurl:hover { text-decoration: underline; }
.cellurl svg { width: 11px; height: 11px; opacity: .7; }

.table__actions { white-space: nowrap; text-align: right; }
.table__actions .btn + .btn { margin-left: var(--sp-1); }
/* 표 안의 작은 버튼은 여백을 줄여 열 폭을 아낍니다 */
.table__actions .btn--sm { padding: 0 var(--sp-3); }

/* 열 폭 — 표마다 제각각이 되지 않게 정해 둔 다섯 가지만 씁니다 */
.col--xs { width: 64px; }
.col--sm { width: 110px; }
.col--md { width: 160px; }
.col--lg { width: 220px; }
.col--act { width: 1%; }

.nowrap { white-space: nowrap; }
.muted { color: var(--text-3); }

.pill {
  display: inline-block; padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-s);
  background: var(--surface-2); border: 1px solid var(--border-2);
  font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap;
}
.pill--ok   { color: var(--ok);     background: var(--ok-bg);     border-color: transparent; }
.pill--bad  { color: var(--danger); background: var(--danger-bg); border-color: transparent; }
.pill--warn { color: var(--warn);   background: var(--warn-bg);   border-color: transparent; }
.pill--muted { color: var(--text-3); border-style: dashed; }

/* ---------------------------------------------------------------- 분류 */
.taxgrid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--sp-6);
}
/* 분류 칸은 좁으므로 제목을 한 단계 작게 씁니다 */
.taxcol .sectionhead__title { font-size: var(--fs-md); }

.taxcol {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-l); overflow: hidden;
}
.taxlist { list-style: none; margin: 0; padding: 0; }
.taxitem {
  display: flex; align-items: center; gap: var(--sp-4);
  min-height: var(--row-h); padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border-2); min-width: 0;
}
.taxitem:first-child { border-top: 0; }
.taxitem__label {
  flex: 1 1 auto; min-width: 0; font-size: var(--fs-md);
  display: flex; flex-direction: column;
}
.taxitem__id { font-size: var(--fs-xs); color: var(--text-3); }
.taxitem__use { font-size: var(--fs-xs); color: var(--text-3); flex: 0 0 auto; }

/* ----------------------------------------------------------- 좁은 화면 */
@media (max-width: 860px) {
  .formgrid--2, .formgrid--3 { grid-template-columns: 1fr; }
  .modal__panel { margin: var(--sp-5) auto; max-height: calc(100vh - var(--sp-7)); }
}

/* --------------------------------------------------------- 회사 이메일 입력
   앞부분만 적고 도메인은 화면이 붙입니다. 손으로 칠 일이 없으니
   오타로 다른 도메인이 들어갈 여지가 없습니다. */
.mailinput {
  display: flex; align-items: stretch;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); overflow: hidden;
}
.mailinput:focus-within { border-color: var(--accent); background: var(--surface); }
.mailinput .input {
  border: 0; border-radius: 0; background: none; flex: 1 1 auto; min-width: 0;
}
.mailinput .input:focus { background: none; }
.mailinput__at {
  display: flex; align-items: center; padding: 0 var(--sp-4);
  background: var(--surface-3); color: var(--text-2);
  font-size: var(--fs-md); white-space: nowrap;
  border-left: 1px solid var(--border);
}

/* ── 키 표시 ──
   단축키 안내에서 "이 키를 누르세요" 를 눈에 띄게 합니다. */
.kbd {
  display: inline-block;
  min-width: var(--ctl-h-sm);
  padding: 0 var(--sp-3);
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-sm);
  line-height: calc(var(--ctl-h-sm) - 2px);
  text-align: center;
  white-space: nowrap;
}

/* 줄만 나누고 테두리는 없는 표 — 안내용 */
.table--plain th,
.table--plain td { border: 0; padding: var(--sp-2) var(--sp-3); }

/* 임시 비밀번호 — 눈으로 읽고 그대로 옮겨 적을 수 있어야 합니다 */
.temppw {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.temppw code {
  flex: 1 1 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--fs-lg); letter-spacing: .08em; color: var(--text);
}

/* 비어 있는 목록에서 다음 행동을 알려 주는 자리 */
.empty__act { margin-top: var(--sp-4); }

/* ── 작업 칸은 오른쪽에 붙여 둡니다 ──
   표가 화면보다 넓으면 맨 오른쪽 "작업" 칸이 먼저 잘립니다.
   그런데 사람이 그 표를 연 이유가 대개 그 버튼입니다 —
   가로 스크롤을 찾아 밀어야 닿는다면 안 보이는 것과 같습니다.

   연락처 표에서 실제로 그랬습니다: 1280px 에서 913px 짜리 표가 854px 칸에
   들어가, "복사" 버튼이 59px 만큼 밖에 있었습니다.

   근무표의 이름 칸이 왼쪽에 붙는 것과 같은 방식입니다. */
.table th.table__actions,
.table td.table__actions {
  position: sticky; right: 0; z-index: 1;
  background: var(--surface);
  box-shadow: -1px 0 0 var(--border-2);
}
.table th.table__actions { z-index: var(--z-thead); background: var(--surface-2); }
/* 줄에 색이 있으면 붙은 칸도 같은 색이어야 이어져 보입니다 */
.table tbody tr:hover td.table__actions { background: var(--surface-2); }
.table tr.row--off td.table__actions { background: var(--surface); }
