:root {
  color-scheme: light;
  --navy: #102a43;
  --blue: #1f5f8b;
  --sky: #dff1fb;
  --gold: #f4b942;
  --ink: #18212b;
  --muted: #607080;
  --line: #dbe3ea;
  --surface: #ffffff;
  --canvas: #eef3f7;
  --danger: #b42318;
  --shadow: 0 14px 40px rgba(16, 42, 67, 0.12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button,
input[type="radio"] {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  padding: calc(12px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  background: var(--navy);
  color: white;
}

.brand-lockup,
.company {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-lockup > div,
.company > div {
  min-width: 0;
}

.brand-mark,
.company-logo {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--gold);
  color: var(--navy);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: -1px;
}

.app-header h1 {
  margin: 2px 0 0;
  font-size: 18px;
  line-height: 1.1;
}

.eyebrow {
  margin: 0;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.app-header .eyebrow {
  color: #a9d5ef;
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 16px 12px calc(112px + env(safe-area-inset-bottom));
}

.toolbar {
  position: fixed;
  z-index: 4;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -8px 28px rgba(16, 42, 67, 0.12);
  backdrop-filter: blur(12px);
}

.toolbar-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  flex: 1 1 100%;
  gap: 8px;
}

.toolbar-actions .button {
  min-width: 0;
  padding-right: 9px;
  padding-left: 9px;
  font-size: 12px;
}

.toolbar-actions #settingsButton {
  min-width: 0;
}

.toolbar-actions .print-action {
  background: var(--blue);
}

.save-state {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2e9d66;
}

.button,
.icon-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 750;
}

.button-primary {
  background: var(--navy);
  color: white;
}

.button-secondary,
.icon-button {
  border-color: #c8d4de;
  background: white;
  color: var(--navy);
}

.icon-button {
  min-height: 38px;
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.receipt-paper {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.receipt-heading {
  display: grid;
  gap: 18px;
  padding: 22px 18px;
  background: var(--navy);
  color: white;
}

.company {
  align-items: flex-start;
}

.company-logo {
  width: 54px;
  height: 54px;
  border-radius: 15px;
  font-size: 18px;
}

.company-name {
  margin: 0 0 5px;
  font-size: clamp(18px, 5vw, 25px);
  font-weight: 900;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.company-products {
  max-width: 650px;
  margin: 0;
  color: #c8dce9;
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.receipt-heading address {
  font-size: 12px;
  font-style: normal;
  line-height: 1.6;
}

.document-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  margin: 0;
  border: 0;
  padding: 3px;
  border-radius: 12px;
  background: #edf2f6;
}

.segmented-control label {
  position: relative;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: block;
  min-width: 92px;
  border-radius: 9px;
  padding: 9px 16px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.segmented-control input:checked + span {
  background: white;
  color: var(--navy);
  box-shadow: 0 2px 8px rgba(16, 42, 67, 0.12);
}

.segmented-control input:focus-visible + span,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(31, 95, 139, 0.25);
  outline-offset: 2px;
}

.receipt-number {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: right;
  text-transform: uppercase;
  width: 100%;
  text-align: left;
}

.receipt-number input {
  width: 100%;
  border: 0;
  border-bottom: 2px solid var(--navy);
  border-radius: 0;
  padding: 4px 2px;
  color: var(--navy);
  font-size: 20px;
  font-weight: 850;
  text-align: left;
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--line);
}

.field {
  display: grid;
  min-width: 0;
  gap: 6px;
  margin: 0;
}

.field > span,
.field legend {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd7e1;
  border-radius: 9px;
  background: white;
  padding: 9px 11px;
  color: var(--ink);
}

.field textarea {
  resize: vertical;
}

.transaction-field {
  border: 0;
  padding: 0;
}

.inline-options {
  display: flex;
  align-items: center;
  min-height: 42px;
  gap: 18px;
}

.inline-options label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 650;
}

.inline-options input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.items-section {
  padding: 20px 18px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.section-heading h2,
.dialog-heading h2 {
  margin: 2px 0 0;
  color: var(--navy);
  font-size: 21px;
}

.item-header {
  display: none;
}

.item-row {
  position: relative;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 44px;
  gap: 9px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.item-field {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.item-field::before {
  content: attr(data-label);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.item-field input {
  width: 100%;
  min-width: 0;
  min-height: 39px;
  border: 1px solid #cbd7e1;
  border-radius: 8px;
  padding: 7px 9px;
}

.item-description,
.item-part {
  grid-column: 1 / 4;
}

.item-amount {
  display: grid;
  align-content: end;
  min-height: 39px;
  padding: 0 2px 8px;
  font-weight: 800;
  text-align: right;
}

.remove-line {
  align-self: end;
  width: 39px;
  height: 39px;
  border: 1px solid #ebc5c1;
  border-radius: 8px;
  background: #fff5f3;
  color: var(--danger);
  font-size: 21px;
  line-height: 1;
}

.receipt-footer {
  display: grid;
  gap: 18px;
  padding: 20px 18px;
}

.notes-area {
  display: grid;
  gap: 14px;
}

.warranty {
  border-left: 4px solid var(--gold);
  border-radius: 0 8px 8px 0;
  background: #fff9e9;
  padding: 11px 13px;
}

.warranty h3 {
  margin: 0 0 4px;
  color: var(--navy);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.warranty p {
  margin: 0;
  color: #4f5660;
  font-size: 11px;
  line-height: 1.45;
}

.totals-card {
  align-self: start;
  border-radius: 12px;
  background: #f2f6f9;
  padding: 13px 15px;
}

.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 36px;
  color: var(--muted);
  font-size: 14px;
}

.total-row output {
  color: var(--ink);
  font-weight: 750;
}

.tax-input {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tax-summary,
.card-fee-details {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.card-fee-details[hidden] {
  display: none;
}

.tax-summary output {
  min-width: 68px;
  text-align: right;
}

.tax-input input {
  width: 76px;
  min-height: 36px;
  border: 1px solid #cbd7e1;
  border-radius: 8px;
  padding: 6px 8px;
  text-align: right;
}

.card-fee-row {
  flex-wrap: wrap;
}

.card-fee-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.card-fee-toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--blue);
}

.fee-input {
  display: flex;
  align-items: center;
  gap: 3px;
}

.fee-input input {
  width: 72px;
  min-height: 36px;
  border: 1px solid #cbd7e1;
  border-radius: 8px;
  padding: 6px 8px;
  text-align: right;
}

.card-fee-details output {
  color: var(--ink);
  min-width: 62px;
  font-weight: 750;
  text-align: right;
}

.grand-total {
  margin-top: 6px;
  border-top: 2px solid var(--navy);
  padding-top: 10px;
  color: var(--navy);
  font-size: 19px;
  font-weight: 900;
}

.grand-total output {
  color: var(--navy);
  font-size: 21px;
}

.acknowledgement {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 0 18px 22px;
}

.iphone-tips {
  margin: 14px 8px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.iphone-tips p {
  margin: 4px 0;
}

.print-only,
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

dialog {
  width: min(calc(100% - 28px), 560px);
  max-height: min(80vh, 680px);
  border: 0;
  border-radius: 18px;
  padding: 0;
  box-shadow: 0 22px 80px rgba(16, 42, 67, 0.28);
}

dialog::backdrop {
  background: rgba(16, 42, 67, 0.55);
  backdrop-filter: blur(2px);
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 20px 14px;
}

.dialog-search {
  padding: 0 20px 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 13px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 0 20px 18px;
}

.close-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: #edf2f6;
  color: var(--navy);
  font-size: 26px;
}

.draft-list {
  display: grid;
  gap: 8px;
  max-height: 45vh;
  overflow-y: auto;
  padding: 0 20px 16px;
}

.draft-empty {
  border: 1px dashed #cbd7e1;
  border-radius: 12px;
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.draft-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px;
}

.draft-load {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 2px;
  text-align: left;
}

.draft-load strong,
.draft-load span {
  display: block;
}

.draft-load span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.draft-delete {
  min-width: 42px;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: #fff2f0;
  color: var(--danger);
  font-weight: 800;
}

.dialog-actions {
  padding: 14px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.dialog-actions .button {
  width: 100%;
}

.toast {
  position: fixed;
  z-index: 5;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 16px;
  max-width: 420px;
  margin: auto;
  border-radius: 10px;
  background: var(--navy);
  color: white;
  padding: 12px 15px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  transform: translateY(140%);
  transition: transform 180ms ease;
}

.toast.is-visible {
  transform: translateY(0);
}

@media (min-width: 680px) {
  .app-shell {
    padding: 24px 20px 48px;
  }

  .toolbar {
    position: static;
    margin-bottom: 12px;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  .toolbar-actions {
    display: flex;
    flex: 0 1 auto;
  }

  .toolbar-actions .button {
    flex: 0 1 auto;
    font-size: inherit;
  }

  .receipt-heading {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    padding: 26px 28px;
  }

  .receipt-heading address {
    text-align: right;
  }

  .document-title {
    flex-wrap: nowrap;
  }

  .receipt-number {
    width: auto;
    text-align: right;
  }

  .receipt-number input {
    width: 135px;
    text-align: right;
  }

  .document-title,
  .items-section,
  .receipt-footer {
    padding-right: 28px;
    padding-left: 28px;
  }

  .details-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 24px 28px;
  }

  .field-wide {
    grid-column: 1 / -1;
  }

  .item-header,
  .item-row {
    display: grid;
    grid-template-columns: 62px 1.1fr 2fr 100px 100px 40px;
    gap: 8px;
    align-items: center;
  }

  .item-header {
    padding: 0 5px 7px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .item-row {
    margin: 0;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    padding: 8px 0;
  }

  .item-field::before {
    display: none;
  }

  .item-description,
  .item-part {
    grid-column: auto;
  }

  .item-amount {
    padding: 0 5px 0 0;
  }

  .receipt-footer {
    grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.8fr);
  }

  .acknowledgement {
    grid-template-columns: 2fr 1fr;
    padding: 0 28px 28px;
  }

  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media print {
  @page {
    size: auto;
    margin: 0.35in;
  }

  :root {
    --navy: #000;
    --ink: #000;
    --muted: #333;
    --line: #aaa;
  }

  body {
    background: white;
    font-size: 10pt;
  }

  .no-print,
  .remove-line {
    display: none !important;
  }

  .print-only {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    clip-path: none;
  }

  .app-shell {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .receipt-paper {
    overflow: visible;
    border: 1px solid #555;
    border-radius: 0;
    box-shadow: none;
  }

  .receipt-heading {
    grid-template-columns: 1fr auto;
    align-items: end;
    padding: 14px 16px;
    background: white;
    color: black;
  }

  .company-logo {
    border: 2px solid black;
    background: white;
    color: black;
  }

  .company-products {
    color: #222;
  }

  .receipt-heading address {
    text-align: right;
  }

  .document-title {
    align-items: center;
    padding: 10px 16px;
  }

  .document-title h2 {
    margin: 0;
    font-size: 18pt;
  }

  .details-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 14px;
    padding: 12px 16px;
  }

  .field-wide {
    grid-column: 1 / -1;
  }

  .field input,
  .field textarea,
  .item-field input,
  .tax-input input {
    min-height: 0;
    border: 0;
    border-bottom: 1px solid #777;
    border-radius: 0;
    padding: 3px 1px;
    resize: none;
  }

  .items-section {
    padding: 12px 16px;
  }

  .section-heading {
    margin-bottom: 6px;
  }

  .section-heading h2 {
    font-size: 14pt;
  }

  .item-header,
  .item-row {
    display: grid;
    grid-template-columns: 42px 1.1fr 2fr 75px 78px;
    gap: 6px;
    align-items: center;
  }

  .item-header {
    padding: 5px 3px;
    border-top: 1px solid #777;
    border-bottom: 1px solid #777;
  }

  .item-row {
    break-inside: avoid;
    margin: 0;
    border: 0;
    border-bottom: 1px solid #ccc;
    border-radius: 0;
    padding: 4px 0;
  }

  .item-field::before {
    display: none;
  }

  .item-description,
  .item-part {
    grid-column: auto;
  }

  .item-amount {
    min-height: 0;
    padding: 0;
  }

  .receipt-footer {
    grid-template-columns: 1.5fr 0.8fr;
    gap: 14px;
    padding: 12px 16px;
  }

  .warranty {
    border-left-color: #555;
    background: white;
  }

  .totals-card {
    background: white;
    border: 1px solid #777;
  }

  .card-fee-row.is-disabled {
    display: none;
  }

  .card-fee-details[hidden] {
    display: none;
  }

  .acknowledgement {
    grid-template-columns: 2fr 1fr;
    padding: 0 16px 14px;
  }
}
