:root {
  color-scheme: light;
  --canvas: #fbf8f5;
  --surface: #fff;
  --ink: #27211f;
  --muted: #6f625d;
  --line: #e7ded8;
  --accent: #9f303b;
  --accent-deep: #84232e;
  --accent-soft: #f9eceb;
  --green: #285f4a;
  --green-soft: #eaf4ed;
  --amber: #804719;
  --amber-soft: #fcf0df;
  --neutral: #5e5350;
  --neutral-soft: #f0ebe7;
  --radius: 16px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  background: var(--canvas);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; }
button, input, select, textarea { font: inherit; }
button, summary { cursor: pointer; }
a { color: inherit; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin: 0; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { cursor: wait; opacity: .62; }

.shell { width: min(100% - 56px, 1104px); margin-inline: auto; }
.topbar { background: #fffdfa; border-bottom: 1px solid var(--line); }
.topbar-inner { min-height: 77px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; user-select: none; }
.brand strong, .brand small, .account-meta strong, .account-meta small { display: block; }
.brand strong { font-size: 20px; letter-spacing: .045em; line-height: 1.2; }
.brand small, .account-meta small { color: var(--muted); font-size: 12px; margin-top: 4px; }
.brand-mark {
  display: grid; place-items: center; width: 43px; height: 43px; flex: none;
  border-radius: 13px; background: var(--accent); color: #fff;
}
.brand-mark::before {
  content: ""; width: 22px; height: 15px; border: 1.7px solid currentColor; border-radius: 3px;
  background: linear-gradient(to bottom, currentColor 50%, transparent 50%) 62% 0 / 1px 4px repeat-y;
  mask: radial-gradient(circle at left, transparent 2px, black 2.5px) left / 50% 100% no-repeat,
        radial-gradient(circle at right, transparent 2px, black 2.5px) right / 50% 100% no-repeat;
}
.account-menu { position: relative; z-index: 2; }
.account-menu > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 12px; }
.account-menu > summary::-webkit-details-marker { display: none; }
.account-menu[open] > summary, .account-menu > summary:hover { background: var(--neutral-soft); }
.avatar {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: #f3ddda; color: var(--accent-deep); font-weight: 800; flex: none;
}
.account-meta strong { max-width: 135px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.chevron { width: 7px; height: 7px; border: solid var(--muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); margin: -4px 3px 0; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 9px); min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 28px #48282316;
}
.dropdown button { display: block; text-align: left; width: 100%; border: 0; background: transparent; padding: 11px 12px; min-height: 43px; border-radius: 8px; color: var(--ink); }
.dropdown button:hover { background: var(--accent-soft); }
.dropdown button:last-child { color: var(--accent-deep); }

.button {
  display: inline-flex; justify-content: center; align-items: center; gap: 5px; min-height: 44px; padding: 8px 15px;
  border: 1px solid transparent; border-radius: 9px; font-size: 14px; font-weight: 700; text-align: center;
  text-decoration: none; white-space: nowrap; color: inherit; background: transparent;
}
.button.primary { color: white; background: var(--accent); border-color: var(--accent); }
.button.primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.button.secondary { color: var(--accent-deep); border-color: #e5c6c4; background: #fffafa; }
.button.secondary:hover, .button.text:hover { background: var(--accent-soft); }
.button.neutral { border-color: var(--line); background: var(--surface); }
.button.neutral:hover { background: var(--neutral-soft); }
.button.text { color: var(--muted); }
.button.danger { color: #962c38; }
.muted { color: var(--muted); }
.loading { padding-block: 55px; color: var(--muted); }
.login-layout { min-height: calc(100svh - 78px); display: grid; place-items: start center; padding-block: clamp(48px, 12vh, 126px); }
.login-card {
  width: min(100%, 400px); background: var(--surface); border: 1px solid var(--line); border-radius: 19px;
  padding: clamp(23px, 6vw, 35px); box-shadow: 0 12px 38px #402e2310;
}
.login-card h1 { font-size: 29px; letter-spacing: -.04em; }
.login-card p { margin-top: 9px; font-size: 14px; }
.login-card form { display: grid; gap: 16px; margin-top: 25px; }
.login-card form > .button { margin-top: 4px; }

.inventory { padding-block: 42px 70px; }
.overview { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 24px; }
.overview h1 { font-size: clamp(30px, 4vw, 42px); letter-spacing: -.045em; line-height: 1.15; }
.overview p { font-size: 14px; margin-top: 10px; }
.add-button { min-height: 46px; padding-inline: 17px; }
.add-button span { font-size: 19px; line-height: 1; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.stat {
  --stat-color: var(--green); --stat-background: var(--green-soft);
  position: relative; overflow: hidden; display: grid; text-align: left; justify-items: start; gap: 9px;
  padding: 15px 17px; color: var(--stat-color); background: var(--stat-background); border: 1px solid transparent; border-radius: 13px;
}
.stat:hover, .stat[aria-pressed="true"] { border-color: var(--stat-color); }
.stat span { font-size: 13px; font-weight: 700; }
.stat strong { color: var(--ink); font-size: 31px; font-variant-numeric: tabular-nums; line-height: 1; }
.stat-expire { --stat-color: var(--accent-deep); --stat-background: var(--accent-soft); }
.stat-pending { --stat-color: var(--amber); --stat-background: var(--amber-soft); }
.collection { margin-top: 34px; }
.collection-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.collection-title h2 { font-size: 22px; }
.refresh-button { padding-inline: 8px; }
.refresh-button span { font-size: 19px; line-height: 1; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 13px; }
.duration-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; background: #f0e9e4; border-radius: 12px; }
.duration-tabs button {
  min-height: 42px; border: 1px solid transparent; border-radius: 8px; font-weight: 700; font-size: 14px;
  padding: 6px 11px; color: var(--muted); background: transparent; white-space: nowrap;
}
.duration-tabs button[aria-pressed="true"] { background: var(--surface); color: var(--accent-deep); border-color: #eaddd7; box-shadow: 0 1px 3px #4327190a; }
.duration-tabs button:hover { color: var(--accent-deep); }
.duration-tabs span { display: inline-block; font-size: 11px; margin-left: 4px; color: inherit; font-weight: 600; }
.filters { display: flex; gap: 9px; }
.filters input { width: clamp(170px, 20vw, 240px); }
.filters select { width: auto; }
input:not([type="checkbox"]), select, textarea {
  min-height: 44px; padding: 9px 11px; border: 1px solid #d9ccc4; border-radius: 9px;
  max-width: 100%; color: var(--ink); background: var(--surface); font-size: 16px;
}
input::placeholder, textarea::placeholder { color: #776963; opacity: 1; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.list-info { color: var(--muted); font-size: 13px; margin: 13px 0; min-height: 20px; }
.list-info.error { color: var(--accent-deep); }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.voucher {
  display: flex; flex-direction: column; position: relative; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 3px 9px #402e2306;
}
.voucher.expiring { border-top: 3px solid #b85458; }
.voucher.pending-soon { border-top: 3px solid #bd8745; }
.voucher.voucher-inactive { background: #f0f0f0; filter: grayscale(1); }
.voucher-main { padding: 16px 16px 13px; flex: 1; }
.voucher-top, .voucher-admin { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.voucher-top { align-items: flex-start; }
.voucher h3 { font-size: 16px; padding-top: 3px; }
.badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.badge { padding: 4px 7px; border-radius: 5px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-ready { background: var(--green-soft); color: var(--green); }
.badge-neutral { background: var(--neutral-soft); color: var(--neutral); }
.badge-expire { background: var(--accent-soft); color: var(--accent-deep); }
.badge-pending { background: var(--amber-soft); color: var(--amber); }
.voucher-price { display: flex; align-items: baseline; gap: 3px; font-size: 28px; line-height: 1.1; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 16px; }
.voucher-price > span { font-size: 18px; color: var(--accent-deep); }
.voucher-price > small { font-size: 11px; font-weight: 600; color: var(--muted); margin-left: 5px; }
.voucher-meta { margin: 14px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.voucher-meta dt { color: var(--muted); }
.voucher-meta dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.voucher-expiry { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: 4px 8px; }
.expiry-countdown { color: var(--accent-deep); font-weight: 700; white-space: nowrap; }
.voucher-meta .code-tail { font-family: ui-monospace, Consolas, monospace; letter-spacing: .06em; }
.buyer-note { margin-top: 11px; padding: 8px 9px; border-radius: 7px; background: #f7f3ef; font-size: 13px; overflow-wrap: anywhere; white-space: pre-wrap; }
.buyer-note strong { margin-right: 7px; color: var(--muted); }
.voucher-actions {
  display: flex; flex-wrap: wrap; gap: 6px; min-height: 64px; padding: 10px 13px;
  border-top: 1px dashed var(--line);
}
.voucher-actions > .button { flex: 1 0 auto; padding-inline: 7px; min-height: 42px; font-size: 12px; }
.voucher-admin { justify-content: flex-end; padding: 0 13px 6px; }
.voucher-admin .button { min-height: 38px; font-size: 12px; padding-inline: 8px; }
.empty { padding: 44px 16px; border: 1px dashed #decfc5; background: #fffdfa; border-radius: var(--radius); text-align: center; }
.empty-mark { background: var(--accent-soft); color: var(--accent); margin: 0 auto 12px; }
.empty h3 { font-size: 18px; }
.empty p { margin: 8px 0 13px; color: var(--muted); font-size: 14px; }

dialog {
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  width: min(100% - 28px, 550px); max-height: calc(100dvh - 36px); padding: 0; box-shadow: 0 20px 70px #38211c40;
}
dialog::backdrop { background: #25151480; }
body:has(dialog[open]) { overflow: hidden; }
.dialog-header {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 19px 20px 13px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.dialog-header h2 { font-size: 22px; line-height: 1.25; }
.dialog-header p { margin-top: 5px; font-size: 13px; }
.close-button {
  flex: none; width: 42px; height: 42px; border: 0; border-radius: 8px; background: var(--neutral-soft);
  color: var(--ink); font-size: 24px; line-height: 1; padding: 0;
}
.close-button:hover { background: var(--accent-soft); }
.dialog-body { padding: 17px 20px 21px; }
form label:not(.checkbox) { display: grid; min-width: 0; align-content: start; gap: 6px; font-size: 14px; font-weight: 700; }
form label input:not([type="checkbox"]), form label select, form label textarea { width: 100%; min-width: 0; font-weight: 400; }
.password-field { display: grid; gap: 6px; min-width: 0; }
.icon-definitions { position: absolute; width: 0; height: 0; overflow: hidden; }
.password-control { position: relative; }
.password-control input { width: 100%; min-width: 0; min-height: 48px; padding-inline-end: 53px; }
.password-control input::-ms-reveal { display: none; }
.password-control button {
  position: absolute; inset-inline-end: 2px; inset-block-start: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 7px;
  color: var(--muted); background: transparent;
}
.password-control button svg {
  width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round; pointer-events: none;
}
.password-control button:hover { color: var(--accent-deep); background: var(--accent-soft); }
.dialog-form { display: grid; gap: 14px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.field-grid .wide { grid-column: 1 / -1; }
.field-hint { font-size: 12px; line-height: 1.55; color: var(--muted); font-weight: 400; }
.upload-box { min-width: 0; padding: 12px; border: 1px dashed #d8c8bd; border-radius: 10px; background: #fcfaf8; }
.upload-box input[type="file"] { padding: 7px 8px; font-size: 13px; }
.upload-box input::file-selector-button { margin-right: 7px; min-height: 30px; border: 0; border-radius: 5px; background: var(--neutral-soft); padding: 3px 7px; color: var(--ink); }
.upload-options { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.upload-options .button { font-size: 12px; min-height: 38px; }
.checkbox { display: flex; gap: 5px; align-items: center; font-size: 13px; min-height: 40px; }
.image-preview {
  display: block; max-width: 100%; margin: 8px auto 0; padding: 0; border: 0; background: transparent; cursor: zoom-in;
}
.image-preview img { display: block; max-height: 176px; max-width: 100%; object-fit: contain; border-radius: 6px; }
.form-error { color: var(--accent-deep); background: var(--accent-soft); padding: 8px 10px; border-radius: 7px; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.ocr-result { margin-top: 5px; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.dialog-actions .button { min-width: 88px; }
.confirmation { line-height: 1.6; overflow-wrap: anywhere; }
.code-display { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.code-display input { min-width: 0; font-family: ui-monospace, Consolas, monospace; color: var(--ink); font-weight: 700; letter-spacing: .04em; }
.share-preview { display: grid; place-items: center; min-height: 135px; margin-block: 14px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fcfaf8; }
.share-preview .image-preview { margin: 0; }
.share-preview img { max-height: 300px; object-fit: contain; }
#image-viewer { width: min(100% - 20px, 860px); }
#image-viewer[open] { display: flex; flex-direction: column; overflow: hidden; }
#image-viewer .dialog-header { align-items: center; }
#image-viewer .dialog-header h2 { font-size: 17px; }
.image-viewer-actions { display: flex; gap: 8px; }
.image-viewer-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; }
.image-viewer-scroll img { display: block; width: 100%; max-width: none; }
.image-viewer-scroll.zoomed img { width: 200%; }
.image-hint { line-height: 1.5; margin-bottom: 10px; font-size: 13px; }
.user-list { display: grid; gap: 8px; margin-top: 13px; }
.user-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; border: 1px solid var(--line); padding: 10px; gap: 5px 10px; border-radius: 9px; }
.user-row h3 { font-size: 15px; overflow-wrap: anywhere; }
.user-row p { margin-top: 3px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 4; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 30px); padding: 11px 16px; border-radius: 9px; background: #2f2421; color: white;
  font-size: 14px; box-shadow: 0 7px 18px #2617112c; text-align: center;
}

@media (max-width: 830px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .shell { width: calc(100% - 28px); }
  .topbar-inner { min-height: 64px; }
  .account-meta { display: none; }
  .brand-mark { width: 39px; height: 39px; }
  .brand strong { font-size: 18px; }
  .inventory { padding-block: 25px 45px; }
  .overview { margin-bottom: 17px; align-items: flex-start; }
  .overview h1 { font-size: 29px; }
  .overview p { font-size: 12px; line-height: 1.5; margin-top: 6px; }
  .add-button { font-size: 13px; padding-inline: 9px; }
  .stats { gap: 7px; }
  .stat { padding: 10px 8px; gap: 7px; }
  .stat span { font-size: 12px; }
  .stat strong { font-size: 25px; }
  .collection { margin-top: 21px; }
  .collection-title { margin-bottom: 4px; }
  .collection-title h2 { font-size: 20px; }
  .toolbar { display: grid; gap: 8px; }
  .duration-tabs button { padding-inline: 4px; }
  .filters input { width: 100%; min-width: 0; }
  .filters select { flex: none; }
  .cards { grid-template-columns: 1fr; gap: 10px; }
  .voucher-main { padding: 13px 14px; }
  .list-info { margin: 10px 0; }
  .dialog-header, .dialog-body { padding-inline: 14px; }
}
@media (max-width: 360px) {
  .field-grid { grid-template-columns: 1fr; }
  .duration-tabs span { margin-left: 1px; }
  .voucher-actions { padding-inline: 8px; gap: 4px; }
  .voucher-actions > .button { padding-inline: 3px; }
}
