:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --panel: #ffffff;
  --field: #f8fafc;
  --line: #dae3ed;
  --ink: #172741;
  --muted: #506078;
  --accent: #0b6e64;
  --warm: #9c3d16;
  --hover: #e8eef6;
  --control-line: #7b8ca2;
  --primary: #a63820;
  --primary-hover: #87301f;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 300px; background: radial-gradient(ellipse at 70% 0, #e5edf7 0, transparent 34rem), var(--bg); color: var(--ink); font: 1rem/1.5 system-ui, sans-serif; }
.shell { width: min(1150px, calc(100% - 48px)); margin-inline: auto; }
.top { border-bottom: 1px solid var(--line); background: var(--panel); }
.top-inner, .hero { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.top-inner { min-height: 76px; padding-block: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo { display: block; flex: 0 0 auto; width: clamp(48px, 8vw, 64px); height: auto; }
.hero { padding-block: 42px 28px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.85rem, 4vw, 2.75rem); line-height: 1.13; letter-spacing: -.035em; }
h2 { font-size: 1.12rem; letter-spacing: -.015em; }
h3 { font-size: .94rem; }
.active-sheet, .inventory-header p { margin-top: 7px; color: var(--muted); }
.active-sheet { overflow-wrap: anywhere; }
.active-sheet strong { color: var(--ink); }
.layout { display: grid; grid-template-columns: minmax(0, 2.3fr) minmax(268px, 1fr); gap: 20px; align-items: start; padding-bottom: 44px; }
.workspace, .sidebar { display: grid; gap: 18px; min-width: 0; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: 0 12px 32px #253e6210; }
.scores { padding: 19px; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; align-items: start; }
.scores label, .field-label { color: var(--muted); font-size: .9rem; font-weight: 650; }
.scores input, .scores output { display: block; margin-top: 7px; font-weight: 750; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.scores output { padding: 7px 0; color: var(--accent); overflow-wrap: anywhere; }
button, input { font: inherit; }
button { cursor: pointer; border-radius: 8px; white-space: nowrap; }
button:disabled { opacity: .36; cursor: default; }
button:focus-visible, input:focus-visible, .drag-handle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary, .secondary { padding: 8px 14px; min-height: 42px; font-weight: 700; }
.primary { border: 1px solid transparent; color: var(--panel); background: var(--primary); }
.primary:hover { background: var(--primary-hover); }
.secondary { border: 1px solid var(--control-line); color: var(--ink); background: transparent; }
.secondary:hover { background: var(--hover); }
input:not([type=file], [type=checkbox]) { width: 100%; min-width: 0; padding: 8px 10px; border: 1px solid var(--control-line); border-radius: 8px; background: var(--field); color: var(--ink); }
input[aria-invalid=true] { border-color: var(--warm); }
.inventory { padding: 19px; }
.inventory-header { margin-bottom: 17px; }
.inventory-header p, .tip, .storage-note { font-size: .875rem; }
.row-grid { display: grid; grid-template-columns: minmax(140px, 2.4fr) minmax(72px, .95fr) minmax(68px, .8fr) minmax(76px, .95fr) 36px; gap: 8px; align-items: center; }
.items-heading { border-bottom: 1px solid var(--line); padding: 0 0 9px; font-size: .875rem; font-weight: 650; color: var(--muted); }
.item { position: relative; padding: 9px 0; border-bottom: 1px solid var(--line); }
@media (hover: hover) {
  .item:hover { background: var(--hover); }
}
.item input { font-variant-numeric: tabular-nums; appearance: textfield; }
.item input::-webkit-inner-spin-button, .item input::-webkit-outer-spin-button { appearance: none; }
.items-heading > :first-child { padding-inline-start: 36px; }
.drag-handle { display: grid; place-items: center; flex: 0 0 28px; height: 40px; border-radius: 8px; color: var(--muted); cursor: grab; touch-action: none; user-select: none; }
.drag-handle span { width: 12px; height: 18px; background: radial-gradient(circle, currentColor 1.5px, transparent 1.75px) 0 0 / 6px 6px; }
.drag-handle[hidden] { display: none; }
.item.is-dragging { opacity: .45; }
.item.is-dragging .drag-handle { cursor: grabbing; }
.item[data-drop]::after { content: ""; position: absolute; inset-inline: 0; height: 2px; background: var(--accent); pointer-events: none; }
.item[data-drop="before"]::after { top: -1px; }
.item[data-drop="after"]::after { bottom: -1px; }
.identity { display: flex; align-items: center; gap: 8px; min-width: 0; }
.image-wrap { position: relative; flex: 0 0 40px; }
.item-image { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; color: var(--accent); background: #e8f3f2; border: 1px dashed #618780; overflow: hidden; }
.item-image img { display: block; width: 100%; height: 100%; object-fit: cover; }
.clear-image { position: absolute; top: -7px; right: -5px; border: 1px solid var(--line); border-radius: 50%; padding: 0; width: 20px; height: 20px; line-height: 1; background: var(--field); color: var(--ink); }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 3px; }
.row-actions button { width: 30px; height: 34px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 1.12rem; }
.row-actions button:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.add { margin-top: 14px; color: var(--accent); }
.tip { margin-top: 16px; color: var(--muted); }
.mobile-label { display: none; }
.result, .drafts { padding: 19px; }
.result { background: linear-gradient(155deg, #e4f4ef, var(--panel) 60%); }
.total { display: flex; flex-wrap: wrap; align-items: baseline; gap: 7px; margin-top: 9px; }
.total output { font-size: clamp(1.8rem, 3.5vw, 2.6rem); line-height: 1.2; font-weight: 800; letter-spacing: -.04em; overflow-wrap: anywhere; min-width: 0; }
.total span { color: var(--muted); }
progress { display: block; width: 100%; height: 8px; margin-top: 14px; appearance: none; border: 0; border-radius: 12px; background: #cddedb; overflow: hidden; }
progress::-webkit-progress-bar { background: #cddedb; }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
#result-status { color: var(--accent); font-size: .9rem; margin-top: 9px; min-height: 1.4em; }
#result-status[data-state=attention] { color: var(--warm); }
.result-details-toggle { display: none; }
.plan { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 14px; }
ul { margin: 0; padding: 0; list-style: none; }
#plan li { display: flex; gap: 10px; justify-content: space-between; align-items: baseline; padding-top: 8px; font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.plan-amount { flex: 0 0 auto; max-width: 55%; text-align: right; }
.plan-amount span { display: block; font-size: .8125rem; }
#plan strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.draft-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.draft-heading button { min-height: 34px; padding: 5px 9px; font-size: .875rem; }
.draft-export { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; font-size: .875rem; }
.draft-export label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.draft-bulk-download { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 36px; min-height: 36px; padding: 5px 9px; margin-inline-start: auto; }
.download-icon { position: relative; display: inline-grid; place-items: center; width: 16px; height: 16px; font: 700 18px/12px system-ui, sans-serif; padding-bottom: 4px; }
.download-icon::after { position: absolute; inset: auto 1px 0; height: 4px; border: 1.5px solid currentColor; border-top: 0; border-radius: 0 0 2px 2px; content: ""; }
.drafts input[type=checkbox] { width: 16px; height: 16px; flex: 0 0 auto; margin: 0; accent-color: var(--accent); cursor: pointer; }
#drafts li { display: flex; align-items: center; gap: 6px; margin-top: 9px; padding: 3px 5px 3px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); }
#drafts button { min-height: 36px; border: 0; background: transparent; }
#drafts button:hover { background: var(--hover); }
#drafts .open-draft { flex: 1; min-width: 0; padding-inline: 5px; text-align: left; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
#drafts .draft-action { display: grid; place-items: center; width: 32px; flex: 0 0 32px; padding: 0; color: var(--muted); font-size: 1.125rem; }
#empty-drafts, .storage-note { margin-top: 9px; color: var(--muted); }
.notice { position: fixed; z-index: 1; bottom: 20px; right: 20px; max-width: calc(100% - 40px); padding: 10px 15px; background: var(--panel); border: 1px solid var(--control-line); border-radius: 9px; box-shadow: 0 8px 32px #24365426; }
dialog { width: min(435px, calc(100% - 30px)); border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); padding: 22px; }
dialog::backdrop { background: #17274166; }
dialog label { display: block; margin-block: 13px 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 15px; }
#save-error { color: var(--warm); margin-top: 8px; }
@media (max-width: 925px) { .layout { grid-template-columns: 1fr; } .sidebar { grid-template-columns: 1fr 1fr; align-items: start; } }
@media (max-width: 640px) {
  .shell { width: calc(100% - 28px); }
  .hero { padding-block: 18px 14px; }
  .hero h1 { font-size: clamp(1.2rem, 5.4vw, 1.55rem); }
  .active-sheet { margin-top: 5px; font-size: .875rem; }
  .hero .primary { padding-inline: 10px; font-size: .875rem; }
  .scores { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 13px; gap: 9px; }
  .scores input, .scores output { font-size: 1rem; }
  .scores > div { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
  .scores output { margin-top: 0; padding-block: 0; }
  .inventory, .result, .drafts { padding: 14px; }
  .result .total output { font-size: clamp(2.2rem, 10vw, 2.75rem); }
  .result-details-toggle { display: block; width: 100%; margin-top: 12px; color: var(--accent); }
  .result-details-toggle[aria-expanded="false"] + .plan { display: none; }
  .items-heading { display: none; }
  .row-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .item { padding: 12px 0; }
  .identity { grid-area: 1 / 1 / 2 / -1; padding-inline-end: 44px; }
  .row-actions { grid-area: 1 / 3; justify-self: end; }
  .row-actions [data-action="remove"] { width: 36px; height: 40px; }
  .mobile-label { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 3px; }
  .sidebar { grid-template-columns: 1fr; }
}
