/* ── Calendar tool ── */

main.wide .page-layout {
  max-width: 1440px;
}

main.wide .page-layout > .container {
  flex: 1 1 auto;
  max-width: none;
}

.cal-intro { margin-bottom: var(--stack-md); }
.cal-intro .back-link { margin-top: 0; margin-bottom: var(--stack-xs); }

.cal-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 48px;
  align-items: start;
}

/* ── Controls ── */
.cal-controls {
  position: sticky;
  top: var(--stack-sm);
  max-height: calc(100vh - 2 * var(--stack-sm));
  overflow-y: auto;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: var(--stack-md);
}

.cal-controls fieldset {
  border: none;
  display: flex;
  flex-direction: column;
  gap: var(--stack-sm);
}

.cal-controls legend {
  font-family: 'Libre Caslon Text', Georgia, serif;
  font-size: 24px;
  line-height: 1.4;
  padding: 0 0 var(--stack-xs);
  width: 100%;
  border-bottom: 0.5px solid var(--outline-variant);
  margin-bottom: var(--stack-sm);
}

.cal-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--stack-sm);
}

.cal-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.cal-caption,
.cal-controls output {
  font-family: 'Work Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
}

.cal-controls output { color: var(--on-surface); text-transform: none; }

.cal-controls select,
.cal-controls input[type="number"] {
  font-family: 'Libre Caslon Text', Georgia, serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--on-surface);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--outline);
  border-radius: 0;
  padding: 0.3rem 0;
  width: 100%;
  outline: none;
  text-transform: none;
  letter-spacing: normal;
}

.cal-controls select:focus,
.cal-controls input[type="number"]:focus {
  border-bottom: 2px solid var(--primary);
  padding-bottom: calc(0.3rem - 1px);
}

.cal-controls select option { background: var(--surface); }

.cal-unit {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  text-transform: none;
}

.cal-unit input[type="number"] { flex: 1; min-width: 0; }

.cal-controls input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

/* Segmented radio group */
.cal-seg {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--outline);
  width: fit-content;
  max-width: 100%;
}

.cal-seg > label {
  position: relative;
  flex-direction: row;
  gap: 0;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  color: var(--on-surface);
  border-left: 1px solid var(--outline);
  line-height: 1.2;
  user-select: none;
}

.cal-seg > label:first-child { border-left: none; }

.cal-seg input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.cal-seg > label:has(input:checked) {
  background: var(--primary);
  color: var(--on-primary);
}

.cal-seg > label:has(input:focus-visible) {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.cal-seg > label:hover:not(:has(input:checked)) { background: var(--surface-container); }

/* Weekend shade swatches */
.cal-swatches > label {
  width: 40px;
  height: 32px;
  padding: 0;
}

.cal-swatches > label:has(input:checked) {
  background: var(--swatch);
  box-shadow: inset 0 0 0 2px var(--surface), inset 0 0 0 4px var(--primary);
}

.cal-swatches > label,
.cal-swatches > label:hover:not(:has(input:checked)) { background: var(--swatch); }

.cal-actions {
  display: flex;
  gap: var(--stack-sm);
  flex-wrap: wrap;
}

.cal-hint {
  font-size: 15px;
  line-height: 1.5;
  color: var(--on-surface-variant);
}

/* ── Preview ── */
.cal-preview-bar {
  font-family: 'Work Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
  margin-bottom: var(--stack-sm);
}

#cal-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--stack-md);
}

.cal-frame {
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 6px 24px rgba(0, 0, 0, 0.08);
  background: #fff;
  flex: none;
}

/* ── Printed sheet (all sizes in physical units) ── */
.cal-sheet {
  background: #fff;
  color: #000;
  transform-origin: 0 0;
  display: grid;
  line-height: 1.15;
  overflow: hidden;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.cal-month {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.cal-title {
  text-align: center;
  font-size: var(--cal-title-size, 1.6em);
  font-weight: 700;
  line-height: 1.2;
  padding-bottom: 0.3em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-style: solid;
  border-color: #000;
}

.cal-cell {
  border-style: solid;
  border-color: #000;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.15em 0.3em;
  white-space: nowrap;
}

.cal-head {
  font-size: var(--cal-head-size, 0.8em);
  font-weight: 700;
  padding: 0.3em 0.2em;
  text-overflow: ellipsis;
  display: block;
  text-align: center;
}

.cal-sheet.pos-top-left .cal-day { justify-content: flex-start; align-items: flex-start; }
.cal-sheet.pos-top-right .cal-day { justify-content: flex-end; align-items: flex-start; }

@media (max-width: 900px) {
  .cal-layout { grid-template-columns: minmax(0, 1fr); }
  .cal-controls { position: static; max-height: none; overflow: visible; padding-right: 0; }
}

/* ── Print: only the sheets, at true size ── */
@media print {
  html, body { background: #fff !important; }
  body > header,
  body > footer,
  .cal-intro,
  .cal-controls,
  .cal-preview-bar { display: none !important; }

  main,
  main.wide .page-layout,
  main.wide .page-layout > .container,
  .cal-layout,
  .cal-preview,
  #cal-pages {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
    gap: 0 !important;
  }

  .cal-frame {
    width: auto !important;
    height: auto !important;
    box-shadow: none;
    overflow: visible;
    break-after: page;
    page-break-after: always;
  }

  .cal-frame:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .cal-sheet { transform: none !important; }
}
