:root {
  color-scheme: light dark;
  --page: #f4f1ea;
  --surface: #fffdfa;
  --surface-2: #ebe7de;
  --line: #ddd7cc;
  --text: #252822;
  --muted: #686b62;
  --accent: #245f4a;
  --accent-text: #fff;
  --ok: #217447;
  --ok-bg: #dcefe3;
  --soon: #8a5900;
  --soon-bg: #fae9bd;
  --late: #a32e2a;
  --late-bg: #f6d9d7;
  --never: #62655f;
  --never-bg: #e5e5e0;
  --shadow: 0 8px 24px rgba(48, 43, 33, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #171a1d;
    --surface: #22262a;
    --surface-2: #2d3236;
    --line: #393f43;
    --text: #f2f1ec;
    --muted: #b1b4ad;
    --accent: #68bc96;
    --accent-text: #10251b;
    --ok: #8bd3aa;
    --ok-bg: #193c2c;
    --soon: #f2c467;
    --soon-bg: #493917;
    --late: #ff9690;
    --late-bg: #4b2423;
    --never: #c3c6c0;
    --never-bg: #34383a;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--page);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, textarea, input { color: inherit; font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 24px) 16px calc(env(safe-area-inset-bottom, 0px) + 40px);
}

.plain { padding: 14vh 8px; text-align: center; }
.plain h1 { font-size: clamp(30px, 9vw, 44px); letter-spacing: -0.035em; }
.error h1 { color: var(--muted); }

.item-head { padding: 4px 3px 20px; }
.item-head h1 {
  margin: 0;
  font-size: clamp(35px, 10vw, 50px);
  line-height: 1.04;
  letter-spacing: -0.045em;
}
.item-head p { margin: 7px 0 0; color: var(--muted); font-size: 19px; }
.item-head .actor-line { margin-top: 11px; font-size: 14px; }
.actor-line button, .text-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.status-card, .card {
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.status-card { padding: 22px; }
.status-card[data-status="ok"] { color: var(--ok); background: var(--ok-bg); }
.status-card[data-status="due_soon"] { color: var(--soon); background: var(--soon-bg); }
.status-card[data-status="overdue"] { color: var(--late); background: var(--late-bg); }
.status-card[data-status="never"] { color: var(--never); background: var(--never-bg); }
.status-card__label {
  margin: 0 0 13px;
  font-size: clamp(31px, 9vw, 43px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.035em;
}
.status-card p:not(.status-card__label) { margin: 4px 0 0; font-weight: 650; }

.log-panel { margin-bottom: 16px; }
.quantity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 64px;
  margin-bottom: 10px;
  padding: 4px 2px;
  font-weight: 700;
}

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: 52px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  cursor: pointer;
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
}
.stepper button:active { transform: scale(0.96); }
.stepper output { min-width: 42px; text-align: center; font-size: 24px; font-weight: 800; }

.note-toggle {
  min-height: 48px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-weight: 750;
}
.note-field { display: block; margin: 0 0 12px; }
.note-field span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 14px; font-weight: 700; }
.note-field textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  padding: 13px;
}

.primary {
  width: 100%;
  min-height: 68px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-size: 21px;
  font-weight: 800;
  box-shadow: var(--shadow);
}
.primary:active { transform: translateY(1px); }
.primary:disabled, .stepper button:disabled { cursor: wait; opacity: 0.55; }

.log-extras { padding: 11px 2px 0; }
.text-button { display: block; font-size: 14px; }
.date-field { display: flex; align-items: center; gap: 10px; margin-top: 10px; color: var(--muted); font-size: 14px; }
.date-field input, .spares-edit input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  padding: 7px 10px;
}
.photo-control { display: inline-block; margin-top: 11px; color: var(--accent); cursor: pointer; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.photo-control input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-name { margin-left: 8px; color: var(--muted); font-size: 13px; }

.confirmation {
  min-height: 64px;
  margin-top: 10px;
  padding: 8px 8px 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 16px;
  background: var(--ok-bg);
  color: var(--ok);
  font-weight: 800;
}
.confirmation button {
  min-width: 92px;
  min-height: 48px;
  border: 1px solid currentColor;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-weight: 800;
}

.card { padding: 20px; background: var(--surface); }
.card h2 { margin: 0 0 14px; font-size: 21px; letter-spacing: -0.02em; }
.spares {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}
.spares h2 { margin-bottom: 4px; }
.spares__count { margin: 0; padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 21px; font-weight: 800; text-align: left; }
.spares-edit { display: flex; gap: 7px; margin-top: 7px; }
.spares-edit input { width: 82px; }
.spares-edit button {
  border: 1px solid var(--accent);
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 7px 13px;
  cursor: pointer;
  font-weight: 750;
}
.warning { margin: 2px 0 0; color: var(--late); font-weight: 800; }
.part { grid-column: 1 / -1; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); }
.part p { margin: 0 0 5px; }
.part a { font-size: 15px; font-weight: 750; }
.part a.reorder {
  display: block;
  width: 100%;
  min-height: 52px;
  margin-top: 11px;
  padding: 13px 18px;
  border-radius: 14px;
  background: var(--late);
  color: #fff;
  text-align: center;
  text-decoration: none;
  font-size: 18px;
}
a { color: var(--accent); text-underline-offset: 3px; }

.steps { margin: 0; padding-left: 27px; }
.steps li { padding-left: 5px; margin-bottom: 13px; }
.steps li::marker { color: var(--accent); font-weight: 800; }
.notes { margin: 17px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); }

.history { list-style: none; margin: 0; padding: 0; }
.history li { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.history li:first-child { padding-top: 0; border: 0; }
.history strong { display: block; }
.history span { display: block; color: var(--muted); font-size: 15px; }
.history__photo { grid-column: 2; grid-row: 1 / span 2; }
.history__photo img { display: block; width: 72px; height: 58px; border-radius: 10px; object-fit: cover; }
.history .empty { color: var(--muted); }

.sensor__value { margin: -3px 0 8px; color: var(--accent); font-size: 43px; font-weight: 850; line-height: 1; }
.sensor__track { overflow: hidden; height: 13px; border-radius: 99px; background: var(--surface-2); }
.sensor__track span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.sensor > p:not(.sensor__value) { margin: 9px 0 0; }
.sensor__updated { color: var(--muted); font-size: 14px; }
.sensor.stale { filter: grayscale(1); opacity: 0.58; }

.overview-head { padding-bottom: 27px; }
.overview-list { display: grid; gap: 14px; }
.overview-card {
  display: block;
  border: 1px solid var(--line);
  border-left: 8px solid var(--never);
  border-radius: 17px;
  padding: 17px 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
}
.overview-card[data-status="ok"] { border-left-color: var(--ok); }
.overview-card[data-status="due_soon"] { border-left-color: var(--soon); }
.overview-card[data-status="overdue"] { border-left-color: var(--late); }
.overview-card h2 { margin: 0 0 5px; font-size: 21px; }
.overview-card p { margin: 2px 0 0; color: var(--muted); }
.overview-card .overview-warning { color: var(--late); font-weight: 800; }

.identity {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
}
.identity__panel {
  width: min(100%, 420px);
  border-radius: 22px;
  padding: 25px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.identity h2 { margin: 0 0 18px; font-size: 30px; }
.identity button {
  width: 100%;
  min-height: 62px;
  margin-top: 10px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-size: 20px;
  font-weight: 800;
}

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: 12px 17px;
  border-radius: 999px;
  background: var(--text);
  color: var(--page);
  box-shadow: var(--shadow);
  font-weight: 750;
  text-align: center;
}

@media (max-width: 390px) {
  .spares { grid-template-columns: 1fr; }
  .spares .stepper { justify-content: flex-start; }
  .part { grid-column: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  #item:not([hidden]) { animation: enter 220ms ease-out both; }
  @keyframes enter { from { opacity: 0; transform: translateY(5px); } }
}
