:root {
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef1ed;
  color: #1d221e;
  --green: #08763f;
  --green-dark: #075c33;
  --green-soft: #e6f2ea;
  --line: #d9dfda;
  --muted: #687169;
  --danger: #a63327;
  --danger-soft: #fbe8e4;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
}

.shell {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 8px;
  overflow: hidden;
}

.panel {
  width: min(100%, 580px);
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 12px 34px rgba(23, 34, 26, 0.1);
}

.app-header,
.box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header { margin-bottom: 14px; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 25px; line-height: 1.2; }
h2 { font-size: 17px; line-height: 1.3; }

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 700;
  background: #edf1ed;
  color: #3f4841;
  white-space: nowrap;
}

.badge::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #6b746d;
}

.badge[data-variant="busy"] { background: #fff3d5; color: #715300; }
.badge[data-variant="busy"]::before { background: #c38a00; }
.badge[data-variant="success"] { background: #e0f2e6; color: #126137; }
.badge[data-variant="success"]::before { background: #16824a; }
.badge[data-variant="error"] { background: var(--danger-soft); color: #8f2b20; }
.badge[data-variant="error"]::before { background: #c63c2e; }
.badge[data-variant="warning"] { background: #fff0d1; color: #76500d; }
.badge[data-variant="warning"]::before { background: #cb8500; }

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 16px;
  border: 1px solid #c9d0ca;
  border-radius: 7px;
  overflow: hidden;
}

.mode-tab {
  min-width: 0;
  min-height: 50px;
  border: 0;
  border-right: 1px solid #c9d0ca;
  border-radius: 0;
  padding: 10px 8px;
  background: #ffffff;
  color: #252b26;
  font-size: 15px;
  font-weight: 750;
}

.mode-tab:last-child { border-right: 0; }
.mode-tab.is-active { background: var(--green); color: #ffffff; }

label {
  display: grid;
  gap: 6px;
  color: #4d574f;
  font-size: 14px;
  font-weight: 600;
}

.number-field { margin-bottom: 14px; }
.number-field small { color: var(--muted); font-size: 12px; font-weight: 500; }

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid #c7cfc8;
  border-radius: 6px;
  padding: 11px 13px;
  font: inherit;
  color: #1d221e;
  background: #ffffff;
}

.number-field input {
  min-height: 68px;
  padding: 7px 12px;
  border-width: 0 0 1px;
  border-radius: 0;
  font-size: 43px;
  line-height: 1;
  font-weight: 800;
}

input:focus,
button:focus {
  outline: 2px solid #78a98b;
  outline-offset: 2px;
}

.mode-view { margin-bottom: 16px; }
.form { display: grid; gap: 13px; margin-bottom: 16px; }

.type-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

.type-switch legend {
  grid-column: 1 / -1;
  padding: 0 0 6px;
  color: #4d574f;
  font-size: 14px;
  font-weight: 600;
}

.type-switch label { display: block; }
.type-switch input { position: absolute; opacity: 0; pointer-events: none; }

.type-switch span {
  min-height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid #c7cfc8;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 750;
  color: #354039;
  background: #ffffff;
}

.type-switch input:focus + span { outline: 2px solid #78a98b; outline-offset: 2px; }
.type-switch input:checked + span { border-color: var(--green); background: var(--green); color: #ffffff; }

button {
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  padding: 11px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  background: var(--green);
  color: #ffffff;
  cursor: pointer;
}

button:hover { background: var(--green-dark); }
.primary-action { width: 100%; min-height: 54px; font-size: 16px; }
button.secondary { background: var(--green-soft); color: #155c39; }
button.secondary:hover { background: #d7e9dd; }
button.danger { background: var(--danger-soft); color: var(--danger); }
button.danger:hover { background: #f6d7d0; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
button.small { min-height: 36px; padding: 7px 10px; font-size: 13px; }

.box,
.saved-section {
  display: grid;
  gap: 11px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.box:last-child,
.saved-section:last-child { border-bottom: 1px solid var(--line); }
.box-head strong { color: var(--green); font-size: 14px; }

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.recipe-actions button:first-child { grid-column: 1 / -1; }
.items { display: grid; }

.row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border-top: 1px solid #e5e9e5;
  padding: 10px 0;
  color: #20251f;
  font-size: 14px;
}

.row:first-child { border-top: 0; }
.row > div:first-child { min-width: 0; }
.row b { overflow-wrap: anywhere; }

.row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.row > strong { color: #293129; font-size: 13px; white-space: nowrap; }

.row-side {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.recipe-total {
  color: var(--green-dark);
  font-size: 16px;
  line-height: 1.2;
  white-space: nowrap;
}

.row button {
  min-height: 36px;
  padding: 7px 9px;
  background: #ffffff;
  color: #155c39;
  border: 1px solid #c7cfc8;
  font-size: 13px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}

.row-actions .danger { background: var(--danger-soft); color: var(--danger); border-color: #f1c5bc; }
.photo-box { padding-top: 2px; border-top: 0; }

.photo-upload {
  display: grid;
  justify-items: center;
  gap: 7px;
  text-align: center;
}

.qr-code {
  width: min(240px, 68vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
}

.qr-code svg { width: 100%; height: 100%; display: block; shape-rendering: crispEdges; }
.photo-upload p { margin: 0; color: #4d574f; font-size: 13px; overflow-wrap: anywhere; }
.photo-link { max-width: 100%; opacity: 0.7; }

.empty-state {
  padding: 26px 16px;
  border: 1px dashed #c7cfc8;
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
}

.age-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: #24844b;
  box-shadow: 0 0 0 3px rgba(36, 132, 75, 0.12);
}

.row[data-age="old"] .age-dot { background: #c93624; box-shadow: 0 0 0 3px rgba(201, 54, 36, 0.12); }
.row[data-status="used"] { opacity: 0.82; }
.row[data-problem="true"] b::after { content: " !"; color: #c93624; }

.feedback {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 22px;
  margin: 0;
  padding: 9px 0 2px;
  border-top: 1px solid #e2e7df;
  background: #ffffff;
}

.message {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  color: #4d574f;
  font-size: 13px;
}

.items .message { position: static; border: 0; padding: 5px 0; }
.data-freshness { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.data-freshness[data-variant="warning"] { color: #8c5b12; font-weight: 700; }

@media (max-width: 460px) {
  .shell { padding: 0; place-items: start center; }
  .panel {
    max-height: 100vh;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    padding: 14px;
    box-shadow: none;
  }
  .mode-tab { min-height: 48px; font-size: 14px; }
  .number-field input { font-size: 38px; }
  .row { align-items: start; }
  .row-actions { max-width: 142px; }
}

@media (max-width: 360px) {
  .panel { padding: 11px; }
  .actions { grid-template-columns: 1fr; }
  .recipe-actions button:first-child { grid-column: auto; }
  .row { grid-template-columns: 1fr; }
  .row-side { justify-items: start; }
  .row-actions { max-width: none; justify-content: flex-start; }
}

@media (prefers-reduced-motion: no-preference) {
  .mode-view:not([hidden]) { animation: mode-in 140ms ease-out; }
  @keyframes mode-in {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: translateY(0); }
  }
}
