:root {
  --ink: #1d2430;
  --muted: #657083;
  --line: #aebdcc;
  --panel: #ffffff;
  --bg: #f4f7fa;
  --brand: #145c63;
  --brand-strong: #0d4247;
  --accent: #d79b2b;
  --ok: #1d7f52;
  --warn: #a26000;
  --danger: #a83232;
  --shadow: 0 10px 26px rgba(28, 42, 58, 0.10);
}

.nss-work-order { max-width: 780px; margin: 18px auto; color: #111; font-size: 12px; }
.nss-order-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.nss-order-title img { width: 150px; height: auto; }
.nss-order-title h2 { font-size: 22px; }
.nss-order-meta { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); border-top: 1px solid #111; border-left: 1px solid #111; }
.nss-order-meta > div { padding: 8px; min-height: 58px; border-right: 1px solid #111; border-bottom: 1px solid #111; overflow-wrap: anywhere; }
.nss-order-meta p { margin-top: 8px; }
.nss-order-work { min-height: 300px; border: 1px solid #111; border-top: 0; background: repeating-linear-gradient(to bottom,transparent 0,transparent 23px,#bbb 24px); }
.nss-order-items { padding: 10px; background: #fff; }
.nss-order-items p { margin-bottom: 8px; overflow-wrap: anywhere; }
.nss-order-notes { min-height: 240px; padding: 8px; border: 1px solid #111; border-top: 0; background: repeating-linear-gradient(to bottom,transparent 0,transparent 23px,#bbb 24px); }
.nss-order-agreement { padding: 8px; border: 1px solid #111; border-top: 0; }
.nss-order-completion { display: grid; grid-template-columns: 2fr 1fr; gap: 40px; padding: 12px 0; }
.nss-order-line { height: 25px; border-bottom: 1px solid #111; margin-bottom: 6px; }
@media (max-width: 600px) { .nss-order-meta { grid-template-columns: 1fr; } }
@media print {
  .nss-work-order { break-after: page; padding: 0; border: 0; box-shadow: none; }
  .nss-work-order:last-child { break-after: auto; }
  .nss-order-meta { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .nss-order-meta > div, .nss-order-items p, .nss-order-completion { break-inside: avoid; }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}

.logged-out .app-header,
.logged-out .layout {
  display: none;
}

.logged-in .login-screen {
  display: none;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 30px;
}

.error-text {
  min-height: 20px;
  color: var(--danger);
  font-weight: 700;
}

.demo-users {
  display: grid;
  gap: 5px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  background: var(--brand);
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

button:hover {
  background: var(--brand-strong);
}

.button-link:hover {
  background: var(--brand-strong);
}

.secondary {
  background: #e8edf3;
  color: var(--ink);
}

.secondary:hover {
  background: #dce4ed;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-logo {
  width: min(95px, 22vw);
  height: auto;
  object-fit: contain;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(18px, 2.1vw, 22px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h2 {
  font-size: 22px;
}

.eyebrow {
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  background: #f8fafc;
  color: var(--ink);
  font-weight: 700;
}

.icon-btn,
.import-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
}

.import-label input {
  display: none;
}

.layout {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  min-height: calc(100vh - 90px);
}

.sidebar {
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #eef3f7;
}

.nav-btn {
  width: 100%;
  margin-bottom: 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.sidebar a {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}

.nav-btn:hover,
.nav-btn.active,
.sidebar a:hover {
  background: #dfe9ee;
}

.content {
  padding: 26px;
  min-width: 0;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat {
  padding: 18px;
}

.stat-link {
  color: var(--text);
  display: block;
  text-decoration: none;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.stat-link:hover,
.stat-link.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(11, 102, 116, .16);
  transform: translateY(-1px);
}

.stat span {
  display: block;
  font-size: 34px;
  font-weight: 800;
}

.stat p,
.muted {
  color: var(--muted);
}

.block {
  display: block;
  margin-top: 6px;
}

.panel {
  padding: 20px;
}

.panel-heading,
.form-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-title,
.full {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1.5px solid #aebdcc;
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.reference-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 7px 12px;
  background: #e5f2f3;
  color: var(--brand-strong);
  white-space: nowrap;
}

.status-pill {
  font-size: 12px;
}

.status-Closed {
  background: #e6f3ec;
  color: var(--ok);
}

.status-Ready {
  background: #fff3d8;
  color: var(--warn);
}

.status-Under,
.status-Awaiting {
  background: #e8edf8;
  color: #274d88;
}

.file-drop {
  border: 1.5px dashed #9caec0;
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.file-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.file-grid .file-drop {
  display: grid;
  gap: 10px;
}

.file-drop span {
  color: var(--muted);
  font-weight: 400;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.search {
  max-width: 380px;
}

.return-search {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  padding: 14px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
}

.dashboard-search {
  margin-bottom: 14px;
  border-color: #8fa5b8;
}

.return-search label {
  font-weight: 700;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.search-row input {
  min-width: 0;
}

.search-result-count {
  margin-top: -4px;
  margin-bottom: 14px;
}

.record-list {
  display: grid;
  gap: 10px;
}

.record-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.2fr) minmax(220px, 1fr);
  gap: 14px 18px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.record-row strong {
  display: block;
  margin-bottom: 4px;
}

.row-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.row-actions button,
.row-actions .button-link {
  padding: 8px 10px;
  min-height: 36px;
  min-width: 92px;
}

.empty-state {
  text-align: center;
  padding: 34px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #b6dfc8;
  border-radius: 8px;
  background: #e6f3ec;
  color: var(--ok);
  font-weight: 700;
}

.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.attachment-list,
.user-list,
.email-log-list {
  display: grid;
  gap: 10px;
}

.user-form {
  margin-bottom: 18px;
}

.attachment-row,
.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.user-row {
  grid-template-columns: minmax(140px, 1fr) minmax(180px, 1.2fr) minmax(120px, 0.8fr) minmax(140px, 1fr) auto auto;
}

.user-row input,
.user-row select {
  min-width: 0;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.email-log-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(140px, auto) minmax(220px, 1fr);
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.activity-panel {
  margin-top: 16px;
}

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

.activity-row {
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.activity-row p {
  margin: 8px 0 0;
}

.email-error {
  grid-column: 1 / -1;
  margin: 0;
  padding: 10px;
  overflow-x: auto;
  border-radius: 6px;
  color: #7f1d1d;
  background: #fff1f2;
  white-space: pre-wrap;
}

.quick-email-test {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 14px;
}

.quick-email-test input {
  flex: 1 1 260px;
}

dialog {
  width: min(1040px, calc(100vw - 30px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.24);
}

dialog::backdrop {
  background: rgba(9, 20, 30, 0.55);
}

.dialog-shell {
  position: relative;
  padding: 24px;
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  background: #e8edf3;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
}

.detail-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.detail-block h3 {
  margin-bottom: 12px;
}

.kv {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid #edf1f5;
}

.kv span:first-child {
  color: var(--muted);
}

.product-photo {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  background: #f3f6f8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tech-form {
  display: grid;
  gap: 12px;
}

.stacked-section {
  margin-top: 18px;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 6px 0;
}

.email-draft {
  min-height: 260px;
  white-space: pre-wrap;
}

.doc-preview {
  background: #fff;
  color: #111;
  padding: 28px;
  border: 1px solid #d0d0d0;
}

.doc-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 2px solid #111;
  padding-bottom: 14px;
  margin-bottom: 18px;
}

.doc-logo {
  display: block;
  width: 210px;
  max-width: 100%;
  height: auto;
  margin-bottom: 12px;
}

.inspection-report {
  max-width: 820px;
  margin: 0 auto;
  font-size: 13px;
  line-height: 1.45;
}

.report-company {
  margin-bottom: 18px;
}

.report-company strong {
  display: block;
  font-size: 15px;
}

.report-title {
  text-align: center;
  font-size: 20px;
  margin: 14px 0 16px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 18px;
}

.report-table th,
.report-table td {
  border: 1px solid #777;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.report-table th {
  background: #e8edf3;
}

.report-table td:first-child,
.report-table th:first-child {
  width: 32%;
  font-weight: 700;
}

.report-section {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 14px;
  border-top: 1px solid #bbb;
  padding: 10px 0;
}

.report-section h3 {
  font-size: 13px;
}

.prepared-line {
  margin-top: 20px;
}

.return-form-doc {
  max-width: 900px;
  margin: 0 auto;
  font-size: 13px;
  line-height: 1.35;
}

.return-form-header {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  margin-bottom: 24px;
}

.return-form-logo {
  width: 250px;
  max-width: 100%;
}

.return-form-header h2 {
  font-size: 24px;
  text-align: center;
}

.return-form-header p {
  margin-top: 12px;
  text-align: right;
  font-weight: 700;
}

.return-form-table,
.return-form-meta {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.return-form-table th,
.return-form-table td,
.return-form-meta th,
.return-form-meta td {
  border: 1px solid #222;
  padding: 10px;
  vertical-align: top;
}

.return-form-table th,
.return-form-meta th {
  font-weight: 700;
  text-align: left;
}

.return-form-table th:nth-child(3),
.return-form-table th:nth-child(4),
.return-form-table th:nth-child(5),
.return-form-table th:nth-child(6),
.check-cell {
  text-align: center;
}

.return-form-meta th {
  width: 34%;
}

.customer-line {
  margin: 28px 0 34px;
  font-size: 14px;
}

.return-photo-box {
  display: grid;
  gap: 10px;
  margin: 0 0 28px;
  padding: 12px;
  border: 1px solid #222;
}

.return-photo-box img {
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
}

.return-signatures {
  display: grid;
  gap: 48px;
  margin-top: 20px;
}

.long-sign-line {
  border-bottom: 1px solid #111;
  height: 34px;
}

.signature-pair {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr);
  gap: 40px;
  align-items: end;
  margin-top: 28px;
}

.short-sign-line {
  border-bottom: 1px solid #111;
  height: 24px;
}

.sign-labels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 6px;
  font-size: 12px;
}

.signature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 50px;
}

.signature-line {
  border-top: 1px solid #111;
  padding-top: 8px;
}

@media (max-width: 820px) {
  .app-header,
  .panel-heading,
  .form-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow-x: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-btn {
    min-width: 0;
    margin-bottom: 0;
    text-align: center;
    white-space: normal;
  }

  .content {
    padding: 16px;
  }

  .stats-grid,
  .form-grid,
  .file-grid,
  .detail-grid,
  .signature-grid,
  .return-form-header,
  .signature-pair {
    grid-template-columns: 1fr;
  }

  .record-row,
  .user-row,
  .email-log-row {
    grid-template-columns: 1fr;
  }

  .row-actions {
    justify-content: flex-start;
  }
}

@media print {
  body * {
    visibility: hidden;
  }

  .doc-preview,
  .doc-preview * {
    visibility: visible;
  }

  .doc-preview {
    position: absolute;
    inset: 0;
    border: 0;
    box-shadow: none;
  }

  .close-btn,
  .print-hide {
    display: none !important;
  }
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.section-heading:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.return-entry .section-heading h3,
.master-data h3 {
  font-size: 17px;
}

.sub-panel {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.mini-stats {
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  margin-bottom: 4px;
}

.party-records {
  display: grid;
  gap: 12px;
}

.party-card {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(220px, 1fr) minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.party-card h3 {
  margin-top: 8px;
}

.party-card p {
  margin-top: 6px;
  color: var(--muted);
  white-space: pre-wrap;
}

.reason-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

@media (max-width: 820px) {
  .party-card,
  .mini-stats {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

.quick-add-party {
  margin-bottom: 18px;
}

.quick-add-party .panel-heading {
  margin-bottom: 12px;
}

.notification-box {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.notification-box h3 {
  font-size: 18px;
}

.notification-box p,
.notification-box small {
  color: var(--muted);
}

.notification-box textarea {
  min-height: 120px;
  font-weight: 700;
}

.returned-items {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.item-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 12px;
}
.item-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
}
.item-summary div {
  display: grid;
  gap: 3px;
}
.item-summary span {
  color: var(--muted);
  font-size: 13px;
}
.item-fields {
  display: grid;
  grid-template-columns: minmax(150px, .8fr) minmax(180px, 1fr) minmax(90px, .4fr) minmax(150px, .6fr);
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.item-row.is-collapsed .item-fields {
  display: none;
}
.item-row:not(.is-collapsed) .edit-item {
  visibility: hidden;
}
.edit-item[hidden] {
  display: none !important;
}
.icon-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  font-size: 20px;
}
.item-photos {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.item-photo-count {
  color: var(--muted);
}
.finish-item,
.review-return {
  grid-column: 1 / -1;
}
.review-return {
  margin-top: 4px;
}
.item-serials,
.item-notes {
  grid-column: span 2;
}

.party-actions {
  display: flex;
  justify-content: flex-end;
}

.party-actions .button-link {
  min-width: 78px;
  text-align: center;
}

.serial-help {
  display: block;
  margin: 4px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.serial-lines {
  line-height: 34px;
  min-height: 112px;
  background-color: #fff;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 32px,
    #8da1b5 33px,
    #8da1b5 34px
  );
  background-size: 100% 34px;
  resize: vertical;
}

.scan-barcode {
  margin-top: 8px;
  width: 100%;
}

.scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 12, 22, .82);
}

.scanner-box {
  width: min(520px, 100%);
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  background: #fff;
}

.scanner-box video {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: #111827;
}

.scanner-box p {
  margin: 0;
  color: var(--muted);
  text-align: center;
}

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

.signature-instructions {
  padding: 12px 14px;
  border: 1.5px solid #9fb0c1;
  border-radius: 8px;
  background: #eef7fa;
  color: var(--text);
  font-weight: 700;
}

.signature-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
}

.signature-pad-wrap {
  height: 180px;
  border: 1.5px solid #9fb0c1;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  touch-action: none;
}

.signature-pad {
  display: block;
  width: 100%;
  height: 100%;
}

.item-check {
  align-self: end;
  min-height: 42px;
}
@media (max-width: 820px) {
  .item-fields { grid-template-columns: 1fr; }
  .item-serials,
  .item-notes { grid-column: auto; }
}

.return-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow-y: auto;
  padding: 24px;
  background: rgba(7, 24, 39, .72);
}
.return-preview-overlay[hidden] {
  display: none;
}
.return-preview-panel {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 20px;
  border-radius: 8px;
  background: #fff;
}
.preview-heading,
.preview-item-heading,
.preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.return-preview-content {
  display: grid;
  gap: 14px;
  margin: 18px 0;
}
.preview-party,
.preview-item {
  padding: 14px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.return-preview-content dl {
  display: grid;
  grid-template-columns: minmax(130px, .4fr) 1fr;
  gap: 8px 14px;
  margin: 12px 0 0;
}
.return-preview-content dt {
  font-weight: 700;
}
.return-preview-content dd {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.edit-preview-item {
  width: auto;
  min-height: 38px;
  padding: 8px 12px;
}
.preview-open {
  overflow: hidden;
}

/* Mobile-first polish for field use on phones */
@media (max-width: 820px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    background: #eef3f7;
    font-size: 15px;
  }

  .app-header {
    gap: 10px;
    padding: 10px 12px;
  }

  .brand-lockup {
    gap: 10px;
  }

  .app-logo {
    width: 70px !important;
  }

  .brand-lockup h1 {
    font-size: 17px !important;
    line-height: 1.15;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .user-badge,
  .header-actions .button-link {
    min-height: 38px;
    font-size: 14px;
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    position: sticky;
    top: 0;
    z-index: 5;
    gap: 8px;
    padding: 8px 10px;
    overflow-x: hidden;
    overflow-y: visible;
    background: #e2eaf1;
    border-bottom: 1.5px solid var(--line);
  }

  .sidebar a {
    min-width: 0;
    margin: 0;
    padding: 11px 13px;
    border: 1.5px solid #b7c5d3;
    background: #f8fafc;
    text-align: center;
    white-space: normal;
  }

  .content {
    padding: 12px;
    max-width: 100%;
    overflow-x: hidden;
  }

  .return-search {
    padding: 12px;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .search-row button,
  .search-row .button-link {
    width: 100%;
  }

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

  .signature-pad-wrap {
    height: 210px;
  }

  @media (orientation: landscape) {
    .signature-pad-wrap {
      height: 260px;
    }
  }

  .panel,
  .stat,
  .sub-panel,
  .notification-box,
  .returned-items,
  .record-row,
  .party-card,
  .attachment-row,
  .email-log-row,
  .item-row {
    border-width: 1.5px;
    box-shadow: none;
  }

  .panel {
    padding: 14px;
    max-width: 100%;
  }

  .stats-grid {
    gap: 10px;
    margin-bottom: 12px;
  }

  .stat {
    padding: 13px 14px;
  }

  .stat span {
    font-size: 26px;
  }

  h2 {
    font-size: 19px;
  }

  h3,
  .return-entry .section-heading h3,
  .master-data h3 {
    font-size: 16px;
  }

  .form-grid {
    gap: 13px;
  }

  label {
    gap: 6px;
    font-size: 14px;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    padding: 11px 12px;
    border-width: 1.5px;
    font-size: 16px;
  }

  textarea {
    min-height: 96px;
  }

  .button-link,
  button {
    width: 100%;
    min-height: 46px;
    padding: 12px 14px;
    font-size: 15px;
  }

  .form-actions,
  .row-actions,
  .doc-actions,
  .quick-email-test {
    flex-direction: column;
    align-items: stretch;
  }

  .reference-pill,
  .status-pill {
    white-space: normal;
    line-height: 1.2;
  }

  .record-row,
  .item-row,
  .party-card {
    padding: 12px;
    gap: 12px;
  }

  .return-preview-overlay {
    padding: 0;
    background: #fff;
  }

  .return-preview-panel {
    min-height: 100%;
    padding: 14px;
  }

  .return-preview-content dl {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .return-preview-content dd {
    margin-bottom: 9px;
  }

  .preview-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .row-actions .button-link {
    min-width: 0;
  }

  .file-grid {
    gap: 10px;
  }

  .file-drop {
    padding: 12px;
  }

  .notification-box textarea {
    min-height: 135px;
  }

  .returned-items {
    padding: 12px;
  }

  .item-check {
    align-self: stretch;
    min-height: 44px;
    padding: 10px 12px;
    border: 1.5px solid #aebdcc;
    border-radius: 6px;
    background: #fff;
  }

  .item-check input,
  .inline-check input {
    width: auto;
    min-height: auto;
  }

  .return-form-table,
  .return-form-meta,
  .report-table {
    font-size: 12px;
  }
}

@media (max-width: 820px) {
  .layout,
  .content,
  .panel,
  .sidebar {
    width: 100%;
    max-width: 100%;
  }

  .sidebar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    overflow-x: hidden !important;
  }

  .sidebar a,
  .nav-btn {
    min-width: 0 !important;
    width: 100% !important;
    white-space: normal !important;
  }
}

/* Responsive layout safeguards for tablets and field phones. */
@media (min-width: 821px) and (max-width: 1100px) {
  .layout {
    grid-template-columns: 184px minmax(0, 1fr);
  }

  .content {
    padding: 20px;
  }

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

  .record-row,
  .email-log-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-row > :last-child,
  .email-log-row > :last-child {
    grid-column: 1 / -1;
  }

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

  .party-card > :last-child {
    grid-column: 1 / -1;
  }

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

@media (max-width: 820px) {
  .app-header {
    align-items: stretch;
  }

  .brand-lockup {
    width: 100%;
    justify-content: space-between;
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }

  .header-actions .button-link {
    width: 100%;
    min-width: 0;
  }

  .header-actions .button-link:first-child {
    grid-column: 1;
    grid-row: 2;
  }

  .header-actions .button-link:last-child {
    grid-column: 2;
    grid-row: 2;
  }

  .header-actions .user-badge {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100%;
    justify-content: center;
    overflow-wrap: anywhere;
    text-align: center;
  }

  .login-screen {
    align-items: start;
    padding: 72px 16px 24px;
  }

  .login-card {
    padding: 24px 20px;
  }

  .login-card h1 {
    font-size: clamp(24px, 7vw, 29px);
    line-height: 1.08;
  }

  .panel-heading,
  .form-title,
  .section-heading {
    gap: 10px;
  }

  .panel-heading > .button-link,
  .section-heading > button {
    width: 100%;
  }

  .record-row,
  .email-log-row,
  .party-card,
  .user-row,
  .attachment-row {
    grid-template-columns: 1fr;
  }

  .record-row > :last-child,
  .email-log-row > :last-child,
  .party-card > :last-child {
    grid-column: auto;
  }

  .kv,
  .report-section {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .doc-preview {
    padding: 16px;
    overflow-x: auto;
  }

  .doc-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .return-form-header {
    gap: 14px;
  }

  .return-form-header h2,
  .return-form-header p {
    text-align: left;
  }

  .return-form-table,
  .return-form-meta,
  .report-table {
    min-width: 620px;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 10px;
  }

  .brand-lockup h1 {
    font-size: 16px !important;
    letter-spacing: .03em !important;
  }

  .app-logo {
    width: 58px !important;
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    position: static;
    align-items: stretch;
    grid-auto-rows: auto;
  }

  .content,
  .panel {
    padding: 10px;
  }

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

  .reference-pill,
  .status-pill,
  .user-badge {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .item-summary {
    align-items: flex-start;
  }

  .item-summary span {
    overflow-wrap: anywhere;
  }

  .return-preview-panel {
    padding: 12px;
  }
}
