:root {
  --bg: #12161c;
  --bg-raised: #171c24;
  --bg-row: #151a21;
  --bg-row-alt: #131720;
  --line: #262e39;
  --line-soft: #1e252f;
  --text: #e6e9ee;
  --text-dim: #8b95a5;
  --text-faint: #5a6577;
  --accent: #4fb3a8;
  --accent-soft: rgba(79, 179, 168, 0.16);
  --amber: #d9a441;
  --danger: #d9634f;
  --mono: "SFMono-Regular", ui-monospace, "JetBrains Mono", Consolas, monospace;
  --sans: "Pretendard", -apple-system, "Malgun Gothic", sans-serif;

  --lvl1: #4fb3a8;
  --lvl2: #4a8fbf;
  --lvl3: #8f7fd6;
  --lvl4: #6f7885;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font-family: inherit; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  flex-wrap: wrap;
}
.topbar-left { min-width: 0; }
.proj-switch { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.proj-select {
  appearance: auto; min-width: 200px; max-width: 520px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 8px; font-size: 12.5px; cursor: pointer;
}
.proj-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.proj-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.proj-sub .sep { margin: 0 8px; color: var(--text-faint); }
.proj-sub b { color: var(--text); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.btn.ghost:hover { background: var(--line-soft); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1613;
  font-weight: 700;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger-ghost { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn:disabled { opacity: .45; cursor: default; filter: none; }

.user-badge {
  font-size: 12px; color: var(--text-dim);
  padding: 4px 8px; border: 1px solid var(--line-soft); border-radius: 6px;
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.save-status {
  font-size: 12px;
  color: var(--text-faint);
  min-width: 90px;
}
.save-status.dirty { color: var(--amber); }
.save-status.saved { color: var(--accent); }

/* ---------- Workspace layout ---------- */
.workspace {
  display: flex;
  height: calc(100vh - 66px);
  height: calc(100dvh - 66px);
}
.pane { display: flex; flex-direction: column; min-width: 0; }
.pane-table { width: 760px; flex: 0 0 auto; border-right: 1px solid var(--line); }
.pane-gantt { flex: 1 1 auto; overflow: hidden; }
.pane-scroll { overflow: auto; flex: 1 1 auto; }

/* 가운데(표) 세로 스크롤바는 숨긴다 — 마우스 휠 스크롤은 그대로 동작하고,
   세로 스크롤은 우측 간트 스크롤바로 통합 제어된다(스크롤 동기화). 가로 스크롤바는 유지. */
#tableScroll { scrollbar-width: none; }          /* Firefox */
#tableScroll::-webkit-scrollbar { width: 0; }    /* Chromium: 세로 스크롤바 폭 0 (가로바는 height로 유지) */

/* 테이블/간트 사이 드래그 구분자 (테이블 영역 너비 조절) */
.pane-resizer {
  flex: 0 0 6px; align-self: stretch;
  cursor: col-resize; background: var(--line);
  position: relative; z-index: 4;
}
.pane-resizer:hover, .pane-resizer.dragging { background: var(--accent); }

@media (max-width: 900px) {
  .workspace { flex-direction: column; height: auto; }
  .pane-table { width: 100% !important; border-right: none; border-bottom: 1px solid var(--line); }
  .pane-gantt { height: 480px; }
  .pane-resizer { display: none; }
}

/* ---------- Table ---------- */
.wbs-table { border-collapse: collapse; table-layout: fixed; width: 760px; }
.wbs-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-raised);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 컬럼 너비 드래그 핸들 */
.col-resizer {
  position: absolute; top: 0; right: -3px; width: 7px; height: 100%;
  cursor: col-resize; z-index: 3; user-select: none; touch-action: none;
}
.col-resizer:hover, .col-resizer.dragging { background: var(--accent-soft); }
.wbs-table td {
  padding: 0;
  border-bottom: 1px solid var(--line-soft);
  height: 34px;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
}
.wbs-table tr.row:nth-child(even) { background: var(--bg-row-alt); }
.wbs-table tr.row:nth-child(odd) { background: var(--bg-row); }
.wbs-table tr.row:hover { background: #1a212b; }
.wbs-table tr.row.hidden { display: none; }

/* 일정 경과(지연) 표시 */
.overdue-mark { flex: 0 0 auto; color: var(--danger); font-size: 12px; line-height: 1; }
.row.overdue .name-input { color: var(--danger); }
.row.overdue input[data-field="end"] { color: var(--danger); font-weight: 700; }
.row.overdue td.col-num { color: var(--danger); }

td.col-toggle { width: 26px; text-align: center; }
.toggle-btn {
  border: none; background: none; color: var(--text-faint);
  cursor: pointer; font-size: 10px; width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
}
.toggle-spacer { display: inline-block; width: 20px; }

td.col-id {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  padding: 0 8px;
}
.id-cell { display: flex; align-items: center; gap: 0; overflow: hidden; }
.id-cell > span { overflow: hidden; text-overflow: ellipsis; }
.id-lvl1 { color: var(--lvl1); font-weight: 700; }
.id-lvl2 { color: var(--lvl2); }
.id-lvl3 { color: var(--lvl3); }
.id-lvl4 { color: var(--lvl4); }

td.col-name { padding: 0 6px; }
.name-cell {
  display: flex; align-items: center; gap: 6px;
  overflow: hidden;
}
.name-indent { flex: 0 0 auto; }
.name-input {
  border: none; background: none; color: var(--text);
  font-size: 13px; width: 100%; padding: 4px 2px;
  border-radius: 4px;
}
.row-lvl-1 .name-input { font-weight: 700; }
.row-lvl-2 .name-input { font-weight: 600; }
.name-input:focus { outline: none; background: var(--accent-soft); }
.name-cell .name-input { flex: 1 1 auto; min-width: 0; width: auto; }
.add-sib-btn, .add-child-btn {
  flex: 0 0 auto; border: none; background: none; color: var(--text-faint);
  cursor: pointer; font-size: 14px; line-height: 1; height: 20px;
  border-radius: 4px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 0; opacity: 0; overflow: hidden;
  transition: width .1s ease, opacity .1s ease;
}
tr.row:hover .add-sib-btn, tr.row:hover .add-child-btn { width: 18px; opacity: 1; margin-left: 3px; }
.add-sib-btn:hover, .add-child-btn:hover { color: var(--accent); background: var(--accent-soft); }

/* 완료 토글 버튼 (작업명 셀) */
.done-btn {
  flex: 0 0 auto; border: 1px solid var(--line); background: transparent;
  color: var(--text-dim); font-size: 11px; padding: 2px 9px; border-radius: 999px;
  cursor: pointer; white-space: nowrap; line-height: 1.4;
  opacity: 0; transition: opacity .1s ease;
}
.name-cell:focus-within .done-btn, tr.row:hover .done-btn { opacity: 1; }
.done-btn:hover { border-color: var(--accent); color: var(--text); }
.done-btn.on {
  opacity: 1; color: #0b1613; background: var(--accent);
  border-color: var(--accent); font-weight: 700;
}
.done-btn.on::before { content: "✓ "; }
.done-btn.on:hover { color: #0b1613; }

.cell-input {
  border: none; background: none; color: var(--text);
  font-size: 12.5px; width: 100%; padding: 6px 8px;
  border-radius: 4px;
}
.cell-input:focus { outline: none; background: var(--accent-soft); }
.cell-input.mono { font-family: var(--mono); font-size: 11.5px; }
td.col-dept .cell-input { width: 100%; }
td.col-deliv .cell-input { width: 100%; }
td.col-num { color: var(--text-dim); font-size: 12px; text-align: center; }
td.col-prog .cell-input { width: 100%; text-align: right; }

/* ---------- 줄바꿈 모드 (작업명·산출물을 textarea로) ---------- */
body.wrap-cells .wbs-table td { height: auto; white-space: normal; }
body.wrap-cells td.col-name, body.wrap-cells td.col-deliv { vertical-align: top; }
body.wrap-cells .name-cell { align-items: flex-start; }
.name-input.wrap, .cell-input.wrap {
  display: block; resize: none; overflow: hidden;
  line-height: 1.4; min-height: 24px; padding-top: 6px; padding-bottom: 6px;
  white-space: pre-wrap; word-break: break-word;
  field-sizing: content;
}
.name-input.wrap { font-size: 13px; }

td.col-del { width: 30px; text-align: center; }
.del-btn {
  border: none; background: none; color: var(--text-faint);
  cursor: pointer; font-size: 13px; opacity: 0;
}
tr.row:hover .del-btn { opacity: 1; }
.del-btn:hover { color: var(--danger); }

/* ---------- Gantt ---------- */
.gantt-header {
  height: 34px; border-bottom: 1px solid var(--line);
  background: var(--bg-raised); overflow: hidden; position: relative;
}
.gantt-months { display: flex; height: 100%; }
.gantt-month {
  border-right: 1px solid var(--line);
  font-size: 11px; color: var(--text-dim);
  display: flex; align-items: center; padding-left: 8px;
  font-weight: 600;
}
#ganttScroll { position: relative; }
.gantt-grid { position: absolute; top: 0; left: 0; height: 100%; z-index: 0; }
/* 월별 배경 밴드 — 파스텔, 배경과 유사한 저채도. 짝수달/홀수달 교차 */
.gantt-month-band { position: absolute; top: 0; bottom: 0; z-index: 0; }
.gantt-month-band.b0 { background: rgba(255, 255, 255, 0.016); }
.gantt-month-band.b1 { background: rgba(126, 166, 210, 0.06); }
.gantt-month.b0 { background: rgba(255, 255, 255, 0.016); }
.gantt-month.b1 { background: rgba(126, 166, 210, 0.06); }
.gantt-gridline {
  position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line-soft);
}
.gantt-gridline.month { background: var(--line); }
.gantt-today {
  position: absolute; top: 0; bottom: 0; width: 2px; background: var(--amber);
  z-index: 1;
}
.gantt-rows { position: relative; z-index: 2; }
.gantt-row {
  height: 34px; position: relative; border-bottom: 1px solid var(--line-soft);
}
.gantt-row:nth-child(even) { background: rgba(255,255,255,0.012); }
.gantt-bar {
  position: absolute; top: 7px; height: 20px; border-radius: 4px;
  display: flex; align-items: center; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
  cursor: default;
}
.gantt-bar .fill {
  position: absolute; top: 0; left: 0; bottom: 0;
  background: rgba(255,255,255,0.35);
}
.gantt-bar .label {
  position: relative; z-index: 1; font-size: 10.5px; color: #0b1613;
  padding: 0 6px; white-space: nowrap; font-weight: 600;
  mix-blend-mode: normal;
}
.gantt-bar.lvl-1 { background: var(--lvl1); }
.gantt-bar.lvl-2 { background: var(--lvl2); }
.gantt-bar.lvl-3 { background: var(--lvl3); }
.gantt-bar.lvl-4 { background: var(--lvl4); }
.gantt-bar .label { color: rgba(0,0,0,0.65); }
.gantt-bar.lvl-4 .label { color: #eef1f5; }
.gantt-bar.lvl-3 .label { color: #f3f1fb; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px);
  background: #1c232d; border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 8px; font-size: 12.5px;
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); color: #ffb3a3; }

/* ---------- 작업 내역 모달 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal.hidden { display: none; }
.modal-box {
  width: 100%; max-width: 560px; max-height: 82vh;
  display: flex; flex-direction: column;
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 14px; font-weight: 700; }
.modal-close {
  border: none; background: none; color: var(--text-dim);
  cursor: pointer; font-size: 15px; padding: 4px 6px; border-radius: 6px;
}
.modal-close:hover { color: var(--text); background: var(--line-soft); }
.modal-body { padding: 8px 18px 18px; overflow: auto; }

/* 새 프로젝트 모달 폼 */
.pm-field { margin: 14px 0; }
.pm-field > label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.pm-field input[type="text"], .pm-field input[type="date"] {
  width: 100%; box-sizing: border-box; padding: 9px 11px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 7px;
  color: var(--text); font-size: 13.5px;
}
.pm-field input[type="date"] { color-scheme: dark; }
.pm-field input[type="text"]:focus, .pm-field input[type="date"]:focus { outline: none; border-color: var(--accent); }
.pm-row { display: flex; gap: 10px; }
.pm-row .pm-field { flex: 1; min-width: 0; }
@media (max-width: 480px) { .pm-row { flex-direction: column; gap: 0; } }
.pm-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }
.pm-slug { color: var(--accent); font-family: var(--mono); }
.pm-radio { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin: 8px 0; cursor: pointer; }
.pm-radio input { margin: 0; width: auto; flex: 0 0 auto; }
.pm-msg { font-size: 12.5px; min-height: 18px; color: var(--danger); margin-top: 4px; }
.pm-submit { width: 100%; margin-top: 8px; }

/* 삭제 확인 모달 */
.del-warn { font-size: 13px; color: var(--text-dim); line-height: 1.65; margin: 4px 0 16px; }
.del-warn b { color: var(--text); }
.del-target { color: var(--danger); font-weight: 700; }
.del-submit { width: 100%; margin-top: 8px; }
.btn.danger-solid {
  background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 700;
}
.btn.danger-solid:hover { filter: brightness(1.08); }

.hist-empty { color: var(--text-dim); font-size: 13px; padding: 24px 0; text-align: center; }
.hist-user-head {
  position: sticky; top: 0; z-index: 2; background: var(--bg-raised);
  font-size: 13px; font-weight: 700; color: var(--text);
  padding: 10px 0 8px; margin-top: 4px; border-bottom: 1px solid var(--line);
}
.hist-user-head::before { content: "👤 "; }
.hist-date {
  font-size: 11.5px; font-weight: 700; color: var(--text-dim);
  padding: 8px 0 4px; margin-left: 2px;
}
.hist-foot { text-align: center; color: var(--text-faint); font-size: 11.5px; padding: 14px 0 4px; }
.hist-entry {
  padding: 8px 0; border-bottom: 1px solid var(--line-soft);
}
.hist-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.hist-user { font-size: 12px; font-weight: 600; color: var(--text); }
.hist-time { font-size: 11px; color: var(--text-faint); }
.hist-line { font-size: 12.5px; line-height: 1.5; color: var(--text); margin: 2px 0; }
.hist-line b {
  display: inline-block; min-width: 62px; font-weight: 700; font-size: 11px;
  padding: 1px 6px; border-radius: 4px; margin-right: 6px;
}
.hist-line.add b { color: var(--accent); background: var(--accent-soft); }
.hist-line.del b { color: #ffb3a3; background: rgba(217, 99, 79, 0.16); }
.hist-line.upd b { color: var(--amber); background: rgba(217, 164, 65, 0.16); }
