:root {
  --bg: #FFFFFF;
  --surface: #F4F5F3;
  --group: #F7F8F6;
  --line: #E5E7E4;
  --divider: #EEF0ED;
  --ink: #111412;
  --ink-2: #565C58;
  --tab-off: #5F6662;
  --check-border: #7A807C;
  --accent: #2B50D6;
  --accent-strong: #1E3CA8;
  --neg: #C2410C;
  --neg-bg: #FFF1EA;
  --warn: #8F5200;
  --warn-bg: #FFF6E0;
  --track: #ECEEEB;
  --bar-neg: #C2410C;
  --bar-warn: #D98A00;
  --bar-ok: #1E7A4C;
  --toast-bg: #111412;
  --toast-action: #A9BDFF;
  --toast-track: #2A2F2C;

  --f-head: 'Space Grotesk', system-ui, sans-serif;
  --f-body: Inter, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: var(--f-body);
  min-height: 100vh;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

svg {
  flex-shrink: 0;
  display: block;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.tone-neg { color: var(--neg); }
.tone-warn { color: var(--warn); }
.tone-ink { color: var(--ink); }
.tone-muted { color: var(--ink-2); }

/* ---- Demo banner ---- */

.demo-banner {
  font-size: 12px;
  text-align: center;
  padding: 6px 12px;
  background: var(--warn-bg);
  color: var(--warn);
}

/* ---- Screen shell ---- */

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: 96px;
}

.screen-header {
  padding: 28px 16px 16px 20px;
}

.screen-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.h1 {
  font-family: var(--f-head);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.subtitle {
  font-size: 14px;
  color: var(--ink-2);
  margin: 4px 0 0;
}

.round-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.round-btn svg {
  width: 18px;
  height: 18px;
}

/* ---- Home tiles ---- */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 16px 8px 20px;
}

.tile {
  border-radius: 14px;
  padding: 12px;
  text-align: left;
}

.tile-neg { background: var(--neg-bg); color: var(--neg); }
.tile-warn { background: var(--warn-bg); color: var(--warn); }
.tile-ink { background: var(--surface); color: var(--ink); }

.tile-number {
  font-family: var(--f-head);
  font-size: 30px;
  font-weight: 700;
  display: block;
}

.tile-label {
  font-size: 12px;
  font-weight: 600;
  display: block;
}

/* ---- Sections / rows (Home) ---- */

.section {
  padding: 0 0 8px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 16px 16px 8px 20px;
}

.section-head h2 {
  font-family: var(--f-head);
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.section-count {
  font-size: 13px;
  color: var(--ink-2);
}

.row {
  display: flex;
  align-items: center;
  min-height: 58px;
  padding: 4px 8px 4px 20px;
  border-bottom: 1px solid var(--divider);
  gap: 10px;
}

.row-checked-off .row-name {
  text-decoration: line-through;
  color: var(--ink-2);
}

.countdown-col {
  width: 46px;
  flex-shrink: 0;
  text-align: left;
}

.countdown-big {
  font-family: var(--f-head);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: block;
  line-height: 1.1;
}

.countdown-small {
  font-size: 11px;
  font-weight: 600;
  display: block;
}

.row-main {
  flex: 1;
  min-width: 0;
}

.row-name {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0;
  font-family: inherit;
  color: inherit;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-meta {
  font-size: 12px;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  flex-shrink: 0;
  display: inline-block;
}

.swatch-store-name {
  font-weight: 600;
  color: var(--ink);
}

.onlist-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.onlist-square {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.onlist-square svg {
  width: 14px;
  height: 14px;
}

.onlist-square.on {
  background: var(--ink);
  color: #fff;
}

.onlist-square.off {
  border: 2px solid var(--ink);
  color: var(--ink);
}

/* ---- First run ---- */

.first-run {
  padding: 28px 16px 16px 20px;
}

.first-run h1 {
  font-family: var(--f-head);
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0;
}

.first-run-body {
  font-size: 15px;
  color: var(--ink-2);
  margin: 10px 0 20px;
}

.step-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

.step-card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 2px;
}

.step-card-sub {
  font-size: 13px;
  color: var(--ink-2);
  margin: 0;
}

.primary-btn {
  width: 100%;
  height: 54px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  margin-top: 12px;
}

.text-btn {
  display: block;
  margin: 14px auto 0;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
}

/* ---- List screen ---- */

.chips-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 12px 20px;
  -webkit-overflow-scrolling: touch;
}

.chip {
  height: 44px;
  border-radius: 12px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  background: var(--surface);
  color: var(--ink);
}

.chip.selected {
  background: var(--ink);
  color: #fff;
}

.group-header {
  background: var(--group);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 10px 20px;
  gap: 8px;
}

.group-header-name {
  font-family: var(--f-head);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-header-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.checkbox-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.checkbox-square {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid var(--check-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.checkbox-square.checked {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.checkbox-square svg {
  width: 14px;
  height: 14px;
}

.list-status {
  font-family: var(--f-head);
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 64px 24px;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 6px;
}

.empty-state-hint {
  font-size: 14px;
  color: var(--ink-2);
  margin: 0;
}

/* ---- Items screen ---- */

.search-field {
  height: 44px;
  background: var(--surface);
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  margin: 0 16px 12px 20px;
}

.search-field svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--ink-2);
}

.search-field input {
  border: none;
  background: none;
  outline: none;
  font-size: 16px;
  color: var(--ink);
  flex: 1;
  min-width: 0;
  font-family: var(--f-body);
}

.underline-tabs {
  display: flex;
  padding: 0 16px 0 20px;
  border-bottom: 1px solid var(--divider);
}

.underline-tab {
  height: 44px;
  padding: 0 4px;
  margin-right: 24px;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-2);
  border-bottom: 2px solid transparent;
}

.underline-tab.selected {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--ink);
}

.category-head {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-2);
  padding: 16px 16px 6px 20px;
}

.chevron-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
}

.chevron-btn svg {
  width: 16px;
  height: 16px;
}

.supplement-row-wrap {
  border-bottom: 1px solid var(--divider);
  padding: 4px 16px 10px 20px;
}

.supplement-row-wrap .row {
  border-bottom: none;
  padding-left: 0;
  padding-right: 0;
}

.supplement-row-wrap .countdown-big {
  font-size: 22px;
}

.supply-bar-track {
  height: 6px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
  margin-top: 4px;
}

.supply-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.supply-bar-fill.neg { background: var(--bar-neg); }
.supply-bar-fill.warn { background: var(--bar-warn); }
.supply-bar-fill.ok { background: var(--bar-ok); }

.supply-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 6px;
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(68px + max(24px, env(safe-area-inset-bottom)));
  max-width: 456px;
  margin: 0 auto;
  background: var(--toast-bg);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  z-index: 20;
}

.toast-message {
  flex: 1;
  color: #fff;
  font-size: 14px;
  min-width: 0;
}

.toast-undo-btn {
  height: 44px;
  padding: 0 10px;
  color: var(--toast-action);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.toast-timer-track {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--toast-track);
}

.toast-timer-fill {
  height: 100%;
  width: 100%;
  background: var(--toast-action);
  transition: width 5s linear;
}

/* ---- Tab bar ---- */

.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 6px 8px max(24px, env(safe-area-inset-bottom));
  display: flex;
  z-index: 10;
}

.tab-btn {
  flex: 1;
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--tab-off);
  font-weight: 500;
  position: relative;
}

.tab-btn.active {
  color: var(--accent);
  font-weight: 600;
}

.tab-btn svg {
  width: 22px;
  height: 22px;
}

.tab-label {
  font-size: 11px;
}

.tab-badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 22px);
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Sheets (Add/Edit item, Store picker, Staples) ---- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 50;
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 12px;
  flex-shrink: 0;
}

.sheet-close-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-close-btn svg {
  width: 20px;
  height: 20px;
}

.sheet-title {
  font-family: var(--f-head);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  flex: 1;
  outline: none;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 24px;
}

.sheet-footer {
  flex-shrink: 0;
  padding: 10px 16px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.discard-bar {
  margin: 0 16px 12px;
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.discard-actions {
  display: flex;
  gap: 8px;
}

.discard-keep-btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.discard-discard-btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 9px;
  background: var(--neg);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

/* ---- Form fields ---- */

.sheet-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}

.field-input {
  background: var(--surface);
  border-radius: 12px;
  padding: 8px 14px;
  border: none;
  outline: none;
  font-size: 16px;
  color: var(--ink);
  font-family: var(--f-body);
  width: 100%;
}

.textarea {
  min-height: 80px;
  resize: vertical;
}

.field-error {
  font-size: 12px;
  color: var(--neg);
  margin: 0;
}

.kind-readonly {
  font-size: 16px;
  color: var(--ink);
  margin: 0;
  padding: 8px 0;
}

.kind-toggle {
  display: flex;
  gap: 8px;
}

.kind-btn {
  flex: 1;
  height: 48px;
  border-radius: 12px;
  border: 2px solid var(--line);
  color: var(--ink-2);
  font-size: 15px;
  font-weight: 600;
}

.kind-btn.selected {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.store-picker-btn {
  height: 44px;
  background: var(--surface);
  border-radius: 12px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.store-picker-btn-label {
  flex: 1;
  text-align: left;
  font-size: 15px;
  color: var(--ink);
}

.store-picker-btn svg {
  width: 16px;
  height: 16px;
  color: var(--ink-2);
}

.warn-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.warn-stepper-label {
  font-size: 14px;
  color: var(--ink);
  flex: 1;
}

.warn-stepper-control {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.stepper-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}

.warn-stepper-value {
  font-family: var(--f-head);
  font-size: 20px;
  font-weight: 600;
  min-width: 72px;
  text-align: center;
}

.supply-callout {
  border: 2px dashed #CBD5F5;
  background: #F3F6FF;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.supply-callout-text {
  font-size: 14px;
  color: #2B3A66;
}

.supply-callout-days {
  font-family: var(--f-head);
  font-size: 22px;
  font-weight: 700;
  color: #1E3CA8;
}

.supply-callout-sub {
  font-size: 12px;
  color: #2B3A66;
}

.preview-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--divider);
  border-bottom: 1px solid var(--divider);
  font-size: 14px;
  color: var(--ink-2);
}

.preview-days {
  font-family: var(--f-head);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  flex-shrink: 0;
}

.more-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.more-options-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  align-self: flex-start;
}

.more-options-toggle svg {
  width: 14px;
  height: 14px;
  color: var(--ink-2);
}

.more-options-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.segmented {
  display: flex;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--line);
}

.segment-btn {
  flex: 1;
  height: 44px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}

.segment-btn.selected {
  background: var(--ink);
  color: #fff;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  font-size: 15px;
  color: var(--ink);
}

.switch {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--line);
  padding: 2px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.switch.on {
  background: var(--accent);
  justify-content: flex-end;
}

.switch-knob {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #fff;
  display: block;
}

.purchases-heading {
  font-family: var(--f-head);
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.purchases-empty {
  font-size: 14px;
  color: var(--ink-2);
  margin: 0;
}

.purchase-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  border-bottom: 1px solid var(--divider);
}

.purchase-row-text {
  font-size: 14px;
  color: var(--ink);
}

.delete-purchase-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--neg);
}

.delete-purchase-btn svg {
  width: 18px;
  height: 18px;
}

.add-purchase-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
}

.add-purchase-row .field-input {
  flex: 1;
  min-width: 0;
}

.add-purchase-btn {
  height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.delete-item-btn {
  color: var(--neg);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 0;
  text-align: center;
  width: 100%;
}

/* ---- Store picker / editor ---- */

.store-list {
  display: flex;
  flex-direction: column;
}

.store-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--divider);
}

.store-row-main {
  flex: 1;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  text-align: left;
}

.store-row-name {
  flex: 1;
  font-size: 16px;
  color: var(--ink);
}

.store-row-type {
  font-size: 12px;
  color: var(--ink-2);
}

.store-row-check svg {
  width: 14px;
  height: 14px;
  color: var(--accent);
}

.store-row-edit-btn {
  height: 44px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.add-store-row {
  min-height: 48px;
  text-align: left;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 0;
}

.store-editor {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 4px;
}

/* ---- Staples ---- */

.staples-body {
  display: flex;
  flex-direction: column;
}

.staples-store-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  font-size: 14px;
  color: var(--ink);
  border-bottom: 1px solid var(--divider);
  margin-bottom: 8px;
}

.staple-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  text-align: left;
  width: 100%;
  border-bottom: 1px solid var(--divider);
}

.staple-row.disabled {
  opacity: 0.5;
}

.staple-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}

.staple-meta {
  font-size: 12px;
  color: var(--ink-2);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.staples-link-btn {
  margin: 0;
  font-size: 14px;
}
