.cost-page { overflow-x: clip; }
.cost-main {
  max-width: 940px;
  padding: calc(var(--nav-height) + 22px) clamp(12px, 4vw, 24px) 48px;
}

.cost-page [hidden] { display: none !important; }
.cost-page .nav-in { padding-inline: clamp(12px, 4vw, 24px); }
.cost-page .btn { min-height: 44px; padding: 8px 14px; font-size: .97rem; white-space: normal; text-align: center; }
.cost-page .cost-home, .cost-page .cost-square { min-width: 44px; min-height: 44px; padding: 0; }
.cost-page .cost-square { font-size: 1.5rem; }
.cost-page :focus-visible { outline: 2px solid var(--terra-d); outline-offset: 2px; }
.cost-delete-area { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.cost-page .cost-delete { color: #992c1b; }
.cost-page .cost-delete-confirm { background: #992c1b; }
.cost-page .cost-delete-confirm:hover { background: #792316; }

.cost-heading { display: grid; gap: 12px; align-items: center; }
.cost-heading h1 { font-size: clamp(1.95rem, 5.5vw, 2.85rem); overflow-wrap: anywhere; }
.cost-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cost-main .menu-foodnik-note .text-link { display: inline; }

.cost-work {
  min-width: 0;
  margin-top: 16px;
  padding: clamp(10px, 3vw, 20px);
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.cost-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border-radius: var(--r-sm);
  background: var(--cream);
}

.cost-tabs button {
  min-height: 44px;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  font: 700 .92rem/1.2 'Nunito', sans-serif;
  cursor: pointer;
}

.cost-tabs [aria-selected="true"] {
  border-color: var(--line);
  background: var(--card);
  color: var(--terra-d);
  box-shadow: var(--shadow-sm);
}
.cost-tab-short { display: none; }

.cost-work [role="tabpanel"] { padding: 0; }
.cost-toolbar {
  display: grid;
  justify-items: start;
  gap: 10px;
  align-items: end;
  margin-block: 14px 10px;
}

.cost-toolbar .cost-field { width: 100%; }
.cost-list { display: grid; gap: 8px; }
.cost-empty, .cost-no-script { padding-block: 8px; color: var(--muted); font-size: .92rem; }
.cost-status {
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  overflow-wrap: anywhere;
}
.cost-error, .cost-status[data-error] { color: #992c1b; }
.cost-status[data-error] { background: #fff1eb; }
.cost-error { overflow-wrap: anywhere; font-size: .87rem; }

.cost-card { min-width: 0; border: 1px solid var(--line); border-radius: var(--r-sm); }
.cost-summary, .cost-product-row, .cost-choice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 14px;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  text-align: left;
  color: var(--ink);
}
.cost-summary { list-style: none; border-radius: var(--r-sm); cursor: pointer; }
.cost-summary::-webkit-details-marker { display: none; }
.cost-summary::after {
  content: "";
  width: 7px;
  height: 7px;
  justify-self: center;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: translateY(-2px) rotate(45deg);
}
.cost-card[open] > .cost-summary { background: var(--cream); border-radius: var(--r-sm) var(--r-sm) 0 0; }
.cost-card[open] > .cost-summary::after { transform: translateY(2px) rotate(225deg); }
.cost-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cost-summary strong:last-child, .cost-line-price, .cost-totals strong { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.cost-summary strong:last-child { text-align: right; max-width: 13ch; }
.cost-summary .cost-incomplete { font-size: .8rem; line-height: 1.25; }
.cost-incomplete { color: #894411; }
.cost-missing-prices { overflow-wrap: anywhere; font-size: .9rem; }
.cost-product-row, .cost-choice {
  grid-template-columns: minmax(0, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: #fff;
  font: inherit;
  cursor: pointer;
}
.cost-product-row > span, .cost-choice > span { min-width: 0; overflow-wrap: anywhere; }
.cost-product-row > :last-child, .cost-choice > :last-child { max-width: 15ch; color: var(--muted); text-align: right; font-size: .83rem; }
.cost-card-body { display: grid; gap: 12px; padding: 10px; }
.cost-fields { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.cost-field { display: grid; gap: 4px; align-content: start; min-width: 0; font-size: .85rem; font-weight: 600; }
.cost-field :is(input, select, textarea) {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 7px 9px;
  border: 1px solid #cfc2b4;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font: 400 1rem/1.3 'Inter', sans-serif;
  scroll-margin-block: calc(var(--nav-height) + 10px) 20px;
}
.cost-field [aria-invalid="true"] { border-color: #992c1b; }
.cost-card-body h3 { font-size: 1.08rem; }
.cost-lines { display: grid; gap: 8px; list-style: none; }
.cost-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(65px, .85fr) auto;
  gap: 6px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.cost-line-name { grid-column: 1 / 3; align-self: center; overflow-wrap: anywhere; }
.cost-line .cost-square { grid-column: 3; grid-row: 1; justify-self: end; }
.cost-line-price { grid-column: 3; max-width: 10ch; margin-top: 25px; text-align: right; font-size: .88rem; }
.cost-totals { display: grid; gap: 4px; padding: 9px 10px; border-radius: 9px; background: var(--cream); }
.cost-totals p { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); gap: 8px; font-size: .9rem; }
.cost-totals strong { max-width: 15ch; text-align: right; }
.cost-label { color: var(--muted); }
.cost-help { margin-top: 24px; max-width: 690px; padding: 0; }
.cost-help h2 { margin-top: 0; }

.cost-dialog {
  position: fixed;
  inset: auto 0;
  top: calc(var(--cost-viewport-top, 0px) + var(--cost-viewport-height, 100dvh));
  transform: translateY(-100%);
  width: min(100%, 480px);
  max-width: 100%;
  max-height: calc(var(--cost-viewport-height, 100dvh) - 8px);
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r) var(--r) 0 0;
  background: var(--card);
  color: var(--ink);
}
.cost-dialog[open] { display: flex; flex-direction: column; }
.cost-dialog::backdrop { background: rgba(42, 39, 36, .52); }
.cost-dialog-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.cost-dialog-head h2 { font-size: 1.24rem; }
.cost-dialog-body {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px 12px max(14px, env(safe-area-inset-bottom));
}
.cost-dialog-body .cost-field :is(input, select) { scroll-margin-block: 8px; }
.cost-panel-content { display: grid; gap: 10px; overflow-wrap: anywhere; }
.cost-panel-content > .cost-error:empty { display: none; }
.cost-references { padding-inline-start: 22px; }
.cost-picker-results {
  display: grid;
  gap: 6px;
  max-height: min(40vh, 18rem);
  max-height: min(calc(var(--cost-viewport-height, 100dvh) * .4), 18rem);
  overflow: auto;
}
.cost-dialog-body .cost-actions { margin-top: 2px; }

#purchases { scroll-margin-top: calc(var(--nav-height) + 12px); }
.cost-purchase-view { display: grid; gap: 10px; padding-top: 14px; }
.cost-purchase-view h2 { font-size: 1.3rem; }
.cost-purchase-view .cost-toolbar { margin-block: 0; }
.cost-purchase-bar {
  position: sticky;
  top: var(--nav-height);
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-block: 6px;
  background: var(--card);
}
.cost-purchase-view button { scroll-margin-top: calc(var(--nav-height) + 12px); }
.cost-purchase-groups, .cost-purchase-rows { display: grid; gap: 8px; }
.cost-purchase-group h3 { margin: 6px 0; font-size: 1.08rem; }
.cost-purchase-rows { list-style: none; }
.cost-purchase-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(126px, .8fr);
  align-items: center;
  gap: 6px 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.cost-purchase-row[data-checked] { background: var(--cream); }
.cost-purchase-name { overflow-wrap: anywhere; }
.cost-purchase-row .cost-purchase-quantity {
  grid-template-columns: minmax(52px, 1fr) minmax(0, auto);
  align-items: center;
  gap: 3px 5px;
}
.cost-purchase-quantity > :first-child { display: none; }
.cost-purchase-quantity input { grid-area: 1 / 1; }
.cost-purchase-quantity .cost-error { grid-column: 1 / -1; }
.cost-purchase-unit { grid-area: 1 / 2; overflow-wrap: anywhere; }
.cost-purchase-total {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: .9rem;
  overflow-wrap: anywhere;
}
.cost-purchase-row-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
}
.cost-purchase-check {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding-inline: 3px 5px;
  cursor: pointer;
  font-size: .9rem;
}
.cost-purchase-check input { width: 20px; height: 20px; accent-color: var(--green); }
.cost-purchase-row-actions .btn { font-size: .9rem; padding-inline: 10px; }
.cost-purchase-print { display: none; }

@media (max-width: 430px) {
  .cost-tab-full { display: none; }
  .cost-tab-short { display: inline; }
  .cost-shopping-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cost-shopping-actions .btn { padding-inline: 8px; font-size: .91rem; }
}

@media (max-width: 659px) {
  #cost-purchase-compose:has(input:focus) .cost-purchase-bar { position: static; }
}

@media (min-width: 660px) {
  .cost-heading { grid-template-columns: minmax(0, 1fr) auto; }
  .cost-toolbar { grid-template-columns: minmax(170px, 1fr) auto; }
  .cost-fields { grid-template-columns: minmax(0, 1fr) minmax(132px, .45fr); }
  .cost-line {
    grid-template-columns: minmax(0, 1fr) minmax(84px, .45fr) minmax(68px, .25fr) minmax(78px, auto) auto;
    align-items: center;
  }
  .cost-line-name, .cost-line-price, .cost-line .cost-square { grid-column: auto; grid-row: auto; }
  .cost-line-price { margin-top: 18px; }
  .cost-purchase-row:has(.cost-purchase-row-actions) {
    grid-template-columns: minmax(0, 1fr) minmax(126px, .45fr) auto;
  }
  .cost-purchase-row-actions { grid-area: 1 / 3; }
  .cost-dialog {
    top: calc(var(--cost-viewport-top, 0px) + var(--cost-viewport-height, 100dvh) / 2);
    transform: translateY(-50%);
    max-height: calc(var(--cost-viewport-height, 100dvh) - 24px);
    border-radius: var(--r);
  }
}

@page { size: A4; margin: 14mm; }

@media print {
  .cost-page { background: #fff; color: #000; }
  .cost-page > :not(.cost-purchase-print) { display: none !important; }
  .cost-page .cost-purchase-print { display: block; padding: 0; font-size: 11pt; }
  .cost-purchase-print h1 { margin-bottom: 5mm; font-size: 20pt; }
  .cost-purchase-print h2 { margin: 4mm 0 2mm; font-size: 13pt; break-after: avoid; }
  .cost-purchase-print ul { list-style: none; }
  .cost-purchase-print li {
    display: grid;
    grid-template-columns: 5mm minmax(0, 1fr) minmax(30mm, 45%);
    align-items: center;
    gap: 3mm;
    padding: 1.5mm 0;
    border-bottom: 1px solid #ccc;
    overflow-wrap: anywhere;
    break-inside: avoid;
  }
  .cost-print-check { width: 4mm; height: 4mm; border: 1px solid; text-align: center; line-height: 4mm; }
}
