/* Fonts and tokens follow codavo.dev: paper, ink, and one stamp-red accent. */
@font-face {
  font-family: 'Bricolage Grotesque';
  src: url(/fonts/bricolage-grotesque-latin-wght-normal.woff2) format('woff2');
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  src: url(/fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2) format('woff2');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200F, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  src: url(/fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2) format('woff2');
  font-weight: 500;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200F, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  src: url(/fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2) format('woff2');
  font-weight: 600 700;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200F, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url(/fonts/ibm-plex-mono-latin-400-normal.woff2) format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url(/fonts/ibm-plex-mono-latin-500-normal.woff2) format('woff2');
  font-weight: 500 700;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --paper: #f6f1e7;
  --paper-2: #ede6d8;
  --paper-3: #e2d9c7;
  --ink: #16130f;
  --ink-2: #5a5348;
  --line: rgb(22 19 15 / 0.14);
  --line-strong: rgb(22 19 15 / 0.32);
  --stamp: #c42e14;
  --on-stamp: #fff8f0;
  --sans: 'Bricolage Grotesque', 'IBM Plex Sans Arabic', ui-sans-serif, system-ui, sans-serif;
  --mono: 'IBM Plex Mono', 'IBM Plex Sans Arabic', ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #13110d;
    --paper-2: #1c1914;
    --paper-3: #28241d;
    --ink: #f1ebdd;
    --ink-2: #a79f90;
    --line: rgb(241 235 221 / 0.14);
    --line-strong: rgb(241 235 221 / 0.34);
    --stamp: #ff6a4d;
    --on-stamp: #1a0b06;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
body {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.5;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--stamp);
  outline-offset: 2px;
}
::selection {
  background: var(--stamp);
  color: var(--on-stamp);
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

/* ---------- App chrome ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: 0.45rem 0.8rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  background: none;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition:
    transform 160ms cubic-bezier(0.3, 0, 0.2, 1),
    box-shadow 160ms cubic-bezier(0.3, 0, 0.2, 1),
    background-color 160ms,
    border-color 160ms;
}
.btn-primary {
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 3px 0 0 var(--stamp);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 0 0 var(--stamp);
}
.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 0 var(--stamp);
}
.btn-ghost {
  border-color: var(--line-strong);
}
.btn-ghost:hover {
  background: var(--paper-2);
  border-color: var(--ink);
}

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.bar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
}
.bar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
#saved {
  min-height: 2.5rem;
  max-width: 13rem;
  padding-inline: 0.6rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.5rem;
  background: var(--paper-2);
}
.menu {
  position: relative;
}
.menu summary {
  list-style: none;
}
.menu summary::-webkit-details-marker {
  display: none;
}
.menu-pop {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 0.4rem);
  display: grid;
  gap: 0.4rem;
  padding: 0.5rem;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 0.6rem;
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
@media (width >= 64rem) {
  .layout {
    grid-template-columns: minmax(24rem, 34rem) minmax(0, 1fr);
  }
  /* Two scrolling panes on the website. The Mac app scrolls as one page: each pane is a
     composited layer in WebKit, and measured this way the app uses about 50 MB less. */
  html:not(.is-app) .layout {
    height: calc(100dvh - 4.1rem);
  }
  html:not(.is-app) :is(.editor, .preview) {
    overflow-y: auto;
  }
}

.editor {
  padding: 1.25rem 1rem 3rem;
  border-inline-end: 1px solid var(--line);
}
.app-only,
.is-app .web-only {
  display: none;
}
.is-app .app-only {
  display: inline;
}
.hint {
  margin: 0 0 1.25rem;
  font-size: 0.8125rem;
  color: var(--ink-2);
}
#status {
  display: block;
  color: var(--stamp);
  font-weight: 500;
}
fieldset {
  margin: 0 0 1.5rem;
  padding: 0;
  border: 0;
}
legend {
  margin-bottom: 0.6rem;
  padding: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.75rem;
}
fieldset > label,
.grid > label,
.field {
  display: grid;
  gap: 0.3rem;
  font-size: 0.8125rem;
  color: var(--ink-2);
}
fieldset > label + label {
  margin-top: 0.75rem;
}
input:not([type='radio'], [type='checkbox'], [type='file']),
select,
textarea {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.45rem;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 0.9375rem;
}
textarea {
  resize: vertical;
  line-height: 1.45;
}
input[type='number'] {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
input:hover,
select:hover,
textarea:hover {
  border-color: var(--ink-2);
}
.seg {
  display: flex;
  min-height: 2.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.45rem;
  overflow: hidden;
}
.seg label {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--ink);
  cursor: pointer;
}
.seg label:has(:checked) {
  background: var(--ink);
  color: var(--paper);
}
.seg label:has(:focus-visible) {
  outline: 2px solid var(--stamp);
  outline-offset: -2px;
}
.seg input {
  position: absolute;
  opacity: 0;
}
.check {
  display: flex !important;
  align-items: center;
  gap: 0.5rem !important;
  margin-top: 0.85rem;
  color: var(--ink) !important;
  font-size: 0.9375rem !important;
}
.check input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--stamp);
}
.sum {
  margin: 0.85rem 0 0;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}
.sum b {
  font-family: var(--mono);
  font-weight: 500;
}
.warn {
  margin: 0;
  color: var(--stamp);
  font-size: 0.8125rem;
}
.warn:not(:empty) {
  margin-bottom: 0.6rem;
}

.rows {
  display: grid;
  gap: 0.6rem;
}
.rows:not(:empty) {
  margin-bottom: 0.75rem;
}
.row {
  display: grid;
  gap: 0.5rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: color-mix(in srgb, var(--paper-2) 45%, transparent);
}
.row label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--ink-2);
}
.item {
  grid-template-columns: 1.6rem 1fr 1fr auto;
  grid-template-areas:
    'no desc desc tools'
    '. details details details'
    '. qty price price';
}
.item .row-no {
  grid-area: no;
  align-self: center;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--stamp);
}
.item [name='desc'] {
  grid-area: desc;
  font-weight: 500;
}
.item textarea {
  grid-area: details;
  min-height: 2.5rem;
  font-size: 0.875rem;
}
.item label:nth-of-type(1) {
  grid-area: qty;
}
.item label:nth-of-type(2) {
  grid-area: price;
}
.item .row-tools {
  grid-area: tools;
}
.ms {
  grid-template-columns: 1fr 6.5rem auto;
  align-items: center;
}
.pct {
  display: flex !important;
  align-items: center;
  gap: 0.35rem !important;
  font-family: var(--mono);
  font-size: 0.875rem !important;
}
.row-tools {
  display: flex;
  gap: 0.25rem;
}
.row-tools button {
  width: 2.25rem;
  height: 2.5rem;
  border: 1px solid transparent;
  border-radius: 0.4rem;
  background: none;
  color: var(--ink-2);
  font-size: 1.05rem;
  cursor: pointer;
}
.row-tools button:hover:not(:disabled) {
  border-color: var(--line-strong);
  color: var(--ink);
}
.row-tools button:disabled {
  opacity: 0.3;
  cursor: default;
}
.add {
  width: 100%;
  border-style: dashed;
}

.preview {
  padding: 1.5rem 1rem 3rem;
  background: var(--paper-3);
}
#sheet {
  width: 210mm;
  margin-inline: auto;
}

/* ---------- The quotation (always printed light) ---------- */

.doc {
  --ink: #16130f;
  --ink-2: #5a5348;
  --line: rgb(22 19 15 / 0.13);
  --stamp: #c42e14;
  color-scheme: light;
  width: 210mm;
  min-height: 297mm;
  padding: 16mm 16mm 18mm;
  background: #fff;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 9.5pt;
  line-height: 1.5;
  box-shadow:
    0 1px 2px rgb(0 0 0 / 0.08),
    0 18px 48px rgb(0 0 0 / 0.16);
}
.doc:lang(ar) {
  line-height: 1.75;
}
.doc:lang(ar) * {
  letter-spacing: 0 !important;
}
:where(.doc) :is(p, h1, h2, dl, dd) {
  margin: 0;
}

.d-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10mm;
  padding-bottom: 6mm;
  border-bottom: 1.5pt solid var(--ink);
}
.d-brand {
  display: flex;
  align-items: center;
  gap: 2.6mm;
  font-size: 17pt;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1;
}
.d-brand svg {
  width: 9mm;
  height: 9mm;
}
.d-from {
  text-align: end;
  font-family: var(--mono);
  font-size: 7.5pt;
  line-height: 1.65;
  color: var(--ink-2);
}

.d-title {
  margin-top: 11mm;
}
.d-kicker,
.d-meta dt,
.d-items th,
.d-sched th,
.d-sec h2 {
  font-family: var(--mono);
  font-size: 7pt;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.d-kicker {
  display: flex;
  align-items: center;
  gap: 2mm;
  color: var(--stamp);
  font-size: 7.5pt;
}
.d-kicker::before {
  content: '';
  width: 1.8mm;
  height: 1.8mm;
  border-radius: 0.3mm;
  background: var(--stamp);
  print-color-adjust: exact;
}
.doc:lang(ar) :is(.d-meta dt, .d-items th, .d-sched th, .d-sec h2) {
  font-size: 8pt;
}
.doc:lang(ar) .d-kicker {
  font-size: 9pt;
}
.d-title h1 {
  margin-top: 2.5mm;
  max-width: 150mm;
  font-size: 25pt;
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.03em;
  text-wrap: balance;
  white-space: pre-line;
}
.doc:lang(ar) .d-title h1 {
  line-height: 1.35;
}
.d-intro {
  margin-top: 4mm;
  max-width: 145mm;
  font-size: 10pt;
  color: var(--ink-2);
  white-space: pre-line;
  text-wrap: pretty;
}

.d-meta {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 9mm;
  margin-top: 9mm;
  padding-block: 4.5mm;
  border-block: 0.75pt solid var(--line);
}
.d-meta dd {
  margin-top: 1.2mm;
}
.d-client {
  justify-self: end;
  text-align: end;
}
.strong {
  font-weight: 600;
}
.soft {
  font-size: 8pt;
  color: var(--ink-2);
}

.d-items,
.d-sched {
  width: 100%;
  border-collapse: collapse;
}
.d-items {
  margin-top: 9mm;
}
.d-items th,
.d-sched th {
  padding: 0 0 2.2mm;
  text-align: start;
  border-bottom: 0.75pt solid var(--ink);
}
.d-items td,
.d-sched td {
  padding: 3.2mm 0;
  border-bottom: 0.75pt solid var(--line);
  vertical-align: top;
}
.d-items tr,
.d-sched tr {
  break-inside: avoid;
}
.doc .n {
  text-align: end;
  white-space: nowrap;
  padding-inline-start: 6mm;
}
.d-items .idx {
  width: 9mm;
  padding-top: 3.6mm;
  font-size: 7.5pt;
  color: var(--stamp);
}
.d-desc {
  font-weight: 550;
  white-space: pre-line;
}
.d-details {
  margin-top: 1mm;
  max-width: 105mm;
  font-size: 8.5pt;
  color: var(--ink-2);
  white-space: pre-line;
}

.d-totals {
  width: 82mm;
  margin-top: 5mm;
  margin-inline-start: auto;
  break-inside: avoid;
}
.d-totals > div {
  display: flex;
  justify-content: space-between;
  gap: 6mm;
  padding-block: 1.4mm;
  color: var(--ink-2);
}
.d-totals .grand {
  align-items: baseline;
  margin-top: 2mm;
  padding-top: 3.5mm;
  border-top: 1.5pt solid var(--ink);
  color: var(--ink);
  font-weight: 600;
  font-size: 11pt;
}
.d-totals .grand .num {
  font-size: 17pt;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.d-totals small {
  font-size: 8pt;
  font-weight: 500;
  color: var(--ink-2);
}

.d-sec {
  margin-top: 10mm;
  break-inside: avoid;
}
.d-sec h2 {
  margin-bottom: 3mm;
}
.d-sched td {
  padding-block: 2.6mm;
}
.d-terms {
  font-size: 8.5pt;
  color: var(--ink-2);
  white-space: pre-line;
  max-width: 160mm;
}

.d-sign {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14mm;
  margin-top: 16mm;
  break-inside: avoid;
}
.d-sign p {
  font-weight: 550;
}
.d-line {
  display: block;
  height: 14mm;
  border-bottom: 0.75pt solid var(--ink);
}
.d-sign small {
  display: block;
  margin-top: 1.5mm;
  font-size: 7.5pt;
  color: var(--ink-2);
}

/* ---------- Print: only the quotation, on A4 ---------- */

@page {
  size: A4;
  margin: 16mm 16mm 18mm;

  @bottom-center {
    content: counter(page) ' / ' counter(pages);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 7pt;
    color: #5a5348;
  }
}

@media print {
  html,
  body {
    background: #fff;
  }
  .bar,
  .editor {
    display: none;
  }
  .layout {
    display: block;
    height: auto;
  }
  .preview {
    padding: 0;
    background: none;
    overflow: visible;
  }
  #sheet {
    width: auto;
    zoom: 1 !important;
  }
  .doc {
    width: auto;
    min-height: 0;
    padding: 0;
    box-shadow: none;
  }
}
