:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #697586;
  --line: #d9dee7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --soft: #edf7f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* SSO banner styling */
.sso-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.sso-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: #ddd; }
.sso-name { font-weight: 600; font-size: 14px; }

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  min-height: 36px;
  padding: 0 12px;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
}

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

.actions button:nth-child(2),
.actions button:nth-child(3) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(420px, 1fr);
  gap: 18px;
  padding: 18px;
}

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

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 12px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 10px;
  text-transform: none;
}

textarea {
  resize: vertical;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.btn-icon {
  min-height: 24px;
  min-width: 24px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  border-radius: 50%;
  flex-shrink: 0;
}

.add-customer-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.add-customer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

#newCustomerStatus {
  font-size: 12px;
  color: var(--muted);
}

.customer-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 12px;
  min-height: 72px;
  color: var(--muted);
}

.customer-card strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.add-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 12px;
  min-height: 26px;
  border-radius: 13px;
  color: var(--accent);
  border-color: var(--accent);
  background: var(--soft);
}
.add-badge:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.btn-remove-section {
  padding: 0;
  min-height: 22px;
  min-width: 22px;
  border-radius: 50%;
  font-size: 14px;
  color: var(--muted);
}
.btn-remove-section:hover { color: #dc2626; border-color: #dc2626; }

#serviceOrderSection, #invoicePartsSection {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--soft);
}
#serviceOrderSection[hidden], #invoicePartsSection[hidden] { display: none; }

.inv-part-line {
  display: grid;
  grid-template-columns: 1fr 64px 92px 36px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.ipl-remove { padding: 0; min-width: 36px; font-size: 16px; }

.add-part-row { font-size: 12px; min-height: 28px; padding: 0 10px; align-self: flex-start; }

/* Invoice preview service order / parts boxes */
.so-preview-box {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 16px 18px;
}
.so-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.so-preview-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: #667085; }
.so-preview-wo { font-weight: 700; font-size: 15px; }
.so-meta { font-size: 13px; color: #4b5563; margin-bottom: 3px; }
.so-preview-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.so-preview-table th {
  color: #667085; font-size: 11px; text-transform: uppercase;
  border-bottom: 1px solid #e5e7eb; padding: 5px 0; text-align: left;
}
.so-preview-table th:not(:first-child),
.so-preview-table td:not(:first-child) { text-align: right; }
.so-preview-table td { padding: 5px 0; border-bottom: 1px solid #f3f4f6; }
.so-labour-line { font-size: 13px; color: #374151; padding: 6px 0; border-top: 1px solid #e5e7eb; margin-top: 4px; }
.so-section-total { text-align: right; font-weight: 700; font-size: 13px; padding-top: 6px; }

.line-head,
.line-item {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 72px 92px 72px 36px;
  gap: 8px;
  align-items: center;
}

.line-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

#lineItems {
  display: grid;
  gap: 8px;
}

.remove-line {
  padding: 0;
  min-width: 36px;
}

.preview-wrap {
  padding: 22px;
  overflow: auto;
}

.invoice {
  max-width: 860px;
  min-height: 980px;
  margin: 0 auto;
  background: #fff;
  color: #111827;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 44px;
}

.invoice-header,
.invoice-meta,
.invoice-total-row,
.invoice-party-grid {
  display: flex;
  justify-content: space-between;
  gap: 28px;
}

.invoice-title {
  font-size: 34px;
  font-weight: 800;
}

.invoice-subtitle,
.invoice-muted {
  color: #667085;
}

.invoice-box {
  margin-top: 28px;
}

.invoice-party-grid > div {
  flex: 1;
}

.invoice table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 28px;
}

.invoice th,
.invoice td {
  border-bottom: 1px solid #e5e7eb;
  padding: 11px 0;
  text-align: left;
  vertical-align: top;
}

.invoice th:not(:first-child),
.invoice td:not(:first-child) {
  text-align: right;
}

.totals {
  margin: 24px 0 0 auto;
  width: min(340px, 100%);
}

.invoice-total-row {
  padding: 7px 0;
  border-bottom: 1px solid #e5e7eb;
}

.invoice-total-row.grand {
  font-size: 20px;
  font-weight: 800;
  border-bottom: 0;
}

.notes {
  margin-top: 34px;
  white-space: pre-wrap;
}

.invoice-number-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  text-align: right;
}

.invoice-qr-box {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
}

.invoice-qr {
  display: block;
  width: 88px;
  height: 88px;
}

.invoice-qr-label {
  font-size: 11px;
  font-weight: 700;
  color: #111827;
  letter-spacing: 0.04em;
  text-align: center;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .grid.two,
  .line-head,
  .line-item {
    grid-template-columns: 1fr;
  }

  .line-head {
    display: none;
  }
}

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

  .topbar,
  .controls {
    display: none;
  }

  .workspace,
  .preview-wrap {
    display: block;
    padding: 0;
  }

  .panel,
  .invoice {
    border: 0;
    border-radius: 0;
  }

  .invoice {
    max-width: none;
    min-height: auto;
    padding: 24px;
  }
}
