:root {
  color-scheme: dark;
  --bg: #0d100e;
  --surface: #151a17;
  --surface-2: #1c231f;
  --surface-3: #242d27;
  --border: #303b34;
  --text: #f5f7f5;
  --muted: #aeb9b1;
  --accent: #90e56b;
  --accent-strong: #b3f18e;
  --accent-ink: #12200d;
  --danger: #ff827a;
  --warning: #f5ca67;
  --shadow: 0 18px 50px rgb(0 0 0 / 28%);
  --radius: 18px;
  --nav-height: 76px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 90% -10%, rgb(144 229 107 / 12%), transparent 35rem),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgb(144 229 107 / 55%);
  outline-offset: 2px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 5vw, 2rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 4.8vw, 1.65rem);
  line-height: 1.2;
}

h3 {
  margin-bottom: 0.55rem;
  font-size: 1.08rem;
}

.eyebrow {
  margin-bottom: 0.35rem;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.offline-banner {
  position: fixed;
  z-index: 100;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.7rem;
  padding: calc(0.55rem + env(safe-area-inset-top)) 1rem 0.55rem;
  background: var(--warning);
  color: #211b0b;
  font-size: 0.85rem;
  font-weight: 750;
  text-align: center;
}

.offline-banner button {
  min-height: 40px;
  padding: 0.35rem 0.7rem;
  border: 1px solid rgb(33 27 11 / 45%);
  border-radius: 10px;
  background: rgb(255 255 255 / 28%);
  color: inherit;
  font: inherit;
  white-space: nowrap;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.1rem
    max(1.25rem, env(safe-area-inset-bottom));
}

.login-card {
  width: min(100%, 420px);
  padding: clamp(1.4rem, 6vw, 2.2rem);
  border: 1px solid var(--border);
  border-radius: 26px;
  background: rgb(21 26 23 / 94%);
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 1.4rem;
  place-items: center;
  border-radius: 17px;
  background: var(--accent);
  box-shadow: 0 12px 28px rgb(144 229 107 / 20%);
  color: var(--accent-ink);
  font-size: 1.8rem;
  font-weight: 950;
}

.stack {
  display: grid;
  gap: 0.85rem;
  margin-top: 1.5rem;
}

label {
  color: #d9dfda;
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #101511;
  color: var(--text);
  padding: 0.75rem 0.9rem;
}

input::placeholder {
  color: #7d8a81;
}

.primary-button,
.secondary-button,
.icon-button,
.text-button {
  min-height: 46px;
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.78rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
}

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

.secondary-button {
  padding: 0.72rem 1rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.compact {
  min-width: fit-content;
  min-height: 48px;
  padding-inline: 1rem;
}

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

.primary-button.danger {
  background: var(--danger);
  color: #2a0e0c;
}

.link-button {
  width: 100%;
  margin-top: 1rem;
  text-decoration: none;
}

.button-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgb(18 32 13 / 35%);
  border-top-color: var(--accent-ink);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

button.loading .button-spinner {
  display: inline-block;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.app-view {
  min-height: 100vh;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 1rem);
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 78px;
  padding: calc(0.8rem + env(safe-area-inset-top)) 1rem 0.8rem;
  border-bottom: 1px solid rgb(48 59 52 / 75%);
  background: rgb(13 16 14 / 88%);
  backdrop-filter: blur(18px);
}

.offline-banner:not([hidden]) + .login-view,
.offline-banner:not([hidden]) ~ .app-view .app-header {
  padding-top: calc(4.5rem + env(safe-area-inset-top));
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 0.45rem;
}

.icon-button {
  display: grid;
  width: 46px;
  min-width: 46px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.25rem;
}

.icon-button.syncing span {
  animation: spin 0.9s linear infinite;
}

.page-content {
  width: min(100%, 880px);
  margin: 0 auto;
  padding: 1.2rem 1rem 2rem;
}

.page-section {
  animation: reveal 0.2s ease-out;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.freshness,
.count-pill {
  flex: 0 0 auto;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.offers-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 240px);
  align-items: center;
  justify-content: end;
  gap: 0.65rem;
  margin: -0.2rem 0 1rem;
}

.offers-toolbar label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.offers-toolbar select {
  min-width: 0;
  min-height: 44px;
}

.count-pill {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.card-list {
  display: grid;
  gap: 0.85rem;
}

.product-card {
  position: relative;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 0.9rem;
  min-width: 0;
  padding: 0.9rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(145deg, #171d19, #131714);
  box-shadow: 0 10px 24px rgb(0 0 0 / 14%);
}

.product-image-wrap {
  display: grid;
  width: 92px;
  height: 108px;
  place-items: center;
  overflow: hidden;
  border-radius: 13px;
  background: #f5f5ef;
}

.product-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-placeholder {
  color: #637067;
  font-size: 0.7rem;
  font-weight: 800;
  text-align: center;
}

.product-body {
  min-width: 0;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.badge {
  max-width: 100%;
  padding: 0.23rem 0.48rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgb(144 229 107 / 14%);
  color: var(--accent-strong);
  font-size: 0.68rem;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge.offer {
  background: var(--accent);
  color: var(--accent-ink);
}

.badge.permanent-price {
  background: rgb(245 202 103 / 15%);
  color: var(--warning);
}

.badge.favorite {
  background: rgb(111 191 255 / 16%);
  color: #9fd4ff;
}

.badge.warning {
  background: rgb(245 202 103 / 15%);
  color: var(--warning);
}

.product-title {
  margin: 0 0 0.35rem;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.25;
}

.product-copy,
.base-price,
.inventory,
.validity {
  margin: 0.2rem 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.price-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 0.65rem;
}

.price {
  color: var(--text);
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.price-comparison {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.55rem;
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.price-comparison strong {
  color: var(--accent-strong);
}

.card-actions {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.card-actions button {
  min-width: 0;
  min-height: 44px;
  padding: 0.55rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  font-size: 0.78rem;
  font-weight: 800;
}

.card-actions button:first-child {
  border-color: rgb(144 229 107 / 32%);
  background: rgb(144 229 107 / 12%);
  color: var(--accent-strong);
}

.empty-state,
.error-state,
.loading-state {
  display: grid;
  min-height: 180px;
  padding: 1.5rem;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty-state h3,
.error-state h3 {
  color: var(--text);
}

.error-state {
  border-color: rgb(255 130 122 / 35%);
}

.loader {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.search-panel,
.manual-item-form,
.settings-card,
.totals-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.search-panel {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 1rem;
  padding: 0.9rem;
}

.search-row {
  display: flex;
  gap: 0.5rem;
}

.search-summary {
  min-height: 1.8rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-top: 1rem;
}

.pagination span {
  color: var(--muted);
  font-size: 0.85rem;
}

.text-button {
  min-height: 44px;
  padding: 0.45rem 0;
  background: transparent;
}

.manual-item-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px 100px;
  gap: 0.65rem;
  margin-bottom: 1rem;
  padding: 0.85rem;
}

.manual-item-form .primary-button {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  min-width: 0;
  gap: 0.35rem;
}

.shopping-list {
  display: grid;
  gap: 0.65rem;
}

.shopping-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  gap: 0.65rem;
  align-items: center;
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
}

.shopping-item.checked {
  opacity: 0.62;
}

.shopping-item.checked .shopping-name {
  text-decoration: line-through;
}

.check-control {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
}

.check-control input {
  width: 24px;
  min-height: 24px;
  accent-color: var(--accent);
}

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

.shopping-name {
  display: block;
  margin-bottom: 0.4rem;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.shopping-fields {
  display: grid;
  grid-template-columns: 78px minmax(95px, 1fr);
  gap: 0.45rem;
}

.shopping-fields input {
  min-height: 40px;
  padding: 0.45rem 0.55rem;
  font-size: 0.85rem;
}

.delete-button {
  display: grid;
  width: 46px;
  height: 46px;
  padding: 0;
  place-items: center;
  border: 1px solid rgb(255 130 122 / 25%);
  border-radius: 12px;
  background: rgb(255 130 122 / 8%);
  color: var(--danger);
  cursor: pointer;
}

.totals-card {
  position: sticky;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 0.65rem);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-top: 1rem;
  padding: 0.9rem;
  box-shadow: 0 12px 30px rgb(0 0 0 / 35%);
}

.totals-card div {
  display: grid;
  gap: 0.2rem;
}

.totals-card div + div {
  padding-left: 0.8rem;
  border-left: 1px solid var(--border);
}

.totals-card span {
  color: var(--muted);
  font-size: 0.75rem;
}

.totals-card strong {
  font-size: 1.1rem;
}

.settings-card {
  margin-bottom: 1rem;
  padding: 1rem;
}

.inline-form {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0;
}

.editable-list,
.favorite-list {
  display: grid;
  gap: 0.55rem;
}

.category-group {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgb(255 255 255 / 1.5%);
}

.category-group + .category-group {
  margin-top: 0.65rem;
}

.category-group summary {
  display: flex;
  min-height: 46px;
  padding: 0.65rem 0.8rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--text);
  cursor: pointer;
  font-weight: 850;
}

.category-count {
  display: inline-grid;
  min-width: 28px;
  min-height: 28px;
  padding: 0 0.4rem;
  place-items: center;
  border-radius: 999px;
  background: rgb(144 229 107 / 14%);
  color: var(--accent-strong);
  font-size: 0.72rem;
}

.category-group-items {
  display: grid;
  gap: 0.5rem;
  padding: 0 0.55rem 0.55rem;
}

.category-group .editable-item,
.category-group .favorite-item {
  border-color: rgb(255 255 255 / 7%);
}

.editable-item,
.favorite-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(132px, 0.75fr) 46px;
  gap: 0.5rem;
  align-items: center;
  min-width: 0;
  padding: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #111612;
}

.editable-item input,
.editable-item select {
  min-width: 0;
  min-height: 42px;
  padding: 0.45rem 0.55rem;
  font-size: 0.82rem;
}

.favorite-item {
  grid-template-columns: minmax(0, 1fr) auto 46px;
}

.favorite-item strong {
  overflow-wrap: anywhere;
}

.favorite-item span {
  color: var(--accent-strong);
  font-weight: 850;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 42px;
  padding: 0.4rem 0.45rem 0.4rem 0.75rem;
  border: 1px solid rgb(255 130 122 / 28%);
  border-radius: 999px;
  background: rgb(255 130 122 / 8%);
}

.chip button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.1rem;
}

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding: 0.45rem 0.4rem env(safe-area-inset-bottom);
  border-top: 1px solid var(--border);
  background: rgb(17 22 18 / 94%);
  backdrop-filter: blur(18px);
}

.bottom-nav button {
  display: grid;
  min-width: 0;
  min-height: 58px;
  padding: 0.35rem 0.15rem;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.64rem;
  font-weight: 750;
}

.bottom-nav button span:first-child {
  font-size: 1.25rem;
  line-height: 1;
}

.bottom-nav button.active {
  background: rgb(144 229 107 / 11%);
  color: var(--accent-strong);
}

dialog {
  color: var(--text);
}

dialog::backdrop {
  background: rgb(0 0 0 / 70%);
  backdrop-filter: blur(5px);
}

.app-dialog {
  width: min(calc(100% - 1rem), 620px);
  max-height: min(86vh, 800px);
  margin: auto auto 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.dialog-content {
  max-height: 60vh;
  padding: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dialog-actions {
  display: flex;
  gap: 0.65rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.dialog-actions > * {
  flex: 1;
}

.detail-grid,
.status-grid {
  display: grid;
  gap: 0.65rem;
}

.detail-hero {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 0.9rem;
  align-items: center;
}

.detail-hero .product-image-wrap {
  width: 110px;
  height: 130px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.8rem;
}

.metric,
.status-row {
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #101511;
}

.metric span,
.status-row span {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.metric strong,
.status-row strong {
  overflow-wrap: anywhere;
}

.history-list {
  display: grid;
  gap: 0.45rem;
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.history-list small {
  color: var(--muted);
}

.notice,
.warning-box,
.saving-box {
  padding: 0.75rem;
  border-radius: 12px;
  background: rgb(144 229 107 / 8%);
  color: #cfe4d2;
  font-size: 0.82rem;
  line-height: 1.45;
}

.warning-box {
  background: rgb(245 202 103 / 10%);
  color: #f1dba6;
}

.saving-box {
  background: rgb(144 229 107 / 15%);
  color: var(--accent-strong);
}

.confirm-dialog {
  width: min(calc(100% - 2rem), 420px);
  padding: 1.2rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
}

.confirm-dialog p {
  color: var(--muted);
}

.confirm-dialog .dialog-actions {
  padding: 0.8rem 0 0;
  border: 0;
}

.toast-region {
  position: fixed;
  z-index: 110;
  right: 0.8rem;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 0.8rem);
  left: 0.8rem;
  display: grid;
  justify-items: center;
  pointer-events: none;
}

.toast {
  max-width: 440px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #28322b;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 750;
  animation: toast-in 0.2s ease-out;
}

.toast.error {
  border-color: rgb(255 130 122 / 35%);
  background: #3a201f;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
}

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

@media (min-width: 680px) {
  .app-header {
    padding-inline: max(1rem, calc((100vw - 880px) / 2 + 1rem));
  }

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

  .product-card {
    align-content: start;
  }

  .inline-form {
    grid-template-columns: minmax(0, 1fr) minmax(160px, 0.65fr) auto;
  }

  #exclusion-form {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .app-dialog {
    margin: auto;
    border-radius: 24px;
  }
}

@media (max-width: 390px) {
  .offers-toolbar {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .product-card {
    grid-template-columns: 78px minmax(0, 1fr);
  }

  .product-image-wrap {
    width: 78px;
    height: 98px;
  }

  .card-actions {
    grid-template-columns: 1fr 1fr;
  }

  .card-actions button:last-child {
    grid-column: 1 / -1;
  }

  .manual-item-form {
    grid-template-columns: 1fr 1fr;
  }

  .manual-item-form .grow {
    grid-column: 1 / -1;
  }

  .editable-item {
    grid-template-columns: minmax(0, 1fr) 46px;
  }

  .editable-item select {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .editable-item .delete-button {
    grid-column: 2;
    grid-row: 1;
  }
}

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