:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d6dae1;
  --accent: #116466;
  --accent-dark: #0b4648;
  --paper: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(520px, 1fr);
  min-height: 100vh;
}

.editor {
  padding: 24px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow: auto;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.header-actions {
  display: grid;
  flex: 0 0 auto;
  justify-items: end;
  gap: 8px;
}

.document-actions {
  display: flex;
  gap: 8px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
}

.panel {
  margin: 0 0 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

legend {
  padding: 0 6px;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

textarea {
  resize: vertical;
}

.wide-label {
  margin-top: 16px;
}

.custom-observation-panel {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding-top: 4px;
}

.custom-observation-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.custom-observation-head h2 {
  margin: 0 0 4px;
}

.custom-observation-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.custom-observation-composer {
  display: grid;
  gap: 12px;
}

.custom-observation-category {
  max-width: 320px;
}

.custom-observation-textarea textarea {
  min-height: 150px;
  line-height: 1.4;
  resize: vertical;
}

.custom-observation-actions {
  display: flex;
  justify-content: flex-end;
}

.custom-observation-list {
  display: grid;
  gap: 10px;
}

.custom-observation-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.custom-observation-tools {
  display: flex;
  gap: 6px;
}

.custom-observation-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef7f6;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.custom-observation-content {
  white-space: pre-wrap;
  line-height: 1.4;
  padding-top: 4px;
}

.compact-button {
  padding: 8px 12px;
  white-space: nowrap;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.icon-button:hover {
  background: #f8fafc;
}

.check-columns {
  display: grid;
  gap: 16px;
}

.check-columns h2 {
  margin: 0 0 8px;
  font-size: 15px;
}

.check-list {
  display: grid;
  gap: 8px;
}

.check-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 9px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 500;
  line-height: 1.35;
}

.check-row input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.print-button {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

.print-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
  background: #fff;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.secondary-button:hover {
  background: #eef7f6;
}

.secondary-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.help-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.help-button:hover {
  background: #eef7f6;
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: start end;
  padding: 24px;
  background: rgba(31, 41, 51, 0.38);
}

.help-modal[hidden] {
  display: none;
}

.help-dialog {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 24px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(31, 41, 51, 0.25);
}

.help-dialog h2 {
  margin: 0 44px 12px 0;
  font-size: 20px;
}

.help-dialog ol {
  margin: 0 0 14px 22px;
  padding: 0;
}

.help-dialog li {
  margin-bottom: 8px;
  line-height: 1.45;
}

.help-dialog p {
  margin: 0;
  line-height: 1.45;
}

.help-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.help-close:hover {
  background: #f8fafc;
}

.preview-wrap {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: 32px;
  overflow: auto;
}

.document {
  width: min(210mm, 100%);
  min-height: 297mm;
  margin: 0 auto;
  padding: 20mm;
  background: var(--paper);
  box-shadow: 0 12px 36px rgba(31, 41, 51, 0.15);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10pt;
  line-height: 1.45;
}

.pdf-export {
  width: 174mm;
  max-width: 174mm;
  min-height: auto;
  margin: 0 auto;
  padding: 0;
  box-shadow: none;
  font-size: 8.8pt;
  line-height: 1.18;
}

.pdf-export .doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
}

.pdf-export h1 {
  font-size: 15pt;
}

.pdf-export h2 {
  margin: 10px 0 4px;
  font-size: 11.2pt;
}

.pdf-export h3 {
  margin: 6px 0 2px;
  font-size: 9.6pt;
}

.pdf-export ul {
  margin-bottom: 4px;
}

.pdf-export p {
  margin: 4px 0;
}

.pdf-export .signature-row {
  margin-top: 12px;
}

.pdf-export .teacher-signature-row {
  margin-top: 30px;
}

.doc-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
  font-size: 10pt;
}

.document h1 {
  margin: 0 0 14px;
  font-size: 18pt;
  text-align: center;
}

.document h2 {
  margin: 20px 0 8px;
  font-size: 13pt;
}

.document h3 {
  margin: 12px 0 4px;
  font-size: 11.5pt;
}

.document ul {
  margin: 4px 0 10px 22px;
  padding: 0;
}

.lead {
  margin-bottom: 16px;
}

.muted {
  color: var(--muted);
  font-style: italic;
}

.signature-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-top: 30px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.teacher-signature-row {
  margin-top: 42px;
}

.signature-row.bottom {
  grid-template-columns: 1fr 1fr 1fr;
}

.signature-row span {
  color: var(--muted);
  font-size: 10pt;
}

.date-field,
.signature-field {
  display: grid;
  align-content: start;
  gap: 5px;
}

.date-field {
  grid-template-columns: auto 1fr;
  align-items: start;
  column-gap: 6px;
}

.date-field span:first-child {
  color: var(--ink);
  font-size: 12pt;
  line-height: 1.25;
}

.signature-line {
  display: block;
  height: 1.25em;
  border-bottom: 1px solid var(--ink);
}

.signature-field .signature-line {
  width: 100%;
}

.teacher-signature-field {
  max-width: 240px;
  justify-self: end;
  gap: 3px;
}

.teacher-signature-field strong {
  font-weight: 400;
}

hr {
  margin: 28px 0 18px;
  border: 0;
  border-top: 1px solid #9aa3af;
}

.ack-section {
  break-before: page;
  page-break-before: always;
  break-inside: avoid;
  page-break-inside: avoid;
}

.ack-section h2 {
  margin-top: 0;
}

.ack-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  width: 100%;
  margin: 10px 0 16px;
  padding: 10px 12px;
  border: 1px solid #9aa3af;
  overflow: hidden;
}

.ack-meta div {
  display: grid;
  gap: 2px;
}

.ack-meta span {
  color: var(--muted);
  font-size: 9pt;
}

.ack-meta strong {
  font-size: 11pt;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .editor {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-wrap {
    position: static;
    height: auto;
  }
}

@media (max-width: 640px) {
  .editor,
  .preview-wrap {
    padding: 16px;
  }

  .app-header,
  .doc-header {
    display: grid;
  }

  .header-actions {
    justify-items: start;
  }

  .document-actions {
    display: flex;
    flex-wrap: wrap;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .custom-observation-head {
    display: grid;
  }

  .custom-observation-item {
    grid-template-columns: 1fr;
  }

  .custom-observation-tools {
    justify-content: flex-start;
  }

  .icon-button {
    justify-self: start;
  }

  .custom-observation-category {
    max-width: none;
  }

  .signature-row,
  .signature-row.bottom,
  .ack-meta {
    grid-template-columns: 1fr;
  }

  .document {
    padding: 12mm;
  }

  .help-modal {
    place-items: start center;
    padding: 12px;
  }

  .help-dialog {
    max-height: calc(100vh - 24px);
    padding: 20px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 10mm 14mm 12mm;
  }

  body {
    background: white;
  }

  .editor {
    display: none;
  }

  .help-modal {
    display: none;
  }

  .app-shell {
    display: block;
    min-height: auto;
  }

  .preview-wrap {
    padding: 0;
  }

  .document {
    width: auto;
    min-height: auto;
    margin: 0;
    padding: 0;
    box-shadow: none;
    font-size: 9.5pt;
    line-height: 1.24;
  }

  .doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 14px;
  }

  .document h1 {
    font-size: 16pt;
    margin-bottom: 8px;
  }

  .document h2 {
    margin: 12px 0 5px;
    font-size: 12pt;
  }

  .document h3 {
    margin: 7px 0 2px;
    font-size: 10.5pt;
  }

  .document ul {
    margin-bottom: 5px;
  }

  .document p {
    margin: 6px 0;
  }

  .signature-row {
    margin-top: 18px;
  }

  .teacher-signature-row {
    margin-top: 32px;
  }

  .signature-row {
    grid-template-columns: 1fr 1fr;
  }

  .signature-row.bottom {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .ack-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
