:root {
  --brand: #f08a24;
  --brand-dark: #9b4b00;
  --ink: #171717;
  --muted: #6f665e;
  --line: #e8ded2;
  --paper: #fffdf9;
  --wash: #fff8ef;
  --green: #178a56;
  --green-soft: #e9f8f0;
  --amber: #b45309;
  --amber-soft: #fff1d6;
  --red: #b42318;
  --red-soft: #ffe5e0;
  --blue: #2563eb;
  --shadow: 0 14px 34px rgba(30, 24, 18, 0.08);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

html,
body {
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

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

body {
  min-width: 0;
  background: var(--wash);
  color: var(--ink);
}

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

button {
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

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

.app-shell {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 calc(82px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  background: rgba(255, 248, 239, 0.94);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(232, 222, 210, 0.8);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-logo {
  width: 102px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--brand);
  object-fit: contain;
  object-position: center;
  border: 1px solid rgba(23, 23, 23, 0.12);
}

.brand-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand-subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.date-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.date-input {
  max-width: 136px;
  color: var(--ink);
  font-weight: 700;
}

.app-main,
.page,
.page-inner {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  padding: 0 16px;
}

.page-inner > :first-child {
  margin-top: 16px;
}

.app-main > *,
.page-inner > *,
.page-content > * {
  max-width: 100%;
}

.section {
  margin-top: 20px;
}

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

.section-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.section-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 12px;
}

.summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat {
  min-height: 106px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.stat strong {
  display: block;
  font-size: 30px;
  line-height: 1;
}

.stat span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.action-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.action-grid-one,
.action-grid.one {
  grid-template-columns: minmax(0, 1fr);
}

.action-grid-two,
.action-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.action-grid-three,
.action-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.btn {
  width: 100%;
  min-height: 64px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  text-decoration: none;
}

.btn-full {
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1;
}

.btn.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #1b1007;
}

.btn.danger {
  border-color: #ffc5bc;
  background: var(--red-soft);
  color: var(--red);
}

.btn.ghost {
  background: transparent;
}

.icon-btn,
.stepper-btn {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.icon-btn svg,
.stepper-btn svg {
  width: 19px;
  height: 19px;
  display: block;
}

.edit-btn {
  width: 42px;
  height: 42px;
  align-self: center;
  justify-self: end;
  color: var(--muted);
  padding: 0;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  inset-inline: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.96);
  backdrop-filter: blur(16px);
}

.nav-link {
  display: grid;
  min-height: 54px;
  place-items: center;
  gap: 3px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

.nav-link svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.4;
}

.nav-link.active {
  background: #151515;
  color: #fff8ef;
}

.card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.list {
  display: grid;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.item-main {
  min-width: 0;
}

.item-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 15px;
}

.item-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  background: var(--green-soft);
  color: var(--green);
}

.badge.low {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.critical {
  background: var(--red-soft);
  color: var(--red);
}

.badge.neutral {
  background: #eef2f7;
  color: #475467;
}

.category-tabs {
  position: sticky;
  top: 66px;
  z-index: 15;
  display: flex;
  gap: 8px;
  margin: 0 0 12px;
  padding: 10px 0;
  overflow-x: auto;
  background: rgba(255, 248, 239, 0.94);
  border-bottom: 1px solid rgba(232, 222, 210, 0.7);
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.inventory-row {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.inventory-controls {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  gap: 12px;
  align-items: center;
}

.inventory-controls .stepper-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 10px;
  font-size: 26px;
}

.qty-input {
  min-width: 0;
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

.field,
.select {
  width: 100%;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-size: 15px;
  line-height: 1;
}

.textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.textarea {
  min-height: 76px;
  padding-top: 10px;
  resize: vertical;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.reorder-actions {
  margin-top: 12px;
}

.stock-in-form {
  gap: 12px;
}

.stock-in-form .form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stock-in-form .field,
.stock-in-form .select {
  height: 54px;
  font-size: 16px;
  font-weight: 700;
}

.toolbar-card {
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 12px;
  overflow: hidden;
}

.search-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.search-row .field,
.search-row .btn {
  height: 64px;
}

.inventory-card,
.stock-card,
.check-card,
.item-card,
.product-tools,
.search-panel,
.filter-panel {
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.field-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.fixed-actions {
  position: sticky;
  bottom: 82px;
  z-index: 14;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px -4px 0;
  padding: 10px 4px;
  background: rgba(255, 248, 239, 0.94);
  backdrop-filter: blur(14px);
}

.empty {
  padding: 24px 14px;
  border: 1px dashed #d8cabc;
  border-radius: 8px;
  background: rgba(255, 253, 249, 0.65);
  color: var(--muted);
  text-align: center;
}

.copy-box {
  width: 100%;
  min-height: 230px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151515;
  color: #fff8ef;
  line-height: 1.55;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #151515;
  color: #fff8ef;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.2);
  font-weight: 800;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  align-items: center;
  justify-items: center;
  min-width: 0;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.32);
  overflow: auto;
  overscroll-behavior: contain;
}

.dialog {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
  padding: 16px;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

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

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
}

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

.divider {
  height: 1px;
  margin: 14px 0;
  background: var(--line);
}

@media (min-width: 760px) {
  .app-shell {
    padding-bottom: 24px;
  }

  .page,
  .page-inner {
    max-width: 920px;
  }

  .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .bottom-nav {
    right: auto;
    top: 96px;
    bottom: auto;
    inset-inline: auto;
    inset-inline-start: 20px;
    width: 86px;
    grid-template-columns: 1fr;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    box-shadow: var(--shadow);
  }

  .page,
  .page-inner {
    padding: 0 22px;
  }

  .fixed-actions {
    bottom: 0;
  }

  .category-tabs {
    top: 67px;
    border: 1px solid rgba(232, 222, 210, 0.7);
    border-radius: 8px;
    margin: 0 0 12px;
  }

  .dialog {
    max-width: 640px;
  }
}
