/* 便当账本 — 移动优先样式 */

:root {
  color-scheme: light dark;
  --bg: #f6f1e8;
  --surface: #fffdf9;
  --surface-2: #f2ebdf;
  --ink: #2d2a25;
  --muted: #7b7368;
  --line: #e5dccd;
  --accent: #c0573b;
  --accent-strong: #a8442c;
  --accent-soft: #f6e0d7;
  --green: #4e7a52;
  --danger: #b23a2c;
  --danger-soft: #f9e1dd;
  --warn: #a26a1a;
  --warn-soft: #f8ebcf;
  --ok: #3f7a4f;
  --shadow: 0 1px 2px rgba(45, 42, 37, 0.05), 0 8px 24px rgba(45, 42, 37, 0.06);
  --radius: 18px;
  --tabbar-height: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181613;
    --surface: #23201c;
    --surface-2: #2c2823;
    --ink: #f1eae0;
    --muted: #a79d90;
    --line: #3a342c;
    --accent: #e28062;
    --accent-strong: #f09578;
    --accent-soft: #3a2620;
    --green: #8fb98f;
    --danger: #f08a7c;
    --danger-soft: #3a2421;
    --warn: #e2b15f;
    --warn-soft: #3a2f1d;
    --ok: #8fc49a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 18px);
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.sheet-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:not(:disabled) {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 800;
}

h2 {
  font-size: 17px;
  line-height: 1.35;
  font-weight: 700;
}

.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: block;
}

.net-status {
  flex-shrink: 0;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.net-status.is-offline {
  color: var(--warn);
  border-color: var(--warn-soft);
  background: var(--warn-soft);
}

.view {
  padding: 6px 0 24px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 16px;
}

.page-head-text {
  min-width: 0;
}

.sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.page-actions {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  padding-bottom: 2px;
}

/* 按钮 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  transition: transform 0.1s ease, background 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.btn-primary:active:not(:disabled) {
  background: var(--accent-strong);
}

.btn-danger {
  border-color: transparent;
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
}

.btn-sm {
  min-height: 34px;
  padding: 0 11px;
  border-radius: 10px;
  font-size: 12.5px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.icon-btn:active:not(:disabled) {
  background: var(--surface-2);
}

.link-btn {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.danger-text {
  color: var(--danger) !important;
}

.muted {
  color: var(--muted);
}

.hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.ok-text {
  color: var(--ok);
  font-size: 13px;
}

/* 卡片与通用 */

.card {
  margin-bottom: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head h2 {
  font-size: 16px;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface-2);
}

.kv-grid > div {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.kv-grid span {
  color: var(--muted);
  font-size: 10.5px;
}

.kv-grid strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.btn-row .btn {
  flex: 1 1 140px;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border: 1px solid color-mix(in srgb, var(--warn) 28%, var(--line));
  border-radius: 14px;
  background: var(--warn-soft);
  color: var(--warn);
}

.banner-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.banner-text strong {
  font-size: 12.5px;
}

.banner-text span {
  font-size: 11px;
  opacity: 0.85;
}

.banner .btn {
  flex-shrink: 0;
  background: transparent;
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
  color: var(--warn);
}

.notice {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
}

.notice-warn {
  border: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
  background: var(--warn-soft);
  color: var(--warn);
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.5;
  vertical-align: 1px;
  white-space: nowrap;
}

.chip-muted {
  background: transparent;
  border: 1px solid var(--line);
}

.chip-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

/* 便当卡 */

.type-card {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
}

.type-card:active {
  transform: scale(0.994);
}

.type-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px 12px;
}

.type-card-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.type-name {
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.type-meta {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 11.5px;
}

.type-count {
  display: flex;
  align-items: baseline;
  gap: 3px;
  flex-shrink: 0;
  color: var(--accent);
}

.type-count strong {
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}

.type-count span {
  color: var(--muted);
  font-size: 11px;
}

.type-card-bottom {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 12px;
}

.type-card-bottom span:nth-child(2) {
  margin-left: auto;
}

.chev {
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

/* 食材卡 */

.ingredient-card {
  display: block;
  width: 100%;
  margin: 0 0 10px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
}

.ingredient-card:active {
  transform: scale(0.994);
}

.ingredient-card.is-archived {
  opacity: 0.62;
}

.ingredient-card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.ingredient-name {
  font-size: 15.5px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.ingredient-card-mid {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 3px;
}

.ingredient-stock {
  font-size: 22px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.ingredient-stock.is-negative {
  color: var(--danger);
}

.ingredient-card-bottom {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

.is-positive {
  color: var(--green);
}

.is-negative {
  color: var(--danger);
}

/* 空态 */

.empty {
  margin-top: 8px;
  padding: 42px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.empty-emoji {
  font-size: 42px;
  line-height: 1;
  margin-bottom: 10px;
}

.empty h2 {
  font-size: 17px;
}

.empty p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

/* 统计 */

.stats-toolbar {
  margin-bottom: 14px;
}

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
}

.segmented button {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(45, 42, 37, 0.12);
}

.period-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
}

.period-label {
  flex: 1;
  min-height: 40px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 650;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
}

.stat-card:nth-child(5) {
  grid-column: span 2;
}

.stat-label {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 21px;
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat-sub {
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.35;
}

.stats-section {
  margin-bottom: 18px;
}

.section-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 750;
}

.section-note {
  margin-left: 4px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 12.5px;
}

th,
td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
}

thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
}

thead th:first-child {
  background: var(--surface-2);
}

tbody tr:last-child td {
  border-bottom: 0;
}

table.table-compact {
  min-width: 0;
}

table.table-compact th,
table.table-compact td {
  padding: 8px 6px;
  font-size: 11.5px;
}

.table-hint {
  margin-top: 5px;
}

@media (min-width: 720px) {
  .table-hint {
    display: none;
  }
}

.recon-card {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.recon-row {
  padding: 8px 0;
}

.recon-row + .recon-row {
  border-top: 1px dashed var(--line);
}

.recon-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
}

.recon-eq {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.recon-diff {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 650;
  background: var(--surface-2);
}

.recon-diff.ok {
  color: var(--ok);
}

.recon-diff.bad {
  color: var(--danger);
  background: var(--danger-soft);
}

.record-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.record-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
}

.record-row + .record-row {
  border-top: 1px solid var(--line);
}

.record-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 1px;
}

.record-main strong {
  font-size: 12.5px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-main span {
  color: var(--muted);
  font-size: 10.5px;
}

/* 表单 */

.form {
  display: block;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field > span:first-child,
.field > label,
.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.3;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

select.input {
  padding-right: 8px;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-with-action {
  display: flex;
  gap: 8px;
}

.input-with-action .input {
  flex: 1;
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 16px 0 8px;
}

.make-row {
  margin-bottom: 9px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.make-row-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.make-row-top select {
  flex: 1;
  min-width: 0;
}

.make-row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
  gap: 8px;
  margin-top: 8px;
}

.mini-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.mini-field > span {
  color: var(--muted);
  font-size: 10.5px;
}

.mini-field .input {
  min-height: 40px;
  padding: 7px 9px;
  font-size: 15px;
}

.mini-field strong {
  display: flex;
  align-items: center;
  min-height: 40px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stock-hint {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10.5px;
}

.stock-hint.is-warn {
  color: var(--danger);
  font-weight: 650;
}

.totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--accent-soft);
}

.total-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-align: center;
}

.total-item span {
  color: var(--muted);
  font-size: 10.5px;
}

.total-item strong {
  color: var(--accent-strong);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

/* 抽屉 */

#sheet-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 17, 14, 0.46);
  pointer-events: auto;
  animation: fade-in 0.18s ease;
}

.sheet {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  max-height: 92dvh;
  margin: 0 auto;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  box-shadow: 0 -10px 50px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
  outline: none;
  animation: sheet-up 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  padding: 17px 18px 11px;
  border-bottom: 1px solid var(--line);
}

.sheet-head h2 {
  font-size: 19px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.sheet-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  padding: 14px 18px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sheet-foot {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
  padding: 11px 18px calc(11px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.sheet-foot .btn {
  flex: 1;
}

.type-sheet-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}

.big-count {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.big-count strong {
  font-size: 34px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.big-count span {
  color: var(--muted);
  font-size: 11px;
}

.batch-list {
  margin-bottom: 12px;
  border-top: 1px solid var(--line);
}

.batch-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
}

.batch-line-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px 8px;
  min-width: 0;
}

.batch-line-main strong {
  flex-basis: 100%;
  font-size: 13px;
  font-weight: 700;
}

.batch-line-main span {
  color: var(--muted);
  font-size: 11px;
}

.batch-line .btn {
  flex-shrink: 0;
}

.sheet-controls {
  margin-top: 4px;
}

.stepper {
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
}

.stepper .icon-btn {
  width: 42px;
  min-width: 42px;
  height: 44px;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
}

.stepper .input {
  width: 56px;
  min-width: 0;
  min-height: 42px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-size: 16px;
}

.stepper .input:focus {
  box-shadow: none;
}

.alloc-preview {
  min-height: 38px;
  margin: 2px 0 12px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
}

.alloc-preview:empty::before {
  content: "选择数量后显示分摊";
}

.alloc-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
}

.alloc-line strong {
  color: var(--ink);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ingredient-detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.ingredient-detail-head .big-count strong {
  font-size: 29px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0 18px;
}

.history-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  background: var(--surface);
}

.history-row + .history-row {
  border-top: 1px solid var(--line);
}

.history-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 1px;
}

.history-main strong {
  font-size: 12px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-main span {
  color: var(--muted);
  font-size: 10.5px;
}

.history-amount {
  min-width: 64px;
  font-size: 12.5px;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.lock-note {
  color: var(--muted);
  font-size: 9.5px;
  white-space: nowrap;
}

.stocktake-book {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.stocktake-book strong {
  color: var(--ink);
  font-size: 17px;
}

.stocktake-diff {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.stocktake-diff.is-positive {
  color: var(--green);
}

.stocktake-diff.is-negative {
  color: var(--danger);
}

.stocktake-list {
  overflow: hidden;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 13px;
}

.stocktake-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 56px;
  align-items: center;
  gap: 7px;
  padding: 9px 10px;
  background: var(--surface);
}

.stocktake-row + .stocktake-row {
  border-top: 1px solid var(--line);
}

.stocktake-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.stocktake-name strong {
  font-size: 12px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stocktake-name span {
  color: var(--muted);
  font-size: 10px;
}

.stocktake-row .input {
  min-height: 38px;
  padding: 6px 8px;
  font-size: 14px;
  text-align: right;
}

.stocktake-row .stocktake-diff {
  margin: 0;
  text-align: right;
  white-space: nowrap;
}

/* 设置 */

.manage-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
}

.manage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  background: var(--surface);
}

.manage-row + .manage-row {
  border-top: 1px solid var(--line);
}

.manage-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 1px;
}

.manage-main strong {
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manage-main span {
  color: var(--muted);
  font-size: 10.5px;
}

.manage-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 1px;
}

.rules-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}

.rules-list li + li {
  margin-top: 3px;
}

.danger-zone {
  border-color: var(--line);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--line));
}

.version-line {
  margin: 22px 0 4px;
  color: var(--muted);
  font-size: 10.5px;
  text-align: center;
}

/* 对话框 */

#dialog-root {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: none;
}

.dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 17, 14, 0.52);
  pointer-events: auto;
}

.dialog {
  position: relative;
  width: min(420px, 100%);
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 19px;
  border-radius: 19px;
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
}

.dialog h2 {
  margin-bottom: 8px;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.dialog p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.dialog p + p {
  margin-top: 7px;
}

.dialog-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}

.dialog .kv-grid {
  grid-template-columns: repeat(2, 1fr);
}

.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 17px;
}

.dialog-actions .btn {
  flex: 1;
}

/* Toast */

#toast-root {
  position: fixed;
  right: 0;
  bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 14px);
  left: 0;
  z-index: 80;
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 520px;
  padding: 11px 14px;
  border-radius: 13px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  font-size: 13px;
  pointer-events: auto;
  animation: toast-in 0.18s ease;
}

.toast-text {
  min-width: 0;
}

.toast-action {
  flex-shrink: 0;
  min-height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
  font-weight: 750;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 浮动按钮与底栏 */

.fab {
  position: fixed;
  right: max(16px, calc((100vw - 720px) / 2 + 16px));
  bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 14px);
  z-index: 41;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 38%, transparent);
  font-size: 29px;
  font-weight: 300;
  line-height: 1;
  transition: transform 0.12s ease;
}

.fab:active {
  transform: scale(0.94);
}

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: flex;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 5px 0 calc(5px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.tab-btn {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 50px;
  padding: 4px 2px 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
}

.tab-btn svg {
  width: 22px;
  height: 22px;
}

.tab-btn.active {
  color: var(--accent);
}

.tab-btn.active svg {
  stroke-width: 2;
}

/* 动画 */

@keyframes sheet-up {
  from {
    transform: translateY(28px);
    opacity: 0.55;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (min-width: 600px) {
  .summary-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .stat-card:nth-child(5) {
    grid-column: auto;
  }

  .stat-value {
    font-size: 19px;
  }
}

@media (min-width: 720px) {
  .app {
    padding: 0 24px;
  }

  .tabbar {
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
    border-radius: 0 0 16px 16px;
  }

  .sheet {
    bottom: 24px;
    border-radius: 22px;
  }

  .sheet-foot {
    border-radius: 0 0 22px 22px;
  }

  #toast-root {
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 24px);
  }
}

@media (max-width: 380px) {
  h1 {
    font-size: 23px;
  }

  .page-head {
    gap: 8px;
  }

  .page-actions {
    gap: 4px;
  }

  .btn-sm {
    padding: 0 8px;
  }
}

@media (max-width: 360px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .type-count strong {
    font-size: 26px;
  }

  .stocktake-row {
    grid-template-columns: minmax(0, 1fr) 76px 50px;
    gap: 5px;
  }
}

.noscript {
  padding: 24px;
  color: var(--danger);
  text-align: center;
}

/* v2: auth, members, cloud status */

.auth-mode {
  padding-bottom: 24px;
}

.auth-wrap {
  display: flex;
  justify-content: center;
  padding: 20px 0 40px;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  padding: 22px 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.app-tagline {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.auth-card h1 {
  margin-top: 20px;
  font-size: 23px;
}

.auth-card .sub {
  margin: 4px 0 16px;
}

.auth-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.auth-actions .btn {
  flex: 1;
}

.auth-lang {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.auth-error {
  margin-top: 12px;
  padding: 9px 11px;
  border-radius: 11px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

.code-input {
  text-align: center;
  font-size: 20px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.code-box {
  margin: 14px 0;
  padding: 16px 12px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.member-chip {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.status-dot.is-online {
  background: var(--green);
}

.status-dot.is-offline {
  background: var(--warn);
}

.lang-select {
  width: auto;
  min-height: 38px;
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 10px;
}

.banner-offline {
  color: var(--warn);
}

.member-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
}

.member-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 11px;
  background: var(--surface);
}

.member-row + .member-row {
  border-top: 1px solid var(--line);
}

.member-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
  flex: 1;
}

.member-main > strong {
  font-size: 13px;
  font-weight: 700;
}

.member-main > span {
  color: var(--muted);
  font-size: 10.5px;
}

.device-list {
  margin-top: 5px;
  padding: 5px 7px;
  border-radius: 9px;
  background: var(--surface-2);
}

.device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.5;
}

.device-row + .device-row {
  border-top: 1px dashed var(--line);
  margin-top: 3px;
  padding-top: 3px;
}

.device-row .link-btn {
  min-height: 24px;
  font-size: 10.5px;
}

.member-row .manage-actions {
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.member-row .manage-actions .btn {
  min-height: 30px;
  padding: 0 7px;
  font-size: 11px;
}

@media (max-width: 420px) {
  .auth-card {
    padding: 18px 16px;
    border-radius: 18px;
  }

  .member-row {
    flex-direction: column;
  }

  .member-row .manage-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
  }
}

/* v2.1: management switch, sorting, filters */

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 10.5px;
  font-weight: 650;
  cursor: pointer;
}

.mode-toggle-label {
  white-space: nowrap;
}

.mode-toggle-track {
  position: relative;
  width: 30px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.16s ease;
}

.mode-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.16s ease;
}

.mode-toggle.is-on {
  color: var(--accent);
}

.mode-toggle.is-on .mode-toggle-track {
  background: var(--accent);
}

.mode-toggle.is-on .mode-toggle-thumb {
  transform: translateX(12px);
}

.mode-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 8px;
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.toolbar-field {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  min-width: 132px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
}

.toolbar-field .input,
.sort-select {
  min-height: 36px;
  padding: 5px 9px;
  font-size: 12px;
  border-radius: 10px;
}

.stocktake-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.stocktake-toolbar .field {
  flex: 1;
  margin: 0;
}

.stocktake-toolbar .toolbar-field {
  flex: 1;
}

@media (max-width: 360px) {
  .mode-toggle-label {
    display: none;
  }

  .member-chip {
    max-width: 82px;
  }
}

.dialog .field {
  margin: 12px 0 4px;
  text-align: left;
}
