/* =============================================================
   달력 페이지 — 좌측 캘린더 패널 + 우측 그리드
   ============================================================= */

/* ---------- 좌측 패널 ---------- */
.cal-panel {
  width: 248px; min-width: 248px; height: 100%;
  border-right: 1px solid var(--card-border); background: var(--surface);
  display: flex; flex-direction: column; overflow: hidden;
}
.cal-panel-top { padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 10px; }
.btn-create {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 14px; font-weight: 700; box-shadow: var(--shadow-1);
}
.btn-create:hover { filter: brightness(1.06); }
.panel-quicklink {
  display: block; text-decoration: none; color: var(--muted);
  font-size: 12px; font-weight: 600; padding: 5px 6px; border-radius: 6px;
}
.panel-quicklink:hover { background: var(--surface-2); color: var(--fg); }

/* 미니 달력 */
.mini-cal { padding: 0 12px 8px; }
.mini-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px 6px; }
.mini-title { font-size: 12.5px; font-weight: 700; }
.mini-nav { display: flex; gap: 2px; }
.mini-nav button { border: 0; background: none; color: var(--muted); padding: 2px 6px; border-radius: 5px; }
.mini-nav button:hover { background: var(--surface-2); color: var(--fg); }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.mini-grid .dow { font-size: 10px; color: var(--faint); text-align: center; padding: 2px 0; font-weight: 600; }
.mini-grid .dow.sun { color: var(--danger); }
.mini-grid button {
  border: 0; background: none; aspect-ratio: 1; font-size: 11px; border-radius: 50%;
  color: var(--fg); padding: 0; line-height: 1;
}
.mini-grid button.out { color: var(--faint); }
.mini-grid button.hol { color: var(--danger); }
.mini-grid button:hover { background: var(--surface-2); }
.mini-grid button.today { font-weight: 800; color: var(--accent); }
.mini-grid button.sel { background: var(--accent); color: #fff; font-weight: 700; }

/* 캘린더 목록 */
.cal-list { flex: 1; overflow-y: auto; padding: 4px 8px 20px; }
.cal-group-title {
  font-size: 11px; font-weight: 700; color: var(--faint); letter-spacing: .03em;
  padding: 12px 8px 5px; text-transform: none;
}
.cal-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 7px; position: relative;
}
.cal-item:hover { background: var(--surface-2); }
.cal-item input[type=checkbox] {
  appearance: none; width: 15px; height: 15px; min-width: 15px; border-radius: 4px;
  border: 2px solid var(--cal-color, var(--primary)); margin: 0; position: relative;
}
.cal-item input[type=checkbox]:checked { background: var(--cal-color, var(--primary)); }
.cal-item input[type=checkbox]:checked::after {
  content: ''; position: absolute; left: 4px; top: 1px; width: 3px; height: 7px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.cal-item-text { flex: 1; min-width: 0; }
.cal-item-label {
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.cal-item-sub {
  font-size: 10.5px; color: var(--faint); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.cal-item-menu {
  border: 0; background: none; color: var(--faint); padding: 2px 4px;
  border-radius: 5px; opacity: 0; font-size: 14px; line-height: 1;
}
.cal-item:hover .cal-item-menu, .cal-item-menu:focus { opacity: 1; }
.cal-bell { font-size: 10px; opacity: .55; }

/* ---------- 우측 메인 ---------- */
.cal-main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.cal-toolbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px;
  border-bottom: 1px solid var(--card-border); background: var(--surface); flex-wrap: wrap;
}
.cal-nav { display: flex; align-items: center; gap: 4px; }
.cal-nav button {
  border: 1px solid var(--card-border); background: var(--surface);
  border-radius: 7px; padding: 5px 9px; color: var(--muted);
}
.cal-nav button:hover { background: var(--surface-2); color: var(--fg); }
.btn-today { font-weight: 600; padding: 5px 12px !important; color: var(--fg) !important; }
.cal-period { font-size: 17px; font-weight: 800; letter-spacing: -.02em; margin-left: 4px; }
.cal-spacer { flex: 1; }
.view-switch { display: flex; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.view-switch button {
  border: 0; background: none; padding: 5px 11px; border-radius: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
}
.view-switch button[aria-selected="true"] { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-1); }

.cal-body { flex: 1; overflow: auto; position: relative; }

/* ---------- 월 보기 ---------- */
.month-dow {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--card-border); background: var(--surface);
  position: sticky; top: 0; z-index: 3;
}
.month-dow div {
  text-align: center; padding: 7px 0; font-size: 11.5px; font-weight: 700; color: var(--muted);
}
.month-dow div.sun { color: var(--danger); }
.month-dow div.sat { color: var(--primary); }

.month-grid { display: flex; flex-direction: column; min-height: calc(100% - 30px); }
.month-week {
  flex: 1; display: grid; grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--line); position: relative; min-height: 108px;
}
.month-day { border-right: 1px solid var(--line); padding: 2px 3px 4px; min-width: 0; position: relative; }
.month-day:last-child { border-right: 0; }
.month-day.out { background: oklch(98.6% 0.003 260); }
.month-day.today .day-num { background: var(--accent); color: #fff; border-radius: 999px; }
.day-head { display: flex; align-items: center; gap: 4px; padding: 3px 2px; }
.day-num {
  font-size: 11.5px; font-weight: 700; min-width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
}
.month-day.sun .day-num { color: var(--danger); }
.month-day.sat .day-num { color: var(--primary); }
.month-day.out .day-num { color: var(--faint); }
.day-hol { font-size: 10px; color: var(--danger); font-weight: 600; overflow: hidden;
           text-overflow: ellipsis; white-space: nowrap; }

/* 기간 막대 레인 */
.week-bars { position: absolute; left: 0; right: 0; top: 26px; pointer-events: none; z-index: 2; }
.bar {
  position: absolute; height: 18px; line-height: 18px; border-radius: 4px;
  font-size: 11px; font-weight: 600; padding: 0 6px; color: #fff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  pointer-events: auto; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.04);
}
.bar:hover { filter: brightness(1.08); }
.bar.cont-l { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.cont-r { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.bar.masked { opacity: .45; font-style: italic; }

.day-events { display: flex; flex-direction: column; gap: 1px; position: relative; z-index: 1; }
.ev-chip {
  display: flex; align-items: center; gap: 4px; font-size: 11px; padding: 1px 4px;
  border-radius: 4px; cursor: pointer; overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis; line-height: 1.5;
}
.ev-chip:hover { background: var(--surface-2); }
.ev-dot { width: 7px; height: 7px; min-width: 7px; border-radius: 50%; }
.ev-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 10.5px; }
.ev-title { overflow: hidden; text-overflow: ellipsis; }
.ev-chip.masked .ev-title { color: var(--faint); font-style: italic; }
.ev-chip.done .ev-title { text-decoration: line-through; color: var(--faint); }
.day-more { font-size: 10.5px; color: var(--muted); padding: 1px 5px; border: 0; background: none;
            text-align: left; border-radius: 4px; }
.day-more:hover { background: var(--surface-2); }

/* ---------- 주/일 보기 ---------- */
.tg-wrap { display: flex; flex-direction: column; height: 100%; }
.tg-allday {
  display: grid; border-bottom: 2px solid var(--card-border);
  background: var(--surface); position: sticky; top: 0; z-index: 4;
}
.tg-allday-label { font-size: 10.5px; color: var(--faint); padding: 6px 4px; text-align: right;
                   border-right: 1px solid var(--line); }
.tg-allday-cell { border-right: 1px solid var(--line); padding: 3px; min-height: 34px;
                  display: flex; flex-direction: column; gap: 2px; }
.tg-head { display: grid; border-bottom: 1px solid var(--card-border); background: var(--surface);
           position: sticky; top: 0; z-index: 4; }
.tg-head .gut { border-right: 1px solid var(--line); }
.tg-head-cell { text-align: center; padding: 6px 0; border-right: 1px solid var(--line); }
.tg-head-dow { font-size: 11px; font-weight: 600; color: var(--muted); }
.tg-head-num { font-size: 17px; font-weight: 700; }
.tg-head-cell.today .tg-head-num { color: var(--accent); }
.tg-head-cell.sun .tg-head-dow, .tg-head-cell.sun .tg-head-num { color: var(--danger); }

.tg-scroll { flex: 1; overflow-y: auto; }
.tg-grid { display: grid; position: relative; }
.tg-gutter { border-right: 1px solid var(--line); }
.tg-hour-label {
  height: 44px; font-size: 10.5px; color: var(--faint); text-align: right;
  padding-right: 6px; transform: translateY(-6px);
}
.tg-col { border-right: 1px solid var(--line); position: relative; }
.tg-hour-line { height: 44px; border-bottom: 1px solid var(--line); }
.tg-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 5; }
.tg-now::before { content:''; position:absolute; left:-4px; top:-3px; width:8px; height:8px;
                  border-radius:50%; background: var(--danger); }
.tg-ev {
  position: absolute; border-radius: 5px; padding: 2px 5px; font-size: 11px;
  color: #fff; overflow: hidden; cursor: pointer; box-shadow: var(--shadow-1);
}
.tg-ev:hover { filter: brightness(1.08); z-index: 6; }
.tg-ev b { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-ev span { font-size: 10px; opacity: .85; }
.tg-ev.masked { opacity: .5; }

/* ---------- 일정(Agenda) 보기 ---------- */
.agenda { padding: 8px 18px 60px; max-width: 860px; }
.agenda-day { display: flex; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.agenda-date { width: 88px; min-width: 88px; }
.agenda-date .d { font-size: 22px; font-weight: 800; line-height: 1.1; }
.agenda-date .w { font-size: 11.5px; color: var(--muted); }
.agenda-date.today .d, .agenda-date.today .w { color: var(--accent); }
.agenda-date.sun .d, .agenda-date.sun .w { color: var(--danger); }
.agenda-items { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.agenda-row {
  display: flex; align-items: center; gap: 9px; padding: 6px 9px;
  border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.agenda-row:hover { background: var(--surface); border-color: var(--card-border); }
.agenda-time { font-size: 11.5px; color: var(--muted); width: 92px; min-width: 92px;
               font-variant-numeric: tabular-nums; }
.agenda-title { font-weight: 600; flex: 1; }
.agenda-cal { font-size: 11px; color: var(--faint); }
.agenda-empty { color: var(--faint); font-size: 12.5px; padding: 40px 0; text-align: center; }

/* ---------- 연간 보기 (엑셀 대체) ---------- */
.year-wrap { padding: 0 0 60px; }
.year-toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 18px; flex-wrap: wrap; }
.year-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.year-table th {
  position: sticky; top: 0; z-index: 2; background: var(--surface);
  border: 1px solid var(--line); padding: 6px 4px; font-weight: 700; color: var(--muted);
}
.year-table td { border: 1px solid var(--line); vertical-align: top; padding: 3px; }
.year-table td.meta { text-align: center; font-weight: 700; color: var(--muted);
                      background: var(--surface-2); white-space: nowrap; width: 42px; }
.year-table td.todo { width: 260px; background: oklch(99% 0.004 260); }
.year-day-num { font-size: 10px; color: var(--faint); display: block; margin-bottom: 2px; }
.year-day-num.hol { color: var(--danger); font-weight: 700; }
.year-chip {
  display: block; font-size: 10.5px; padding: 1px 4px; border-radius: 3px;
  margin-bottom: 1px; cursor: pointer; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: #fff; font-weight: 600;
}
.year-todo-item { display: flex; gap: 5px; font-size: 11px; padding: 1px 0; cursor: pointer; }
.year-todo-item .n { color: var(--faint); min-width: 12px; }
.year-todo-item.sub { padding-left: 14px; color: var(--muted); }
.year-todo-item:hover { background: var(--surface-2); }

@media (max-width: 900px) {
  .cal-panel {
    position: fixed; left: 0; top: var(--navbar-h); bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-3);
  }
  .cal-panel.open { transform: none; }
  .cal-panel-toggle { display: inline-flex !important; }
}
.cal-panel-toggle { display: none; }

/* ---------- 날짜 클릭 / 드래그 선택 ---------- */
.month-day.sel-range {
  background: var(--accent-weak);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.month-day.sel-range.out { background: var(--accent-weak); }

.tg-ghost {
  position: absolute; left: 2px; right: 3px; z-index: 4;
  background: var(--accent-weak);
  border: 1px solid var(--accent);
  border-radius: 5px; pointer-events: none;
}

/* 드래그 중 텍스트가 선택되지 않도록 */
.month-grid, .tg-col { user-select: none; }

/* 터치에서 드래그 선택이 스크롤로 가로채이지 않게 */
.month-day { touch-action: none; }
