/* Theme palette: light by default, dark via [data-theme="dark"] */
:root {
  color-scheme: light;
  --shell: #314a5e;
  --ink: #21140e;
  --mute: #5e5750;
  --bg: #f4f3f0;
  --card: #fff;
  --line: #e0dbcf;
  --field: #b3ac98;
  --accent: #4078b5;
  --on: #fff;
  --olive: #5d6442;
  --oon: #fff;
  --sand: #baa178;
  --good: #5d6442;
  --warn: #94661a;
  --bad: #a5402d;
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --shell: #22384a;
  --ink: #efe8dc;
  --mute: #a79e90;
  --bg: #17110e;
  --card: #231a15;
  --line: #3a2e27;
  --field: #5a4b40;
  --accent: #7db0e3;
  --on: #0f1a24;
  --olive: #8e9a68;
  --oon: #1a1f0c;
  --good: #a3b073;
  --warn: #e2b458;
  --bad: #ec8f7a;
}

/* Base and shell bar */
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    16px/1.4 '72',
    '72full',
    -apple-system,
    'Segoe UI',
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}
main {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(52px + env(safe-area-inset-top) + 16px) 16px 0;
}
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 7;
  height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0 8px;
  background: var(--shell);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}
h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}
h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 10px;
}
#mb {
  width: auto;
  padding: 9px;
  line-height: 0;
  color: #fff;
  background: none;
  border: 0;
}

/* Cards and form controls */
.card,
form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
label {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin: 12px 0 4px;
}
label:first-child {
  margin-top: 0;
}
input,
select,
button {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--field);
  border-radius: 8px;
  padding: 11px 12px;
}
input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.hint,
.meta {
  color: var(--mute);
  font-size: 0.82rem;
  margin-top: 3px;
}
.primary {
  background: var(--accent);
  color: var(--on);
  border: 0;
  font-weight: 600;
  margin-top: 16px;
}
.primary:disabled {
  opacity: 0.5;
}
#msg {
  min-height: 1.3em;
  margin: 0 0 10px;
  font-weight: 600;
  font-size: 0.92rem;
}
#msg.err {
  color: var(--bad);
}
#msg.ok {
  color: var(--good);
}

/* Dashboard tiles and grids */
.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  min-height: 104px;
  justify-content: flex-end;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}
.tile b {
  font-size: 2.25rem;
  font-weight: 300;
  line-height: 1.1;
}
.tile span {
  color: var(--mute);
  font-size: 0.86rem;
  font-weight: 600;
}
.tile.soon b {
  color: var(--warn);
}
.tile.bad b {
  color: var(--bad);
}
.tile.jar {
  background: var(--olive);
  border-color: var(--olive);
}
.tile.jar b,
.tile.jar span {
  color: var(--oon);
}
.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  align-items: start;
}
.grid .card {
  margin: 0;
}

/* Lists, status pills and filter chips */
.item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 11px 8px;
  margin: 0 -8px;
  border-bottom: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.item:last-child {
  border-bottom: 0;
}
.item.sel {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.grow {
  flex: 1;
  min-width: 0;
}
.right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.pill {
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 2px 9px;
  border-radius: 99px;
  background: color-mix(in srgb, currentColor 13%, transparent);
}
.pill.bad {
  color: var(--bad);
}
.pill.soon {
  color: var(--warn);
}
.pill.ok {
  color: var(--mute);
  background: none;
  padding: 0;
  font-weight: 400;
}
.pill.ok.g {
  color: var(--good);
  background: color-mix(in srgb, currentColor 13%, transparent);
  padding: 2px 9px;
  font-weight: 600;
}
.use {
  width: auto;
  padding: 5px 12px;
  font-size: 0.85rem;
  color: var(--accent);
  border-color: var(--accent);
  background: none;
}
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin: 12px 0;
}
.chips button {
  width: auto;
  white-space: nowrap;
  padding: 7px 14px;
  border-radius: 99px;
  font-size: 0.88rem;
}
.chips button.on {
  background: var(--accent);
  color: var(--on);
  border-color: var(--accent);
}
.empty {
  color: var(--mute);
  padding: 6px 0;
}

/* Group breakdown bars and add-stock lines */
.hb {
  display: grid;
  grid-template-columns: 110px 1fr 36px;
  gap: 8px;
  align-items: center;
  padding: 5px 0;
  font-size: 0.88rem;
}
.hb span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hb div {
  height: 10px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.hb i {
  display: block;
  height: 100%;
  background: var(--olive);
}
.hb b {
  text-align: right;
  font-weight: 600;
}
.ln {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}
.ln .row {
  margin-top: 8px;
}
div.tile {
  cursor: default;
}

/* Stock page: list plus detail panel */
.master {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
}
#detail {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  max-height: 80vh;
  overflow: auto;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.3);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(105%);
  visibility: hidden;
  transition: transform 0.2s;
}
#detail.open {
  transform: none;
  visibility: visible;
}
.dh {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
#dx {
  width: auto;
  padding: 2px 12px;
  font-size: 1.4rem;
  line-height: 1.2;
  border: 0;
  background: none;
}
.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.kv span {
  color: var(--mute);
}
.kv b {
  font-weight: 600;
  text-align: right;
}

/* Navigation drawer */
#scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 5;
}
#scrim[hidden] {
  display: none;
}
#drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(280px, 80vw);
  background: var(--card);
  border-right: 1px solid var(--line);
  z-index: 6;
  padding: calc(60px + env(safe-area-inset-top)) 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform 0.2s;
}
#drawer.open {
  transform: none;
  visibility: visible;
}
#drawer a,
#drawer button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}
#drawer a.on {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}
#drawer hr {
  border: 0;
  border-top: 1px solid var(--line);
  width: 100%;
  margin: 8px 0;
}

/* Vertical bar charts */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 118px;
}
.bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  font-size: 0.72rem;
  color: var(--mute);
}
.bar i {
  display: block;
  width: 100%;
  min-height: 2px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
}
.bar i.olive {
  background: var(--olive);
}
.bar i.sand {
  background: var(--sand);
}
.bar i.bad {
  background: var(--bad);
}
.bar span {
  color: var(--ink);
}

/* Reduced motion, then desktop layout (900px and wider) */
@media (prefers-reduced-motion: reduce) {
  #drawer,
  #detail {
    transition: none;
  }
}
@media (min-width: 900px) {
  body {
    padding-left: 220px;
  }
  main {
    max-width: 1160px;
    padding-left: 28px;
    padding-right: 28px;
  }
  #mb,
  #scrim {
    display: none !important;
  }
  #drawer {
    transform: none;
    visibility: visible;
    z-index: 3;
    top: calc(52px + env(safe-area-inset-top));
    width: 220px;
    padding-top: 12px;
  }
  header {
    padding-left: 16px;
  }
  .tiles {
    grid-template-columns: repeat(4, 1fr);
  }
  .master {
    grid-template-columns: minmax(0, 1fr) 380px;
    align-items: start;
  }
  #detail {
    position: sticky;
    top: calc(52px + env(safe-area-inset-top) + 16px);
    transform: none;
    visibility: visible;
    max-height: calc(100vh - 100px);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: none;
    padding: 16px;
  }
  #dx {
    display: none;
  }
  #view > .primary {
    width: auto;
    padding: 12px 24px;
  }
}
