:root {
  --ink: #1d2430;
  --muted: #7b8494;
  --line: #dfe3e8;
  --line-strong: #bfc6d0;
  --navy: #344766;
  --navy-soft: #edf2f8;
  --blue: #55759e;
  --blue-soft: #edf4fb;
  --green: #658d78;
  --green-soft: #edf5ef;
  --orange: #c58a58;
  --orange-soft: #faf3e9;
  --purple: #81749c;
  --purple-soft: #f2eff7;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  font-family: "Pretendard", "Segoe UI", "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: #f3f5f7;
}

button { font: inherit; }

@media screen {
  /* 페이지 자체 스크롤 제거: 화면 높이에 맞추고 표 영역(.board-scroll)만 스크롤 */
  html, body { height: 100%; overflow: hidden; }
}

.board-shell {
  position: relative;
  /* 최대 폭 제한 없이 화면(모니터·휴대폰) 폭에 맞춤 */
  width: calc(100% - 32px);
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  margin: 16px auto;
  border: 1px solid #e2e5ea;
  background: #fff;
  box-shadow: 0 10px 35px rgba(55, 67, 82, .08);
}

.board-header {
  min-height: 92px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 18px 28px 14px;
  border-bottom: 1px solid var(--line);
}

.title-block { min-width: 0; }
.eyebrow {
  margin: 0 0 6px;
  color: #8a93a2;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
}
.title-block h1 {
  margin: 0;
  font-family: "Malgun Gothic", sans-serif;
  font-size: 27px;
  line-height: 1.15;
  letter-spacing: -1px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-actions button {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  color: #526178;
  background: #fff;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.header-actions .admin-link { gap: 7px; white-space: nowrap; }
.header-actions button svg,
.header-actions .admin-link svg {
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.header-actions button:hover { background: #f7f9fb; }
.header-actions .admin-link {
  height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  color: #526178;
  background: #fff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 800;
}
.header-actions .admin-link:hover { background: #f7f9fb; }


.today-box {
  height: 44px;
  min-width: 122px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-left: 4px;
  border-left: 1px solid var(--line);
  padding-left: 14px;
}
.today-box span { color: #969eaa; font-size: 10px; }
.today-box strong { margin-top: 3px; font-size: 14px; }

.guide-row {
  position: relative;
  z-index: 40;
  width: 100%;
  min-width: 0;
  height: 34px;
  display: flex;
  align-items: center;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
  overflow: hidden;
}
.guide-row p {
  margin: 0;
  color: #687486;
  font-family: "Pretendard", "Segoe UI", "Malgun Gothic", sans-serif;
  font-size: 11px;
  font-weight: 700;
  line-height: 34px;
}
.board-scroll {
  overflow-x: auto;
  overflow-y: auto;
}

.board-header, .guide-row { flex: 0 0 auto; }

.board-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  /* 위·좌우 여백이 있으면 고정된 범례/부서명 옆으로 표가 비쳐 보이므로 0 (좌우 여백은 .board-content에서 줌) */
  padding: 0 0 28px;
  max-width: 100%;
  position: relative;
  scroll-padding-top: 80px;
  /* 화면 폭에 따라 표가 늘어나고 줄어듦. 월 칸이 --month-min보다 좁아지면 가로 스크롤 (부서명 열은 고정) */
  --board-pad: 28px;
  --dept-col: 180px;
  --month-min: 80px;
}

.board-content {
  position: relative;
  padding-inline: var(--board-pad);
  width: 100%;
  min-width: calc(var(--dept-col) + 12 * var(--month-min) + 2 * var(--board-pad));
}

.board-grid {
  width: 100%;
  display: grid;
  grid-template-columns: var(--dept-col) repeat(12, minmax(0, 1fr));
  border-width: 1px;
}

.grid-header,
.department-cell,
.month-cell,
.month-grid-line,
.department-separator {
  border-top-width: 1px;
  border-right-width: 1px;
  border-bottom-width: 1px;
  border-left-width: 1px;
}

.grid-header {
  position: sticky;
  top: 0;
  z-index: 39;
  height: 46px;
  display: grid;
  place-items: center;
  color: #536176;
  background: var(--navy-soft);
  font-size: 12px;
  font-weight: 900;
  border-bottom: 1px solid var(--line-strong);
}
.grid-header.department-heading {
  position: sticky;
  top: 0;
  z-index: 41;
  left: 0;
  justify-content: center;
  text-align: center;
  padding-left: 0;
}

.department-row { display: contents; }
.department-cell {
  /* 가로 스크롤 시 부서명 열 고정 (월 구분선 z-index 20보다 위) */
  position: sticky;
  left: 0;
  z-index: 25;
  border-bottom: 1px solid var(--line);
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px 12px;
  background: #fbfcfd;
  color: #364254;
  font-size: 12.5px;
  font-weight: 900;
  line-height: 1.35;
  border-bottom-width: 1px;
  border-left: 1px solid var(--line-strong);
  border-right: 1px solid var(--line-strong);
}

.month-cell {
  min-height: 24px;
  align-content: start;
  padding: 7px 6px;
  background: #fff;
}
.month-cell:nth-child(odd) { background: #fcfdfe; }
.task-card {
  position: relative;
  margin-bottom: 5px;
  border-left: 3px solid var(--blue);
  border-radius: 3px;
  padding: 0 6px;
  height: 20px;
  min-height: 20px;
  display: flex;
  align-items: center;
  line-height: 20px;
  overflow: visible;
  pointer-events: auto;
  color: #3f4a5b;
  background: var(--blue-soft);
  font-size: 10.5px;
  cursor: default;
}
.task-card.blue{border-left-color:#2878c8;background:#edf5ff}.legend-dot.blue{background:#edf5ff;border:2px solid #2878c8}
.task-card.green{border-left-color:#658d78;background:#edf5ef}.legend-dot.green{background:#edf5ef;border:2px solid #658d78}
.task-card.orange{border-left-color:#d97720;background:#fff3e8}.legend-dot.orange{background:#fff3e8;border:2px solid #d97720}
.task-card.purple{border-left-color:#81749c;background:#f2eff7}.legend-dot.purple{background:#f2eff7;border:2px solid #81749c}
.task-card.teal{border-left-color:#3aa6a6;background:#edf8f8}.legend-dot.teal{background:#edf8f8;border:2px solid #3aa6a6}
.task-card.pink{border-left-color:#b66b84;background:#faeef2}.legend-dot.pink{background:#faeef2;border:2px solid #b66b84}
.task-card.navy{border-left-color:#7a5c28;background:#f7f1df}.legend-dot.navy{background:#f7f1df;border:2px solid #7a5c28}
.task-card.cyan{border-left-color:#5c9db8;background:#eef7fa}.legend-dot.cyan{background:#eef7fa;border:2px solid #5c9db8}
.task-card.gray{border-left-color:#8a9098;background:#f1f2f3}.legend-dot.gray{background:#f1f2f3;border:2px solid #8a9098}
.task-card.yellow{border-left-color:#a43d72;background:#fdeef5}.legend-dot.yellow{background:#fdeef5;border:2px solid #a43d72}
.task-card strong {
  display: block;
  width: 100%;
  height: 20px;
  overflow: hidden;
  font-size: 8.5px;
  line-height: 20px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.task-card span { display: none; }
.task-card:hover { z-index: 3; box-shadow: 0 5px 15px rgba(66,78,96,.13); }

.filter-popover {
  position: absolute;
  z-index: 100;
  top: 80px;
  right: 185px;
  width: 280px;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-6px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #ffffff;
  box-shadow: 0 16px 38px rgba(48,60,78,.16);
  transition: .16s ease;
}
.filter-popover.open { visibility: visible; opacity: 1; transform: none; }
.filter-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.filter-heading strong { font-size: 13px; }
.filter-heading button { border: 0; background: transparent; color: #8b929d; font-size: 20px; cursor: pointer; }
.filter-options {
  position: relative;
  z-index: 1;
  background: #ffffff;
  max-height: 280px;
  overflow: auto;
}
.filter-option {
  position: relative;
  z-index: 1;
  background: #ffffff;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.filter-option input { accent-color: var(--blue); }
.filter-actions { display: flex; justify-content: space-between; margin-top: 10px; }
.filter-actions button { height: 34px; border: 0; border-radius: 7px; padding: 0 10px; color: #66748a; background: #f2f4f7; font-size: 11px; font-weight: 800; cursor: pointer; }
.filter-actions .apply-button { color: #fff; background: var(--blue); }

.month-grid-layer {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: 1fr;
  align-self: stretch;
  pointer-events: none;
  background: transparent;
}
.month-grid-line {
  height: 100%;
  min-height: 24px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
}
.month-grid-line:last-child { border-right: 1px solid var(--line-strong); }
.month-grid-line:nth-child(12) {
  border-right: 1px solid var(--line-strong);
}

.merged-task-cell,
.recurring-task-cell {
  position: relative;
  z-index: 3;
  height: 24px;
  min-height: 24px;
  border: 0;
  background: transparent;
  padding: 2px 3px;
}
.task-card {
  position: relative;
  z-index: 3;
}

/* 업무명이 길면 '...' 대신 칸 폭 안에서 줄바꿈하여 전부 표시 (줄 높이는 내용만큼 늘어남) */
.merged-task-cell,
.recurring-task-cell { height: auto; }
.board-grid .task-card,
.print-lanes .task-card {
  height: auto;
  min-height: 20px;
  margin-bottom: 0;
  padding: 3px 6px;
  line-height: 1.3;
}
.board-grid .task-card strong,
.print-lanes .task-card strong {
  height: auto;
  overflow: visible;
  white-space: normal;
  text-overflow: clip;
  line-height: 1.3;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.task-detail-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  visibility: hidden;
  opacity: 0;
  background: rgba(32, 40, 52, .38);
  transition: .18s ease;
}
.task-detail-modal.open { visibility: visible; opacity: 1; }
.task-detail-panel {
  position: relative;
  width: min(520px, calc(100% - 32px));
  border: 1px solid #dfe4ea;
  border-radius: 14px;
  padding: 28px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(32, 40, 52, .22);
}
.task-detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  color: #69758a;
  background: #f2f4f7;
  font-size: 22px;
  cursor: pointer;
}
.task-detail-department { margin: 0 0 8px; color: #7f8998; font-size: 16px; font-weight: 800; }
.task-detail-panel h2 { margin: 0 32px 24px 0; font-size: 24px; line-height: 1.35; }
/* 비고(엑셀 K열): 제목(24px)의 1/2 크기 */
.task-detail-panel h2:has(+ .task-detail-note:not([hidden])) { margin-bottom: 8px; }
.task-detail-note { margin: 0 32px 20px 0; color: #5f6b7c; font-size: 12px; font-weight: 600; line-height: 1.5; white-space: pre-line; word-break: keep-all; overflow-wrap: anywhere; }
.task-detail-panel dl { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0; }
.task-detail-panel dl div { min-width: 0; display: flex; flex-direction: column; border: 1px solid #e3e7ec; border-radius: 10px; padding: 14px 10px; background: #f8fafc; text-align: center; }
.task-detail-panel dt { margin-bottom: 7px; color: #7c8796; font-size: 14px; font-weight: 800; }
/* 값이 길면 script.js(fitDetailValues)가 글자 크기를 줄여 2줄 안에 모두 표시 */
.task-detail-panel dd {
  /* 박스 높이가 서로 달라도 값은 제목 아래 남은 공간의 위아래 중앙에 배치 */
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  line-height: 1.3;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.task-card { cursor: pointer; }
.task-card:hover { box-shadow: none; }

.department-separator {
  height: 1px;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 0;
  border-left: 0;
}

.average-progress {
  height: 40px;
  display: flex;
  align-items: center;
  margin-left: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  color: #526178;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.average-progress .progress-value.recommended { color: #1f6fd1; }
.average-progress .progress-value.actual { color: #8a93a2; }

/* 실제 진행률 신호등 (권장 진행률 대비) */
.signal-blue { color: #1f6fd1 !important; }
.signal-orange { color: #e07b00 !important; }
.signal-red { color: #d6363b !important; }
.signal-none { color: #8a93a2 !important; }

.signal-light {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 4px;
  border-radius: 999px;
  padding: 3px 5px;
  background: #2b313b;
  vertical-align: middle;
  line-height: 0;
}
.signal-lamp {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  opacity: .22;
}
.signal-lamp.red { background: #ff4d4f; }
.signal-lamp.orange { background: #ffa223; }
.signal-lamp.blue { background: #3d9bff; }
.signal-lamp.on { opacity: 1; box-shadow: 0 0 6px currentColor; }
.signal-lamp.red.on { color: #ff4d4f; }
.signal-lamp.orange.on { color: #ffa223; }
.signal-lamp.blue.on { color: #3d9bff; }
.task-detail-panel dd .signal-light { margin-left: 0; padding: 4px 6px; gap: 4px; }
/* 글자 크기 자동 조정 시에는 늘어난 높이가 아닌 실제 내용 높이로 측정 */
.task-detail-panel.measuring dd { flex: none; }
.task-detail-panel dd .signal-lamp { width: 10px; height: 10px; }

.december-right-line {
  height: 100%;
  min-height: 24px;
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
  background: transparent;
  pointer-events: none;
}

@media (max-width: 1500px) {
  .board-scroll { --board-pad: 16px; --dept-col: 150px; --month-min: 72px; }
}

@media (max-width: 900px) {
  .board-shell {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    margin: 0;
  }
  .board-header {
    position: sticky;
    z-index: 10;
    top: 0;
    background: #fff;
  }
  .board-scroll {
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    --dept-col: 120px;
    --month-min: 64px;
  }
  .board-header { min-height: 0; padding: 12px 16px; }
  .title-block { flex: 1 1 100%; }
  .title-block h1 { font-size: 22px; }
  .average-progress { margin-left: 0; }
  .header-actions { margin-left: auto; }
  .header-actions button { white-space: nowrap; }
  .guide-row { padding: 0 16px; }
  .board-shell .color-legend { height: auto; flex-wrap: wrap; row-gap: 4px; padding: 6px 16px; }
  .department-cell { padding: 8px 6px; font-size: 11.5px; }
}

@media (max-width: 520px) {
  .board-header {
  }
  .title-block h1 {
    white-space: normal;
  }
  .header-actions {
    gap: 6px;
  }
  .header-actions .dept-button,
  .header-actions .pdf-button {
    height: 38px;
  }
  .guide-row {
    height: 38px;
  }
  .guide-row p {
    font-size: 10px;
  }
  .board-scroll {
    padding: 0 0 16px;
  }
  .board-scroll { --board-pad: 8px; --dept-col: 84px; --month-min: 56px; }
  .board-header { padding: 10px 10px; }
  .title-block h1 { font-size: 18px; }
  .average-progress { height: auto; min-height: 32px; padding: 4px 10px; white-space: normal; }
  .today-box { display: none; }
  .header-actions button { padding: 0 10px; }
  .guide-row { padding: 0 10px; }
  .board-shell .color-legend { gap: 4px 10px; padding: 6px 10px; }
  .department-cell { padding: 6px 4px; font-size: 10.5px; word-break: keep-all; }
}

/* ===== PDF 저장(인쇄) ===== */
.print-board { display: none; }

@media print {
  /* A4 가로 고정: 12월까지 한 페이지 폭에 표시 */
  @page { size: A4 landscape; margin: 8mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { height: auto; overflow: visible; background: #fff; }
  .board-shell { display: block; width: 100%; height: auto; margin: 0; border: 0; box-shadow: none; }
  .header-actions, .filter-popover, .guide-row, .color-legend, .board-scroll, .task-detail-modal { display: none !important; }
  .board-header { height: auto; padding: 0 0 6px; border-bottom: 0; }
  .title-block h1 { font-size: 18px; }
  .average-progress { height: 26px; font-size: 10px; }

  .print-board { display: block; --print-lane-height: 15px; }
  .print-table { width: 100%; table-layout: fixed; border-collapse: collapse; }
  .print-col-dept { width: 26mm; }
  /* thead는 페이지가 넘어가도 매 페이지 상단에 반복 출력 */
  .print-table thead { display: table-header-group; }
  .print-legend {
    padding: 4px 6px 6px;
    text-align: left;
    font-size: 8px;
    font-weight: 800;
    color: #4b5668;
    background: #fff;
  }
  .print-legend-item { display: inline-flex; align-items: center; gap: 3px; margin-right: 12px; }
  .print-legend .legend-dot { width: 9px; height: 9px; border-radius: 2px; }
  .print-month-row th {
    height: 20px;
    border: 1px solid #c9d2de;
    color: #3f4b5d;
    background: var(--navy-soft);
    font-size: 8.5px;
    font-weight: 900;
    text-align: center;
  }
  /* 부서 단위로 묶어서 페이지 중간에 잘리지 않게 (남는 공간은 여백으로 둠) */
  .print-dept, .print-dept tr { break-inside: avoid; page-break-inside: avoid; }
  .print-dept td { border: 1px solid #d3dae3; }
  .print-dept-name {
    padding: 3px 4px;
    color: #364254;
    background: #fbfcfd;
    font-size: 8.5px;
    font-weight: 900;
    text-align: center;
    vertical-align: middle;
  }
  .print-tasks { padding: 0; vertical-align: top; }
  .print-lanes {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    row-gap: 2px;
    padding: 3px 0;
  }
  .print-month-bg { border-left: 1px solid #e6eaef; margin: -3px 0; }
  .print-month-bg:first-child { border-left: 0; }
  .print-lanes .task-card {
    position: relative;
    z-index: 1;
    min-width: 0;
    height: auto;
    min-height: var(--print-lane-height);
    margin: 0 2px;
    padding: 2px 3px;
    border-left-width: 2px;
    line-height: 1.25;
    box-shadow: none;
  }
  .print-lanes .task-card strong {
    height: auto;
    font-size: 7px;
    line-height: 1.25;
  }
}

.filter-presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.filter-presets button {
  width: 100%;
  min-width: 0;
  padding-inline: 6px;
  text-align: center;
}
.filter-presets #applyFilter {
  grid-column: 1 / -1;
}

.color-legend {
  position: relative;
  z-index: 40;
  flex: 0 0 auto;
  height: 34px;
  min-height: 34px;
  margin: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 56px;
  overflow: hidden;
  white-space: nowrap;
  flex-wrap: nowrap;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #687486;
  font-size: 10.5px;
  font-weight: 800;
  line-height: 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 4px 6px;
  background: transparent;
  cursor: pointer;
}
.legend-item:hover,
.legend-item.active {
  border-color: #cfd6df;
  background: #f7f9fb;
}
.legend-dot {
  width: 12px;
  height: 12px;
  display: inline-block;
  flex: none;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, .12);
}

.grid-header {
  top: 0;
  z-index: 31;
}
.grid-header.department-heading {
  top: 0;
  z-index: 32;
}
