/* ══════════════════════════════════════════════════════════════════════
   MÀN LỊCH

   Luật chung của dự án: bảng ở màn nhỏ KHÔNG thu nhỏ, mà chuyển hẳn sang
   danh sách. Ở đây cũng vậy — lưới 7 cột ở 360px thì mỗi ô rộng ~45px,
   không chữ nào đọc được. Nên:

     ≤768px   -> chỉ hiện danh sách theo ngày (.cal__agenda)
     ≥769px   -> chỉ hiện lưới tháng (.cal__panel)

   Hai khối cùng đọc một bộ dữ liệu, không có cái nào là bản rút gọn.
══════════════════════════════════════════════════════════════════════ */

.cal {
  padding: var(--space-5);
  display: grid;
  gap: var(--space-5);
  align-content: start;
}

.cal__header {
  display: grid;
  gap: var(--space-3);
}

.cal__title {
  font-size: clamp(var(--fs-md), 5vw, var(--fs-lg));
  font-weight: var(--fw-semi);
}

.cal__subtitle {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.cal__nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Neo cho bang chon thang xo ra */
.cal__month-wrap {
  position: relative;
  min-width: 0;
  flex: 1;
}

.cal__month {
  width: 100%;
  min-height: var(--row-h);
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}

.cal__month[aria-expanded="true"] {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

/* Dau « » — dung ky tu chu khong ve SVG rieng cho hai nut nhay nam */
.cal__double {
  font-size: var(--fs-md);
  line-height: 1;
}

/* ── Bang chon thang / nam ─────────────────────────────────────────── */

.cal__month-picker {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% + var(--space-1));
  left: 50%;
  transform: translateX(-50%);
  width: max(240px, 100%);
  padding: var(--space-3);
  display: grid;
  gap: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.cal__year-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.cal__picker-year {
  flex: 1;
  text-align: center;
  font-weight: var(--fw-medium);
}

.cal__month-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-1);
}

.cal__month-option {
  min-height: var(--row-h);
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.cal__month-option.is-active {
  background: var(--primary);
  color: #fff;
  font-weight: var(--fw-medium);
}

.cal__icon {
  width: var(--space-5);
  height: var(--space-5);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cal__icon--flip { transform: scaleX(-1); }

/* ── Lưới tháng — ẩn ở màn hẹp ─────────────────────────────────────── */

.cal__panel { display: none; }

.cal__weekdays,
.cal__grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal__weekdays {
  border-bottom: 1px solid var(--border);
}

.cal__weekdays span {
  padding: var(--space-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.cal__day {
  min-height: calc(var(--row-h) * 2.4);
  min-width: 0;
  padding: var(--space-2);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: grid;
  align-content: start;
  gap: var(--space-1);
}

/* Bỏ viền mép phải của cột cuối và mép dưới của hàng cuối */
.cal__day:nth-child(7n) { border-right: 0; }
.cal__day:nth-last-child(-n + 7) { border-bottom: 0; }

.cal__day.is-outside { background: var(--surface-2); }
.cal__day.is-outside .cal__day-number { opacity: .45; }

.cal__day-number {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.cal__day.is-today .cal__day-number {
  width: var(--space-6);
  height: var(--space-6);
  display: grid;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  font-weight: var(--fw-semi);
}

.cal__day-items {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.cal__day-more {
  color: var(--text-muted);
  font-size: var(--fs-xs);
}

/* ── Một việc trên lịch ────────────────────────────────────────────── */

.cal__item {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-1);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-xs);
  text-align: left;
}

.cal__item-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: var(--radius-full);
  background: var(--text-muted);
}

/* Cùng bộ màu độ gấp với chip hạn ở màn Tasks */
.cal__item.is-overdue .cal__item-dot { background: var(--due-overdue); }
.cal__item.is-today .cal__item-dot { background: var(--due-today); }
.cal__item.is-soon .cal__item-dot { background: var(--due-soon); }
.cal__item.is-done .cal__item-dot { background: var(--success); }

.cal__item-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal__item.is-done .cal__item-title {
  color: var(--text-muted);
  text-decoration: line-through;
}

/* ── Danh sách theo ngày — bản dùng ở màn hẹp ──────────────────────── */

.cal__agenda {
  display: grid;
  gap: 0;
  overflow: hidden;
}

.cal__agenda-day {
  padding: var(--space-4);
  display: grid;
  gap: var(--space-2);
}

.cal__agenda-day + .cal__agenda-day {
  border-top: 1px solid var(--border);
}

.cal__agenda-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.cal__agenda-date {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

.cal__agenda-items {
  display: grid;
  gap: var(--space-1);
}

/* Ở danh sách thì có chỗ, cho chữ to hơn và cao hơn cho dễ chạm */
.cal__agenda-items .cal__item {
  min-height: var(--row-h);
  padding: var(--space-2);
  font-size: var(--fs-base);
  background: none;
}

.cal__empty-icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ══ 769px trở lên: đổi sang lưới tháng ═══════════════════════════════ */
@media (min-width: 769px) {
  .cal__panel { display: block; }
  .cal__agenda { display: none; }

  .cal__header {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .cal__nav { flex: none; }
  .cal__month-wrap { flex: none; min-width: 12ch; }
}

@media (min-width: 1280px) {
  .cal { padding: var(--space-6) var(--space-8); }
  .cal__day { min-height: calc(var(--row-h) * 3); }
}

@media (hover: hover) {
  .cal__month:hover { background: var(--surface-hover); }
  .cal__month-option:hover { background: var(--surface-hover); }
  .cal__month-option.is-active:hover { background: var(--primary); }
  .cal__item:hover { background: var(--surface-hover); }
  .cal__day:hover { background: var(--surface-hover); }
  .cal__day.is-outside:hover { background: var(--surface-2); }
}
