:root {
  --page: #f5f2ea;
  --paper: #fffdf8;
  --ink: #1d2526;
  --muted: #687273;
  --line: #d9d0bf;
  --line-strong: #9e8d6c;
  --accent: #2f6f68;
  --accent-dark: #214d49;
  --accent-soft: #dfece8;
  --warm: #b26f34;
  --danger: #9e2f2f;
  --shadow: 0 18px 48px rgba(45, 48, 42, 0.12);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
  color: var(--ink);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(47, 111, 104, 0.12), rgba(47, 111, 104, 0) 260px),
    var(--page);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(47, 111, 104, 0.28);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.topbar {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 18px;
  display: grid;
  gap: 18px;
}

.top-actions {
  display: grid;
  gap: 10px;
}

.kicker {
  margin: 0 0 6px;
  color: var(--warm);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(28px, 7vw, 48px);
  line-height: 1;
  letter-spacing: 0;
}

.lead {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab,
.teacher-button {
  background: rgba(255, 253, 248, 0.72);
  color: var(--ink);
  border: 1px solid rgba(158, 141, 108, 0.45);
  white-space: nowrap;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.teacher-button {
  justify-self: start;
  min-height: 36px;
  padding: 0 12px;
  color: var(--accent-dark);
  font-size: 13px;
}

.workspace {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto 48px;
}

.teacher-access,
.panel {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid rgba(158, 141, 108, 0.34);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.teacher-access {
  margin-bottom: 16px;
  display: grid;
  gap: 12px;
}

.password-field {
  margin: 0;
}

.teacher-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.form-grid {
  display: grid;
  gap: 18px;
}

fieldset {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

legend {
  padding: 0 8px;
  color: var(--accent-dark);
  font-size: 18px;
  font-weight: 800;
}

.field {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field > span,
.field-title > span,
.activity-card strong {
  color: #2f3637;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.field-title {
  display: grid;
  gap: 3px;
}

.field-title small,
.activity-card > span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

input[type="text"],
input[type="date"],
input[type="password"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px 13px;
}

textarea {
  min-height: 82px;
  resize: vertical;
  line-height: 1.45;
}

.split,
.family-blocks,
.activity-grid {
  display: grid;
  gap: 14px;
}

.option-grid {
  display: grid;
  gap: 10px;
}

.option-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  line-height: 1.35;
}

.choice input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.children-section {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.inline-head {
  display: grid;
  gap: 10px;
}

.children-list {
  display: grid;
  gap: 12px;
}

.child-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.child-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.child-card-head h3 {
  margin: 0;
  color: var(--accent-dark);
  font-size: 15px;
}

.child-grid {
  display: grid;
  gap: 12px;
}

.empty-inline {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 253, 248, 0.7);
  color: var(--muted);
  font-weight: 700;
}

.conditional[hidden] {
  display: none;
}

.activity-card {
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.outside-activity {
  background: #fff8ec;
}

.school-activity {
  background: #eef7f4;
}

.parent-card {
  padding: 12px 0 4px;
  border-top: 1px solid var(--line);
}

.parent-card:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.parent-card h2 {
  margin-bottom: 12px;
  color: var(--accent-dark);
  font-size: 17px;
}

.action-bar,
.toolbar,
.print-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.primary {
  background: var(--accent);
  color: #fff;
}

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

.secondary,
.file-button {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.ghost {
  background: transparent;
  color: var(--muted);
}

.danger {
  background: #f6dfda;
  color: var(--danger);
}

.status {
  min-height: 20px;
  margin: 0;
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 700;
}

.section-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 0;
  font-size: 24px;
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.records-list {
  margin-top: 16px;
  overflow-x: auto;
}

.empty-state,
.print-hint {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 22px;
  background: rgba(255, 253, 248, 0.68);
  color: var(--muted);
  font-weight: 700;
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.records-table th,
.records-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.records-table th {
  background: #efe7d6;
  color: #3c3529;
  font-size: 13px;
}

.records-table tr:last-child td {
  border-bottom: 0;
}

.records-table input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.student-name {
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.print-area {
  display: grid;
  gap: 18px;
  margin-top: 16px;
}

.print-sheet {
  --sheet-scale: 1;
  width: 210mm;
  min-height: 297mm;
  max-width: 100%;
  overflow: hidden;
  background: #fff;
  color: #111;
  border: 1px solid #d3d3d3;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
  padding: 10mm;
}

.print-inner {
  transform: scale(var(--sheet-scale));
  transform-origin: top left;
  width: calc(100% / var(--sheet-scale));
}

.print-header {
  display: grid;
  gap: 8px;
  align-items: start;
  border-bottom: 1.5px solid #1f4f4b;
  padding-bottom: 5mm;
  margin-bottom: 4mm;
}

.print-title h1 {
  margin: 0 0 1.5mm;
  color: #173d3a;
  font-size: 16pt;
  line-height: 1.05;
}

.print-title p {
  margin: 0;
  color: #5a5a5a;
  font-size: 8pt;
}

.print-section {
  margin-bottom: 3.2mm;
  break-inside: avoid;
}

.print-section h2 {
  margin: 0 0 1.8mm;
  color: #173d3a;
  font-size: 9.5pt;
  line-height: 1.1;
  text-transform: uppercase;
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1.6mm;
}

.data-field {
  min-height: 8.5mm;
  border: 0.35pt solid #c8c0ad;
  border-radius: 1.5mm;
  padding: 1.3mm 1.8mm;
  background: #fffdf8;
  overflow: hidden;
}

.data-field.span-3 {
  grid-column: span 3;
}

.data-field.span-4 {
  grid-column: span 4;
}

.data-field.span-5 {
  grid-column: span 5;
}

.data-field.span-6 {
  grid-column: span 6;
}

.data-field.span-7 {
  grid-column: span 7;
}

.data-field.span-8 {
  grid-column: span 8;
}

.data-field.span-12 {
  grid-column: span 12;
}

.data-label {
  display: block;
  margin-bottom: 0.6mm;
  color: #5f5b50;
  font-size: 6.5pt;
  font-weight: 700;
  line-height: 1.1;
}

.data-value {
  min-height: 3.8mm;
  white-space: pre-wrap;
  color: #111;
  font-size: 8.1pt;
  line-height: 1.18;
}

.parents-print,
.child-print {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 7.7pt;
}

.parents-print th,
.parents-print td,
.child-print th,
.child-print td {
  border: 0.35pt solid #c8c0ad;
  padding: 1mm 1.4mm;
  vertical-align: top;
  line-height: 1.15;
}

.parents-print th,
.child-print th {
  background: #e8f1ee;
  color: #173d3a;
  text-align: left;
  font-weight: 800;
}

.parents-print .row-label {
  width: 24%;
  background: #fff8ec;
  color: #4f4a40;
  font-weight: 700;
}

.child-print .col-num {
  width: 7%;
}

.child-print .col-birth {
  width: 17%;
}

.child-print .col-place {
  width: 16%;
}

.child-print .col-institution {
  width: 25%;
}

.blank-sheet {
  min-height: 297mm;
}

.blank-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 3mm;
}

.blank-field {
  grid-column: span 12;
  break-inside: avoid;
}

.blank-field.span-3 {
  grid-column: span 3;
}

.blank-field.span-4 {
  grid-column: span 4;
}

.blank-field.span-6 {
  grid-column: span 6;
}

.blank-label {
  display: block;
  margin-bottom: 1mm;
  color: #173d3a;
  font-size: 8.5pt;
  font-weight: 800;
}

.blank-line {
  height: 8mm;
  border-bottom: 0.45pt solid #777;
}

.blank-box {
  min-height: 18mm;
  border: 0.45pt solid #aaa;
  border-radius: 1.4mm;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 7mm,
      rgba(119, 119, 119, 0.7) 7.2mm,
      transparent 7.4mm
    );
}

.blank-box.tall {
  min-height: 34mm;
}

.blank-checks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2mm 4mm;
}

.blank-choice {
  display: flex;
  align-items: center;
  gap: 2mm;
  font-size: 8.5pt;
}

.blank-choice::before {
  content: "";
  width: 4mm;
  height: 4mm;
  border: 0.55pt solid #555;
  flex: 0 0 auto;
}

.blank-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 8pt;
}

.blank-table th,
.blank-table td {
  border: 0.45pt solid #999;
  padding: 1.5mm;
  height: 12mm;
  vertical-align: top;
}

.blank-table th {
  background: #e8f1ee;
  color: #173d3a;
  text-align: left;
  font-weight: 800;
}

.blank-child-name {
  width: 30%;
}

.blank-child-birth {
  width: 18%;
}

.blank-child-place {
  width: 20%;
}

.blank-parent-label {
  width: 24%;
}

@media (min-width: 760px) {
  .topbar {
    grid-template-columns: 1fr auto;
    align-items: end;
  }

  .top-actions {
    justify-items: end;
  }

  .split,
  .family-blocks,
  .activity-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .inline-head {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .panel,
  .teacher-access {
    padding: 24px;
  }
}

@media (max-width: 620px) {
  .topbar,
  .workspace {
    width: min(100% - 20px, 1180px);
  }

  .panel,
  .teacher-access,
  fieldset {
    padding: 14px;
  }

  .section-head {
    display: grid;
  }

  .action-bar button,
  .toolbar button,
  .print-actions button,
  .file-button,
  .teacher-actions button,
  .teacher-button,
  #addChild {
    width: 100%;
    justify-content: center;
  }

  .tabs {
    width: 100%;
  }

  .records-table {
    min-width: 620px;
  }

  .print-area {
    overflow-x: hidden;
  }

  .print-sheet {
    width: 100%;
    min-height: auto;
    padding: 14px;
  }

  .data-grid,
  .blank-grid {
    grid-template-columns: 1fr;
  }

  .data-field.span-3,
  .data-field.span-4,
  .data-field.span-5,
  .data-field.span-6,
  .data-field.span-7,
  .data-field.span-8,
  .data-field.span-12,
  .blank-field.span-3,
  .blank-field.span-4,
  .blank-field.span-6 {
    grid-column: 1 / -1;
  }

  .blank-checks {
    grid-template-columns: 1fr;
  }
}

@page {
  size: A4 portrait;
  margin: 8mm;
}

@media print {
  html,
  body {
    width: 210mm;
    min-height: 297mm;
    background: #fff;
  }

  .topbar,
  .teacher-access,
  .workspace > .panel:not(#print),
  #print .section-head,
  #printHint {
    display: none !important;
  }

  .workspace,
  #print,
  .print-area {
    display: block !important;
    width: auto;
    margin: 0;
    padding: 0;
    background: #fff;
    border: 0;
    box-shadow: none;
  }

  .print-sheet {
    width: auto;
    height: 281mm;
    min-height: 0;
    max-width: none;
    border: 0;
    box-shadow: none;
    padding: 0;
    page-break-after: always;
  }

  .print-sheet:last-child {
    page-break-after: auto;
  }
}
