:root {
  --page: #edf3ef;
  --paper: #f8fbf8;
  --ink: #27303a;
  --muted: #5d6874;
  --line: #9aa6a1;
  --brand: #0b5d6b;
  --brand-deep: #093845;
  --focus: #d39d45;
  --shadow: 0 20px 60px rgba(21, 34, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Arial, "Assistant", sans-serif;
  background: linear-gradient(180deg, #eef5f1 0%, #dfe9e5 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.ticket-page {
  width: min(980px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 28px 0;
}

.ticket-form {
  min-height: calc(100vh - 56px);
  padding: clamp(20px, 4vw, 42px);
  border: 1px solid rgba(39, 48, 58, 0.12);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.ticket-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.ticket-meta {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.ticket-brand {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.ticket-brand img {
  width: 180px;
  max-width: 42vw;
  height: auto;
  object-fit: contain;
}

.ticket-brand strong {
  font-size: clamp(1.8rem, 5vw, 2.55rem);
  color: #3d444c;
  letter-spacing: 0.02em;
}

.ticket-title {
  margin: 42px 0 26px;
  text-align: center;
}

.ticket-title p {
  margin: 0 0 12px;
  color: var(--muted);
}

.ticket-title h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.1;
  color: #5a5f63;
}

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

.stacked-fields,
.closure-section,
.signature-section {
  display: grid;
  gap: 18px;
  margin-top: 24px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

label span,
legend {
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbfdfb;
  color: var(--ink);
  padding: 12px 14px;
}

textarea {
  min-height: 104px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
}

.closure-section {
  justify-items: end;
}

.closure-section h2,
.signature-heading h2 {
  margin: 0;
  font-size: 1.25rem;
}

fieldset {
  width: min(220px, 100%);
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 8px;
}

.radio-line,
.approval-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-weight: 400;
}

.radio-line input,
.approval-line input {
  width: auto;
  margin-top: 4px;
}

.signature-section {
  padding-top: 4px;
}

.signature-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.signature-heading p {
  margin: 0;
  color: var(--muted);
}

.signature-help {
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.signature-pad-wrap {
  width: 100%;
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  overflow: hidden;
  touch-action: none;
}

#signatureCanvas {
  display: block;
  width: 100%;
  height: 190px;
  cursor: crosshair;
}

.signature-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #fff;
}

.secondary-button {
  background: #e8eeeb;
  color: var(--ink);
  border: 1px solid rgba(39, 48, 58, 0.16);
}

.base64-output {
  display: none;
}

.approval-line {
  margin-top: 22px;
  line-height: 1.7;
}

.form-actions {
  margin-top: 24px;
}

.form-status {
  min-height: 24px;
  margin: 16px 0 0;
  color: var(--brand-deep);
  font-weight: 700;
}

.form-status.is-error {
  color: #9c3722;
}

body.is-exporting .signature-actions,
body.is-exporting .form-actions,
body.is-exporting .form-status,
body.is-exporting .base64-output {
  display: none;
}

@media (max-width: 760px) {
  .ticket-page {
    width: min(100vw - 18px, 100%);
    padding: 10px 0;
  }

  .ticket-form {
    min-height: auto;
    padding: 18px;
  }

  .ticket-header {
    align-items: center;
    flex-direction: column-reverse;
    text-align: center;
    gap: 12px;
  }

  .ticket-meta {
    justify-content: center;
    flex-wrap: wrap;
  }

  .ticket-title {
    margin: 24px 0 20px;
  }

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

  .stacked-fields,
  .closure-section,
  .signature-section {
    margin-top: 18px;
    gap: 14px;
  }

  .signature-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .signature-pad-wrap {
    min-height: 170px;
  }

  #signatureCanvas {
    height: 170px;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }
}

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

  html,
  body {
    background: #fff;
    height: auto;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body {
    font-size: 10.5pt;
    line-height: 1.25;
  }

  .ticket-page {
    width: 100%;
    padding: 0;
  }

  .ticket-form {
    min-height: auto;
    padding: 0;
    box-shadow: none;
    border: 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .ticket-header {
    gap: 12px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .ticket-meta {
    font-size: 8.5pt;
  }

  .ticket-brand {
    gap: 3px;
  }

  .ticket-brand img {
    width: 112px;
  }

  .ticket-brand strong {
    font-size: 20pt;
  }

  .ticket-title {
    margin: 12px 0 10px;
  }

  .ticket-title p {
    margin-bottom: 4px;
    font-size: 9pt;
  }

  .ticket-title h1 {
    font-size: 23pt;
  }

  .form-grid {
    grid-template-columns: 1.05fr 0.95fr 0.62fr;
    gap: 7px 9px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .form-grid label {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 5px;
  }

  .form-grid label span {
    white-space: nowrap;
  }

  .form-grid input,
  .form-grid select {
    min-height: 26px;
  }

  .stacked-fields,
  .closure-section,
  .signature-section {
    gap: 8px;
    margin-top: 9px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  label {
    gap: 3px;
  }

  input,
  select,
  textarea {
    padding: 5px 7px;
    border-color: #6f7a75;
  }

  textarea {
    min-height: 0;
    resize: none;
  }

  textarea[name="notes"] {
    height: 40px;
  }

  textarea[name="workDetails"] {
    height: 94px;
  }

  textarea[name="equipmentDetails"] {
    height: 78px;
  }

  .closure-section h2,
  .signature-heading h2 {
    font-size: 12pt;
  }

  fieldset {
    gap: 3px;
  }

  .radio-line,
  .approval-line {
    gap: 6px;
  }

  .signature-section {
    padding-top: 0;
  }

  .signature-heading {
    gap: 10px;
  }

  .signature-heading p,
  .signature-help {
    font-size: 8.5pt;
  }

  .signature-pad-wrap {
    min-height: 76px;
  }

  #signatureCanvas {
    height: 76px;
  }

  .approval-line {
    margin-top: 9px;
    line-height: 1.35;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .form-status {
    display: none;
  }

  .signature-actions,
  .form-actions,
  .base64-output {
    display: none;
  }
}
