/* =========================================================
 * HS Calendar Shell
 * 역할:
 * - 월간 / 주간 / 연간 / 미니 달력의 공통 UI 껍데기
 * - 워크스페이스와 예약 도큐먼트가 같이 사용
 * - 데이터 로딩, 클릭 동작, AJAX는 각 기능 JS가 담당
 * =======================================================*/

/* =========================
 * 0. Variables
 * =======================*/

:root {
  --hs-cal-primary: #984ee2;
  --hs-cal-primary-dark: #7e37c9;
  --hs-cal-primary-soft: #faf5ff;
  --hs-cal-primary-line: #c4b5fd;

  --hs-cal-blue: #2563eb;
  --hs-cal-green: #16a34a;
  --hs-cal-amber: #f59e0b;
  --hs-cal-red: #dc2626;

  --hs-cal-border: #e5e7eb;
  --hs-cal-border-soft: #f1f5f9;
  --hs-cal-bg: #ffffff;
  --hs-cal-soft: #f8fafc;
  --hs-cal-muted: #64748b;
  --hs-cal-text: #111827;

  --hs-cal-radius-lg: 16px;
  --hs-cal-radius-md: 12px;
  --hs-cal-shadow: 0 14px 32px rgba(15, 23, 42, 0.16);

  --week-col-width: 120px;
  --week-hour-height: 60px;
}

/* =========================================================
 * 1. Calendar Header
 * 월간 / 주간 / 연간 공통 상단
 * =======================================================*/

.hs-calendar__header-bar {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 12px !important;
  margin-bottom: 16px !important;
}

.hs-calendar__header-bar .hs-header-left,
.hs-header-left {
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  min-width: 0;
}

.hs-doc-calendar-title-wrap {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.hs-calendar__title {
  font-size: 18px;
  font-weight: 800;
  color: var(--hs-cal-text);
  line-height: 1;
  white-space: nowrap;
}

/* 이전 / 다음 버튼 */
.hs-header-left button,
.hs-calendar__nav-btn {
  all: unset;
  box-sizing: border-box;
  width: 32px;
  height: 32px;
  margin: 0 !important;
  border-radius: 10px;
  background: #f3f4f6;
  color: #475569;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  line-height: 1;
  font-size: 14px;
  font-weight: 800;

  transition:
    background 0.15s ease,
    color 0.15s ease,
    transform 0.15s ease;
}

.hs-header-left button:hover,
.hs-calendar__nav-btn:hover {
  background: #e5e7eb;
  color: #111827;
}

.hs-header-left button:disabled,
.hs-calendar__nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.hs-header-left button[hidden],
.hs-calendar__nav-btn[hidden] {
  display: none !important;
}

/* 주간 / 월간 / 연간 토글 */
.hs-doc-calendar-switch,
.hs-header-mode {
  margin-left: auto !important;
  margin-right: 0 !important;

  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;

  flex: 0 0 auto !important;
  padding: 4px;

  border: 1px solid var(--hs-cal-border);
  border-radius: 12px;
  background: #f3f4f6;
}

.hs-doc-calendar-switch button,
.hs-header-mode button {
  all: unset;
  box-sizing: border-box;

  min-width: 48px;
  height: 32px;
  padding: 0 12px;
  border-radius: 9px;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  color: #6b7280;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  margin: 0 !important;
}

.hs-doc-calendar-switch button.is-active,
.hs-header-mode button.is-active {
  background: #fff;
  color: #111827;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

/* =========================================================
 * 2. Month Calendar
 * =======================================================*/

.hs-calendar__header,
.hs-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0 !important;
}

.hs-calendar__header {
  margin: 0 !important;
  border: 1px solid var(--hs-cal-border);
  border-bottom: 0 !important;
  border-radius: 12px 12px 0 0 !important;
  overflow: hidden;
}

.hs-calendar__header > div,
.hs-calendar__header div {
  height: 36px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-right: 1px solid var(--hs-cal-border);
  background: var(--hs-cal-soft);

  font-size: 12px;
  font-weight: 700;
  color: var(--hs-cal-muted);
  text-align: center;
}

.hs-calendar__header > div:last-child,
.hs-calendar__header div:last-child {
  border-right: 0;
}

.hs-calendar__header > div:first-child,
.hs-calendar__header div:first-child {
  color: #ef4444;
}

.hs-calendar__header > div:last-child,
.hs-calendar__header div:last-child {
  color: #2563eb;
}

.hs-calendar {
  margin-top: 0 !important;
  border-left: 1px solid var(--hs-cal-border);
  border-top: 0 !important;
  border-radius: 0 0 12px 12px !important;
  overflow: visible;
  background: #fff;
}

.hs-calendar__day {
  position: relative;

  min-height: 92px;
  margin: 0 !important;
  padding: 10px;

  border: 0 !important;
  border-top: 1px solid var(--hs-cal-border) !important;
  border-right: 1px solid var(--hs-cal-border) !important;
  border-bottom: 1px solid var(--hs-cal-border) !important;
  border-radius: 0 !important;

  background: #fff;
  box-shadow: none !important;
  cursor: default;

  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 8px;

  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: #64748b;

  transition: background 0.15s ease;
  overflow: visible;
}

.hs-calendar__day:not(.hs-calendar__day--empty) {
  cursor: pointer;
}

.hs-calendar__day:hover {
  background: #fafafa;
  box-shadow: none !important;
}

.hs-calendar__day--empty {
  background: #fafafa;
  cursor: default;
}

.hs-calendar__day-number {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
}

.hs-calendar__day-number--muted {
  color: #cbd5e1;
}

/* 주말 */
.hs-calendar__day.is-sunday,
.hs-mini-day.is-sunday,
.hs-doc-mini-day.is-sunday {
  color: #ef4444;
}

.hs-calendar__day.is-saturday,
.hs-mini-day.is-saturday,
.hs-doc-mini-day.is-saturday {
  color: #3b82f6;
}

/* 오늘 */
.hs-calendar__day--today {
  background: #fff !important;
  border-color: var(--hs-cal-primary-line) !important;
  box-shadow: inset 0 0 0 1px var(--hs-cal-primary) !important;
}

.hs-calendar__day--today .hs-calendar__day-number {
  color: var(--hs-cal-primary-dark);
  font-weight: 800;
}

/* 선택 */
.hs-calendar__day--active {
  background: var(--hs-cal-primary-soft) !important;
  box-shadow: inset 0 0 0 2px var(--hs-cal-primary) !important;
}

.hs-calendar__day--today.hs-calendar__day--active {
  background: var(--hs-cal-primary-soft) !important;
}

/* 기존 active dot 제거 */
.hs-calendar__day--active::after {
  display: none !important;
}

/* 월간 일정 표시 */
.hs-calendar__events {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 2px;
}

.hs-calendar__event-pill {
  border-radius: 3px;
  padding: 3px 5px;
  background: #fff1c2;
  color: #374151;

  font-size: 10px;
  line-height: 1.35;
  font-weight: 700;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hs-calendar__event-pill + .hs-calendar__event-pill {
  background: #ecfdf5;
}

.hs-calendar__more {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--hs-cal-primary-dark);
  text-align: right;
}

/* 워크스페이스 기존 dot/count 호환 */
.hs-calendar__dot {
  display: none !important;
}

.hs-calendar__count {
  position: static !important;

  width: fit-content;
  max-width: 100%;
  margin-top: auto;
  padding: 4px 7px;

  border-radius: 999px;
  background: #111827;
  color: #fff !important;

  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

/* =========================================================
 * 3. Calendar Cell Preview
 * =======================================================*/

.hs-calendar__preview {
  position: absolute;
  top: calc(100% + 8px);
  left: 8px;

  min-width: 220px;
  width: max-content;
  max-width: 320px;

  padding: 12px;

  border: 1px solid #e2e8f0;
  border-radius: 16px;
  background: #fff;

  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.16);

  font-size: 13px;
  z-index: 100;
  text-align: left;

  display: block;
  opacity: 0;
  pointer-events: none;
}

.hs-calendar__preview.is-show {
  opacity: 1;
  pointer-events: auto;
}

.hs-calendar__preview--left {
  left: auto;
  right: 8px;
}

.hs-preview__item {
  padding: 7px 0;
  border-bottom: 1px solid #f1f5f9;

  color: #334155;
  font-size: 13px;
  line-height: 1.4;
  word-break: keep-all;
}

.hs-preview__item:last-child {
  border-bottom: 0;
}

.hs-preview__more {
  margin-top: 8px;
  color: var(--hs-cal-blue);
  font-size: 12px;
  font-weight: 800;
}

@media (hover: none) {
  .hs-calendar__preview {
    display: none !important;
  }
}

/* =========================================================
 * 4. Year View
 * =======================================================*/

.hs-year-grid,
.hs-doc-year-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.hs-year-month-box,
.hs-doc-year-month-box {
  border: 1px solid var(--hs-cal-border);
  border-radius: 14px;
  padding: 18px;
  background: #fff;

  text-align: center;
  cursor: pointer;

  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease;
}

.hs-year-month-box:hover,
.hs-doc-year-month-box:hover {
  border-color: #d8b4fe;
  background: #fcfcff;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.08);
  transform: translateY(-1px);
}

.hs-year-month-title,
.hs-doc-year-month-title {
  margin-bottom: 12px;
  font-size: 17px;
  font-weight: 800;
  color: var(--hs-cal-text);
}

.hs-year-mini-calendar,
.hs-doc-year-mini-calendar {
  margin-top: 10px;
}

.hs-year-month-count {
  font-size: 12px;
  color: #9ca3af;
}

.hs-year-stats {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
}

.hs-year-total {
  font-size: 13px;
  color: #64748b;
}

.stat-green {
  color: #16a34a;
  font-weight: 600;
}

.stat-orange {
  color: #ea580c;
  font-weight: 600;
}

.stat-gray {
  color: #6b7280;
  font-weight: 600;
}

/* =========================================================
 * 5. Mini Calendar
 * =======================================================*/

.hs-mini-grid,
.hs-doc-mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.hs-mini-day,
.hs-doc-mini-day {
  min-height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;

  color: #374151;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  line-height: 28px;

  cursor: pointer;

  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    background 0.12s ease,
    color 0.12s ease;
}

.hs-mini-day.empty,
.hs-doc-mini-day.empty {
  opacity: 0.2;
  cursor: default;
}

.hs-mini-day:hover,
.hs-doc-mini-day:hover {
  background: var(--hs-cal-primary-soft);
  box-shadow:
    0 0 0 1px var(--hs-cal-primary-line) inset,
    0 3px 10px rgba(124, 58, 237, 0.08);
  transform: translateY(-1px);
}

.hs-mini-day.is-today,
.hs-doc-mini-day.is-today {
  outline: none;
  border-color: var(--hs-cal-primary);
  background: #fff;
  color: var(--hs-cal-primary-dark);
  font-weight: 700;
}

.hs-mini-day.is-selected,
.hs-doc-mini-day.is-selected {
  background: var(--hs-cal-primary-soft);
  box-shadow: 0 0 0 2px var(--hs-cal-primary) inset;
  color: var(--hs-cal-primary-dark);
  font-weight: 800;
}

.hs-mini-day.has-event,
.hs-doc-mini-day.has-event {
  background: var(--hs-cal-blue);
  color: #fff;
  font-weight: 700;
}

.hs-mini-day.has-event::after,
.hs-doc-mini-day.has-event::after {
  content: attr(data-count);
  display: block;
  font-size: 9px;
  opacity: 0.8;
}

.hs-mini-day.event-1,
.hs-doc-mini-day.event-1 {
  background: #ede9fe;
  color: #6d28d9;
}

.hs-mini-day.event-2,
.hs-doc-mini-day.event-2 {
  background: #8b5cf6;
  color: #fff;
}

.hs-mini-day.event-3,
.hs-doc-mini-day.event-3 {
  background: #5b21b6;
  color: #fff;
}

/* =========================================================
 * 6. Week View
 * =======================================================*/

.hs-week-wrapper {
  display: flex;
  overflow: visible;
  border-top: 1px solid #eee;
}

.hs-week-times {
  width: 55px;
  flex-shrink: 0;
  border-right: 1px solid #eee;
}

.hs-week-time-spacer {
  height: 40px;
  border-bottom: 1px solid #eee;
}

.hs-week-time-label {
  height: var(--week-hour-height);
  padding-top: 4px;
  padding-right: 6px;

  border-bottom: 1px solid #f3f3f3;

  color: #999;
  font-size: 12px;
  text-align: right;
}

.hs-week-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: visible;
  -webkit-overflow-scrolling: touch;
}

.hs-week-columns {
  display: flex;
  width: max-content;
  min-width: unset;
  scroll-snap-type: x mandatory;
}

.hs-week-column {
  min-width: var(--week-col-width);
  flex-shrink: 0;

  display: flex;
  flex-direction: column;

  border-right: 1px solid #f3f3f3;
  scroll-snap-align: start;
}

.hs-week-column-header {
  height: 40px;
  line-height: 40px;

  border-bottom: 1px solid #eee;

  text-align: center;
  font-weight: 700;
  cursor: pointer;
}

.hs-week-column-body {
  position: relative;
  height: calc(var(--week-hour-height) * 10);

  background-image: linear-gradient(
    to bottom,
    #f8f8f8 1px,
    transparent 1px
  );
  background-size: 100% var(--week-hour-height);
}

.hs-week-column-body::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.hs-week-column--today .hs-week-column-body,
.hs-week-header--today {
  background-color: rgba(152, 78, 226, 0.06);
}

.hs-week-event {
  position: absolute;
  z-index: 10;

  left: 4px;
  right: 4px;

  min-height: 42px;
  padding: 5px 6px;

  border-left: 4px solid transparent;
  border-radius: 8px;

  color: #fff;
  font-size: 12px;

  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);

  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;

  overflow: hidden;
  pointer-events: auto;
}

.hs-event-time {
  font-size: 11px;
  font-weight: 700;
}

.hs-event-title {
  font-size: 12px;
  font-weight: 700;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hs-event-school {
  font-size: 11px;
  opacity: 0.85;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
 * 7. Modal Shell
 * 위치/크기는 화면별 CSS에서 override 가능
 * =======================================================*/

.hs-calendar-modal,
.hs-doc-modal,
.hs-modal {
  overscroll-behavior: contain;
}

.hs-doc-modal[hidden],
.hs-calendar-modal[hidden] {
  display: none !important;
}

.hs-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
}

.hs-modal__overlay,
.hs-detail-overlay,
.hs-doc-modal__backdrop,
.hs-calendar-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.36);
}

.hs-modal__content,
.hs-doc-modal__dialog,
.hs-calendar-modal__dialog {
  position: relative;

  width: min(430px, calc(100% - 28px));
  max-height: min(72vh, 560px);
  margin: 80px auto 0;

  border-radius: 10px;
  background: #fff;
  overflow: hidden;

  display: flex;
  flex-direction: column;

  box-shadow: var(--hs-cal-shadow);
}

.hs-doc-modal__head,
.hs-calendar-modal__head {
  min-height: 52px;
  padding: 14px 16px;

  border-bottom: 1px solid var(--hs-cal-border-soft);

  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hs-doc-modal__title,
.hs-calendar-modal__title,
#hs-modal-title {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  color: #111827;
}

.hs-doc-modal__body,
.hs-calendar-modal__body,
#hs-modal-body,
#hs-detail-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.hs-doc-modal__close,
.hs-calendar-modal__close,
#hs-modal-close,
#hs-detail-close {
  all: unset !important;
  box-sizing: border-box !important;

  width: 28px !important;
  height: 28px !important;
  margin: 0 !important;
  border-radius: 999px !important;

  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;

  background: transparent !important;
  color: #64748b !important;

  font-size: 22px !important;
  line-height: 1 !important;
  cursor: pointer !important;
}

.hs-doc-modal__close:hover,
.hs-calendar-modal__close:hover,
#hs-modal-close:hover,
#hs-detail-close:hover {
  background: #f1f5f9 !important;
  color: #111827 !important;
}

/* =========================================================
 * 8. Responsive
 * =======================================================*/

@media (max-width: 768px) {
  .hs-week-times {
    width: 45px;
  }

  .hs-week-column {
    min-width: 130px;
  }

  .hs-week-columns {
    min-width: 900px;
  }
}

@media (max-width: 640px) {
  .hs-calendar__header-bar {
    gap: 10px !important;
  }

  .hs-calendar__title {
    font-size: 14px;
  }

  .hs-doc-calendar-switch button,
  .hs-header-mode button {
    min-width: 38px;
    height: 30px;
    padding: 0 8px;
    font-size: 12px;
  }

  .hs-calendar__day {
    min-height: 74px;
    padding: 6px;
  }

  .hs-calendar__day-number {
    font-size: 12px;
  }

  .hs-calendar__event-pill {
    font-size: 9px;
    padding: 2px 4px;
  }

  .hs-calendar__count {
    font-size: 10px;
    padding: 4px 6px;
  }

  .hs-year-grid,
  .hs-doc-year-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 0 8px 10px;
  }

  .hs-year-month-box,
  .hs-doc-year-month-box {
    padding: 10px;
  }

  .hs-modal__content,
  .hs-doc-modal__dialog,
  .hs-calendar-modal__dialog {
    width: calc(100% - 24px);
    max-height: min(72vh, 520px);
    margin-top: 56px;
  }
}

/* =========================================================
 * Outside month days
 * 이전/다음 달 날짜 표시
 * =======================================================*/

.hs-calendar__day--outside {
  background: #fafafa !important;
  color: #94a3b8;
}

.hs-calendar__day--outside:hover {
  background: #f8fafc !important;
}

.hs-calendar__day--outside .hs-calendar__day-number {
  color: #cbd5e1;
}

.hs-calendar__day--outside .hs-calendar__count {
  opacity: 0.75;
}

.hs-calendar__day--outside .hs-calendar__preview {
  color: #334155;
}