:root {
  color-scheme: light;
  --green: #1e3a8a;
  --green-dark: #172554;
  --green-soft: #dbeafe;
  --text: #17201b;
  --muted: #647067;
  --line: #dce4de;
  --surface: #ffffff;
  --background: #f4f7f5;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--text); }
body, .product-row, input, select, .modal, .modal__header, .catalog-form { transition: background-color .2s, color .2s, border-color .2s; }
button, input, select { font: inherit; }
button { touch-action: manipulation; }

.summary {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  min-height: 78px; padding: .7rem max(1rem, env(safe-area-inset-right)) .7rem max(1rem, env(safe-area-inset-left));
  background: linear-gradient(135deg, var(--green-dark), var(--green)); color: white;
  box-shadow: 0 3px 16px rgb(23 37 84 / 20%);
}
.summary__label { display: block; font-size: .72rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; opacity: .8; }
.summary__value { display: block; margin-top: .1rem; font-size: clamp(1.65rem, 7vw, 2.35rem); font-weight: 800; line-height: 1; }
.summary__actions { display: flex; align-items: center; gap: .45rem; }
.icon-button { width: 44px; height: 44px; border: 1px solid rgb(255 255 255 / 40%); border-radius: 10px; background: rgb(255 255 255 / 12%); color: white; font-size: 1.35rem; cursor: pointer; }
.container { width: min(100% - 1.5rem, 1050px); margin: 0 auto; padding: 1.4rem 0 max(2rem, env(safe-area-inset-bottom)); }
.intro { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
h1 { margin: 0; font-size: 1.35rem; }
.intro p { margin: .25rem 0 0; color: var(--muted); font-size: .9rem; }
.counter { flex: none; padding: .35rem .65rem; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); font-size: .78rem; font-weight: 700; }
.table-head { display: none; }
.product-list { display: grid; gap: .75rem; }
.product-row { position: relative; display: grid; grid-template-columns: 5.5rem 1fr; gap: .75rem; padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 2px 8px rgb(23 32 27 / 4%); }
.field { min-width: 0; }
.field label { display: block; margin: 0 0 .3rem; color: var(--muted); font-size: .7rem; font-weight: 700; text-transform: uppercase; }
.field--product { padding-right: 1.75rem; }
.product-input { display: flex; gap: .35rem; }
.product-input input { min-width: 0; }
.open-catalog { flex: 0 0 46px; height: 46px; border: 0; border-radius: 9px; background: var(--green-soft); color: var(--green-dark); font-size: 1.5rem; font-weight: 700; cursor: pointer; }
.field--price, .field--total { grid-column: span 1; }
input, select { width: 100%; height: 46px; border: 1px solid #cbd5ce; border-radius: 9px; background: white; color: var(--text); padding: 0 .7rem; outline: none; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgb(30 58 138 / 12%); }
.quantity-custom { margin-top: .4rem; }
.money-input { position: relative; }
.money-input span { position: absolute; top: 50%; left: .7rem; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-left: 1.55rem; }
.row-total { display: flex; align-items: center; min-height: 46px; padding: 0 .7rem; border-radius: 9px; background: #f0f5f1; font-weight: 800; overflow-wrap: anywhere; }
.delete-product { position: absolute; top: .7rem; right: .7rem; width: 32px; height: 32px; border: 0; border-radius: 50%; background: #fff1f2; color: #be123c; font-size: 1.35rem; line-height: 1; cursor: pointer; }
.button { min-height: 44px; border: 0; border-radius: 10px; padding: .65rem 1rem; font-weight: 750; cursor: pointer; }
.button--secondary { border: 1px solid rgb(255 255 255 / 40%); background: rgb(255 255 255 / 12%); color: white; }
.button--primary { background: var(--green); color: white; box-shadow: 0 3px 8px rgb(30 58 138 / 16%); }
.button--add { width: 100%; margin-top: 1rem; min-height: 52px; }
.button:active { transform: translateY(1px); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.modal { width: min(94%, 620px); max-height: min(88vh, 720px); padding: 0; border: 0; border-radius: 16px; color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 25%); }
.modal::backdrop { background: rgb(10 30 18 / 55%); backdrop-filter: blur(2px); }
.modal__header { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 1rem; padding: 1rem; border-bottom: 1px solid var(--line); background: white; }
.modal__header h2 { margin: 0; font-size: 1.2rem; }
.modal__header p { margin: .2rem 0 0; color: var(--muted); font-size: .82rem; }
.modal__actions { display: flex; align-items: center; gap: .45rem; }
.modal__sort { height: 40px; min-width: 44px; padding: 0 .65rem; border: 0; border-radius: 9px; background: var(--green-soft); color: var(--green-dark); font-size: .82rem; font-weight: 800; cursor: pointer; }
.modal__search-toggle { height: 40px; padding: 0 .8rem; border: 0; border-radius: 9px; background: var(--green-soft); color: var(--green-dark); font-weight: 800; cursor: pointer; }
.modal__close { width: 40px; height: 40px; border: 0; border-radius: 50%; background: #eef2ef; font-size: 1.5rem; cursor: pointer; }
.catalog-search { position: sticky; top: 73px; z-index: 2; display: flex; align-items: center; gap: .4rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface); }
.catalog-search[hidden] { display: none; }
.catalog-search span { color: var(--muted); font-size: 1.35rem; }
.catalog-search input { height: 42px; }
.catalog-form { display: grid; grid-template-columns: 1fr 8.5rem auto; align-items: end; gap: .6rem; padding: 1rem; background: #f7faf8; }
.catalog-form .field label { text-transform: none; }
.button--plain { background: #e8eeea; color: var(--text); }
.catalog-list { display: grid; gap: .55rem; padding: 1rem; }
.catalog-item { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: .45rem; padding: .7rem; border: 1px solid var(--line); border-radius: 10px; }
.catalog-select { min-width: 0; border: 0; background: transparent; text-align: left; cursor: pointer; }
.catalog-select strong, .catalog-select span { display: block; }
.catalog-select span { margin-top: .15rem; color: var(--green); font-weight: 750; }
.catalog-action { width: 36px; height: 36px; border: 0; border-radius: 8px; cursor: pointer; }
.catalog-edit { background: #e8f0ff; color: #1d4ed8; }
.catalog-delete { background: #fff1f2; color: #be123c; }
.catalog-empty { padding: 1rem; color: var(--muted); text-align: center; }

html[data-theme="dark"] { color-scheme: dark; --text: #e5e7eb; --muted: #9ca3af; --line: #334155; --surface: #172033; --background: #0f172a; --green-soft: #243b6b; }
html[data-theme="dark"] input, html[data-theme="dark"] select { background: #111827; border-color: #475569; color: var(--text); }
html[data-theme="dark"] .row-total, html[data-theme="dark"] .catalog-form { background: #111827; }
html[data-theme="dark"] .modal__header { background: var(--surface); }
html[data-theme="dark"] .modal__close, html[data-theme="dark"] .button--plain { background: #334155; color: var(--text); }
html[data-theme="dark"] .delete-product, html[data-theme="dark"] .catalog-delete { background: #4c1d2b; color: #fda4af; }
html[data-theme="dark"] .catalog-edit { background: #1e3a5f; color: #93c5fd; }

@media (max-width: 560px) {
  .catalog-form { grid-template-columns: 1fr 1fr; }
  .catalog-form .button { width: 100%; }
}

@media (min-width: 720px) {
  .table-head, .product-row { grid-template-columns: 6.5rem minmax(10rem, 1fr) 10rem 10rem 2.25rem; }
  .table-head { display: grid; gap: .75rem; padding: 0 1rem .45rem; color: var(--muted); font-size: .72rem; font-weight: 750; text-transform: uppercase; }
  .product-row { align-items: end; padding: .85rem 1rem; }
  .field label { display: none; }
  .field--product { padding-right: 0; }
  .field--price, .field--total { grid-column: auto; }
  .delete-product { position: static; margin-bottom: 7px; }
}

@media (max-width: 380px) {
  .summary { gap: .5rem; }
  .button--secondary { padding-inline: .65rem; font-size: .82rem; }
  #install-app { display: none; }
  .product-row { grid-template-columns: 5rem 1fr; padding: .8rem; gap: .65rem; }
}
