:root {
  color-scheme: light;
  --line: #e3e6ea;
  --line2: #d1d5db;
  --ink: #1f2937;
  --muted: #6b7280;
  --work-bg: #ffffff;
  --off-bg: #fde68a;
  --off-fg: #92400e;
  --weekend: #f4f5f7;
  --weekend-fg: #dc2626;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --accent: #2563eb;
  --accent-bg: #eff6ff;
  --panel: #ffffff;
  --bg: #f3f4f6;
}

* { box-sizing: border-box; }
body {
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  margin: 0; padding: 0; color: var(--ink); background: var(--bg);
}
h1 { font-size: 1.2rem; margin: 0; }
h2 { font-size: .98rem; margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .78rem; font-weight: 400; }

/* --- Topbar + KPI ------------------------------------------------------ */
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: .8rem 1.25rem; position: sticky; top: 0; z-index: 20;
}
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.toolbar { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.ym { font-size: .76rem; color: var(--muted); display: flex; flex-direction: column; }
.ym input { font-size: .9rem; padding: .2rem .35rem; }
.btn {
  font-size: .85rem; padding: .42rem .75rem; border: 1px solid var(--line2);
  background: #fff; border-radius: 8px; cursor: pointer; transition: all .12s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.badge { font-size: .76rem; padding: .28rem .6rem; border-radius: 999px; font-weight: 600; }
.badge.status { background: var(--accent-bg); color: #1e40af; }
.badge.status.error { background: var(--bad-bg); color: var(--bad); }  /* 검증 오류 있음 */

/* 보기 전환 토글 (직원별 / 캘린더) */
.view-toggle { display: inline-flex; border: 1px solid var(--line2); border-radius: 9px; overflow: hidden; margin-right: .3rem; }
.view-toggle .seg { border: none; background: #fff; color: var(--ink); font-size: .82rem; padding: .42rem .72rem; cursor: pointer; transition: all .12s ease; }
.view-toggle .seg + .seg { border-left: 1px solid var(--line2); }
.view-toggle .seg:hover:not(.active) { color: var(--accent); }
.view-toggle .seg.active { background: var(--accent); color: #fff; }

/* 뷰별 표시 전환 — 같은 데이터, 화면만 변경 */
body.view-grid .calendar-panel { display: none; }
body.view-calendar .board-panel { display: none; }
body.view-calendar .side { display: none; }
body.view-calendar .filterbar { display: none; }
body.view-calendar .edit-only { display: none; }
body.view-calendar .layout { grid-template-columns: 1fr; }

.kpi { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .8rem; }
.kpi .card {
  background: #fafbfc; border: 1px solid var(--line); border-radius: 10px;
  padding: .45rem .85rem; min-width: 92px; text-align: center;
}
.kpi .card .v { font-size: 1.18rem; font-weight: 700; }
.kpi .card .k { font-size: .72rem; color: var(--muted); margin-top: .1rem; }
.kpi .card.bad .v { color: var(--bad); }
.kpi .card.good .v { color: var(--ok); }

/* --- Filter bar -------------------------------------------------------- */
.filterbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .55rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.search { font-size: .85rem; display: flex; align-items: center; gap: .35rem; }
.search input { font-size: .88rem; padding: .35rem .55rem; border: 1px solid var(--line2); border-radius: 8px; min-width: 180px; }
.part-filter { display: flex; gap: .35rem; }
.chip {
  font-size: .8rem; padding: .32rem .7rem; border: 1px solid var(--line2);
  background: #fff; border-radius: 999px; cursor: pointer; transition: all .1s ease;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- Layout (데스크톱 우선 · 근무표 ≈ 80%, 우측 부가 패널 고정) ---------- */
.layout { display: grid; grid-template-columns: minmax(0,1fr) 292px; gap: 1rem; padding: 1rem 1.25rem; align-items: start; }
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }
.main-col { min-width: 0; }
/* 우측 패널: 스크롤해도 항상 보이도록 고정 */
.side {
  position: sticky; top: 122px; align-self: start;
  max-height: calc(100vh - 134px); overflow-y: auto;
  display: flex; flex-direction: column; gap: .85rem;
}
@media (max-width: 1100px) { .side { position: static; max-height: none; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; }
.board-panel { padding-bottom: 1rem; }
.board-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.panel-body { font-size: .85rem; }
.hint { font-size: .78rem; color: var(--muted); margin: 0 0 .7rem; }
.legend { padding: .05rem .35rem; border-radius: 4px; font-size: .75rem; font-weight: 600; }
.legend.ok { background: var(--ok-bg); color: var(--ok); }
.legend.bad { background: var(--bad-bg); color: var(--bad); }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }

/* --- 단일 테이블 (직원 1회 · 주차 컬럼 그룹 · 파트 밴드 · 컴팩트) ------- */
/* 보드는 자체 스크롤 영역 — 세로 스크롤해도 헤더(주차/날짜)는 상단 고정 */
.board { overflow: auto; max-height: calc(100vh - 232px); position: relative; }
table.grid { border-collapse: separate; border-spacing: 0; font-size: .8rem; width: max-content; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
table.grid thead th { border-top: 1px solid var(--line); }
table.grid th:first-child, table.grid td:first-child { border-left: 1px solid var(--line); }

/* 헤더 상단 고정 — 1단(주차) top:0, 2단(날짜) top:23px */
table.grid thead th { position: sticky; z-index: 5; }
table.grid thead tr:first-child th { top: 0; height: 23px; }
table.grid thead tr:last-child th { top: 23px; }

/* 직원 열 = 좌측 고정(1회 표시) */
table.grid th.worker, table.grid td.worker {
  position: sticky; left: 0; z-index: 3; background: #fff; text-align: left;
  min-width: 104px; max-width: 104px; padding: .2rem .55rem; font-weight: 600;
}
table.grid thead th.corner { z-index: 6; top: 0; vertical-align: bottom; background: #f8f9fb; }
table.grid td.worker.floating { background: var(--accent-bg); }
table.grid td.worker.floating .part-tag { color: var(--accent); font-weight: 600; }
.part-tag { font-size: .64rem; color: var(--muted); font-weight: 400; display: block; line-height: 1.1; }
table.grid tr.dim td { opacity: .25; }
table.grid tr.match td.worker { background: #fffbeb; box-shadow: inset 3px 0 0 var(--accent); }

/* 행 줄무늬 (정보 밀도 ↑ · 가독성) — OFF/주말 셀 색은 우선순위로 유지 */
table.grid tbody tr.alt td { background: #fafbfc; }
table.grid tbody tr.alt td.worker { background: #f6f8fa; }

/* 파트 밴드 헤더 (파트1 / 파트2 / 공통 구분) */
table.grid tr.band td.band-cell {
  position: sticky; left: 0; z-index: 2; background: #eef1f5; color: #374151;
  text-align: left; font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  padding: .18rem .6rem; border-top: 2px solid var(--line2);
}

/* 주차 그룹 헤더 (짝수 주 옅은 틴트로 스캔성 ↑) */
th.week-group {
  text-align: center; font-size: .74rem; font-weight: 700; color: var(--accent);
  background: #eef2ff; padding: .2rem 0; border-left: 2px solid var(--accent);
}
th.week-group.wk-even { background: #e2e9ff; }

/* 주별 휴무계 · 총 휴무계 열 */
th.wk-tally-h {
  min-width: 26px; padding: .18rem .1rem; text-align: center;
  font-size: .64rem; color: var(--muted); background: #f3f4f6;
}
td.wk-tally {
  width: 26px; text-align: center; font-size: .7rem; color: var(--muted);
  background: #f8f9fb; font-variant-numeric: tabular-nums;
}
th.wk-tally-h.wk-even, td.wk-tally.wk-even { background: #eef1fb; }
th.total-corner {
  z-index: 6; top: 0; min-width: 34px; padding: 0 .2rem; text-align: center;
  font-size: .66rem; font-weight: 700; color: var(--muted); background: #f8f9fb; line-height: 1.05;
}
td.total {
  width: 34px; text-align: center; font-size: .74rem; font-weight: 700;
  color: var(--ink); background: #f3f4f6; font-variant-numeric: tabular-nums;
}

/* 날짜 헤더 (날짜 + 요일 + 주말 강조 / 공휴일 확장 여지) */
th.date-h { padding: .22rem .1rem; min-width: 40px; background: #f8f9fb; cursor: pointer; line-height: 1.05; text-align: center; }
th.date-h .d { font-size: .82rem; font-weight: 700; }
th.date-h .w { font-size: .6rem; color: var(--muted); display: block; }
th.date-h.weekend { background: #fef2f2; }
th.date-h.weekend .d, th.date-h.weekend .w { color: var(--weekend-fg); }
th.date-h:hover { background: var(--accent-bg); }

/* 주차 경계 구분선 */
th.date-h.week-start, td.cell.week-start { border-left: 2px solid var(--accent); }

/* 셀(편집 우선 — Drag&Drop 하기 쉬운 크기: 너비 ≥40 · 높이 ≥44px) */
td.cell {
  width: 40px; height: 44px; cursor: default; text-align: center; font-size: .78rem;
  background: var(--work-bg); transition: background .12s ease, transform .08s ease;
}
td.cell.weekend { background: var(--weekend); }
td.cell.off { background: var(--off-bg); cursor: grab; padding: 0; }
td.cell.off:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
td.cell.off:active { cursor: grabbing; }
td.cell:hover:not(.off) { background: var(--accent-bg); }
td.cell.dragging { opacity: .4; transform: scale(.85); }
/* 휴무 = 명확한 텍스트 + 드래그 가능한 토큰(편집 어포던스) */
.off-chip {
  display: inline-block; min-width: 30px; padding: .12rem .4rem; border-radius: 6px;
  background: var(--off-fg); color: #fff; font-size: .72rem; font-weight: 700; line-height: 1.4;
  transition: transform .1s ease;
}
td.cell.off:hover .off-chip { transform: scale(1.08); }

/* 연차 = 초록(휴무와 구분) · Drag&Drop 불가(편집 불가 커서) */
td.cell.leave { background: #dcfce7; cursor: not-allowed; padding: 0; }
.leave-chip {
  display: inline-block; min-width: 30px; padding: .12rem .4rem; border-radius: 6px;
  background: #15803d; color: #fff; font-size: .72rem; font-weight: 700; line-height: 1.4;
}
td.cell.drop-ok  { background: var(--ok-bg) !important;  outline: 2px solid var(--ok);  outline-offset: -2px; }
/* 빨강 = '규칙 위반 예상(주의)' — 배치는 가능하므로 차단 커서(no-drop) 대신 이동 커서 유지 */
td.cell.drop-bad { background: var(--bad-bg) !important; outline: 2px dashed var(--bad); outline-offset: -2px; cursor: grabbing; }

/* 검증 오류 강조 — 해당 직원 행 · 날짜 헤더/열 셀에 빨간 테두리(원인은 hover title) */
#board tbody tr.err-row > td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
#board td.cell.err-cell { outline: 2px solid var(--bad); outline-offset: -2px; }
#board th.date-h.err-date { background: var(--bad-bg); color: var(--bad); }
td.cell.flash { animation: flash .6s ease; }
@keyframes flash { 0% { transform: scale(1.3); box-shadow: 0 0 0 3px var(--accent);} 100% { transform: scale(1); box-shadow: none;} }

/* --- 월별 휴무 정책 panel ---------------------------------------------- */
.policy-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .6rem; margin-bottom: .6rem; }
.policy-grid label { font-size: .76rem; color: var(--muted); display: flex; flex-direction: column; gap: .2rem; }
.policy-grid input { font-size: .9rem; padding: .25rem .4rem; border: 1px solid var(--line2); border-radius: 7px; }
.policy-grid input:disabled { background: #f3f4f6; color: var(--muted); }

/* --- Validation panel -------------------------------------------------- */
.val-summary { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: .7rem; }
.val-summary .b { font-size: .8rem; padding: .3rem .65rem; border-radius: 8px; background: #f4f5f7; font-weight: 600; }
.val-summary .b.score { background: var(--ok-bg); color: #065f46; }
.val-summary .b.err { background: var(--bad-bg); color: var(--bad); }
.val-summary .b.err.zero { background: var(--ok-bg); color: #065f46; }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { font-size: .85rem; padding: .3rem 0; display: flex; align-items: center; gap: .5rem; }
.checks .mark { width: 1.2rem; text-align: center; font-weight: 700; }
.checks li.ok .mark { color: var(--ok); }
.checks li.bad .mark { color: var(--bad); }
.err-list { margin: .6rem 0 0; padding-left: 1.1rem; font-size: .8rem; color: var(--bad); }
.val-banner { display: flex; flex-direction: column; gap: .15rem; background: var(--bad-bg); color: var(--bad);
  border: 1px solid var(--bad); border-radius: 8px; padding: .5rem .65rem; margin-bottom: .7rem; }

/* --- Constraint panel -------------------------------------------------- */
.cstr-add { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-bottom: .7rem; }
.cstr-add select, .cstr-add input { font-size: .82rem; padding: .3rem .45rem; border: 1px solid var(--line2); border-radius: 7px; }
.cstr-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.cstr-list li { font-size: .83rem; display: flex; justify-content: space-between; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; padding: .35rem .6rem; }
.cstr-list .del { cursor: pointer; color: var(--bad); border: none; background: none; font-size: .85rem; }

/* --- AI panel ---------------------------------------------------------- */
.ai-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; }
.ai-score { font-size: 1.5rem; font-weight: 800; color: var(--accent); }
.ai-detail { margin-top: .5rem; font-size: .83rem; }
.ai-detail ul { margin: .3rem 0; padding-left: 1.1rem; }
details > summary { cursor: pointer; font-size: .83rem; color: var(--accent); }

/* --- History panel ----------------------------------------------------- */
.history { list-style: none; margin: .6rem 0 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.history li { border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; margin-bottom: .45rem;
  font-size: .8rem; background: #fff; animation: slidein .2s ease; }
.history li.empty-history { border: none; background: none; }
.history .time { color: var(--muted); font-size: .72rem; }
.history .move { margin-top: .15rem; }
.history .arrow { color: var(--accent); margin: 0 .25rem; }
.history li.undone { opacity: .45; text-decoration: line-through; }
@keyframes slidein { from { opacity: 0; transform: translateY(-4px);} to { opacity: 1; transform: none;} }

/* --- Date detail popover ----------------------------------------------- */
.date-detail {
  position: fixed; z-index: 60; background: #fff; border: 1px solid var(--line2);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: .8rem .95rem;
  font-size: .82rem; max-width: 280px;
}
.date-detail h3 { margin: 0 0 .5rem; font-size: .92rem; }
.date-detail .row { margin: .25rem 0; }
.date-detail .k { color: var(--muted); }
.date-detail .close { position: absolute; top: .4rem; right: .55rem; cursor: pointer; color: var(--muted); border: none; background: none; font-size: 1rem; }

/* --- View 2: 캘린더 보기 (macOS Calendar 참고 · 미니멀 · 여백 중심) ---- */
.calendar { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-h {
  padding: .5rem .65rem; text-align: right; font-size: .76rem; font-weight: 600;
  color: var(--muted); background: #fafbfc; border-bottom: 1px solid var(--line);
}
.cal-h.sat { color: #2563eb; }
.cal-h.sun { color: var(--bad); }
/* 조회 우선 — 셀 ≥120px, 휴무·근무 전원 표시(축약 없음). 내용이 많으면 셀이 늘어난다. */
.cal-cell {
  min-height: 124px; padding: .4rem .5rem .55rem; border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: .35rem;
  cursor: pointer; transition: background .12s ease; background: #fff;
}
.cal-grid > .cal-cell:nth-child(7n), .cal-grid > .cal-h:nth-child(7n) { border-right: none; }
.cal-cell.weekend { background: #fcfcfd; }
.cal-cell.empty { background: #fafbfc; cursor: default; min-height: 0; }
.cal-cell:hover:not(.empty) { background: #f7faff; }
.cal-date { font-size: .85rem; font-weight: 700; text-align: right; color: var(--ink); }
.cal-cell.sat .cal-date { color: #2563eb; }
.cal-cell.sun .cal-date { color: var(--bad); }
/* 섹션(휴무 / 근무) — 라벨 + 이름 칩 전체 */
.cal-sec-h { font-size: .68rem; font-weight: 700; margin-bottom: .15rem; }
.cal-sec-h.off { color: var(--off-fg); }
.cal-sec-h.leave { color: #15803d; }
.cal-sec-h.work { color: #374151; }
.cal-names { display: flex; flex-wrap: wrap; gap: 3px; }
.cal-name {
  font-size: .7rem; font-weight: 600; border-radius: 5px; padding: .05rem .35rem; line-height: 1.4;
}
.cal-name.off { background: var(--off-bg); color: var(--off-fg); }
.cal-name.leave { background: #dcfce7; color: #15803d; }
.cal-name.work { background: #eef2f6; color: #374151; }
.cal-name.none { background: none; color: var(--muted); font-weight: 400; padding: 0; }
.cal-parts { margin-top: auto; padding-top: .2rem; font-size: .68rem; color: var(--muted); border-top: 1px dashed var(--line); }

/* 날짜 클릭 상세 Drawer (우측 슬라이드) + 스크림 */
.scrim { position: fixed; inset: 0; background: rgba(17, 24, 39, .18); z-index: 70; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 340px; max-width: 86vw;
  background: #fff; box-shadow: -10px 0 30px rgba(0, 0, 0, .14); z-index: 71;
  padding: 1.2rem 1.35rem; overflow-y: auto; animation: drawerIn .2s ease;
}
@keyframes drawerIn { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer h3 { margin: 0 0 .9rem; font-size: 1.02rem; }
.drawer .close { position: absolute; top: .9rem; right: 1.1rem; cursor: pointer; color: var(--muted); border: none; background: none; font-size: 1.1rem; }
.drawer .sec { margin: .75rem 0; }
.drawer .sec .lbl { font-size: .74rem; color: var(--muted); margin-bottom: .15rem; }
.drawer .sec .val { font-size: .88rem; line-height: 1.45; }
.drawer .d-badge { display: inline-block; font-size: .8rem; font-weight: 600; padding: .25rem .6rem; border-radius: 8px; }
.drawer .d-badge.ok { background: var(--ok-bg); color: #065f46; }
.drawer .d-badge.warn { background: var(--bad-bg); color: var(--bad); }

/* --- Toast ------------------------------------------------------------- */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(2rem);
  background: #111827; color: #fff; padding: .65rem 1.1rem; border-radius: 10px;
  font-size: .85rem; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 80; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: #065f46; }
.toast.bad { background: #991b1b; }
.toast.warn { background: #b45309; }  /* 수정 반영 + 규칙 오류 있음(주의) */
