:root {
  --bg: #f4efe5;
  --panel: #ffffff;
  --panel-soft: #faf7f0;
  --line: #d7cebd;
  --text: #16211b;
  --muted: #5a6a5f;
  --accent: #255a36;
  --danger: #922f2f;
  --danger-soft: #fae7e7;
  --shadow: 0 14px 28px rgba(20, 33, 26, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { font-size: 17px; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f4efe5 0%, #ece3d2 100%);
  line-height: 1.55;
}
button, input, select, textarea { font: inherit; }
.page {
  width: min(980px, calc(100% - 1rem));
  margin: 0 auto;
  padding: 1rem 0 2rem;
}
.card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}
.topbar { display: grid; gap: 0.9rem; }
.topbar h1, h2, h3, legend { margin: 0; line-height: 1.1; }
.topbar-actions { display: grid; gap: 0.8rem; }
.save-status { margin: 0; color: var(--muted); font-size: 0.95rem; }
.stack > * + * { margin-top: 1rem; }
.grid { display: grid; gap: 0.9rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label, .stacked { display: grid; gap: 0.45rem; }
label span, .stacked span, legend { font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 0.85rem 0.95rem;
  background: var(--panel-soft);
  color: var(--text);
}
input[readonly] {
  background: #f1ede4;
  color: var(--muted);
}
textarea { resize: vertical; min-height: 3.4rem; }
input:focus, select:focus, textarea:focus, button:focus {
  outline: 3px solid rgba(37, 90, 54, 0.22);
  outline-offset: 2px;
  border-color: var(--accent);
}
fieldset.work-types {
  margin: 0;
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 0.9rem;
  background: var(--panel-soft);
}
.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.8rem;
}
.check-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: start;
  gap: 0.65rem;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 0.8rem;
  background: #fff;
}
.check-item input {
  width: 20px;
  height: 20px;
  min-width: 20px;
  margin: 0.1rem 0 0;
  padding: 0;
}
.check-item span { font-weight: 700; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}
.section-head-wrap { flex-wrap: wrap; align-items: flex-start; }
.toolbar { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.toolbar.compact { justify-content: flex-end; }
.btn {
  border: 0;
  border-radius: 16px;
  padding: 0.9rem 1rem;
  cursor: pointer;
  background: #edf1ec;
  color: var(--text);
  font-weight: 700;
  min-height: 52px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.help-text { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.95rem; }
.empty-state {
  border: 2px dashed var(--line);
  border-radius: 18px;
  padding: 1rem;
  background: var(--panel-soft);
  color: var(--muted);
}
.photo-preview { margin: 0; display: grid; gap: 0.75rem; }
.photo-preview img {
  width: 100%;
  max-width: 420px;
  border-radius: 18px;
  border: 2px solid var(--line);
  background: #fff;
}
.photo-meta { color: var(--muted); font-size: 0.95rem; }
.material-list { display: grid; gap: 0.9rem; }
.material-card {
  border: 2px solid var(--line);
  border-radius: 18px;
  background: var(--panel-soft);
  padding: 0.9rem;
  display: grid;
  gap: 0.9rem;
}
.material-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}
.material-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}
.line-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: #fff;
  padding: 0.8rem 0.9rem;
  font-weight: 700;
}
.totals { display: grid; gap: 0.75rem; }
.totals div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.9rem 1rem;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--panel-soft);
}
.totals strong { font-size: 1.2rem; }
.totals .grand {
  background: #eef6f0;
  border-color: #b8d0be;
}
.summary-head { margin-top: 0.4rem; }
.summary-toolbar { justify-content: flex-end; }
.hidden,
.print-sheet { display: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.floating-actions {
  position: fixed;
  right: 0.9rem;
  bottom: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  z-index: 40;
}
.fab {
  width: 58px;
  height: 58px;
  min-height: 58px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 24px rgba(20, 33, 26, 0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.fab-icon {
  font-size: 1.45rem;
  line-height: 1;
}
.fab-save {
  background: var(--accent);
  color: #fff;
}
.fab-share {
  background: #ffffff;
  color: var(--accent);
}
.fab:hover {
  transform: translateY(-1px);
}

.print-document {
  color: #111;
  font-size: 12px;
  line-height: 1.35;
}
.print-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 2px solid #222;
  padding-bottom: 0.6rem;
  margin-bottom: 0.75rem;
}
.print-header h1 {
  margin: 0;
  font-size: 1.7rem;
}
.print-subtitle {
  margin: 0.2rem 0 0;
  color: #444;
  font-size: 0.95rem;
}
.print-meta {
  display: grid;
  gap: 0.35rem;
  min-width: 240px;
}
.print-meta div,
.print-inline-summary,
.print-totals div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}
.print-meta span,
.print-totals span {
  color: #444;
}
.print-block {
  margin-bottom: 0.8rem;
  page-break-inside: avoid;
}
.print-block h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}
.print-list {
  margin: 0;
  padding-left: 1.1rem;
}
.print-list li + li { margin-top: 0.15rem; }
.print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.print-table th,
.print-table td {
  border: 1px solid #cfcfcf;
  padding: 0.35rem 0.45rem;
  text-align: left;
  vertical-align: top;
}
.print-table th {
  background: #f4f4f4;
}
.print-notes {
  margin: 0;
  white-space: normal;
}
.print-photo-block { max-width: 280px; }
.print-photo {
  width: 100%;
  border: 1px solid #d7d7d7;
}
.print-photo-note {
  margin: 0.25rem 0 0;
  color: #555;
  font-size: 0.85rem;
}
.print-totals {
  display: grid;
  gap: 0.3rem;
}
.print-totals .grand {
  margin-top: 0.2rem;
  padding-top: 0.35rem;
  border-top: 2px solid #111;
  font-size: 1rem;
}

@page {
  size: A4;
  margin: 10mm;
}

@media print {
  body {
    background: #fff;
    color: #111;
  }

  .page {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .screen-only,
  .topbar,
  .card:not(.screen-only) {
    display: none !important;
  }

  .print-sheet {
    display: block !important;
  }
}

@media (max-width: 760px) {
  html { font-size: 16px; }
  .page { width: min(100%, calc(100% - 0.75rem)); }
  .grid.two, .material-grid, .check-grid { grid-template-columns: 1fr; }
  .section-head, .toolbar.compact, .material-card-head, .print-header {
    flex-direction: column;
    align-items: stretch;
  }
  .print-meta { min-width: 0; }
  .floating-actions {
    right: 0.6rem;
    bottom: 0.6rem;
    gap: 0.5rem;
  }
  .fab {
    width: 52px;
    height: 52px;
    min-height: 52px;
  }
  .fab-icon {
    font-size: 1.25rem;
  }
}
