:root {
  color-scheme: light;
  --ink: #0a0a0a;
  --muted: #717171;
  --line: #c9c9c9;
  --line-strong: #a7a7a7;
  --paper: #fbfbfa;
  --app-bg: #ececea;
  --accent: #ff1414;
  --focus: #111111;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--app-bg);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--app-bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.app-shell {
  min-height: 100vh;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 10px max(18px, calc((100vw - 1240px) / 2));
  background: rgb(250 250 249 / 92%);
  border-bottom: 1px solid #ddddda;
  backdrop-filter: blur(14px);
}

.toolbar-copy {
  display: grid;
  gap: 2px;
  min-width: 150px;
}

.toolbar-copy strong {
  font-size: 14px;
}

.toolbar-copy span,
.tool-field span {
  flex: 0 0 auto;
  color: #666666;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 11px;
  text-transform: uppercase;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.tool-field {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid #d7d7d4;
  border-radius: 6px;
  background: #ffffff;
}

.tool-field input,
.tool-field select {
  flex: 0 0 auto;
  width: 76px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.tool-field select {
  width: 86px;
}

.company-field input {
  width: 132px;
}

.company-field {
  min-width: 206px;
}

.tagline-field {
  min-width: 188px;
}

.tagline-field input {
  width: 116px;
}

.currency-field select {
  width: 72px;
}

.tax-preset-field {
  min-width: 188px;
}

.tax-preset-field select {
  width: 104px;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 42px;
  height: 38px;
  padding: 0 12px;
  color: var(--ink);
  border: 1px solid #cececb;
  border-radius: 6px;
  background: #ffffff;
}

.tool-button.icon-only {
  width: 42px;
  padding: 0;
}

.file-button {
  position: relative;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.tool-button:hover,
.tool-field:focus-within {
  border-color: #8f8f8c;
}

.tool-button:focus-visible,
.editable:focus-visible,
.chat-panel textarea:focus-visible,
.row-action:focus-visible,
.tool-field input:focus-visible,
.tool-field select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.chat-panel {
  position: sticky;
  top: 64px;
  z-index: 9;
  padding: 12px max(18px, calc((100vw - 1240px) / 2));
  background: rgb(250 250 249 / 96%);
  border-bottom: 1px solid #ddddda;
  backdrop-filter: blur(14px);
}

.chat-panel-inner {
  display: grid;
  grid-template-columns: 190px minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: stretch;
}

.chat-panel-copy {
  display: grid;
  align-content: center;
  gap: 4px;
}

.chat-panel-copy strong {
  font-size: 14px;
}

.chat-panel-copy span {
  color: #666666;
  font-size: 12px;
  line-height: 1.35;
}

.chat-panel textarea {
  min-height: 92px;
  resize: vertical;
  padding: 12px;
  color: var(--ink);
  border: 1px solid #d7d7d4;
  border-radius: 6px;
  background: #ffffff;
  line-height: 1.45;
}

.chat-actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.invoice-wrap {
  display: flex;
  justify-content: center;
  padding: 28px 18px 54px;
}

.print-window {
  background: #ffffff;
}

.print-page {
  display: flex;
  justify-content: center;
  padding: 24px;
}

.print-page .invoice {
  box-shadow: none;
}

.invoice {
  position: relative;
  width: min(100%, 1040px);
  min-height: 1348px;
  overflow: hidden;
  padding: clamp(30px, 6vw, 68px);
  background: var(--paper);
  box-shadow: 0 22px 70px rgb(0 0 0 / 13%);
}

.invoice-dot-field {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(24, 18px);
  grid-auto-rows: 18px;
  width: 432px;
  height: 252px;
  pointer-events: none;
  opacity: 0.48;
  overflow: hidden;
  z-index: 0;
}

.invoice-field-dot {
  display: block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #cfcfca;
}

.invoice-dot-field-top {
  top: 0;
  left: 58px;
}

.invoice-dot-field-bottom {
  bottom: 230px;
  left: 56px;
}

.red-dot {
  position: absolute;
  top: 145px;
  left: 60px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
}

.decor-plus {
  position: absolute;
  color: #111111;
  font-size: 28px;
  font-weight: 300;
  line-height: 1;
}

.decor-plus-top {
  top: 48px;
  right: 64px;
}

.decor-plus-bottom {
  bottom: 32px;
  left: 48px;
}

.invoice-header,
.summary-grid,
.invoice-footer {
  position: relative;
  z-index: 1;
}

.invoice-header {
  display: grid;
  grid-template-columns: 1fr 0.85fr;
  gap: 36px;
  align-items: start;
}

.brand-block {
  padding-left: 38px;
}

.brand-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 58px;
}

.dot-logo {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 5px 7px;
  max-width: 430px;
  min-height: 48px;
}

.dot-letter {
  display: grid;
  grid-template-columns: repeat(5, 5px);
  grid-auto-rows: 5px;
  gap: 2px;
}

.dot-letter i {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.dot-letter .on {
  background: #000000;
}

.dot-letter .off {
  background: transparent;
}

.dot-space {
  width: 14px;
}

.brand-logo-image {
  display: block;
  width: auto;
  max-width: min(360px, 100%);
  max-height: 78px;
  object-fit: contain;
  object-position: left center;
}

.brand-text-logo {
  max-width: 430px;
  font-size: clamp(38px, 4.6vw, 58px);
  line-height: 0.98;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.brand-font-sans {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 700;
}

.brand-font-mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-weight: 700;
}

.brand-font-serif {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
}

.studio-label,
.tiny-label,
.section-label {
  margin: 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-weight: 700;
  text-transform: uppercase;
}

.studio-label {
  display: inline-flex;
  gap: 7px;
  margin-top: 18px;
  font-size: 15px;
}

.tiny-label,
.section-label {
  display: inline-flex;
  gap: 4px;
  font-size: 12px;
  line-height: 1.2;
}

.title-block {
  padding-top: 11px;
}

.title-block h1 {
  display: inline-flex;
  gap: 22px;
  margin: 0;
  font-size: clamp(40px, 6vw, 58px);
  font-weight: 400;
  line-height: 1;
}

.invoice-code {
  display: inline-block;
  margin: 32px 0 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 18px;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1px 0.88fr;
  gap: 64px;
  align-items: start;
  margin-top: 74px;
}

.summary-divider {
  width: 1px;
  min-height: 240px;
  background: var(--line-strong);
}

.contact-list {
  padding-left: 31px;
}

.contact-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 31px;
  align-items: center;
  min-height: 57px;
  border-bottom: 1px solid var(--line);
}

.contact-row:first-child {
  min-height: 70px;
}

.contact-icon {
  display: grid;
  place-items: center;
  color: #111111;
}

.contact-icon svg {
  width: 22px;
  height: 22px;
}

.editable {
  min-width: 1px;
  border-radius: 3px;
}

.editable:hover {
  background: rgb(255 20 20 / 5%);
}

.editable:empty::before {
  content: "Type";
  color: #9a9a9a;
}

.multiline {
  white-space: pre-line;
}

.meta-table {
  margin: 0;
  padding: 0;
}

.meta-row {
  display: grid;
  grid-template-columns: 1fr 132px;
  gap: 18px;
  align-items: center;
  min-height: 58px;
  border-bottom: 1px solid var(--line);
}

.meta-row dd {
  margin: 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  text-align: right;
}

.status-value {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.client-section {
  position: relative;
  z-index: 1;
  margin-top: 60px;
  padding-left: 18px;
}

.bracket-label {
  position: relative;
  padding-right: 16px;
}

.bracket-label::after {
  content: "";
  position: absolute;
  top: 1px;
  right: 0;
  width: 8px;
  height: 8px;
  border-top: 1px solid var(--ink);
  border-right: 1px solid var(--ink);
}

.client-section h2 {
  width: fit-content;
  max-width: 100%;
  margin: 23px 0 9px;
  font-size: clamp(27px, 4vw, 32px);
  font-weight: 400;
  line-height: 1.15;
}

.client-address {
  width: fit-content;
  max-width: 100%;
  font-size: 16px;
  line-height: 1.55;
}

.items-section {
  position: relative;
  z-index: 1;
  margin-top: 44px;
  border-top: 1px solid var(--line-strong);
}

.item-head,
.item-row {
  display: grid;
  grid-template-columns: 32px minmax(180px, 1fr) minmax(54px, 0.22fr) minmax(126px, 0.42fr) minmax(126px, 0.42fr);
  gap: 18px;
  align-items: center;
}

.item-head {
  min-height: 58px;
  border-bottom: 1px solid var(--line);
}

.align-center {
  justify-content: center;
}

.align-right {
  justify-content: flex-end;
}

.item-row {
  min-height: 64px;
  border-bottom: 1px solid var(--line);
}

.row-action {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: #8b8b8b;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 23px;
  font-weight: 200;
  transform: rotate(0deg);
  transition: color 140ms ease, transform 140ms ease;
}

.row-action:hover {
  color: var(--accent);
  transform: rotate(45deg);
}

.item-description {
  font-size: 17px;
  font-weight: 700;
}

.item-quantity,
.item-price,
.item-amount {
  font-size: 16px;
}

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

.item-price,
.item-amount {
  text-align: right;
}

.money {
  font-variant-numeric: tabular-nums;
}

.invoice-footer {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 36px;
  margin-top: 31px;
}

.footer-left {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 354px;
  padding-left: 8px;
}

.notes-block {
  max-width: 370px;
}

.notes-block .editable {
  margin-top: 17px;
  line-height: 1.55;
}

.payment-block {
  position: relative;
  padding: 37px 0 35px 7px;
  border-bottom: 1px solid var(--line-strong);
}

.payment-block::after {
  content: "";
  position: absolute;
  top: 26px;
  right: 143px;
  width: 8px;
  height: 8px;
  border-top: 1px solid var(--ink);
  border-right: 1px solid var(--ink);
}

.payment-lines {
  display: grid;
  gap: 6px;
  margin-top: 22px;
  font-size: 15px;
}

.payment-lines strong {
  width: fit-content;
}

.totals-panel {
  position: relative;
  padding: 5px 10px 0 38px;
  border-left: 1px solid var(--line-strong);
}

.totals-panel::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 17px;
  width: 14px;
  height: 14px;
  border-right: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

.total-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: baseline;
  min-height: 35px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

.total-line strong {
  font-weight: 400;
}

.dash-line {
  height: 1px;
  margin: 15px 0 34px;
  background-image: linear-gradient(to right, #999999 40%, transparent 0);
  background-position: top;
  background-size: 8px 1px;
  background-repeat: repeat-x;
}

.grand-total {
  display: block;
  margin-top: 17px;
  font-size: clamp(52px, 7vw, 72px);
  font-weight: 300;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.barcode {
  width: min(310px, 100%);
  height: 22px;
  margin-top: 25px;
  background:
    repeating-linear-gradient(
      to right,
      #000000 0 2px,
      transparent 2px 4px,
      #000000 4px 5px,
      transparent 5px 9px,
      #000000 9px 12px,
      transparent 12px 14px,
      #000000 14px 15px,
      transparent 15px 18px
    );
}

.payment-note {
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: 23px;
  align-items: center;
  margin-top: 32px;
}

.circle-arrow {
  display: grid;
  place-items: center;
  width: 47px;
  height: 47px;
  border: 1px solid var(--ink);
  border-radius: 50%;
}

.payment-note p {
  margin: 0;
  line-height: 1.55;
}

@media screen and (max-width: 820px) {
  .toolbar {
    align-items: flex-start;
    padding: 10px 12px;
  }

  .chat-panel {
    top: 0;
    padding: 10px 12px;
  }

  .chat-panel-inner {
    grid-template-columns: 1fr;
  }

  .chat-actions {
    flex-wrap: wrap;
  }

  .toolbar-actions {
    gap: 6px;
  }

  .company-field input {
    width: 116px;
  }

  .company-field {
    min-width: 196px;
  }

  .tagline-field {
    min-width: 180px;
  }

  .tagline-field input {
    width: 108px;
  }

  .tax-preset-field {
    min-width: 174px;
  }

  .tax-preset-field select {
    width: 92px;
  }

  .tool-field {
    min-height: 36px;
  }

  .invoice-wrap {
    padding: 14px 10px 34px;
  }

  .invoice {
    min-height: auto;
    padding: 31px 20px 38px;
  }

  .invoice-dot-field-top,
  .invoice-dot-field-bottom {
    left: 10px;
  }

  .red-dot {
    top: 78px;
    left: 2px;
  }

  .decor-plus-top {
    top: 21px;
    right: 21px;
  }

  .invoice-header,
  .summary-grid,
  .invoice-footer {
    grid-template-columns: 1fr;
  }

  .brand-block,
  .contact-list,
  .client-section {
    padding-left: 0;
  }

  .dot-logo {
    transform: scale(0.82);
    transform-origin: left center;
    width: 320px;
    max-width: 320px;
  }

  .brand-text-logo {
    max-width: 320px;
    font-size: 41px;
  }

  .title-block h1 {
    gap: 12px;
  }

  .summary-grid {
    gap: 28px;
    margin-top: 42px;
  }

  .summary-divider {
    display: none;
  }

  .contact-row {
    gap: 16px;
  }

  .meta-row {
    grid-template-columns: 1fr minmax(112px, auto);
  }

  .items-section {
    overflow-x: auto;
  }

  .item-head,
  .item-row {
    grid-template-columns: 28px minmax(130px, 1fr) 44px 84px 94px;
    gap: 10px;
    min-width: 580px;
  }

  .invoice-footer {
    gap: 26px;
  }

  .footer-left {
    min-height: 280px;
  }

  .totals-panel {
    padding-left: 0;
    border-left: 0;
  }

  .grand-total {
    font-size: clamp(44px, 14vw, 64px);
  }
}

@media screen and (max-width: 560px) {
  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    justify-content: flex-start;
  }

  .chat-panel {
    position: static;
  }

  .tool-button span {
    display: none;
  }

  .decor-plus-bottom {
    display: none;
  }

  .items-section {
    overflow-x: visible;
  }

  .item-head {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .item-head > div:first-child,
  .item-head > .align-center,
  .item-head > .align-right {
    display: none;
  }

  .item-row {
    grid-template-columns: 28px 1fr 1fr;
    grid-template-areas:
      "action description description"
      ". qty amount"
      ". price price";
    min-width: 0;
    min-height: 0;
    padding: 14px 0;
    gap: 8px 12px;
    align-items: start;
  }

  .row-action {
    grid-area: action;
  }

  .item-description {
    grid-area: description;
  }

  .item-quantity {
    grid-area: qty;
    text-align: left;
  }

  .item-price {
    grid-area: price;
    text-align: left;
  }

  .item-amount {
    grid-area: amount;
    text-align: right;
  }

  .item-quantity::before,
  .item-price::before,
  .item-amount::before {
    color: var(--muted);
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
  }

  .item-quantity::before {
    content: "Qty ";
  }

  .item-price::before {
    content: "Unit ";
  }

  .item-amount::before {
    content: "Amount ";
  }

  .payment-note {
    grid-template-columns: 44px 1fr;
    gap: 15px;
  }

  .circle-arrow {
    width: 42px;
    height: 42px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  .invoice,
  .invoice * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    background: #ffffff;
    overflow: hidden;
  }

  .toolbar {
    display: none;
  }

  .chat-panel {
    display: none;
  }

  .invoice-wrap {
    display: block;
    width: 210mm;
    height: 297mm;
    padding: 0;
    overflow: hidden;
  }

  .print-page {
    display: block;
    width: 210mm;
    height: 297mm;
    padding: 0;
    overflow: hidden;
  }

  .invoice {
    width: 1040px;
    min-height: 1348px;
    box-shadow: none;
    transform: translateX(var(--print-margin-x, 18px)) scale(var(--print-scale, 0.72));
    transform-origin: top left;
  }

  .invoice-dot-field {
    opacity: 0.56;
  }

  .invoice-field-dot {
    background: #c4c4be;
  }

  .editable:hover {
    background: transparent;
  }
}
