/* Hallmark · 淘啡豆仓 · shape: app screen · redesign: full · scope: app · v2.0.0 */
/* The entry form opens beside the ledger. Its actions stay in reach while the fields scroll. */
#dialog {
  --sheet-pad: clamp(20px, 3.1vw, 42px);
  box-sizing: border-box;
  position: fixed;
  inset: 0 0 0 auto;
  width: min(580px, calc(100% - 36px));
  max-width: none;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  margin: 0;
  border: 0;
  border-inline-start: 1px solid var(--rule);
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  overflow: hidden;
  overflow-wrap: anywhere;
}
#dialog[open] { display: flex; flex-direction: column; }
#dialog:not([open]), #dialog [hidden] { display: none; }
#dialog::backdrop { background: var(--backdrop); }
body:has(#dialog[open]) { overflow-y: hidden; }

#dialog .modal-head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px var(--sheet-pad);
  background: var(--dark);
  color: var(--pale-ink);
}
#dialog-title {
  margin: 0;
  min-width: 0;
  overflow-wrap: break-word;
  text-wrap: balance;
  font: 550 28px/1.3 var(--serif);
}
#dialog .modal-head .icon-button {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--pale-ink);
}
#dialog .modal-head .icon-button:hover { background: var(--sheet-tint); color: var(--ink); }
#dialog .dialog-form { display: flex; flex: 1; min-height: 0; flex-direction: column; overflow: hidden; }
#dialog .modal-body {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 24px var(--sheet-pad) 28px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--control-line) transparent;
}
#dialog .modal-foot {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px var(--sheet-pad) max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--sheet-tint);
}
#dialog .modal-foot button { min-height: 44px; }
#dialog .modal-foot .primary { margin-left: auto; padding-inline: 24px; }
#dialog .modal-foot .secondary {
  border-color: transparent;
  background: transparent;
  padding-inline: 1px 12px;
  color: var(--muted);
}
#dialog .modal-foot .secondary:hover { color: var(--ink); text-decoration: underline; }
#dialog .entry-section + .entry-section { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
#dialog .entry-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}
#dialog .entry-section-head h3, #dialog .subsection {
  margin: 0;
  font: 600 17px/1.5 var(--sans);
  color: var(--ink);
}
#dialog .entry-section-head span { font-size: 13px; color: var(--muted); }
#dialog .fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
#dialog .wide { grid-column: 1/-1; }
#dialog .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
}
#dialog .field input, #dialog .field textarea, #dialog .field select, #dialog .allocation input {
  width: 100%;
  height: 44px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--control-bg);
  color: var(--ink);
  font: 400 16px/1.4 var(--sans);
}
#dialog .field input:is([type="number"], [type="date"]), #dialog .allocation input {
  font-variant-numeric: tabular-nums;
}
#dialog :is(input, select, textarea, button, summary):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}
#dialog .modal-head .icon-button:focus-visible { outline-color: var(--pale-ink); }
#dialog .field textarea { min-height: 58px; resize: vertical; }
#dialog .field .unit-field { display: grid; grid-template-columns: minmax(0, 1fr) 64px; gap: 0; }
#dialog .unit-field input { border-radius: 2px 0 0 2px; }
#dialog .unit-field select { border-left-width: 0; border-radius: 0 2px 2px 0; padding-inline: 4px; }
#dialog .checkbox {
  display: flex; align-items: center; gap: 8px;
  width: fit-content; min-height: 44px;
  font-size: 14px; cursor: pointer;
}
#dialog .checkbox input { width: 17px; height: 17px; accent-color: var(--accent); }
#dialog .hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
#dialog .book-quantity {
  padding: 12px 0;
  border-block: 1px solid var(--line);
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
#dialog .allocation {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
#dialog .allocation b { font: 500 16px/1.5 var(--sans); }
#dialog .allocation small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
#dialog .allocation-count { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
#dialog .allocation input { width: 68px; text-align: center; }
#dialog .pairs { display: block; margin: 0; }
#dialog .pairs > div {
  display: grid; grid-template-columns: minmax(84px, .85fr) minmax(0, 1.75fr);
  align-items: baseline; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
#dialog .pairs dt { color: var(--muted); font-size: 14px; font-weight: 400; }
#dialog .pairs dd {
  margin: 0; color: var(--ink); font-size: 15px;
  font-variant-numeric: tabular-nums; line-height: 1.55;
}
#dialog .history-filter { margin-bottom: 16px; }
#dialog .history-filter select { width: min(20em, 100%); }
#dialog .modal-body > .subsection { margin: 24px 0 12px; }
#dialog .review-summary {
  padding: 16px 20px 20px;
  border-block-end: 1px solid var(--rule);
  background: var(--sheet-tint);
  margin-bottom: 16px;
}
#dialog .review-name { color: var(--ink); font-size: 18px; font-weight: 600; line-height: 1.45; }
#dialog .review-total { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 16px 0 0; }
#dialog .review-total dt { flex: none; color: var(--muted); font-size: 14px; }
#dialog .review-total dd {
  margin: 0; color: var(--accent); font: 550 25px/1.25 var(--sans);
  font-variant-numeric: tabular-nums; text-align: right;
}
#dialog .form-error { margin: 16px 0 0; background: var(--error-bg); color: var(--error); border: 1px solid currentColor; padding: 12px; }
#dialog .modal-foot .primary:active { background-color: var(--accent-dark); }
#dialog .form-error:empty { display: none; }
#dialog .modal-body > p + p { margin-top: 8px; }

@media (max-width: 600px) {
  #dialog { --sheet-pad: 20px; inset: auto 0 0; width: 100%; height: auto; max-height: calc(100dvh - 16px); margin: 0; border: 0; }
  #dialog-title { font-size: 23px; }
  #dialog .modal-head { padding-block: 12px; }
  #dialog .modal-body { padding-block: 16px 24px; }
  #dialog .fields { gap: 12px 12px; }
  #dialog .modal-foot .primary { min-width: 46%; }
  #dialog .pairs > div { gap: 12px; padding-block: 8px; }
}
@media (max-width: 360px) {
  #dialog { --sheet-pad: 15px; }
  #dialog .entry-section:has(.unit-field) > .fields > .field:has(.unit-field) { grid-column: 1/-1; }
}
