
:root {
  --bg: #ffffff;
  --card: #fffefb;
  --line: #e2d9cc;
  --text: #2d2420;
  --muted: #70645c;
  --green: #2f7d55;
  --green-soft: #eaf5ee;
  --red: #c0392b;
  --red-soft: #fdf0ee;
  --amber: #a96500;
  --amber-soft: #fff8e8;
  --blue: #2563a8;
  --blue-soft: #eef6ff;
  --blue-line: #9bc7f3;
  --pending: #6f6258;
  --pending-soft: #f4f1ed;
  --pending-line: #c8beb4;
  --shadow: 0 1px 5px rgba(0, 0, 0, .08);
}

*,
*::before,
*::after { box-sizing: border-box; }
html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  touch-action: manipulation;
}
body {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 16px;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
input { min-width: 0; }

.app-shell {
  width: 100%;
  max-width: min(430px, 100vw);
  margin: 0 auto;
  padding: 14px 12px 32px;
  overflow-x: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 22px;
  font-weight: 800;
}

.message {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  background: #f7f4ef;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.message.error {
  color: var(--red);
  border-color: #efb4ad;
  background: var(--red-soft);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  margin-bottom: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.stat-card {
  --stat-color: var(--green);
  --stat-bg: var(--green-soft);
  --stat-border: #afd7bf;
  --stat-active-bg: #dff0e6;
  min-width: 0;
  min-height: 82px;
  border: 1.5px solid var(--stat-border);
  border-radius: 8px;
  background: var(--stat-bg);
  box-shadow: var(--shadow);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 2px 6px;
  touch-action: manipulation;
}

.stat-card.stat-all {
  --stat-color: var(--blue);
  --stat-bg: var(--blue-soft);
  --stat-border: var(--blue-line);
  --stat-active-bg: #dceeff;
}

.stat-card.stat-out {
  --stat-color: var(--red);
  --stat-bg: var(--red-soft);
  --stat-border: #efb4ad;
  --stat-active-bg: #f9ddd9;
}

.stat-card.stat-low {
  --stat-color: var(--amber);
  --stat-bg: var(--amber-soft);
  --stat-border: #e7c66c;
  --stat-active-bg: #fff0c5;
}

.stat-card.stat-pending {
  --stat-color: var(--pending);
  --stat-bg: var(--pending-soft);
  --stat-border: var(--pending-line);
  --stat-active-bg: #e7e0d8;
}

.stat-card.stat-cart {
  --stat-color: var(--green);
  --stat-bg: var(--green-soft);
  --stat-border: #a8d5b8;
  --stat-active-bg: #d9efdf;
}

.stat-card.active {
  border-width: 2.5px;
  border-color: var(--stat-color);
  background: var(--stat-active-bg);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .12);
}

.material-symbols-rounded {
  font-family: 'Material Symbols Rounded', sans-serif;
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  display: inline-block;
}

.stat-icon {
  width: 100%;
  height: 24px;
  max-width: 100%;
  color: var(--stat-color);
  overflow: hidden;
  text-align: center;
  white-space: nowrap;
}

.stat-value {
  color: var(--stat-color);
  font-size: 22px;
  line-height: 1;
  font-weight: 800;
}

.stat-label {
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.view-tabs {
  display: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-bottom: 12px;
}

.view-tab {
  min-width: 0;
  min-height: 46px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-weight: 800;
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 6px;
  white-space: nowrap;
}

.view-tab.active {
  border-width: 3px;
  border-color: var(--green);
  background: var(--green-soft);
}

.cart-count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  flex: 0 0 auto;
}

.search-box {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search-box input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 48px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  padding: 0 16px;
  box-shadow: var(--shadow);
  -webkit-appearance: none;
  appearance: none;
}

.search-box input:focus {
  outline: none;
  border-color: var(--green);
}

.supplier-filter select {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  box-shadow: var(--shadow);
}

.supplier-filter select:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.qr-search-actions {
  display: grid;
  margin: -4px 0 12px;
}

.qr-search-button,
.qr-stop-button {
  background: var(--green);
}

.qr-reader {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.qr-reader[hidden] {
  display: none;
}

.qr-video {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  background: #111;
  object-fit: cover;
  box-shadow: var(--shadow);
}

.qr-reader-actions {
  display: grid;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.item-card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.item-card.out {
  border-left: 5px solid var(--red);
  background: var(--red-soft);
}

.item-card.low {
  border-left: 5px solid var(--amber);
  background: var(--amber-soft);
}

.item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
  min-width: 0;
}

.item-name {
  min-width: 0;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  background: var(--green-soft);
  color: var(--green);
}

.badge.out { background: var(--red-soft); color: var(--red); }
.badge.low { background: var(--amber-soft); color: var(--amber); }

.item-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 10px;
  overflow-wrap: anywhere;
}

.stock-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.stock-box {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .7);
  padding: 7px 4px;
  text-align: center;
}

.stock-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 3px;
}

.stock-value {
  font-size: 22px;
  line-height: 1;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.action-button {
  min-width: 0;
  height: 44px;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 800;
}

.use-button { background: var(--green); }
.add-button { background: #e07b2a; }
.action-button:disabled { opacity: .45; }

.order-row,
.cart-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(118px, .9fr);
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-top: 8px;
}

.quantity-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.quantity-field input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 44px;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  padding: 0 10px;
  -webkit-appearance: none;
  appearance: none;
}

.cart-button {
  align-self: end;
  background: #315f86;
}

.cart-panel,
.cart-list {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.cart-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.cart-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f4ef;
  color: var(--muted);
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 800;
}

.cart-summary strong {
  color: var(--text);
  font-size: 16px;
}

.supplier-section {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #f7f4ef;
  padding: 10px;
}

.supplier-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.supplier-heading h2 {
  min-width: 0;
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.supplier-heading span {
  flex: 0 1 auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 800;
  text-align: right;
}

.copy-button {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: auto;
  min-height: 44px;
  margin: 0 0 9px;
  padding: 9px 10px;
  background: #315f86;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  overflow-wrap: anywhere;
}

.confirm-order-button {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: auto;
  min-height: 44px;
  margin: 0 0 9px;
  padding: 9px 10px;
  background: #6f5b27;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  overflow-wrap: anywhere;
}

.copy-button.copied {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 125, 85, .18);
}

.copy-button.confirm-ready {
  background: #6f5b27;
}

.supplier-cart-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cart-card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.cart-head {
  min-width: 0;
  margin-bottom: 8px;
}

.cart-update-button { background: var(--green); }
.delete-button { background: var(--red); }
.cart-actions {
  grid-template-columns: minmax(0, 1fr) minmax(68px, .55fr) minmax(68px, .55fr);
  align-items: end;
}

.pending-fields {
  display: grid;
  grid-template-columns: minmax(48px, .5fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  align-items: end;
}

.pending-quantity-box {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .7);
  padding: 5px 3px;
  text-align: center;
}

.pending-quantity-box span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 4px;
}

.pending-quantity-box strong {
  display: block;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  overflow-wrap: anywhere;
}

.pending-date-field {
  gap: 3px;
}

.pending-date-field input {
  height: 40px;
  padding: 0 3px;
  font-size: 12px;
}

.pending-actions {
  display: grid;
  grid-template-columns: 1.5fr 0.8fr;
  gap: 8px;
  width: 100%;
  margin-top: 12px;
}

.pending-actions .action-button {
  height: auto;
  min-height: 44px;
  padding: 6px 4px;
  line-height: 1.2;
  white-space: normal;
  word-break: break-word;
}

.pending-receive-sub {
  display: block;
  font-size: 12px;
  font-weight: 700;
}

.pending-receive-button { background: var(--green); }
.pending-cancel-button { background: var(--red); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 44px 8px;
}

@media (max-width: 360px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .stock-value { font-size: 19px; }
  .order-row { grid-template-columns: 1fr; }
  .cart-actions { grid-template-columns: 1fr 1fr; }
  .cart-actions .quantity-field { grid-column: 1 / -1; }
  .pending-fields { grid-template-columns: .62fr 1fr 1fr; gap: 5px; }
  .pending-date-field input { font-size: 12px; padding: 0 3px; }
  .supplier-heading { flex-direction: column; }
  .supplier-heading span { text-align: left; }
}
