:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --surface: #ffffff;
  --ink: #17211d;
  --muted: #69756f;
  --line: #d9dfdb;
  --green: #1f6f5b;
  --green-dark: #174f42;
  --green-soft: #e1f1eb;
  --red: #b8393b;
  --red-soft: #f8dfde;
  --amber: #a05f00;
  --amber-soft: #fff0d1;
  --blue: #316d9f;
  --blue-soft: #e3eef8;
  --gray-soft: #eef2ef;
  --shadow: 0 18px 50px rgba(23, 33, 29, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(31, 111, 91, 0.08), transparent 280px),
    var(--bg);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  touch-action: pan-x pan-y;
}

button,
input,
select,
textarea {
  font: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 16px 96px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 2px 18px;
}

.brand,
.subtle-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 7vw, 3rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.1rem;
}

.today-label {
  flex: 0 0 auto;
  color: var(--green-dark);
  font-size: 0.88rem;
  font-weight: 700;
  padding-bottom: 4px;
}

.topbar-meta {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.store-switch {
  min-height: 34px;
  border: 1px solid rgba(31, 111, 91, 0.35);
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 900;
}

.storage-mode {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  padding: 6px 10px;
  font-size: 0.76rem;
  font-weight: 900;
}

.storage-mode.server {
  border-color: rgba(31, 111, 91, 0.35);
  background: var(--green-soft);
  color: var(--green-dark);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 4px 10px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px 10px;
  box-shadow: 0 6px 20px rgba(23, 33, 29, 0.05);
}

.summary-tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  padding: 5px 8px 5px 20px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.summary-tile::before {
  position: absolute;
  top: 50%;
  left: 8px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--muted);
  content: "";
  transform: translateY(-50%);
}

.summary-tile strong {
  min-width: 3ch;
  font-size: 1rem;
  line-height: 1;
  text-align: right;
}

.summary-label {
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 800;
  white-space: nowrap;
}

.summary-tile.is-active {
  background: var(--green-soft);
}

.summary-tile.is-active::before {
  background: var(--green);
}

.summary-tile.danger strong {
  color: var(--red);
}

.summary-tile.warning strong,
.summary-tile.caution strong {
  color: var(--amber);
}

.summary-tile.calm strong {
  color: var(--blue);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.85fr) minmax(0, 1.15fr);
  gap: 18px;
  align-items: start;
}

.alert-panel,
.form-panel,
.list-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.alert-panel {
  margin-bottom: 18px;
  padding: 18px;
}

.alert-panel[hidden] {
  display: none;
}

.form-panel {
  padding: 18px;
  position: sticky;
  top: 12px;
}

.list-panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.list-heading {
  align-items: flex-start;
}

.alert-heading {
  margin-bottom: 12px;
}

.item-form,
.tool-row {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 12px 12px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 111, 91, 0.14);
}

.field-row,
.select-row,
.barcode-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.expiry-picker-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.expiry-picker-inline input {
  text-align: center;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.expiry-picker-button {
  min-height: 44px;
  padding: 0 12px;
  white-space: nowrap;
}

.quantity-stepper {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
}

.stepper-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 1.3rem;
  font-weight: 900;
  line-height: 1;
  padding: 0;
}

.stepper-button:active {
  transform: translateY(1px);
}

.quantity-stepper input {
  text-align: center;
  font-weight: 800;
}

.barcode-row {
  grid-template-columns: minmax(0, 1fr) 104px;
  align-items: end;
}

.scan-assist-row {
  display: none;
  gap: 8px;
}

.assist-button {
  width: 100%;
}

.assist-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

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

.primary-button,
.secondary-button,
.quiet-button,
.card-action {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-button {
  background: var(--green);
  color: #fff;
  box-shadow: 0 10px 22px rgba(31, 111, 91, 0.25);
}

.primary-button:hover {
  background: var(--green-dark);
}

.secondary-button,
.quiet-button,
.card-action {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.scan-button {
  width: 100%;
}

.quiet-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--muted);
}

.search-box {
  position: relative;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  color: var(--ink);
  font-size: 0.92rem;
}

.toggle-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}

.image-uploader {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.image-preview,
.item-thumb,
.alert-thumb {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--gray-soft);
}

.image-preview {
  display: grid;
  place-items: center;
  width: 96px;
  aspect-ratio: 1;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.image-preview img,
.item-thumb img,
.alert-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-actions {
  display: grid;
  gap: 8px;
}

.image-button {
  display: grid;
  place-items: center;
  color: var(--ink);
}

.image-button input {
  display: none;
}

.empty-state {
  display: none;
  gap: 6px;
  margin-top: 16px;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong,
.empty-state span {
  display: block;
}

.item-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

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

.alert-empty {
  margin-top: 0;
}

.alert-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 6px solid var(--amber);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.alert-thumb {
  width: 72px;
  aspect-ratio: 1;
}

.alert-card.today {
  border-left-color: var(--red);
}

.alert-card.fourteen {
  border-left-color: var(--blue);
}

.alert-card.discount {
  background: var(--amber-soft);
}

.alert-title {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.35;
}

.alert-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.alert-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.item-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--green);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.item-card.expired {
  border-left-color: var(--red);
}

.item-card.today,
.item-card.week {
  border-left-color: var(--amber);
}

.item-card.month {
  border-left-color: var(--blue);
}

.card-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.card-info {
  display: flex;
  min-width: 0;
  gap: 12px;
}

.item-thumb {
  flex: 0 0 78px;
  width: 78px;
  aspect-ratio: 1;
}

.item-thumb.empty {
  display: none;
}

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

.item-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.35;
}

.meta-line,
.note-line,
.price-line {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.days-badge {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  min-width: 72px;
  height: 58px;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-weight: 900;
}

.days-badge small {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.item-card.expired .days-badge {
  background: var(--red-soft);
  color: var(--red);
}

.item-card.today .days-badge,
.item-card.week .days-badge {
  background: var(--amber-soft);
  color: var(--amber);
}

.item-card.month .days-badge {
  background: var(--blue-soft);
  color: var(--blue);
}

.item-card.twoWeek .days-badge {
  background: var(--blue-soft);
  color: var(--blue);
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.card-statuses {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pill {
  border-radius: 999px;
  background: #eef2ef;
  color: var(--muted);
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 900;
}

.status-pill.expired {
  background: var(--red-soft);
  color: var(--red);
}

.status-pill.today,
.status-pill.week {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-pill.twoWeek,
.status-pill.month {
  background: var(--blue-soft);
  color: var(--blue);
}

.handling-pill {
  border-radius: 999px;
  background: var(--gray-soft);
  color: var(--ink);
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 900;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.card-action {
  min-height: 38px;
  padding: 0 11px;
  font-size: 0.82rem;
}

.card-action.delete {
  color: var(--red);
}

.card-action.discount {
  color: var(--amber);
}

.card-action.sold {
  color: var(--green-dark);
}

.card-action.discard {
  color: var(--red);
}

.footer-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(246, 247, 245, 0.94);
  backdrop-filter: blur(10px);
}

.footer-actions .secondary-button {
  width: min(190px, 45vw);
}

.file-button {
  display: grid;
  place-items: center;
  color: var(--ink);
}

.file-button input {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%) translateY(16px);
  min-width: min(320px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  border-radius: 8px;
  background: #17211d;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  padding: 12px 14px;
  text-align: center;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.scanner-modal,
.action-modal,
.store-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(23, 33, 29, 0.72);
}

.scanner-modal[hidden],
.action-modal[hidden],
.store-modal[hidden] {
  display: none;
}

.scanner-panel,
.action-panel,
.store-panel {
  width: min(520px, 100%);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: var(--shadow);
}

.store-modal {
  z-index: 30;
}

.expiry-picker-modal {
  padding: 12px;
}

.store-panel {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.store-panel h2 {
  font-size: 1.6rem;
}

.store-lead {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.store-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.store-option {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 900;
}

.store-option:hover,
.store-option.is-active {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green-dark);
}

.expiry-picker-panel {
  display: grid;
  gap: 12px;
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100svh - 24px);
  overflow: auto;
  padding: 14px;
}

.expiry-picker-panel .panel-heading {
  align-items: center;
}

.expiry-wheel-grid {
  display: grid;
  grid-template-columns: minmax(92px, 1.15fr) minmax(72px, 0.9fr) minmax(72px, 0.9fr);
  gap: 8px;
}

.expiry-wheel-col {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.expiry-wheel-col > span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

.expiry-wheel-select {
  height: 176px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  padding: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.expiry-wheel-select option {
  padding: 7px 2px;
}

.expiry-picker-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 12px;
  gap: 8px;
}

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

.discount-item {
  border: 1px solid var(--line);
  border-left: 6px solid var(--amber);
  border-radius: 8px;
  background: var(--amber-soft);
  padding: 12px;
}

.discount-item strong,
.discount-item span {
  display: block;
}

.discount-item span {
  color: var(--muted);
  font-size: 0.86rem;
  margin-top: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.confirm-panel {
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
}

.confirm-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.video-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background: #101613;
}

.video-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ocr-frame {
  background: #0c1310;
}

.ocr-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ocr-guide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.ocr-guide-box {
  width: min(94%, 520px);
  height: min(76%, 340px);
  border: 3px solid rgba(255, 255, 255, 0.96);
  border-radius: 8px;
  box-shadow:
    0 0 0 999px rgba(0, 0, 0, 0.2) inset,
    0 0 20px rgba(255, 255, 255, 0.35);
}

.ocr-guide-text {
  margin: 10px 0 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

.scan-line {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 3px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.92);
}

.scanner-message {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.ocr-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.ocr-actions .primary-button,
.ocr-actions .secondary-button {
  min-height: 42px;
}

@supports (-webkit-touch-callout: none) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .topbar-meta {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

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

  .summary-tile {
    min-height: 34px;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .field-row,
  .select-row,
  .barcode-row,
  .ocr-actions {
    grid-template-columns: 1fr;
  }

  .expiry-picker-inline {
    grid-template-columns: 1fr;
  }

  .expiry-picker-button {
    width: 100%;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .form-panel,
  .list-panel {
    padding: 14px;
  }

  .card-main,
  .card-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .days-badge {
    width: 100%;
    height: 48px;
  }

  .card-actions {
    justify-content: stretch;
  }

  .card-action {
    flex: 1 1 96px;
  }

  .image-uploader {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .image-preview {
    width: 82px;
  }

  .card-info {
    align-items: flex-start;
  }

  .alert-card {
    grid-template-columns: 64px 1fr;
  }

  .alert-actions {
    justify-content: stretch;
    grid-column: 1 / -1;
  }

  .store-options {
    grid-template-columns: 1fr;
  }

  .expiry-picker-modal {
    align-items: end;
  }

  .expiry-picker-panel {
    width: min(390px, calc(100vw - 20px));
    max-height: calc(100svh - 20px);
  }

  .expiry-wheel-grid {
    grid-template-columns: minmax(86px, 1.1fr) minmax(64px, 0.9fr) minmax(64px, 0.9fr);
    gap: 6px;
  }

  .expiry-wheel-select {
    height: 156px;
  }
}
