/* Print layout: one month per A4 landscape page, strictly monochrome.
   Loaded with media="print"; see the Print section of CONTRACT.md. */

/* Browsers disagree on the printable area: Safari ignores `size` and applies
   its own margins, so a month sized in mm overflows there. Instead html, body
   and .calendar are each 100% tall, which in print resolves to one page's
   content height, and every month takes a share of that just short of 100%
   so rounding can never push it onto a second sheet. */
@page {
  size: A4 landscape;
  margin: 10mm;
}

:root {
  --page-h: 98%;
  --line: 0.2mm;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  color: #000 !important;
  background: none !important;
  box-shadow: none !important;
  text-shadow: none !important;
  border-color: #000 !important;
  outline: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  width: auto;
  height: 100%;
  background: #fff !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    Helvetica, Arial, sans-serif;
  font-size: 9pt;
  line-height: 1.2;
}

.toolbar {
  display: none !important;
}

.calendar {
  display: block;
  height: 100%;
  margin: 0;
  padding: 0;
}

/* ---- Which months print ------------------------------------------------ */

.month {
  display: none;
}

.month.is-current,
body.print-year .month {
  display: flex;
}

/* body.print-month wins if both classes are ever present. */
body.print-month .month:not(.is-current) {
  display: none;
}

/* ---- One month = one page ---------------------------------------------- */

.month {
  flex-direction: column;
  width: 100%;
  height: var(--page-h);
  min-height: 120mm; /* still a usable grid if a browser can't resolve the % */
  margin: 0;
  padding: 0;
  overflow: hidden;
  page-break-inside: avoid;
  break-inside: avoid;
}

/* Break between months, never after the last one (no blank trailing page). */
.month + .month {
  page-break-before: always;
  break-before: page;
}

.month-head {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0;
  padding: 0 0 3mm;
}

.month-name,
.month-year {
  margin: 0;
  padding: 0;
  font-size: 22pt;
  line-height: 1;
}

.month-name {
  font-weight: 700;
}

.month-year {
  font-weight: 400;
}

.weekdays {
  flex: none;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekday {
  padding: 0 1.5mm 1mm;
  overflow: hidden;
  font-size: 9pt;
  font-weight: 600;
  white-space: nowrap;
}

/* ---- Day grid: all remaining height, --weeks equal rows ---------------- */

.days {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(var(--weeks, 6), minmax(0, 1fr));
  border-top: var(--line) solid #000;
  border-left: var(--line) solid #000;
}

/* Fallback if the inline --weeks is missing but data-weeks is present. */
.days[data-weeks="4"] { grid-template-rows: repeat(4, minmax(0, 1fr)); }
.days[data-weeks="5"] { grid-template-rows: repeat(5, minmax(0, 1fr)); }
.days[data-weeks="6"] { grid-template-rows: repeat(6, minmax(0, 1fr)); }

.day {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 1mm 1.5mm;
  overflow: hidden;
  border: 0;
  border-right: var(--line) solid #000;
  border-bottom: var(--line) solid #000;
}

.day-num {
  flex: none;
  font-size: 9pt;
  font-weight: 600;
  line-height: 1;
}

.day-text {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  margin: 1mm 0 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  font-size: 7.5pt;
  line-height: 1.2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---- Rendered Markdown ------------------------------------------------- */

.day-text p,
.day-text ul,
.day-text ol {
  margin: 0;
}

.day-text > * + * {
  margin-top: 0.3em;
}

.day-text ul,
.day-text ol {
  padding-left: 1.3em;
}

.day-text .md-task {
  margin-left: -1.3em;
  list-style: none;
}

.day-text .md-box {
  display: inline-block;
  width: 1.3em;
}

.day-text .md-h {
  font-weight: 700;
}

.day-text .md-h1 {
  font-size: 1.15em;
}

.day-text .md-h2 {
  font-size: 1.05em;
}

.day-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.day-text a {
  text-decoration: none;
}

.day-text hr {
  margin: 0.4em 0;
  border: 0;
  border-top: var(--line) solid #000;
}
