:root {
  color-scheme: light;
  --bg: #ebe4d8;
  --surface: #fffdf8;
  --ink: #1c1612;
  --muted: #5c534c;
  --line: #e0d6c8;
  --copper: #c4622d;
  --copper-dark: #8a3d16;
  --copper-soft: #f6e3d6;
  --on-copper: #fff8f3;
  --in: #0e7a45;
  --on-in: #ffffff;
  --out: #b42318;
  --on-out: #ffffff;
  --low: #92400e;
  --low-bg: #fef3c7;
  --ask: #1e3a8a;
  --ask-bg: #e0e7ff;
  --warn-bg: #fde8e6;
  --warn-ink: #8a1c13;
  --shadow: 0 10px 28px rgba(60, 36, 16, 0.06);
  --tab: rgba(255, 253, 248, 0.94);
  --backdrop: rgba(28, 22, 18, 0.48);
  --fresh: #f6e3d6;
  --danger: #9f1239;
  --kb: 0px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12100e;
    --surface: #1e1a17;
    --ink: #f6f1ea;
    --muted: #b7ada3;
    --line: #3a332c;
    --copper: #e5925b;
    --copper-dark: #f0b48a;
    --copper-soft: #3a261c;
    --on-copper: #1a0e08;
    --in: #3dce8a;
    --on-in: #052117;
    --out: #ff8d7c;
    --on-out: #2a0a10;
    --low: #fbbf24;
    --low-bg: #3a2c12;
    --ask: #bfdbfe;
    --ask-bg: #1e2a44;
    --warn-bg: #3f221d;
    --warn-ink: #ffd2cb;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    --tab: rgba(22, 19, 16, 0.94);
    --backdrop: rgba(0, 0, 0, 0.62);
    --fresh: #3a261c;
    --danger: #fda4af;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12100e;
  --surface: #1e1a17;
  --ink: #f6f1ea;
  --muted: #b7ada3;
  --line: #3a332c;
  --copper: #e5925b;
  --copper-dark: #f0b48a;
  --copper-soft: #3a261c;
  --on-copper: #1a0e08;
  --in: #3dce8a;
  --on-in: #052117;
  --out: #ff8d7c;
  --on-out: #2a0a10;
  --low: #fbbf24;
  --low-bg: #3a2c12;
  --ask: #bfdbfe;
  --ask-bg: #1e2a44;
  --warn-bg: #3f221d;
  --warn-ink: #ffd2cb;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --tab: rgba(22, 19, 16, 0.94);
  --backdrop: rgba(0, 0, 0, 0.62);
  --fresh: #3a261c;
  --danger: #fda4af;
}

:root[data-theme="light"] {
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

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

body {
  background:
    radial-gradient(900px 280px at 0% -10%, rgba(196, 98, 45, 0.14), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.35;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

input,
select,
textarea {
  font-size: 17px;
}

::placeholder {
  color: var(--muted);
  opacity: 1;
}

::selection {
  background: var(--copper-soft);
  color: var(--ink);
}

:focus-visible {
  outline: 3px solid var(--copper);
  outline-offset: 2px;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top,
.main {
  width: min(760px, 100%);
  margin-inline: auto;
}

.top {
  flex: none;
  padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
}

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

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 6vw, 2.15rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
  font-weight: 750;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.summary {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
  min-height: 1.35em;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.search-wrap {
  position: relative;
  display: block;
}

.search-wrap svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search,
.select {
  width: 100%;
  min-height: 52px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  padding: 12px 16px;
}

.search {
  padding-left: 46px;
}

.select {
  appearance: none;
  font-weight: 650;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 14px) 50%;
  background-size: 8px 8px, 8px 8px;
  background-repeat: no-repeat;
  padding-right: 40px;
}

.filters {
  display: flex;
  gap: 8px;
}

.filter {
  min-height: 46px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  font-weight: 700;
  color: var(--muted);
}

.filter.is-on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.main {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px 28px;
}

html.locked .main {
  overflow: hidden;
}

.group {
  margin-top: 6px;
}

.group-title {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 14px 2px 8px;
  background: var(--bg);
  color: var(--copper-dark);
  font-size: 0.98rem;
  font-weight: 750;
  letter-spacing: 0.03em;
}

.group-count {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0;
}

.group-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 78px;
  padding: 14px 16px 14px 18px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  overflow: hidden;
}

.item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: transparent;
}

.item[data-status="low"]::before { background: var(--low); }
.item[data-status="out"]::before { background: var(--out); }
.item[data-status="unconfirmed"]::before { background: var(--ask); }

.item:active {
  transform: scale(0.985);
}

.item-name {
  display: block;
  font-size: 1.14rem;
  font-weight: 720;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.item-note,
.seuil-note {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 750;
  letter-spacing: 0.01em;
}

.badge-low { background: var(--low-bg); color: var(--low); }
.badge-out { background: var(--warn-bg); color: var(--warn-ink); }
.badge-ask { background: var(--ask-bg); color: var(--ask); }

.item-qty {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 72px;
}

.item-num {
  font-size: 1.55rem;
  font-weight: 750;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.item[data-status="out"] .item-num { color: var(--out); }
.item[data-status="low"] .item-num { color: var(--low); }
.item[data-status="unconfirmed"] .item-num { color: var(--ask); }

.item-unit {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.item.is-fresh {
  animation: fresh 900ms ease;
}

@keyframes fresh {
  from { background: var(--fresh); }
  to { background: var(--surface); }
}

.empty {
  margin: 28px 8px;
  padding: 28px 18px;
  border-radius: 20px;
  background: var(--surface);
  text-align: center;
  box-shadow: var(--shadow);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 1.25rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.empty p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.day {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 8px 0;
  padding: 12px 2px 6px;
  background: var(--bg);
  font-size: 0.95rem;
  font-weight: 750;
  color: var(--copper-dark);
}

.move {
  margin-bottom: 10px;
  padding: 14px 16px 10px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.move-name {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 720;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.move-time,
.move-note,
.gone {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 600;
}

.move-delta {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 750;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.move-delta.in { color: var(--in); }
.move-delta.out { color: var(--out); }

.link-danger {
  min-height: 48px;
  margin-top: 6px;
  padding: 8px 2px;
  color: var(--danger);
  font-weight: 750;
  font-size: 1rem;
}

.panel {
  margin-top: 8px;
}

.lede,
.hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 1.02rem;
  font-weight: 550;
}

.section-label {
  margin: 18px 4px 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.settings-group {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.row-btn {
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  text-align: left;
  font-size: 1.08rem;
  font-weight: 700;
  border-top: 1px solid var(--line);
}

.settings-group .row-btn:first-child {
  border-top: 0;
}

.row-btn span {
  color: var(--muted);
  font-weight: 650;
}

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

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.segmented button {
  min-height: 48px;
  border-radius: 12px;
  font-weight: 750;
  color: var(--muted);
}

.segmented button[aria-checked="true"] {
  background: var(--ink);
  color: var(--bg);
}

.tabs {
  flex: none;
  background: var(--tab);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabs-inner {
  width: min(760px, 100%);
  margin-inline: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.tab {
  min-height: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.tab svg {
  width: 24px;
  height: 24px;
}

.tab[aria-current="page"] {
  color: var(--copper-dark);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 14px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.btn:active {
  transform: scale(0.98);
}

.btn-copper {
  background: var(--copper);
  color: var(--on-copper);
}

.btn-ghost {
  background: transparent;
  color: var(--copper-dark);
  min-height: 44px;
  padding: 8px 10px;
}

.btn-quiet {
  background: var(--bg);
  color: var(--ink);
}

.btn-danger {
  background: var(--out);
  color: var(--on-out);
}

.btn-xl {
  min-height: 76px;
  width: 100%;
  border-radius: 18px;
  font-size: 1.28rem;
  line-height: 1.1;
  text-align: center;
  padding: 12px;
}

.btn-in { background: var(--in); color: var(--on-in); }
.btn-out { background: var(--out); color: var(--on-out); }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--backdrop);
  opacity: 0;
  transition: opacity 180ms ease;
}

.backdrop.show { opacity: 1; }

.sheet {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: var(--kb);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--kb) - env(safe-area-inset-top) - 8px);
  max-height: calc(100dvh - var(--kb) - env(safe-area-inset-top) - 8px);
  background: var(--surface);
  color: var(--ink);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.24);
  transform: translateY(110%);
  transition: transform 220ms ease;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  overflow: hidden;
}

.sheet.show { transform: translateY(0); }

.sheet-handle {
  width: 48px;
  height: 5px;
  margin: 8px auto 0;
  border-radius: 999px;
  background: var(--line);
}

.sheet-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px 0 18px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.sheet-stock {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 650;
  font-size: 1.02rem;
}

.sheet-stock strong {
  color: var(--ink);
  font-size: 1.08rem;
}

.sheet-actions-top {
  display: flex;
  flex-shrink: 0;
}

.sheet-body {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 16px 8px;
  -webkit-overflow-scrolling: touch;
}

.sheet-footer {
  flex: none;
  padding: 8px 16px 8px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.commit-label {
  margin: 0 0 8px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.dir-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-weight: 750;
}

.field-label {
  display: block;
}

.optional {
  color: var(--muted);
  font-weight: 650;
}

.qty-input,
.text-input {
  width: 100%;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}

.qty-input {
  min-height: 84px;
  margin-bottom: 12px;
  font-size: 2.75rem;
  font-weight: 750;
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  padding: 8px 12px;
}

.text-input {
  min-height: 52px;
  padding: 12px 14px;
  font-weight: 650;
}

.qty-input:focus,
.text-input:focus,
.search:focus,
.select:focus {
  outline: none;
  border-color: var(--copper);
}

.quick {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}

.quick button {
  min-height: 52px;
  border-radius: 14px;
  background: var(--copper-soft);
  color: var(--copper-dark);
  font-size: clamp(0.95rem, 3.5vw, 1.12rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
}

.banner,
.warn {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 650;
  line-height: 1.35;
}

.banner p,
.warn {
  margin: 0;
}

.banner-ask { background: var(--ask-bg); color: var(--ask); }
.warn { background: var(--warn-bg); color: var(--warn-ink); }

.banner .btn {
  margin-top: 10px;
  background: var(--surface);
  color: var(--ask);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1.5px solid var(--line);
  font-weight: 750;
}

.chip.is-on {
  background: var(--copper-soft);
  border-color: var(--copper);
  color: var(--copper-dark);
}

.unit-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.unit-toggle button {
  min-height: 52px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  font-weight: 800;
  font-size: 1.05rem;
}

.unit-toggle button[aria-checked="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.form-error {
  margin: -4px 0 10px;
  color: var(--out);
  font-weight: 700;
  min-height: 0;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  margin: 4px 0 12px;
  font-weight: 700;
}

.check input {
  width: 22px;
  height: 22px;
  accent-color: var(--copper);
}

.form-submit {
  width: 100%;
  min-height: 60px;
  margin-top: 4px;
  font-size: 1.15rem;
}

.delete-link {
  width: 100%;
  min-height: 52px;
  margin-top: 8px;
  color: var(--danger);
  font-weight: 750;
}

.hint-field {
  margin: -4px 0 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
}

.modal {
  position: fixed;
  z-index: 40;
  left: 50%;
  top: 50%;
  width: min(440px, calc(100vw - 32px));
  padding: 22px 18px 16px;
  border-radius: 22px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  transform: translate(-50%, -42%);
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
}

.modal.show {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 1.4rem;
  letter-spacing: -0.03em;
}

.modal p {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--muted);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions .btn {
  min-height: 54px;
  font-size: 1.05rem;
}

.toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 70;
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
}

html:has(.toast) .sheet {
  bottom: calc(var(--kb) + 168px + env(safe-area-inset-bottom));
}

.sheet-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}

.toast {
  pointer-events: auto;
  width: auto;
  max-width: min(560px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 10px 12px 10px 16px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.toast p {
  margin: 0;
  font-weight: 700;
  line-height: 1.3;
}

.toast button {
  flex: none;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--copper);
  color: var(--on-copper);
  font-weight: 800;
}

.noscript {
  max-width: 36rem;
  margin: 24px auto;
  padding: 0 16px;
  font-size: 1.1rem;
}

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

@media (min-width: 800px) {
  .top,
  .main {
    padding-left: 28px;
    padding-right: 28px;
  }

  .item {
    min-height: 96px;
    padding: 18px 20px 18px 22px;
  }

  .item-name { font-size: 1.35rem; }
  .item-num { font-size: 2rem; }

  .sheet {
    left: 50%;
    right: auto;
    width: min(560px, calc(100vw - 48px));
    bottom: calc(var(--kb) + 24px);
    border-radius: 28px;
    padding-bottom: 12px;
    transform: translate(-50%, 120%);
  }

  .sheet.show { transform: translate(-50%, 0); }

  html:has(.toast) .sheet {
    bottom: calc(var(--kb) + 120px);
  }

  .quick button { min-height: 56px; font-size: 1.15rem; }
  .btn-xl { min-height: 84px; font-size: 1.4rem; }
}

@media (max-width: 360px) {
  .quick { gap: 6px; }
  .quick button { font-size: 0.95rem; padding: 0 2px; }
  .btn-xl { font-size: 1.1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
