.calendar-options,
.calendar-months {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.calendar-toggles,
.calendar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 12px;
}

.calendar-toggles label {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: 8px;
  cursor: pointer;
  font-size: 0.875rem;
}

.calendar-toggles input {
  width: 24px;
  height: 24px;
  margin: 0;
}

.calendar-actions {
  gap: 8px;
}

.calendar-actions .zt-hint {
  margin-inline-start: auto;
}

#calendar-progress {
  margin-top: 12px;
}

.calendar-preview {
  margin-top: 24px;
  border-top: 1px solid var(--ws-line);
  padding-top: 16px;
}

.calendar-preview h2 {
  font-size: var(--fs-h2);
  margin: 0 0 12px;
}

.calendar-month {
  width: 100%;
  align-self: start;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.calendar-month caption {
  border: 1px solid var(--ws-line-strong);
  border-bottom: 0;
  text-align: left;
  padding: 5px 8px;
  font: 400 1.5rem/1.2 var(--font-display);
}

.calendar-month td,
.calendar-month th {
  height: 26px;
  padding: 1px 0;
  border: 1px solid var(--ws-line);
}

.calendar-month thead th,
.calendar-month tbody th {
  background: var(--ws-2);
  color: var(--ws-dim);
  font-size: 0.75rem;
}

.calendar-month tbody th {
  font-weight: 400;
}
.calendar-month thead .calendar-week { width: 9%; }
.calendar-month .calendar-week { background: transparent; }
#calendar-week-note { margin: 0 0 8px; }

.calendar-month tr > :first-child {
  border-left-color: var(--ws-line-strong);
}

.calendar-month tr > :last-child {
  border-right-color: var(--ws-line-strong);
}

.calendar-month tbody tr:last-child > * {
  border-bottom-color: var(--ws-line-strong);
}

.calendar-shaded .calendar-weekend {
  background: var(--ws-2);
}

.calendar-detail .calendar-months {
  grid-template-columns: minmax(0, 1fr);
}

.calendar-detail td {
  height: 60px;
  vertical-align: top;
}

@media screen and (max-width: 780px) {
  .calendar-options,
  .calendar-months {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .calendar-detail .calendar-months { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-detail td { height: 30px; }
}

@media screen and (max-width: 520px) {
  .calendar-options {
    gap: 8px;
  }
  .calendar-preview .calendar-months { gap: 8px; }
  .calendar-preview .calendar-month,
  .calendar-preview .calendar-month th { font-size: 0.6875rem; }
  .calendar-preview .calendar-month caption { padding: 3px 4px; font-size: 1.125rem; }
  .calendar-year .calendar-month :is(th, td) { height: 19px; }
  .calendar-actions .zt-primary {
    width: auto;
    flex: 1 1 auto;
  }
  .calendar-actions .zt-hint {
    width: 100%;
    margin: 0;
  }
}

@page calendarA4Landscape { size: A4 landscape; margin: 10mm; }
@page calendarA4Portrait { size: A4 portrait; margin: 10mm; }
@page calendarLetterLandscape { size: letter landscape; margin: 10mm; }
@page calendarLetterPortrait { size: letter portrait; margin: 10mm; }

@media print {
  body,
  #tool,
  .calendar-preview {
    display: block;
    color: #000;
    background: #fff;
    width: auto;
    max-width: none;
    padding: 0;
    margin: 0;
    border: 0;
  }
  body > :not(main),
  main > :not(.zt-tool-page),
  .zt-tool-page > :not(#tool),
  #tool > :not(.calendar-preview) {
    display: none !important;
  }
  .zt-container,
  .zt-tool-page {
    max-width: none;
    padding: 0;
    margin: 0;
  }
  .calendar-a4-landscape { page: calendarA4Landscape; }
  .calendar-a4-portrait { page: calendarA4Portrait; }
  .calendar-letter-landscape { page: calendarLetterLandscape; }
  .calendar-letter-portrait { page: calendarLetterPortrait; }
  .calendar-preview {
    print-color-adjust: exact;
  }
  .calendar-year .calendar-months {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3mm;
  }
  .calendar-year:is(.calendar-a4-landscape, .calendar-letter-landscape) .calendar-months {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .calendar-year h2 {
    font: 400 20pt/1.1 var(--font-display);
    margin: 0 0 3mm;
  }
  .calendar-month {
    break-inside: avoid;
    font-size: 9pt;
  }
  .calendar-month caption {
    font-size: 12pt;
    padding: 1mm 2mm;
  }
  .calendar-year .calendar-month :is(th, td) { height: 7.5mm; }
  .calendar-year:is(.calendar-a4-landscape, .calendar-letter-landscape) .calendar-month :is(th, td) { height: 6.5mm; }
  .calendar-year.calendar-letter-portrait .calendar-month :is(th, td) { height: 6.7mm; }
  .calendar-detail h2 {
    display: none;
  }
  .calendar-detail .calendar-months {
    display: block;
  }
  .calendar-detail table + table {
    break-before: page;
  }
  .calendar-detail caption {
    font-size: 22pt;
  }
  .calendar-detail td,
  .calendar-detail tbody th {
    height: 24mm;
    vertical-align: top;
    padding-top: 2mm;
  }
  .calendar-detail:is(.calendar-a4-portrait, .calendar-letter-portrait) td,
  .calendar-detail:is(.calendar-a4-portrait, .calendar-letter-portrait) tbody th {
    height: 35mm;
  }
}

.calendar-options { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.calendar-more .calendar-options { grid-template-columns: repeat(auto-fit, minmax(min(8rem, 100%), 1fr)); }
.calendar-more { margin-top: 8px; }
.calendar-more summary { min-height: 44px; width: fit-content; padding: 8px 4px; cursor: pointer; }
.calendar-result { margin-top: 10px; padding: 12px; }
.calendar-result output { display: block; font-size: 1.5rem; font-weight: 600; }
.calendar-result .zt-explain { margin: 2px 0; }
.calendar-result .zt-link, #tool .zt-next-tool a { min-height: 44px; }
.calendar-result .zt-hint { margin: 6px 0 0; }

.calendar-options .zt-field small { max-width: none; }
.calendar-result .calendar-actions { margin-top: 6px; }

.calendar-month tfoot td { text-align: left; padding: 4px 6px; font-size: .8em; line-height: 1.25; }
.calendar-month td[title] strong { text-decoration: underline; text-underline-offset: 2px; }
@media print {
  .calendar-preview.calendar-year .calendar-month:has(tfoot) tfoot td { height: auto; padding: .5mm; font-size: 7pt; }
  .calendar-preview.calendar-year:has(tfoot) .calendar-month :is(tbody td, tbody th, thead th) { height: 4.7mm; }
  .calendar-preview.calendar-detail .calendar-month tfoot td { height: auto; padding: 2mm; font-size: 11pt; }
}
