@font-face {
  font-family: "DM Sans";
  src: url("./assets/dm-sans.woff2") format("woff2");
  font-display: swap;
  font-style: normal;
  font-weight: 100 1000;
}

:root {
  color-scheme: light;
  --ink: #201a2c;
  --muted: #665f70;
  --brand: #4e30a4;
  --brand-strong: #3c237f;
  --brand-wash: #f1ebfc;
  --line: #dfd9e4;
  --field-line: #b9b0c3;
  --page: #f7f5f9;
  --paper: #fffdfa;
  --readonly: #f3f0f5;
  --danger: #982b3b;
  --focus: #7243d5;
  --shadow: 0 2px 6px #2b153409;
  font: 16px/1.5 "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
}
* { box-sizing: border-box; }
body, h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button[disabled] { opacity: .55; cursor: default; }
button, a, input, select { touch-action: manipulation; }
a { color: var(--brand); }
a[aria-disabled=true] { pointer-events: none; opacity: .5; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
.mobile-only { display: none; }
.wrap {
  --wrap-gutter: 28px;
  width: min(100%, 1280px); margin-inline: auto;
  padding-inline: max(var(--wrap-gutter), env(safe-area-inset-left)) max(var(--wrap-gutter), env(safe-area-inset-right));
}

.topbar { padding-top: env(safe-area-inset-top); background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar-in { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.33rem; font-weight: 790; letter-spacing: -.055em; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--brand); color: white; border-radius: 11px 11px 11px 4px; }
.icon { width: 20px; height: 20px; display: block; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; fill: none; flex: none; }

.workspace { padding-block: 36px 112px; }
.intro { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 14px; margin-bottom: 24px; }
.intro-actions { display: flex; gap: 6px; }
.intro-actions .button { gap: 5px; padding: 6px 10px; font-size: .875rem; }
.intro-actions .icon { color: var(--brand); width: 16px; height: 16px; }
h1 { font-size: clamp(2.1rem, 4.5vw, 3.6rem); line-height: 1.02; font-weight: 780; letter-spacing: -.072em; }
h2 { font-size: 1.25rem; line-height: 1.22; font-weight: 740; letter-spacing: -.035em; }
h3 { font-size: 1.05rem; line-height: 1.3; }
.intro p, .panel-heading p { color: var(--muted); margin-top: 5px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  white-space: nowrap;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: .94rem;
  font-weight: 720;
  text-decoration: none;
}
.primary { background: var(--brand); color: white; }
.primary:hover { background: var(--brand-strong); }
.secondary { background: var(--paper); border-color: var(--field-line); color: var(--ink); }
.secondary:hover { border-color: var(--brand); background: var(--brand-wash); }
.text-button { background: transparent; color: var(--brand); padding-inline: 8px; }
.text-button:hover { background: var(--brand-wash); }
.icon-button {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 8px; color: var(--muted); background: transparent;
}
.icon-button:hover { color: var(--brand); background: var(--brand-wash); }
.remove-record { color: var(--danger); background: var(--paper); border-color: var(--line); padding-inline: 10px; }
.remove-record:hover { color: var(--danger); background: #fbeef0; border-color: #cf9ba5; }
.remove-record .icon { width: 17px; height: 17px; }

.receipt-type-section { margin-bottom: 19px; max-width: 680px; }
.receipt-type-section h2 { margin-bottom: 8px; font-size: .98rem; letter-spacing: -.01em; }
.type-picker { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.type-button {
  display: grid; grid-template-columns: 40px minmax(0,1fr) 18px; align-items: center; gap: 10px;
  min-height: 72px; min-width: 0; text-align: left; padding: 10px 12px;
  border: 1px solid var(--field-line); border-radius: 14px; background: var(--paper); color: var(--ink);
}
.type-button:hover { border-color: var(--brand); }
.type-button strong, .type-button small { display: block; }
.type-button strong { font-size: 1.04rem; line-height: 1.2; }
.type-button small { color: var(--muted); font-size: .86rem; line-height: 1.2; margin-top: 3px; }
.type-button[aria-pressed=true] { background: var(--brand-wash); border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.type-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--readonly); color: var(--brand); }
.type-button[aria-pressed=true] .type-icon { background: var(--brand); color: white; }
.radio-icon { width: 18px; height: 18px; border: 1px solid var(--field-line); border-radius: 50%; }
.type-button[aria-pressed=true] .radio-icon { border: 5px solid var(--brand); background: white; }

.layout, .editor { display: grid; gap: 18px; min-width: 0; }
.panel { min-width: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 17px; box-shadow: var(--shadow); }
.panel-heading { padding: 18px 19px 13px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.details-fields, .row-card-inputs, .delivery-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 13px; }
.details-fields { padding: 0 19px 20px; }
.details-fields label, .row-card label, .delivery-fields label {
  display: grid; align-content: start; gap: 6px; min-width: 0; font-size: .94rem; font-weight: 650; line-height: 1.3;
}
.details-fields [data-field=to], .details-fields [data-field=receivedBy], .row-card-inputs .wide, .delivery-fields .wide { grid-column: 1/-1; }
.field-caption { display: flex; flex-wrap: wrap; align-items: baseline; gap: 5px; }
.field-caption small, .receipt-number-note { font-size: .82rem; font-weight: 460; color: var(--muted); }
input:not([type=file]), .details-fields select, .item-size-select {
  width: 100%; min-width: 0; min-height: 45px; border: 1px solid var(--field-line);
  border-radius: 9px; background-color: white; color: var(--ink);
  padding: 8px 10px; font-size: 1rem;
}
input::placeholder, .details-fields select:invalid, .item-size-select:disabled { color: var(--muted); font-weight: 450; }
input:not([type=file])[readonly], .item-size-select:disabled { background-color: var(--readonly); opacity: 1; }
input:not([type=file]):focus, select:focus { border-color: var(--focus); }
.details-fields select, .item-size-select {
  appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2353426b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 17px;
}
#details-fields [aria-invalid=true], #item-editor [aria-invalid=true] {
  border-color: var(--danger);
  background-color: #fff8f8;
  box-shadow: inset 0 0 0 1px var(--danger);
}
.field-error-text {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  color: var(--danger);
  font-size: .82rem;
  font-weight: 560;
  line-height: 1.3;
}
.field-error-text .icon {
  width: 14px;
  height: 14px;
  flex: none;
}

.notice { padding: 10px 13px; margin-bottom: 13px; border: 1px solid #ccbae8; border-radius: 10px; background: var(--brand-wash); font-size: .94rem; overflow-wrap: anywhere; }
.notice[data-kind=error] { background: #fff0f1; border-color: #e3aab2; color: #7b2331; }
.receipt-confirmation { max-width: 630px; padding-block: clamp(24px, 7vw, 76px); }
.confirmation-panel { padding: clamp(20px, 5vw, 42px); }
.confirmation-mark {
  display: grid; place-items: center; width: 46px; height: 46px;
  margin-bottom: 17px; border-radius: 50%; background: #e5f5ee; color: #17644d;
}
.confirmation-mark .icon { width: 25px; height: 25px; }
.confirmation-panel h1 { font-size: clamp(1.75rem, 6vw, 2.6rem); letter-spacing: -.05em; }
.confirmation-reference { margin-top: 12px; font-size: 1.05rem; font-weight: 720; overflow-wrap: anywhere; }
.confirmation-message { margin-top: 8px; color: var(--muted); }
.confirmation-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 23px; }
.confirmation-actions .button { flex: 1 1 135px; }
.confirmation-download { display: inline-flex; align-items: center; min-height: 44px; margin-top: 7px; text-underline-offset: 3px; }
.item-count { display: inline-grid; place-items: center; min-width: 25px; height: 25px; padding-inline: 5px; margin-left: 4px; border-radius: 20px; font-size: .81rem; color: var(--brand-strong); background: var(--brand-wash); vertical-align: 1px; }
.grid-help, .step-type { font-size: .91rem; color: var(--muted); }
.segmented { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--readonly); }
.segmented button { display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border: none; border-radius: 7px; background: transparent; color: var(--muted); }
.segmented button[aria-pressed=true] { background: white; color: var(--brand); box-shadow: 0 1px 3px #27143926; }
.items-foot { display: flex; align-items: center; justify-content: space-between; gap: 9px; padding: 11px 19px 14px; font-size: .94rem; font-weight: 700; }
.add-record, .add-size { border-radius: 22px; color: var(--brand-strong); }
.add-record { background: var(--brand-wash); border-color: #d9c9f0; }
.add-stock { width: 100%; border-radius: 10px; }
.add-record:hover { border-color: var(--brand); }
.add-size { background: var(--paper); border-color: var(--line); padding-inline: 11px; }
.add-size:hover { border-color: var(--brand); background: var(--brand-wash); }
.add-record .icon, .add-size .icon { width: 17px; height: 17px; }
.stock-quantity { font-size: .9rem; color: var(--brand-strong); font-weight: 670; }

.grid-frame { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-color: var(--field-line) var(--readonly); }
.data-grid { border-collapse: collapse; width: 100%; min-width: 725px; table-layout: fixed; }
.data-grid th, .data-grid td { border: 1px solid var(--line); border-left: 0; border-bottom: 0; }
.data-grid tr > :last-child { border-right: 0; }
.data-grid th { background: var(--readonly); text-align: left; padding: 9px 8px; font-size: .86rem; line-height: 1.26; }
.data-grid .row-number { width: 36px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.data-grid th.actions { width: 148px; }
.data-grid .remove-record { margin: 2px 4px; padding-inline: 8px; }
.data-grid .description { width: 30%; }
.data-grid td input:not([type=file]), .data-grid td .item-size-select {
  height: 46px; border: 1px solid transparent; border-radius: 0; padding-inline: 8px;
}
.data-grid td input:not([type=file]):focus, .data-grid td .item-size-select:focus {
  outline: none; border-color: var(--focus); background-color: var(--brand-wash);
}
.data-grid td .item-size-select { padding-inline-end: 24px; background-position: right 5px center; }
.data-grid:has(.item-size-select) th.size { width: 98px; }
.delivery-grid .data-grid { min-width: 585px; }
.delivery-grid .data-grid tr > :last-child { width: 148px; }
.row-card, .delivery-stock { border-top: 1px solid var(--line); }
.row-card { padding: 0 19px 15px; }
.row-card:not([open]) { padding-bottom: 0; }
.row-card-head { display: flex; justify-content: space-between; align-items: center; font-size: .92rem; color: var(--muted); font-weight: 680; }
.row-card summary, .delivery-stock > summary, .delivery-size summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; list-style: none;
  cursor: pointer; min-height: 46px; font-weight: 680; overflow-wrap: anywhere;
}
:is(.row-card,.delivery-stock,.delivery-size) > summary::-webkit-details-marker { display: none; }
:is(.row-card,.delivery-stock,.delivery-size) > summary::after {
  content: ""; width: 8px; height: 8px; flex: none; border: solid currentColor; border-width: 0 2px 2px 0;
  margin-right: 4px; transform: translateY(-2px) rotate(45deg); color: var(--brand);
}
:is(.row-card,.delivery-stock,.delivery-size)[open] > summary::after { transform: translateY(2px) rotate(225deg); }
:is(.row-card,.delivery-stock,.delivery-size) > summary:focus-visible { outline-offset: -3px; }
.delivery-stock > summary { padding: 9px 19px; }
.stock-title { min-width: 0; overflow-wrap: anywhere; }
.delivery-stock[open] > summary { color: var(--brand-strong); }
.delivery-stock-body { padding: 2px 19px 13px; min-width: 0; }
.delivery-stock-foot {
  display: grid; grid-template-columns: auto auto; justify-content: space-between; align-items: center; gap: 6px 9px;
  margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line);
}
.delivery-stock-foot .stock-quantity { grid-column: 1/-1; overflow-wrap: anywhere; text-align: right; }
.delivery-stock-foot .remove-record { justify-self: end; }
.remove-action { display: flex; justify-content: flex-end; }
.row-card .remove-action { padding-top: 8px; }
.delivery-size .remove-action { padding: 0 11px 9px; }
.delivery-sizes { display: grid; gap: 8px; margin-top: 14px; }
.delivery-size { border: 1px solid var(--line); border-radius: 11px; background: var(--readonly); min-width: 0; }
.delivery-size summary { padding: 9px 11px; display: grid; grid-template-columns: 1fr auto; gap: 2px 9px; }
.delivery-size .size-summary { grid-row: 2; color: var(--muted); font-size: .86rem; font-weight: 500; }
.delivery-size .size-summary:empty { display: none; }
.delivery-size summary::after { grid-row: 1 / span 2; grid-column: 2; }
.delivery-size > .delivery-fields { padding: 0 11px 12px; }
.size-limit { grid-column: 1/-1; color: var(--muted); font-size: .84rem; }

.catalog-field { display: grid; gap: 5px; min-width: 0; }
.product-control { position: relative; min-width: 0; }
.product-control input:not([type=file]) { padding-inline-end: 48px; }
.data-grid td .product-control input:not([type=file]) { padding-inline-end: 45px; }
.product-toggle {
  position: absolute; inset: 1px 1px 1px auto; width: 44px; display: grid; place-items: center;
  border: 0; border-radius: 8px; color: var(--brand); background: transparent;
}
.product-toggle::after { content: ""; width: 8px; height: 8px; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); }
.product-toggle:hover { background: var(--brand-wash); }
.product-popup {
  position: fixed; z-index: 12; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  background: white; border: 1px solid var(--field-line); border-radius: 11px; box-shadow: 0 7px 25px #26163d28;
  color: var(--ink); padding-block: 4px;
}
.product-popup [role=option] { display: flex; align-items: center; min-height: 44px; padding: 8px 12px; cursor: pointer; overflow-wrap: anywhere; }
.product-popup [role=option]:hover, .product-popup [aria-selected=true] { background: var(--brand-wash); }
.product-popup p { padding: 9px 12px; color: var(--muted); }

.template-panel { align-self: start; overflow: hidden; }
.template-panel .panel-heading { align-items: start; }
.paper-label { font-size: .8rem; font-weight: 660; border-radius: 7px; padding: 4px 7px; color: var(--brand-strong); background: var(--brand-wash); text-align: center; }
.paper-holder {
  display: flex; justify-content: center; margin-inline: 16px; padding: 18px; border-radius: 10px;
  background: radial-gradient(circle, #b9adca 1px, transparent 1px) 0 0 / 10px 10px, var(--readonly);
}
.paper-holder img { display: block; width: min(100%,226px); height: auto; box-shadow: 0 4px 12px #30214028; }
.template-caption { padding: 7px 17px; }
.template-caption a { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: .9rem; font-weight: 670; text-underline-offset: 3px; }
.template-caption .icon { width: 14px; height: 14px; }

.actionbar {
  position: fixed; z-index: 5; inset: auto 0 0; padding-block: 11px calc(11px + env(safe-area-inset-bottom));
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
  background: var(--paper); border-top: 1px solid var(--line); box-shadow: 0 -5px 24px #281d3a10;
}
.actionbar-in { width: min(100%,1224px); margin-inline: auto; display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.actionbar-in > span { margin-right: auto; color: var(--muted); font-size: .94rem; font-weight: 670; }

.modal {
  --modal-edge: 11px;
  --modal-inline-gutter: max(var(--modal-edge), env(safe-area-inset-left), env(safe-area-inset-right));
  --modal-block-gutter: max(var(--modal-edge), env(safe-area-inset-top), env(safe-area-inset-bottom));
  width: min(760px, calc(100% - 2 * var(--modal-inline-gutter))); max-width: none;
  max-height: calc(100% - 2 * var(--modal-block-gutter)); padding: 0;
  border: 1px solid var(--line); border-radius: 17px; color: var(--ink); background: var(--paper); box-shadow: 0 24px 70px #21193150;
}
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: #211932a8; }
.modal-head, .modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 9px; padding: 12px 17px; }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-head p { margin-top: 4px; color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
.modal-foot { border-top: 1px solid var(--line); justify-content: flex-end; flex-wrap: wrap; }
.button[data-downloading] { opacity: 1; cursor: progress; }
.button[data-downloading] :is([data-icon], .icon), .download-spinner { display: none; }
.button[data-downloading] .download-spinner { display: block; }
.download-spinner {
  width: 17px; height: 17px; flex: none; border: 2px solid currentColor;
  border-inline-end-color: transparent; border-radius: 50%;
}
@media (prefers-reduced-motion: no-preference) {
  .download-spinner { animation: download-spin .75s linear infinite; }
}
@keyframes download-spin { to { transform: rotate(360deg); } }
.modal-body { padding: 16px; overflow: auto; }
.modal-body p { margin-bottom: 8px; color: var(--muted); }
.review-details { display: grid; grid-template-columns: repeat(auto-fit,minmax(120px,1fr)); gap: 8px; font-size: .9rem; margin: 0 0 14px; }
.review-details div { padding: 7px; background: var(--readonly); border-radius: 7px; overflow-wrap: anywhere; }
.review-details dt { font-weight: 700; }
.review-details dd { margin: 0; }
.review-table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.review-table :is(th,td) { border: 1px solid var(--line); text-align: left; padding: 7px; overflow-wrap: anywhere; }
.review-table th { background: var(--readonly); }
.modal-body .grid-frame { border: 1px solid var(--line); border-radius: 9px; }
.pdf-pages { padding: 12px; overflow: auto; background: var(--readonly); }
.pdf-pages canvas { display: block; width: min(100%,640px); height: auto; margin: 0 auto 12px; box-shadow: 0 2px 8px #21193133; }
.pdf-pages canvas:last-child { margin-bottom: 0; }

.history-title, .history-entry-summary { display: flex; align-items: center; min-width: 0; gap: 10px; }
.history-mark { display: grid; place-items: center; width: 37px; height: 37px; flex: none; background: var(--brand-wash); color: var(--brand); border-radius: 10px; }
.history-header-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.history-filter-toggle .icon { width: 17px; height: 17px; }
.history-filter-toggle:is([aria-expanded=true], [data-filtered]) { background: var(--brand-wash); color: var(--brand-strong); }
.history-filters {
  display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); align-items: end; gap: 10px 14px;
  flex: none; padding: 12px 16px 14px; border-bottom: 1px solid var(--line); background: var(--readonly);
  font-size: .91rem; font-weight: 650;
}
.history-filter-date { display: grid; gap: 5px; min-width: 0; }
.history-filter-date input { min-height: 52px; }
.history-filter-type { min-width: 0; margin: 0; padding: 0; border: 0; }
.history-filter-type legend { padding: 0; margin-bottom: 5px; }
.history-type-options { display: flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.history-type-options label { position: relative; flex: 1; min-width: 0; }
.history-type-options input { position: absolute; opacity: 0; inset: 0; height: 100%; margin: 0; cursor: pointer; }
.history-type-options span { display: grid; place-items: center; min-height: 44px; padding: 3px; border-radius: 7px; color: var(--muted); text-align: center; }
.history-type-options input:checked + span { color: var(--brand-strong); background: var(--brand-wash); }
.history-type-options input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }
.history-applied { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 7px; flex: none; padding: 3px 16px; border-bottom: 1px solid var(--line); }
.history-filter-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 3px 9px 3px 11px; border: 1px solid transparent; border-radius: 20px; background: var(--brand-wash); color: var(--brand-strong); font-size: .875rem; font-weight: 650; }
.history-filter-chip:hover { border-color: var(--brand); }
.history-filter-chip .icon { width: 15px; height: 15px; }
.history-filter-clear { font-size: .875rem; }
.history-list { list-style: none; display: grid; gap: 10px; margin: 0; padding: 0; }
.history-entry {
  display: flex; gap: 12px; justify-content: space-between; align-items: center; flex-wrap: wrap;
  padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: white;
}
.history-entry-details { min-width: 0; overflow-wrap: anywhere; }
.history-entry strong { font: 700 1.06rem/1.2 "DM Sans", system-ui, sans-serif; font-variant-numeric: tabular-nums; }
.history-entry p { margin: 2px 0 0; font-size: .91rem; }
.history-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.history-empty { text-align: center; padding: 32px 14px; border: 1px dashed var(--field-line); border-radius: 15px; background: var(--page); }
.history-empty .history-mark { margin: 0 auto 12px; width: 48px; height: 48px; }
.history-empty h3 { margin-bottom: 5px; }
.history-empty p { margin-bottom: 0; }
#history-status:empty { display: none; }
#history-more { margin-top: 12px; }

@media (min-width: 920px) {
  .layout { grid-template-columns: minmax(0,1fr) minmax(270px,320px); gap: 22px; }
  .template-panel { position: sticky; top: 16px; }
  .details-fields { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .details-fields [data-field=to], .details-fields [data-field=receivedBy] { grid-column: auto; }
}
