:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #292927;
  background: #fff;
  font-synthesis: none;
  line-height: 1.5;
  font-size: 15px;
  color-scheme: light;
  --line: #e9e9e5;
  --muted: #777771;
  --surface: #fff;
  --soft: #f5f5f2;
  --danger: #a62b2b;
  --focus: #647487;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  padding: 7px 12px;
  cursor: pointer;
  min-height: 36px;
}
button:hover:not(:disabled) { background: var(--soft); }
button:disabled { cursor: default; opacity: .5; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
button.primary { background: #30302e; color: #fff; border-color: #30302e; }
button.primary:hover:not(:disabled) { background: #4c4c48; }
button.quiet { border: 0; background: transparent; padding: 2px 0; color: var(--muted); font-size: 13px; text-align: left; }
button.danger { color: var(--danger); }
[hidden] { display: none !important; }
h1 { font-size: 26px; letter-spacing: -.7px; margin: 0; font-weight: 650; }
h2 { font-size: 17px; font-weight: 600; margin: 0; }
p { margin: 0 0 12px; }
#app { max-width: 1240px; margin: auto; padding: 44px 36px 80px; }
.header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 25px; }
.tabs { display: flex; gap: 5px; border-bottom: 1px solid var(--line); padding-bottom: 7px; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; color: var(--muted); }
.tabs button[aria-pressed=true] { background: #f0f0ed; color: #292927; font-weight: 600; }
.save-line { min-height: 28px; padding-top: 7px; font-size: 12px; color: var(--muted); }
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 11px 0 14px; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar button { font-size: 13px; }
.muted { color: var(--muted); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
#content { min-width: 0; overflow: visible; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.keyboard-hint { font-size: 12px; }
.empty-hint { margin: 13px 6px 0; max-width: 590px; }
.bag-title { flex: 1 1 180px; width: auto !important; max-width: 460px; font-size: 18px !important; font-weight: 600; }

table { width: 100%; border-collapse: collapse; text-align: left; }
.data-grid { table-layout: fixed; }
th { color: var(--muted); font-size: 12px; font-weight: 500; border-bottom: 1px solid var(--line); padding: 8px 9px; }
td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-grid th + th, .data-grid .data-row td + td, .data-grid .add-row td + td { border-left: 1px solid #f4f4f1; }
.data-grid th:first-child { width: 24%; }
.data-grid th:nth-child(2) { width: 12%; }
.data-grid th:nth-child(3) { width: 10%; }
.data-grid th:nth-child(4) { width: 26%; }
.data-grid th:nth-child(5) { width: 12%; }
.data-grid th:nth-child(6) { width: 12%; }
.data-grid th:last-child { width: 4%; }
.data-grid .data-row { height: 44px; }
.data-grid .data-row:hover { background: #fbfbf9; }
.data-grid td[data-col=actions] { padding: 3px; text-align: center; }
.data-grid td[data-col=actions] > button { border: 0; padding: 3px 6px; min-width: 28px; min-height: 32px; background: transparent; }
.data-grid td[data-col=actions] > button:hover { background: #eeeeea; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #595952; }
input, select { width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid #d9d9d3; border-radius: 5px; background: #fff; }
input[type=number] { font-variant-numeric: tabular-nums; }
.cell-input, .cell-select {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 5px 6px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  font-size: 14px;
}
.cell-input:hover, .cell-select:hover { background: #f2f2ef; }
.cell-input:focus, .cell-select:focus { background: #fff; border-color: var(--focus); outline-offset: 0; }
.cell-input::placeholder { color: #92928b; opacity: 1; }
.name-input { font-weight: 500; }
.qty-input { width: 58px; max-width: 100%; text-align: left; font-variant-numeric: tabular-nums; }
input.qty-input::-webkit-inner-spin-button, input.qty-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input.qty-input { appearance: textfield; -moz-appearance: textfield; }
.cell-select { background-color: #f0f0ed; color: #575752; font-size: 13px; cursor: pointer; padding-right: 2px; }
.bag-cell-button { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; width: 100%; min-height: 34px; border: 0; background: transparent; padding: 4px 5px; text-align: left; }
.bag-cell-button:hover:not(:disabled) { background: #f2f2ef; }
.bag-tag { display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 100%; border-radius: 3px; background: #eeeee9; padding: 1px 6px; font-size: 12px; overflow-wrap: anywhere; }
.cell-placeholder { color: #94948d; font-size: 13px; }
.buy-control { display: flex; flex-direction: row; align-items: center; gap: 3px; min-width: 0; }
.buy-control input[type=checkbox] { flex: 0 0 16px; width: 16px; height: 16px; min-height: 0; padding: 0; margin: 0 3px; accent-color: #55564e; cursor: pointer; }
.buy-control .qty-input { flex: 1 1 40px; width: 40px; }
.packed-control, .inline-number { display: flex; align-items: center; gap: 2px; min-width: 0; }
.packed-control .qty-input { width: 48px; }
.packed-control > .muted { flex: 0 0 auto; white-space: nowrap; }
.packed-control > .quiet { padding: 5px 6px; min-width: 25px; font-size: 14px; }
.add-row { background: #fcfcfa; }
.add-row td { padding-top: 6px; padding-bottom: 6px; }
.add-row .name-input { font-weight: 400; }
.add-row:focus-within { background: #f9f9f6; }
.add-submit { min-height: 32px; width: 29px; padding: 3px; border-color: transparent; background: transparent; font-size: 18px; }
.add-submit:hover:not(:disabled) { background: #eaeae5; }

.panel-row > td { padding: 0; background: #fafaf8; }
.bag-panel, .row-menu { max-width: 540px; margin: 0; padding: 15px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; font-size: 14px; font-weight: 550; overflow-wrap: anywhere; }
.panel-head button { border: 0; background: transparent; min-height: 28px; min-width: 28px; padding: 2px 7px; font-size: 18px; }
.bag-options { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 10px 0 12px; }
.bag-options button { font-size: 13px; min-height: 32px; padding: 4px 9px; text-align: left; overflow-wrap: anywhere; max-width: 100%; }
.bag-options button[aria-pressed=true], .bag-options button.selected { background: #e7e7e1; border-color: #d6d6ce; }
.split-row { display: grid; grid-template-columns: minmax(0, 1fr) 88px 88px; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.split-row > :first-child { min-width: 0; overflow-wrap: anywhere; }
.split-row label { gap: 3px; font-size: 12px; }
.split-row .qty-input { width: 100%; border-color: #deded7; background: #fff; }
.split-head { padding: 8px 0 2px; border-top: 0; color: var(--muted); font-size: 11px; }
.inline-bag-add { display: flex; align-items: center; gap: 7px; margin-top: 12px; min-width: 0; max-width: 500px; }
.inline-bag-add input { flex: 1 1 auto; padding: 7px 9px; font-size: 13px; }
.inline-bag-add button { flex: 0 0 auto; font-size: 13px; }
.row-menu { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.row-menu button { min-height: 32px; padding: 5px 9px; font-size: 13px; }
#queue-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 8px 0 12px; font-size: 13px; }
#queue-actions button { min-height: 32px; font-size: 13px; padding: 5px 9px; }
#queue-actions p { flex-basis: 100%; margin: 0; }
#queue-actions > div { display: flex; flex-wrap: wrap; gap: 7px; }
.bag-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 19px; }
.bag-tabs button { font-size: 13px; }
.bag-tabs button[aria-pressed=true] { background: #eaeae6; font-weight: 600; }
.empty { padding: 25px 0; color: var(--muted); }
.empty p:first-child { font-size: 16px; color: #4c4c48; }
.empty p { max-width: 480px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 7px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button { width: 32px; height: 32px; min-height: 32px; padding: 0; font-size: 18px; }
.stepper span { min-width: 36px; text-align: center; }
.buy-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#message { border: 1px solid var(--line); padding: 9px 12px; border-radius: 5px; margin: 8px 0; font-size: 13px; background: var(--surface); }
#message.error { color: var(--danger); }
#retry-button { margin-bottom: 10px; font-size: 13px; }
.access { padding: 25px 0; color: var(--muted); }
.access h2 { color: #292927; margin-bottom: 10px; }
.access button { margin-top: 10px; }
dialog { padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: inherit; width: calc(100% - 32px); max-width: 590px; max-height: calc(100dvh - 40px); box-shadow: 0 14px 60px #0002; }
dialog::backdrop { background: #15151555; }
#editor-body { padding: 25px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 20px; }
.dialog-head button { font-size: 20px; line-height: 1; padding: 5px 10px; border: 0; background: transparent; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.fields .full { grid-column: 1 / -1; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 12px; }
.form-error:empty { display: none; }
.conflict { background: #faf8f1; padding: 12px; border-radius: 5px; font-size: 13px; margin-top: 12px; }
.conflict p { margin: 0 0 8px; }
.conflict button { margin: 4px 6px 0 0; }
.dialog-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin-top: 24px; }
.dialog-actions .danger { margin-right: auto; }
.person-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; margin: 16px 0; }
.share-field { margin-top: 15px; }
.delete-summary { color: var(--muted); }
.close-only { justify-content: flex-end; }

@media (max-width: 700px) {
  #app { padding: 24px 16px 55px; }
  h1 { font-size: 23px; }
  .header { margin-bottom: 20px; }
  .toolbar { margin: 8px 0 12px; }
  .toolbar-actions { gap: 6px; }
  button { min-height: 44px; }
  .tabs button { padding: 7px 12px; }
  .data-grid, .data-grid tbody { display: block; width: 100%; }
  .data-grid thead { display: none; }
  .data-grid .data-row, .data-grid .add-row {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 5px 12px;
    padding: 12px 0;
    height: auto;
    min-width: 0;
    border-bottom: 1px solid var(--line);
  }
  .data-grid td { display: block; padding: 0; min-width: 0; border: 0; font-size: 14px; }
  .data-grid .data-row td + td, .data-grid .add-row td + td { border-left: 0; }
  .data-grid td[data-label]::before { content: attr(data-label); display: block; color: var(--muted); font-size: 11px; line-height: 1.4; padding-left: 6px; }
  .data-grid td[data-col=name] { grid-column: 1; align-self: center; }
  .data-grid td[data-col=person] { grid-column: 2; align-self: center; }
  .data-grid td[data-col=name]::before, .data-grid td[data-col=person]::before,
  .data-grid td[data-col=actions]::before { display: none; }
  .data-grid td[data-col=bags] { grid-column: 1 / -1; grid-row: 3; }
  .data-grid td[data-col=packed] { grid-column: 2; grid-row: 2; }
  .data-grid td[data-col=total] { grid-column: 1; grid-row: 2; }
  .data-grid td[data-col=buy] { grid-column: 1; }
  .data-grid td[data-col=actions] { grid-column: 2; align-self: end; text-align: right; padding: 0; }
  .data-grid td[data-col=actions] > button { min-height: 44px; min-width: 44px; }
  .cell-input, .cell-select, input, select { font-size: 16px; min-height: 44px; }
  .name-input { font-size: 16px; }
  .cell-select { font-size: 16px; padding-left: 8px; }
  .qty-input { width: 70px; }
  .bag-cell-button { min-height: 44px; padding: 5px 6px; }
  .bag-tag { font-size: 13px; padding: 3px 7px; }
  .buy-control { min-height: 44px; }
  .buy-control input[type=checkbox] { flex-basis: 20px; width: 20px; height: 20px; margin: 0 7px; }
  .buy-control .qty-input { flex: 0 1 62px; width: 62px; }
  .packed-control .qty-input { width: 58px; }
  .data-grid .add-row { padding: 12px 0; }
  .data-grid .add-row td[data-col=name] { grid-column: 1 / -1; grid-row: 1; }
  .data-grid .add-row td[data-col=person] { grid-column: 1; grid-row: 2; }
  .data-grid .add-row td[data-col=total] { grid-column: 2; grid-row: 2; }
  .data-grid .add-row td[data-col=person]::before { display: block; }
  .data-grid .add-row td[data-col=buy]::before { display: none; }
  .data-grid .add-row td[data-col=packed] { display: none; }
  .add-row .add-submit { min-height: 44px; min-width: 44px; border-color: var(--line); }
  .data-grid .panel-row { display: block; width: 100%; }
  .panel-row > td { display: block; width: 100%; border-bottom: 1px solid var(--line); padding: 0; }
  .bag-panel { max-width: none; padding: 12px 10px; }
  .panel-head { gap: 8px; font-size: 14px; }
  .panel-head button { min-height: 44px; min-width: 44px; }
  .bag-options { gap: 6px; }
  .bag-options button { min-height: 44px; padding: 6px 9px; }
  .split-row { grid-template-columns: minmax(0, 1fr) 70px 70px; gap: 7px; }
  .split-row label { font-size: 11px; }
  .split-row .qty-input { min-height: 44px; }
  .inline-bag-add input { font-size: 16px; }
  .inline-bag-add button { min-height: 44px; }
  .keyboard-hint { font-size: 11px; }
  .bag-title { flex-basis: 150px; }
  .row-menu { padding: 10px; }
  .row-menu button, #queue-actions button { min-height: 44px; }
  .bag-tabs { gap: 6px; margin-bottom: 16px; }
  .bag-tabs button { max-width: 100%; overflow-wrap: anywhere; }
  .stepper button { min-height: 44px; width: 44px; }
  .buy-actions button { flex: 1; }
  #editor-body { padding: 20px; }
  .dialog-actions button { flex: 1; }
  .dialog-actions .danger { flex-basis: 100%; order: 2; margin: 8px 0 0; }
  .person-form { grid-template-columns: 1fr auto; }
}

@media (prefers-reduced-motion: no-preference) {
  button { transition: background .1s; }
}

.filters { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; margin: 10px 0 8px; }
.filters label { gap: 4px; min-width: 150px; max-width: 260px; flex: 0 1 220px; font-size: 12px; color: var(--muted); }
.filters .cell-select { min-height: 36px; padding: 6px 9px; }
.filters button { min-height: 36px; padding: 6px 4px; }
@media (max-width: 700px) {
  .filters { gap: 8px; }
  .filters label { flex: 1 1 140px; min-width: 0; max-width: none; }
  .filters .cell-select { min-height: 44px; font-size: 16px; }
  .filters button { min-height: 44px; flex-basis: 100%; }
}
