:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f5;
  --text: #15202b;
  --muted: #61707f;
  --line: #d8e0e6;
  --brand: #0e7c74;
  --brand-dark: #075f59;
  --warn: #b26a00;
  --done: #16824b;
  --danger: #b3261e;
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  color: var(--brand-dark);
  font-weight: 800;
  text-decoration: none;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-user {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 10px;
  color: var(--muted);
  font-weight: 800;
}

.topbar nav a,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.button.warning {
  border-color: var(--danger);
  background: #fff0ef;
  color: var(--danger);
}

.button.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.9rem;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 64px;
}

.page.narrow {
  width: min(820px, calc(100% - 32px));
}

.hero,
.ticket-head,
.panel,
.table-wrap,
.stats > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.hero,
.ticket-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(24px, 4vw, 42px);
}

.hero h1,
.ticket-head h1,
.section-head h1,
.report-cover h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.hero p,
.ticket-head p {
  max-width: 760px;
  margin: 14px 0 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand-dark);
  font-size: 0.86rem;
  font-weight: 800;
}

.notice {
  margin-bottom: 16px;
  border: 1px solid #b5dfcc;
  border-radius: 8px;
  background: #e9f8f0;
  padding: 14px 16px;
  color: #115c37;
  font-weight: 700;
}

.notice.warning {
  border-color: #f0d19a;
  background: #fff7e8;
  color: #7a4a00;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.stats > div {
  padding: 18px;
}

.stats strong {
  display: block;
  font-size: 2rem;
  line-height: 1;
}

.stats span,
.muted {
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}

th {
  background: var(--surface-soft);
  color: #334454;
  font-size: 0.9rem;
}

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

.empty {
  text-align: center;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 10px;
  border-radius: 999px;
  background: #e7edf2;
  color: #394957;
  font-weight: 800;
  white-space: nowrap;
}

.status.in_progress {
  background: #fff4df;
  color: var(--warn);
}

.status.done {
  background: #e5f5ec;
  color: var(--done);
}

.status.overdue {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.late-days {
  color: var(--danger);
  font-weight: 700;
  font-size: 0.9em;
  white-space: nowrap;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.panel {
  padding: clamp(20px, 3vw, 30px);
  margin-top: 16px;
}

.panel h2,
.section-head h1 {
  margin-top: 0;
}

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

.settings-form {
  display: grid;
  gap: 14px;
}

.contact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 180px;
  align-items: end;
  gap: 14px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfd;
}

.settings-row {
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.5fr);
}

.contact-row legend {
  padding: 0 6px;
  color: var(--brand-dark);
  font-weight: 900;
}

.contact-row label {
  display: grid;
  gap: 8px;
  color: #334454;
  font-weight: 800;
}

.phone-ok,
.phone-bad {
  margin: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  border-radius: 7px;
  padding: 8px 10px;
  font-weight: 800;
}

.phone-ok {
  background: #e5f5ec;
  color: var(--done);
}

.phone-bad {
  background: #fff4df;
  color: var(--warn);
}

.form label {
  display: grid;
  gap: 8px;
  color: #334454;
  font-weight: 800;
}

.field-help {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.attachment-field {
  align-items: start;
}

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

.extra-attachment-input {
  background: #fbfcfd;
}

.add-attachment {
  justify-self: start;
}

.form .full {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

textarea {
  resize: vertical;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 16px;
}

.details {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px 14px;
  margin: 0;
}

.details.two {
  grid-template-columns: 170px 1fr 170px 1fr;
}

dt {
  color: var(--muted);
  font-weight: 800;
}

dd {
  margin: 0;
}

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

.attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.attachment {
  display: grid;
  gap: 8px;
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafcfd;
  padding: 10px;
  color: var(--text);
  text-decoration: none;
}

.attachment img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-soft);
}

.file-icon {
  display: grid;
  place-items: center;
  height: 130px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 900;
}

.report-attachments {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.report-attachment {
  display: grid;
  gap: 10px;
  break-inside: avoid;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  color: var(--text);
  text-decoration: none;
}

.report-attachment img {
  width: 100%;
  height: 240px;
  object-fit: contain;
  border-radius: 6px;
  background: #f6f8fa;
}

.report-attachments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.report-attachment-card {
  display: flex;
  flex-direction: column;
  break-inside: avoid;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.report-attachment-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.report-attachment-thumb {
  height: 130px;
  background: #f4f7f9;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.report-attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-thumb {
  font-size: 2.2rem;
}

.report-attachment-info {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.report-attachment-group {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--brand-dark);
}

.report-attachment-name {
  font-size: 0.88rem;
  color: var(--text);
  word-break: break-word;
}

.timeline {
  display: grid;
  gap: 14px;
}

.timeline-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfd;
}

.timeline-item > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--brand-dark);
}

.timeline-item time {
  color: var(--muted);
  font-size: 0.92rem;
}

.report-cover {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 36px;
}

.report-cover h2 {
  margin: 12px 0 24px;
  color: var(--muted);
  font-size: 1.2rem;
}

.description {
  margin: 22px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.report-tools {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.letter-document {
  max-width: 210mm;
  margin: 0 auto;
  border: 1px solid #d0d7de;
  border-radius: 10px;
  background: #fff;
  padding: 34px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

.letter-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  border-bottom: 3px double var(--brand);
  padding-bottom: 22px;
}

.letter-brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.org-name {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--brand-dark);
  letter-spacing: -0.3px;
}

.org-subtitle {
  font-size: 1.05rem;
  color: var(--muted);
  font-weight: 600;
}

.doc-type {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 12px;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  width: fit-content;
}

.letter-meta-box,
.letter-meta-text {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
}

.letter-meta-text {
  align-items: flex-end;
  text-align: right;
}

.meta-row,
.letter-meta-text > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #f8fafb;
}

.meta-row span,
.letter-meta-text span {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}

.meta-row strong,
.letter-meta-text strong {
  font-size: 0.98rem;
  color: var(--text);
}

.letter-title {
  text-align: center;
  padding: 24px 0 12px;
}

.letter-title h1 {
  margin: 0;
  font-size: 2rem;
}

.letter-title p {
  margin: 8px auto 0;
  color: var(--muted);
  font-weight: 800;
}

.letter-summary {
  margin-top: 26px;
}

.letter-summary h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
  color: var(--brand-dark);
}

.report-meta-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 8px;
  font-size: 0.98rem;
  border: 1px solid #d0d7de;
}

.report-meta-table th,
.report-meta-table td {
  border: 1px solid #d0d7de;
  padding: 10px 12px;
  text-align: right;
  vertical-align: top;
}

.report-meta-table th {
  background: #f4f7f9;
  width: 26%;
  font-weight: 800;
  color: #3d4f60;
}

.report-meta-table td {
  background: #fff;
}

.official-letter {
  margin-top: 26px;
  font-size: 1.08rem;
  line-height: 2.15;
}

.letter-body p {
  margin: 0 0 18px;
  text-align: justify;
}

.letter-opener {
  margin-top: 10px;
  padding: 14px 18px;
  border-right: 4px solid var(--brand);
  background: #f6faf9;
  border-radius: 0 8px 8px 0;
  font-size: 1.05rem;
  line-height: 2;
}

.letter-date {
  text-align: left;
}

.letter-to,
.letter-greeting,
.letter-subject {
  font-weight: 800;
}

.letter-subject {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.letter-closing {
  margin-top: 26px;
}

.letter-section {
  margin-top: 22px;
  break-inside: avoid;
}

.letter-section h2 {
  margin: 0 0 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  font-size: 1.15rem;
}

.letter-data {
  display: grid;
  grid-template-columns: 150px 1fr 150px 1fr;
  border: 1px solid var(--line);
  margin: 0;
}

.letter-data dt,
.letter-data dd {
  min-height: 42px;
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
}

.letter-data dt {
  background: #f3f6f8;
  color: #2d3b48;
  font-weight: 900;
}

.letter-data dd {
  margin: 0;
  border-left: 1px solid var(--line);
}

.letter-text {
  min-height: 76px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  white-space: pre-wrap;
}

.letter-table th,
.letter-table td {
  border: 1px solid var(--line);
}

.letter-empty {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.letter-signatures {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 30px;
  margin-top: 50px;
}

.signature-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 110px;
  border-top: 1px solid #3d4f60;
  padding-top: 14px;
  text-align: center;
  gap: 6px;
}

.signature-box span {
  display: block;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.9rem;
}

.signature-box strong {
  display: block;
  margin-top: 4px;
  font-size: 1.05rem;
  color: var(--text);
}

.signature-box em {
  display: block;
  margin-top: auto;
  font-size: 0.8rem;
  color: #8a96a3;
  font-style: normal;
}

@media (max-width: 760px) {
  .topbar,
  .hero,
  .ticket-head {
    align-items: stretch;
    flex-direction: column;
  }

  .stats,
  .grid,
  .form,
  .contact-row {
    grid-template-columns: 1fr;
  }

  .details,
  .details.two,
  .letter-data,
  .letter-signatures {
    grid-template-columns: 1fr;
  }

  .form .full {
    grid-column: auto;
  }
}

@media print {
  @page {
    margin: 14mm;
  }

  body {
    background: #fff;
    color: #000;
  }

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

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

  .letter-document {
    border: 0;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    max-width: none;
  }

  .letter-header {
    padding-bottom: 8mm;
    border-bottom-width: 2px;
  }

  .org-name {
    font-size: 1.5rem;
  }

  .doc-type {
    background: #075f59;
  }

  .letter-title {
    padding: 9mm 0 4mm;
  }

  .letter-summary {
    margin-top: 8mm;
  }

  .letter-opener {
    background: #f0f4f3;
    border-right-color: #075f59;
    padding: 10px 14px;
  }

  .official-letter {
    font-size: 12.5pt;
    line-height: 2;
    margin-top: 8mm;
  }

  .letter-section {
    margin-top: 8mm;
    break-inside: avoid;
  }

  .letter-data {
    grid-template-columns: 34mm 1fr 34mm 1fr;
    font-size: 0.9rem;
  }

  .panel,
  .report-cover,
  .ticket-head,
  .table-wrap {
    break-inside: avoid;
    border-color: #999;
    box-shadow: none;
  }

  .attachment {
    break-inside: avoid;
  }

  .report-attachments-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5mm;
  }

  .report-attachment-card,
  .report-attachment {
    page-break-inside: avoid;
    border-color: #999;
  }

  .report-attachment img,
  .report-attachment-thumb img {
    height: 42mm;
    object-fit: contain;
  }

  .letter-signatures {
    grid-template-columns: repeat(3, 1fr);
    margin-top: 14mm;
    gap: 10mm;
  }

  .signature-box {
    border-top-color: #000;
  }

  a {
    text-decoration: none;
  }
}
