:root {
  color-scheme: light dark;
  --paper: #fffdfb;
  --mat: #fcf7f3;
  --ink: #2b2023;
  --quiet: #6e5457;
  --line: #ead9d6;
  --accent: #a31832;
  --accent-strong: #761327;
  --accent-fill: #a31832;
  --on-accent: #fff9f4;
  --tint: #fae8eb;
  --error: #a62225;
  --mast-start: #761126;
  --mast-end: #a6203a;
  --mast-light: #bd354d;
  --mast-ink: #fff7ef;
  --mast-gold: #efce99;
  --mast-letter-bg: #851a31;
  --mast-rule: #d5ad74;
  font: 400 16px/1.45 system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #241719;
    --mat: #2c1b20;
    --ink: #fff1e9;
    --quiet: #d3aeb1;
    --line: #603940;
    --accent: #fb9da8;
    --accent-strong: #ffbdc2;
    --accent-fill: #f58d9a;
    --on-accent: #371019;
    --tint: #48252d;
    --error: #ffadad;
    --mast-start: #5c0e24;
    --mast-end: #84182f;
    --mast-light: #a52847;
    --mast-letter-bg: #681429;
    --mast-rule: #aa7848;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--mat); color: var(--ink); padding: clamp(12px, 4vw, 42px); }
.shell { max-width: 1060px; margin: 0 auto; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); overflow: hidden; }
.mast {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 90px;
  padding: 20px clamp(14px, 3vw, 28px);
  overflow: hidden;
  color: var(--mast-ink);
  border-bottom: 2px solid var(--mast-rule);
  background: radial-gradient(ellipse at 82% -30%, var(--mast-light), transparent 57%),
    linear-gradient(110deg, var(--mast-start), var(--mast-end));
}
.mast-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mast-actions { display: flex; align-items: center; flex: 0 0 auto; gap: 16px; margin-inline-start: auto; padding-inline-start: 12px; }
.mast-brand, .mast-actions { position: relative; z-index: 1; }
.mast-snow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 43% 79%, #ffe6c58c 1px, transparent 2px),
    radial-gradient(circle at 53% 24%, #ffe6c580 1px, transparent 2px),
    radial-gradient(circle at 62% 76%, #ffe6c57f 1px, transparent 2px),
    radial-gradient(circle at 70% 17%, #ffe6c58c 1px, transparent 2px),
    radial-gradient(circle at 91% 87%, #ffe6c58c 1px, transparent 2px);
}
.mast-snow > span { position: absolute; color: var(--mast-gold); font: 400 12px/1 system-ui, sans-serif; }
.mast-flake-top { top: 11px; left: 47%; opacity: .66; }
.mast-snow .mast-flake-middle { top: 23px; left: 60%; opacity: .55; font-size: 19px; }
.mast-flake-bottom { bottom: 11px; left: 54%; opacity: .64; }
.mast-flake-end { bottom: 8px; right: 23%; opacity: .56; }
.logout button { white-space: nowrap; }
.login-shell { max-width: 470px; }
.login-main .login-form { display: grid; gap: 16px; }
.login-form h2, .login-form [role="alert"] { margin: 0; }
.login-form [role="alert"] { color: var(--error); }
.login-form button { justify-self: start; }
.mast h1 { margin: 0; font: 600 clamp(22px, 4vw, 34px)/1.13 Georgia, serif; letter-spacing: -.025em; }
.mast-mark { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border: 1px solid #efce9990; border-radius: 11px; color: var(--mast-gold); background: #fff6ed13; }
.winter-crystal { position: relative; display: grid; place-items: center; width: var(--crystal-size, 22px); aspect-ratio: 1; }
.winter-crystal > span { position: absolute; width: 92%; height: var(--crystal-stroke, 1.5px); border-radius: 100vw; background: currentColor; }
.winter-crystal > span:nth-child(2) { transform: rotate(60deg); }
.winter-crystal > span:nth-child(3) { transform: rotate(120deg); }
.winter-crystal > span::before, .winter-crystal > span::after {
  position: absolute;
  top: 50%;
  width: var(--crystal-branch, 5px);
  aspect-ratio: 1;
  border-style: solid;
  border-color: currentColor;
  border-width: var(--crystal-stroke, 1.5px) var(--crystal-stroke, 1.5px) 0 0;
  content: '';
}
.winter-crystal > span::before { left: 12%; transform: translateY(-50%) rotate(-135deg); }
.winter-crystal > span::after { right: 12%; transform: translateY(-50%) rotate(45deg); }
.mast-motif {
  display: flex;
  align-items: center;
  gap: 13px;
}
.mast-motif .winter-crystal { --crystal-size: 66px; --crystal-branch: 13px; transform: rotate(15deg); color: #ffe4c79e; }
.winter-letter {
  position: absolute;
  z-index: 1;
  inset: 50% auto auto 50%;
  display: grid;
  place-items: center;
  width: 30px;
  aspect-ratio: 1;
  padding-bottom: 1px;
  transform: translate(-50%, -50%) rotate(-15deg);
  border: 1px solid #efce99b0;
  border-radius: 50%;
  background: var(--mast-letter-bg);
  color: var(--mast-gold);
  font: 600 19px/1 Georgia, serif;
}
.winter-sparkle { color: var(--mast-gold); font-size: 22px; line-height: 1; }
h2 { color: var(--accent-strong); font-size: 20px; line-height: 1.2; margin: 0; }
p { margin: 0; }
main { padding: 20px clamp(14px, 3vw, 28px) 25px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
.section-head, .entry-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.section-head { margin-bottom: 13px; }
.tools, .entry-actions, .dialog-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.shop-actions { display: flex; flex-wrap: wrap; gap: 8px; }
label, .shop-field { display: grid; gap: 5px; font-size: .9375rem; font-weight: 600; min-width: 0; }
.buyer-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.buyer-fields label { align-content: end; }
#entry .buyer-fields { grid-template-columns: repeat(3, minmax(0, 255px)); margin-bottom: 15px; }
.record-buyer { display: block; font-size: .875rem; font-weight: 400; overflow-wrap: anywhere; }
input, button { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
input, .shop-trigger { min-height: 42px; min-width: 0; width: 100%; padding: 7px 10px; font-size: 1rem; font-weight: 400; }
button { min-height: 40px; padding: 6px 12px; font-size: .9375rem; font-weight: 600; cursor: pointer; }
button:hover:not(:disabled) { background-color: var(--mat); }
button:disabled { opacity: .6; cursor: default; }
.shop-trigger { position: relative; padding-right: 28px; text-align: left; overflow-wrap: anywhere; }
.shop-trigger::after { position: absolute; top: calc(50% - 5px); right: 12px; width: 7px; height: 7px; border: solid var(--quiet); border-width: 0 2px 2px 0; transform: rotate(45deg); content: ''; }
.shop-trigger[aria-invalid="true"] { border-color: var(--error); }
input[aria-invalid="true"] { border-color: var(--error); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent-fill); color: var(--on-accent); border-color: var(--accent-fill); }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent-fill) 90%, var(--on-accent)); }
button.export { background: var(--tint); color: var(--accent-strong); }
#open-shop, #open-import, #open-export-history { color: var(--accent-strong); }
#open-remove-shop { color: var(--error); }
.receipts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.receipt-help { color: var(--quiet); font-size: .9375rem; }
#entry .receipt-help { margin-bottom: 8px; }
fieldset { min-width: 0; margin: 0; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; background: var(--mat); display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 10px; }
legend { color: var(--accent); font-weight: 700; padding: 0 5px; }
.entry-footer { margin-top: 14px; }
.entry-actions { justify-content: flex-end; margin-left: auto; max-width: 100%; }
.entry-feedback { min-width: 0; overflow-wrap: anywhere; }
.entry-feedback > span { display: block; }
#entry-confirmation { color: var(--accent-strong); font-weight: 600; }
.total { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; padding: 7px 12px; border-radius: 8px; background: var(--tint); color: var(--accent-strong); }
.total output { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
[role="status"] { margin: 0; color: var(--quiet); font-size: .9375rem; }
[role="status"]:empty, .table-actions:has([hidden]) { display: none; }
[role="status"].error { color: var(--error); }
.records { padding-top: 19px; border-top: 1px solid var(--line); }
#records-status:not(:empty) { margin-bottom: 9px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; }
table { width: 100%; min-width: 550px; border-collapse: collapse; text-align: left; font-size: .9375rem; }
th, td { padding: 10px 12px; overflow-wrap: anywhere; }
th { background: var(--mat); color: var(--quiet); border-bottom: 1px solid var(--line); }
tbody tr + tr { border-top: 1px solid var(--line); }
.record-actions { width: 1%; white-space: nowrap; }
.record-actions button { width: 36px; height: 36px; min-height: 0; padding: 0; font-size: 20px; line-height: 1; }
.record-actions button + button { margin-left: 5px; }
.record-actions .remove { color: var(--error); }
.number { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.total-cell { background: var(--tint); color: var(--accent-strong); font-weight: 700; }
.empty { color: var(--quiet); }
.mobile-label { display: none; }
.table-actions { margin-top: 10px; }
dialog { width: min(410px, calc(100% - 28px)); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow: auto; overscroll-behavior: contain; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: 18px; }
dialog::backdrop { background: #44111e68; }
dialog form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
dialog p { color: var(--quiet); font-size: .9375rem; }
.edit-dialog { width: min(710px, calc(100% - 28px)); }
.edit-dialog .total { justify-self: start; }
.dialog-actions { justify-content: flex-end; }
.danger { color: var(--paper); background: var(--error); border-color: var(--error); }
button.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--error) 90%, var(--paper)); }
.shop-picker { width: min(510px, calc(100% - 24px)); height: min(540px, calc(var(--picker-height, 100vh) - 24px)); max-height: min(540px, calc(var(--picker-height, 100dvh) - 24px)); overflow: hidden; }
.shop-picker[open] { display: grid; grid-template: auto auto minmax(0, 1fr) / minmax(0, 1fr); gap: 10px; }
.shop-picker .section-head { margin: 0; }
.shop-results { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 3px; }
.shop-results h3 { margin: 0 0 5px; padding: 0 9px; color: var(--accent); font-size: .875rem; }
.shop-results ul { list-style: none; margin: 0; padding: 0; }
.shop-results ul + h3 + ul { margin-top: 7px; }
.shop-result { display: grid; grid-template-columns: minmax(0, 1fr) 44px; align-items: stretch; gap: 4px; margin-bottom: 4px; }
.shop-picker-removal .shop-result { grid-template-columns: minmax(0, 1fr); }
.shop-result button { min-height: 44px; }
.shop-option { padding: 7px 9px; text-align: left; overflow-wrap: anywhere; }
.shop-option[aria-current="true"] { background: var(--tint); color: var(--accent-strong); border-color: var(--accent); }
.shop-star { padding: 0; font-size: 1.4rem; line-height: 1; color: var(--quiet); }
.shop-star[aria-pressed="true"] { background: var(--tint); color: var(--accent-strong); }
#clear-shop-choice { justify-self: start; }
.export-history { width: min(580px, calc(100% - 28px)); }
.export-versions { list-style: none; margin: 0; padding: 0; }
.export-versions li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; padding: 10px 0; border-top: 1px solid var(--line); }
.export-file { display: grid; gap: 3px; min-width: 0; overflow-wrap: anywhere; }
.export-file time { color: var(--quiet); font-size: .875rem; }
#export-history-status:not(:empty) { margin-bottom: 10px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 620px) { .receipts { grid-template-columns: minmax(0, 1fr); } }
@media (pointer: coarse), (max-width: 740px) {
  button, input, .shop-trigger { min-height: 44px; }
  .record-actions button { width: 44px; height: 44px; }
}
@media (max-width: 740px) {
  .records .section-head { align-items: stretch; flex-direction: column; }
  .tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tools button { white-space: normal; }
  #open-export-history { grid-column: 1 / -1; }

  .table-scroll { border: 0; border-radius: 0; overflow: visible; padding: 1px; }
  .table-scroll table { display: block; min-width: 0; }
  .table-scroll thead { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .table-scroll tbody { display: grid; gap: 10px; }
  .table-scroll tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "postal actions" "shop1 amount1" "shop2 amount2" "total total";
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
  }
  .table-scroll tbody .first-only { grid-template-areas: "postal actions" "shop1 amount1" "total total"; }
  .table-scroll tbody .second-only { grid-template-areas: "postal actions" "shop2 amount2" "total total"; }
  .table-scroll td { display: block; width: auto; min-width: 0; padding: 8px 12px; }
  .table-scroll .record-actions { grid-area: actions; display: flex; gap: 6px; }
  .record-actions button + button { margin-left: 0; }
  .record-postal { grid-area: postal; font-weight: 700; }
  .shop1 { grid-area: shop1; }
  .shop2 { grid-area: shop2; }
  .amount1 { grid-area: amount1; }
  .amount2 { grid-area: amount2; }
  .table-scroll .number { white-space: normal; }
  .table-scroll .receipt-line { display: flex; flex-direction: column; justify-content: center; align-self: stretch; border-top: 1px solid var(--line); }
  .table-scroll .first-only :is(.shop2, .amount2),
  .table-scroll .second-only :is(.shop1, .amount1) { display: none; }
  .mobile-label { display: block; color: var(--quiet); font-size: .8125rem; font-weight: 500; }
  .table-scroll .total-cell { grid-area: total; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-block: 10px; border-radius: 0 0 9px 9px; }
  .table-scroll .total-cell .mobile-label { color: inherit; }
  .table-scroll tbody .record-placeholder { display: block; }
  .table-scroll .empty { grid-area: 1 / 1 / -1 / -1; padding: 12px; }
}
@media (max-width: 580px) {
  .mast-flake-middle { display: none; }
  .mast-flake-top { top: 6px; }
  .mast-flake-bottom { bottom: 5px; }
}
@media (max-width: 520px) {
  .mast:has(.mast-actions) { padding-inline: 10px; }
  .mast:has(.mast-actions) .mast-brand { gap: 7px; }
  .mast:has(.mast-actions) .mast-mark { width: 28px; height: 28px; }
  .mast:has(.mast-actions) h1 { font-size: 20px; overflow-wrap: anywhere; }
  .mast-actions { gap: 7px; padding-inline-start: 8px; }
  .mast-motif .winter-crystal { --crystal-size: 28px; --crystal-branch: 6px; }
  .winter-letter { width: 15px; font-size: 11px; }
  .winter-sparkle { display: none; }
  .mast-snow { background: radial-gradient(circle at 26% 86%, #ffe6c580 1px, transparent 2px),
    radial-gradient(circle at 70% 13%, #ffe6c58c 1px, transparent 2px); }
  .mast-snow > span { font-size: 9px; }
  .mast-flake-top { top: 5px; left: 42%; }
  .mast-flake-bottom { left: 56%; }
  .mast-flake-end { bottom: 4px; right: 8px; }
  .logout button { padding-inline: 8px; }
}
@media (max-width: 480px) {
  body { padding: 8px; }
  .mast { min-height: 74px; padding-block: 15px; }
  main { padding-block: 16px 20px; gap: 18px; }
  #entry .buyer-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .buyer-fields .postal { grid-column: 1 / -1; }
  fieldset { grid-template-columns: minmax(0, 1fr); }
  .entry-footer { align-items: stretch; flex-direction: column; }
  .entry-footer .total { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 10px; }
  .entry-actions { display: grid; grid-template-columns: minmax(0, 1fr); margin-left: 0; }
  .dialog-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  dialog { padding: 14px; }
}
@media (pointer: coarse) {
  .shop-picker { top: var(--picker-top, 0px); bottom: auto; margin-block: 12px auto; }
}
