:root {
  --page-width: 11in;
  --page-height: 8.5in;
  --print-margin-x: 0.22in;
  --print-margin-y: 0.2in;
  --content-width: calc(var(--page-width) - (2 * var(--print-margin-x)));
  --content-height: calc(var(--page-height) - (2 * var(--print-margin-y)));
  --paper-bg: #fffefc;
  --border: #3f3f3f;
  --grid: #6b6b6b;
  --muted: #6d6d6d;
  --ink: #111;
  --panel: #efede5;
  --accent: #87714e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 11px;
  color: var(--ink);
  background: #ece8df;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  padding: 10px;
}

.top-toolbar {
  width: min(calc(100vw - 20px), var(--content-width));
  margin: 0 auto 4px;
  padding: 5px 6px;
  border: 1px solid rgba(63, 63, 63, 0.14);
  border-radius: 0;
  background: #f7f5ef;
  box-shadow: none;
}

.button-row {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.button-row button {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: #fff;
  cursor: pointer;
  font-size: 10px;
}

.sheet-writing-color {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-bottom: 6px;
}

.sheet-writing-color-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.writing-color-button {
  width: 32px;
  height: 28px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.writing-color-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.writing-color-modal {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.writing-color-modal[hidden] {
  display: none !important;
}

.writing-color-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.writing-color-modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 320px;
  padding: 18px 20px 16px;
  border: 1px solid var(--border);
  background: #fffefc;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

.writing-color-modal-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.writing-color-modal-hint {
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
}

.writing-color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 16px;
}

.writing-color-swatch {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.writing-color-swatch:hover {
  transform: scale(1.06);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.writing-color-swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.writing-color-modal-close {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
}

.writing-color-modal-close:hover {
  background: var(--panel);
}

.sheet {
  width: min(calc(100vw - 20px), var(--content-width));
  min-height: min(
    calc((100vw - 20px) * (var(--content-height) / var(--content-width))),
    var(--content-height)
  );
  margin: 0 auto;
  aspect-ratio: calc(var(--content-width) / var(--content-height));
  padding: 0.12in 0.14in 0.1in;
  border: 1px solid rgba(63, 63, 63, 0.18);
  border-radius: 0;
  background: #fff;
  box-shadow: 0 4px 18px rgba(16, 16, 12, 0.08);
}

.form-section {
  width: 100%;
}

.form-header {
  margin-bottom: 4px;
}

.header-title-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  gap: 8px;
  align-items: center;
}

.header-center h2 {
  margin: 0;
  text-align: center;
  font-family: Georgia, serif;
  font-size: 0.39in;
  line-height: 0.95;
  letter-spacing: 0.015em;
  text-transform: none;
  text-shadow: none;
  white-space: nowrap;
}

.field-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px;
  align-items: center;
  margin-bottom: 3px;
}

.field-row.right-align {
  grid-template-columns: auto 1fr;
}

.field-row label {
  font-size: 0.095in;
  white-space: nowrap;
}

.field-row input {
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  padding: 0 2px;
  min-width: 0;
  font-size: 0.095in;
  height: 0.18in;
}

.week-field-value.week-date-single-line {
  position: relative;
  min-width: 0;
  width: 100%;
}

.week-field-row .week-field-value {
  min-width: 0;
}

.week-range-visible {
  width: 100%;
  min-width: 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  padding: 0 2px;
  font-size: 0.09in;
  height: 0.18in;
  box-sizing: border-box;
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow-x: auto;
}

.week-date-picker-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* Flatpickr popup above sheet/toolbar */
.flatpickr-calendar {
  z-index: 99999;
}

/* Current week (Sun–Sat): today = red, other days = green */
.flatpickr-day.today.fdt-week-today,
.flatpickr-day.fdt-week-today,
.flatpickr-day.fdt-week-today:focus,
.flatpickr-day.fdt-week-today:hover {
  background: #c62828;
  border-color: #b71c1c;
  color: #fff;
}

.flatpickr-day.fdt-week-sibling,
.flatpickr-day.fdt-week-sibling:focus,
.flatpickr-day.fdt-week-sibling:hover {
  background: #e8f5e9;
  border-color: #81c784;
  color: #1b5e20;
}

.flatpickr-day.selected.fdt-week-today,
.flatpickr-day.startRange.fdt-week-today,
.flatpickr-day.endRange.fdt-week-today {
  background: #c62828;
  border-color: #b71c1c;
  color: #fff;
}

/* Same fill as other week days; selection is the date stored in the input (usually Monday). */
.flatpickr-day.selected.fdt-week-sibling,
.flatpickr-day.startRange.fdt-week-sibling,
.flatpickr-day.endRange.fdt-week-sibling {
  background: #e8f5e9;
  border-color: #81c784;
  color: #1b5e20;
  box-shadow: inset 0 0 0 2px #2e7d32;
}

.timesheet-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  border: 1.5px solid var(--border);
}

.timesheet-table th,
.timesheet-table td {
  border: 1px solid var(--grid);
  padding: 0;
  vertical-align: middle;
}

.timesheet-table thead th {
  height: 0.39in;
  padding: 1px 2px;
  font-size: 0.09in;
  text-align: center;
  background: transparent;
}

.timesheet-table tbody td {
  height: 0.21in;
}

.col-day-label {
  width: 7%;
}

.col-date {
  width: 9%;
}

.col-period {
  width: 3%;
}

.col-teacher {
  width: 15%;
}

.col-reason {
  width: 10%;
}

.col-level {
  width: 8%;
}

.col-minutes {
  width: 8%;
}

.col-conversion {
  width: 14%;
}

.col-details {
  width: 18%;
}

.col-cost {
  width: 8%;
}

.day-cell {
  padding: 4px 6px;
  font-size: 0.11in;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
  line-height: 1.35;
}

.date-cell {
  padding: 4px 6px;
  font-size: 0.098in;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
  line-height: 1.25;
}

.period-cell {
  padding: 1px 2px;
  font-size: 0.084in;
  color: var(--muted);
  text-align: center;
}

.date-cell .cycle {
  display: block;
  margin-top: 2px;
}

.col-cost .rh-badge,
.col-cost .cost-title {
  display: block;
}

.col-cost .rh-badge {
  width: fit-content;
  margin: 0 auto 2px;
  padding: 1px 4px;
  border: 1px solid var(--grid);
  font-size: 0.07in;
  font-weight: 400;
}

.col-cost .cost-title {
  line-height: 1.1;
}

.cell-input,
.cell-textarea,
.time-field {
  width: 100%;
  height: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0 2px;
  font-size: 0.084in;
}

.cell-textarea {
  resize: none;
  overflow: hidden;
}

.minutes-output {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0.21in;
  padding: 0 1px;
  font-size: 0.084in;
  font-variant-numeric: tabular-nums;
}

.conversion-cell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1px;
  width: 100%;
  overflow: hidden;
  padding: 0 1px;
}

.conversion-cell span {
  color: var(--muted);
  font-size: 0.074in;
}

.time-field {
  padding: 0;
  font-size: 0.078in;
  text-align: center;
}

.form-footer {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 8px;
  margin-top: 8px;
  align-items: start;
}

.footer-signatures {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  align-items: end;
  min-height: 0.92in;
  padding-top: 2px;
}

.signature-block {
  display: grid;
  gap: 16px;
}

.signature-block.large {
  gap: 16px;
}

.signature-line {
  border-bottom: 1px solid var(--grid);
  height: 12px;
}

.signature-label {
  margin-top: -10px;
  text-align: center;
  font-size: 0.08in;
  color: var(--muted);
}

.footer-right {
  display: grid;
  grid-template-columns: 1fr 135px;
  gap: 0;
}

.lesson-box,
.question-box {
  min-height: 0.92in;
  padding: 3px 5px;
  border: 1px dashed var(--grid);
}

.lesson-title {
  text-align: center;
  margin-bottom: 4px;
  font-size: 0.085in;
}

.lesson-row,
.lesson-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  font-size: 0.078in;
}

.question-box {
  border-style: solid;
  font-size: 0.072in;
}

.question-text {
  margin-bottom: 4px;
  line-height: 1.15;
}

.question-choice {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
  font-size: 0.082in;
}

.checkbox,
.initials-line {
  display: inline-block;
  vertical-align: middle;
}

.checkbox {
  width: 10px;
  height: 10px;
  border: 1px solid var(--grid);
}

.initials-line {
  width: 70px;
  border-bottom: 1px solid var(--grid);
}

.toast {
  color: #513d1f;
}

@media (max-width: 1280px) {
  .sheet {
    overflow-x: auto;
    aspect-ratio: auto;
    min-height: 0;
  }
}

@media print {
  @page {
    size: letter landscape;
    margin: var(--print-margin-y) var(--print-margin-x);
  }

  body {
    background: white;
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  .no-print {
    display: none !important;
  }

  .sheet {
    width: var(--content-width);
    min-height: var(--content-height);
    aspect-ratio: auto;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .timesheet-table thead th {
    background: transparent;
  }

  .cell-input,
  .cell-textarea,
  .time-field,
  .field-row input {
    appearance: none;
    -webkit-appearance: none;
    outline: none;
  }

  .week-date-picker-hidden {
    display: none;
  }

  .flatpickr-calendar {
    display: none !important;
  }

  .sheet input[type="text"]:not(#week-of-input),
  .sheet .cell-textarea,
  .sheet .time-field,
  .minutes-output {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
