:root {
  --ink: #17212b;
  --muted: #687382;
  --line: #d7dee7;
  --paper: #ffffff;
  --wash: #f5f7fa;
  --brand: #1268a8;
  --brand-dark: #0d4f80;
  --success: #1f8a5f;
  --warning: #b36b00;
  --danger: #c24b42;
  --teal: #12847d;
  --radius: 8px;
  --shadow: 0 16px 50px rgba(23, 33, 43, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--wash);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  background: #142535;
  color: #f7fbff;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-block strong,
.brand-block span {
  display: block;
}

.brand-block span {
  margin-top: 3px;
  color: #b9c7d5;
  font-size: 13px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 7px;
  background: #2db39f;
  color: #06231f;
  font-weight: 800;
}

.role-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
}

.role-button,
.nav-item {
  border: 0;
  color: inherit;
  background: transparent;
}

.role-button {
  min-height: 38px;
  border-radius: 6px;
  color: #c7d3df;
}

.role-button.active {
  background: #f7fbff;
  color: #142535;
  font-weight: 700;
}

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

.nav-item {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 7px;
  text-align: left;
  color: #dce7ef;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
}

.main-panel {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

h3 {
  margin-bottom: 0;
  font-size: 15px;
}

.topbar-actions,
.form-actions,
.sticky-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.secondary-button,
.small-button,
.file-button {
  min-height: 42px;
  border-radius: 7px;
  padding: 0 16px;
  border: 1px solid transparent;
  font-weight: 700;
}

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

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

.secondary-button,
.small-button,
.file-button {
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.file-button {
  display: inline-grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.8fr);
  gap: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.panel-heading.compact {
  display: block;
}

.search-input {
  width: min(260px, 100%);
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.status-pill {
  display: inline-grid;
  place-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eaf4ff;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.completed,
.status-pill.closed {
  background: #e8f6ef;
  color: var(--success);
}

.status-pill.progress {
  background: #fff3df;
  color: var(--warning);
}

.row-button,
.text-button {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 800;
}

.timeline {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.timeline-item {
  border-left: 3px solid var(--teal);
  padding-left: 12px;
}

.timeline-item strong,
.timeline-item span {
  display: block;
}

.timeline-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.job-form,
.job-card-layout {
  display: grid;
  gap: 18px;
}

.locked-note {
  display: none;
  margin: 0 18px 18px;
  padding: 11px 12px;
  border: 1px solid #c7e3d5;
  border-radius: 7px;
  background: #eef8f3;
  color: var(--success);
  font-size: 13px;
  font-weight: 700;
}

.job-editor.is-locked .locked-note {
  display: block;
}

.job-editor.is-locked input,
.job-editor.is-locked textarea,
.job-editor.is-locked select,
.job-editor.is-locked canvas,
.job-editor.is-locked .file-button,
.job-editor.is-locked .small-button,
.job-editor.is-locked .remove-line {
  opacity: 0.62;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

textarea {
  resize: vertical;
}

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

.form-actions {
  justify-content: flex-end;
  padding: 0 18px 18px;
}

.job-card-layout {
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.8fr);
  align-items: start;
}

.stock-section,
.attachments-section,
.signature-grid {
  padding: 18px;
  border-top: 1px solid var(--line);
}

.section-title-row,
.signature-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.stock-lines {
  display: grid;
  gap: 10px;
}

.stock-line {
  display: grid;
  grid-template-columns: 1fr 1.6fr 100px 38px;
  gap: 10px;
  align-items: end;
}

.remove-line {
  min-height: 40px;
  border: 1px solid #f1c7c3;
  border-radius: 7px;
  background: #fff3f1;
  color: var(--danger);
  font-weight: 800;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
}

.photo-tile {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  border: 1px dashed var(--line);
  border-radius: 7px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

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

.signature-grid label {
  grid-column: 1 / -1;
}

.signature-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.signature-header {
  min-height: 40px;
  padding: 0 12px;
  margin: 0;
  background: #f8fafc;
  font-size: 13px;
  font-weight: 800;
}

canvas {
  display: block;
  width: 100%;
  height: 150px;
  background: #ffffff;
  touch-action: none;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.pdf-preview {
  position: sticky;
  top: 20px;
}

.pdf-sheet {
  width: min(100%, 794px);
  min-height: 1123px;
  margin: 0 auto;
  padding: 18px;
  border: 1px solid #111111;
  border-radius: 0;
  background: #ffffff;
  box-shadow: var(--shadow);
  color: #111111;
  font-family: Arial, Helvetica, sans-serif;
}

.jobcard-document-header {
  display: grid;
  grid-template-columns: 1fr 210px;
  border: 2px solid #111111;
}

.jobcard-logo-box,
.jobcard-title-box {
  min-height: 78px;
  padding: 10px 12px;
}

.jobcard-logo-box {
  display: grid;
  align-content: center;
}

.jobcard-logo-box strong {
  display: block;
  font-size: 30px;
  letter-spacing: 0;
}

.jobcard-logo-box span,
.jobcard-title-box span {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  text-transform: uppercase;
}

.jobcard-title-box {
  display: grid;
  align-content: center;
  justify-items: center;
  border-left: 2px solid #111111;
  text-align: center;
}

.jobcard-title-box strong {
  display: block;
  font-size: 25px;
}

.jobcard-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-left: 1px solid #111111;
  border-top: 1px solid #111111;
  margin-top: 12px;
}

.jobcard-field {
  display: grid;
  grid-template-columns: 142px 1fr;
  min-height: 34px;
  border-right: 1px solid #111111;
  border-bottom: 1px solid #111111;
}

.jobcard-field span {
  display: grid;
  align-items: center;
  padding: 6px 8px;
  border-right: 1px solid #111111;
  background: #f1f1f1;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.jobcard-field strong {
  display: grid;
  align-items: center;
  min-width: 0;
  padding: 6px 8px;
  font-size: 13px;
  word-break: break-word;
}

.jobcard-field.full {
  grid-column: 1 / -1;
}

.jobcard-section {
  margin-top: 12px;
  border: 1px solid #111111;
}

.jobcard-section-title {
  padding: 7px 9px;
  border-bottom: 1px solid #111111;
  background: #e9e9e9;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.jobcard-fault-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-bottom: 1px solid #111111;
}

.jobcard-fault-grid .jobcard-field {
  grid-template-columns: 1fr;
  border-top: 0;
  border-bottom: 0;
  border-left: 0;
}

.jobcard-fault-grid .jobcard-field span {
  min-height: 25px;
  border-right: 0;
  border-bottom: 1px solid #111111;
  text-align: center;
}

.jobcard-fault-grid .jobcard-field strong {
  min-height: 34px;
  justify-items: center;
  text-align: center;
}

.jobcard-writing-box {
  min-height: 120px;
  padding: 10px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.jobcard-writing-box.tall {
  min-height: 150px;
}

.jobcard-stock-table {
  min-width: 0;
  width: 100%;
  border-collapse: collapse;
}

.jobcard-stock-table th,
.jobcard-stock-table td {
  border-bottom: 1px solid #111111;
  border-right: 1px solid #111111;
  padding: 8px;
  color: #111111;
  font-size: 12px;
}

.jobcard-stock-table th:last-child,
.jobcard-stock-table td:last-child {
  border-right: 0;
}

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

.jobcard-stock-table th {
  background: #f1f1f1;
}

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

.signature-line-box {
  min-height: 78px;
  border-right: 1px solid #111111;
  border-bottom: 1px solid #111111;
  padding: 8px;
}

.signature-line-box:nth-child(2n) {
  border-right: 0;
}

.signature-line-box:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.signature-line-box span {
  display: block;
  color: #333333;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.signature-line-box strong {
  display: block;
  margin-top: 30px;
  border-top: 1px solid #111111;
  padding-top: 5px;
  font-size: 13px;
  font-weight: 700;
}

.archive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  padding: 18px;
}

.archive-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.archive-card strong,
.archive-card span {
  display: block;
}

.archive-card span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 7px;
  background: var(--ink);
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: 0.18s ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .app-shell,
  .content-grid,
  .job-card-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: auto minmax(220px, 300px);
    align-items: center;
  }

  .nav-list {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
  }

  .pdf-preview {
    position: static;
  }
}

@media (max-width: 760px) {
  .main-panel,
  .sidebar {
    padding: 16px;
  }

  .sidebar,
  .topbar,
  .panel-heading,
  .signature-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .form-actions,
  .sticky-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .metrics-grid,
  .form-grid,
  .jobcard-info-grid,
  .jobcard-signature-grid {
    grid-template-columns: 1fr;
  }

  .jobcard-document-header,
  .jobcard-fault-grid {
    grid-template-columns: 1fr;
  }

  .jobcard-title-box {
    border-top: 2px solid #111111;
    border-left: 0;
  }

  .nav-list {
    grid-template-columns: 1fr 1fr;
  }

  .stock-line {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .sidebar,
  .topbar,
  .job-editor,
  .toast {
    display: none;
  }

  .app-shell,
  .main-panel,
  .job-card-layout {
    display: block;
    padding: 0;
  }

  .view {
    display: none;
  }

  #jobcard-view,
  .pdf-preview {
    display: block;
  }

  .pdf-sheet {
    box-shadow: none;
    width: 210mm;
    min-height: 297mm;
    padding: 10mm;
    border: 0;
  }

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