:root {
  color-scheme: light;
  --bg: #f3f1ee;
  --surface: #ffffff;
  --text: #151515;
  --muted: #6c6660;
  --border: #d7d1ca;
  --accent: #4a2418;
  --accent-strong: #2d140d;
  --danger: #b42318;
  --success: #15803d;
  --black: #161616;
  --grey-soft: #ebe7e2;
  --shadow: 0 12px 28px rgba(35, 24, 18, 0.1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
}

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

.brand-block img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex: 0 0 auto;
}

.review-toggle {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--accent);
  font-weight: 900;
  cursor: pointer;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.topbar p {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 14px;
}

.topbar .icon-button {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.panel,
.list-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.add-panel {
  padding: 14px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
}

input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(74, 36, 24, 0.16);
}

select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(74, 36, 24, 0.16);
}

.scan-button,
.primary-button,
.icon-button,
.small-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.scan-button,
.primary-button {
  min-height: 44px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-button {
  width: 100%;
}

.scan-button:hover,
.primary-button:hover {
  background: var(--accent-strong);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--grey-soft);
  color: var(--text);
  font-size: 22px;
}

.results {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 320px;
  overflow-y: auto;
}

.product-option,
.expiry-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.product-option {
  text-align: left;
  cursor: pointer;
}

.load-more-button {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--grey-soft);
  color: var(--accent);
  font-weight: 900;
  cursor: pointer;
}

.product-option strong,
.expiry-card strong {
  display: block;
  font-size: 15px;
  line-height: 1.35;
}

.risk-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #efe3da;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.promo-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 6px;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

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

.expiry-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(170px, 0.45fr);
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

.existing-terms {
  margin-top: 10px;
}

.terms-hint {
  color: var(--muted);
  font-size: 13px;
}

.terms-hint.strong {
  color: var(--text);
  font-weight: 800;
}

.existing-term-list {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-top: 6px;
}

.existing-term {
  flex: 0 0 auto;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: #efe3da;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.selected-product {
  min-height: 44px;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
  margin-top: 12px;
}

.selected-product.ready {
  color: var(--text);
  border-color: rgba(74, 36, 24, 0.45);
  background: rgba(74, 36, 24, 0.06);
}

.selected-product.ready b {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #efe3da;
  color: var(--accent);
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 0;
}

.list-controls {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tab {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 9px 12px;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.list-panel {
  display: grid;
  gap: 8px;
  padding: 8px;
}

.expiry-block {
  display: grid;
  gap: 4px;
  border-radius: 8px;
  padding: 6px;
  border: 1px solid var(--border);
}

.block-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 2px 0;
  color: var(--text);
  font-size: 15px;
  min-height: 44px;
  padding: 2px 4px 4px;
  border-radius: 8px;
}

.block-title span {
  min-width: 34px;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  color: inherit;
  font-size: 13px;
  font-weight: 900;
}

.tone-overdue .block-title {
  background: transparent;
  color: #7f1d1d;
}

.tone-overdue {
  background: #f9e7e5;
  border-color: #efb4ad;
}

.tone-today .block-title {
  background: transparent;
  color: #b42318;
}

.tone-today {
  background: #fff0ee;
  border-color: #f3c2bd;
}

.tone-7 .block-title {
  background: transparent;
  color: #4a2418;
}

.tone-7 {
  background: #f7f1ed;
  border-color: #e4d6cd;
}

.tone-14 .block-title {
  background: transparent;
  color: #6b3a29;
}

.tone-14 {
  background: #efe3da;
  border-color: #d8c2b5;
}

.tone-30 .block-title {
  background: transparent;
  color: #161616;
}

.tone-30 {
  background: #e7d4c8;
  border-color: #c9aa99;
}

.tone-60 .block-title {
  background: transparent;
  color: #161616;
}

.tone-60 {
  background: #d8bdad;
  border-color: #b9927e;
}

.tone-later .block-title {
  background: transparent;
  color: #161616;
}

.tone-later {
  background: #c8a895;
  border-color: #a77c66;
}

.expiry-card {
  display: grid;
  gap: 6px;
  align-items: center;
  padding: 7px 8px;
}

.product-title {
  display: flex !important;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.product-title-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions {
  display: grid;
  gap: 8px;
  justify-items: stretch;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

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

.summary-side {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.summary-dates {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: flex-start;
  max-width: 178px;
  overflow-x: auto;
  scrollbar-width: none;
}

.summary-dates::-webkit-scrollbar {
  display: none;
}

.date-item {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 3px;
}

.date-action-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.action-buttons {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  justify-content: flex-end;
  width: min(100%, 640px);
}

.date-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 28px;
  border-radius: 8px;
  background: #efe3da;
  color: var(--accent-strong);
  font-weight: 800;
  font-size: 12px;
}

.compact-date {
  min-width: auto;
  white-space: nowrap;
  padding: 0 8px;
}

.nearest-date {
  outline: 2px solid rgba(74, 36, 24, 0.18);
}

.date-pill.overdue {
  background: #fff0ee;
  color: var(--danger);
}

.small-button {
  min-height: 36px;
  padding: 0 8px;
  background: var(--black);
  color: #fff;
  font-weight: 800;
  white-space: nowrap;
}

.expand-button {
  width: 30px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: var(--black);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

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

.promo-button {
  background: var(--accent);
  color: #fff;
}

.sold-button {
  grid-column: span 2;
  background: var(--success);
  color: #fff;
}

.danger-button {
  grid-column: span 3;
  background: #fff0ee;
  color: var(--danger);
  border: 1px solid #f0c3bd;
}

body.review-mode .add-panel,
body.review-mode .mode-tabs {
  display: none;
}

body.review-mode .app-shell {
  max-width: 1240px;
  padding: 8px;
}

body.review-mode .topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: -8px -8px 8px;
  padding: 8px;
  background: var(--accent);
  border-bottom: 1px solid var(--border);
}

body.review-mode .brand-block {
  gap: 7px;
}

body.review-mode .brand-block img {
  width: 32px;
  height: 32px;
}

body.review-mode .list-controls {
  position: sticky;
  top: 52px;
  z-index: 2;
  margin: 0 0 5px;
  padding: 5px;
  box-shadow: none;
}

body.review-mode .list-controls label {
  gap: 2px;
  font-size: 10px;
}

body.review-mode .list-controls select {
  min-height: 32px;
  padding: 4px 9px;
  font-size: 13px;
}

body.review-mode h1 {
  font-size: 16px;
}

body.review-mode .topbar p {
  display: none;
}

body.review-mode .list-panel {
  padding: 6px;
  gap: 6px;
}

body.review-mode .expiry-block {
  gap: 4px;
  padding: 5px;
}

body.review-mode .block-title {
  position: sticky;
  top: 93px;
  z-index: 1;
  margin: 0;
  padding: 2px 4px;
  border-radius: 8px;
  min-height: 26px;
  font-size: 13px;
}

body.review-mode .block-title span {
  min-width: 24px;
  min-height: 20px;
  font-size: 11px;
}

body.review-mode .expiry-card {
  gap: 4px;
  padding: 6px 7px;
}

body.review-mode .expiry-card strong {
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.review-mode .meta {
  font-size: 12px;
}

body.review-mode .date-pill {
  min-width: 52px;
  min-height: 25px;
  font-size: 11px;
}

body.review-mode .compact-date {
  min-width: auto;
  max-width: 58px;
}

body.review-mode .small-button {
  min-height: 30px;
  padding: 0 7px;
  font-size: 12px;
}

.empty-state {
  padding: 24px 10px;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(120px);
  width: min(420px, calc(100% - 28px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  opacity: 0;
  transition:
    transform 0.18s ease,
    opacity 0.18s ease;
}

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

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

  h1 {
    font-size: 21px;
  }

  .search-row,
  .expiry-form,
  .expiry-card {
    grid-template-columns: 1fr;
  }

  .results {
    max-height: 260px;
  }

  .scan-button,
  .primary-button {
    width: 100%;
  }

  .date-pill {
    justify-self: start;
  }

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

  .action-buttons {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    justify-content: flex-start;
  }

  body.review-mode .expiry-card {
    grid-template-columns: 1fr;
  }

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

  .summary-dates {
    max-width: 164px;
  }

  .record-action-row {
    grid-template-columns: 1fr;
  }
}
