: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;
}
.proj-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: pre-line;
}
.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; }

.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; }

/* 테이블/간트 사이 드래그 구분자 (테이블 영역 너비 조절) */
.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; }

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-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 {
  flex: 0 0 auto; border: none; background: none; color: var(--text-faint);
  cursor: pointer; font-size: 15px; line-height: 1; width: 20px; height: 20px;
  border-radius: 4px; opacity: 0; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
tr.row:hover .add-sib-btn { opacity: 1; }
.add-sib-btn:hover { color: var(--accent); background: var(--accent-soft); }
body.wrap-cells .add-sib-btn { align-self: flex-start; margin-top: 4px; }

.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-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; }
