/* Shopping list dashboard. One stylesheet for the dashboard and the Teams tab
   configuration page. No external resources: system fonts, no images.

   Themes: light is the default, dark follows the device unless <html data-theme>
   says otherwise (set by the page: the user's choice, or the Teams theme
   default / dark / contrast). */

:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #efeee8;
  --text: #1b231f;
  --muted: #56615b;
  --line: #dddbd2;
  --line-strong: #8a938d;
  --accent: #1f7a4d;
  --accent-strong: #165c39;
  --on-accent: #ffffff;
  --accent-soft: #e3f0e8;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn-bg: #fff3d1;
  --warn-text: #5a4300;
  --warn-line: #e6c65c;
  --toast-bg: #1f2925;
  --toast-text: #f3f6f4;
  --toast-action: #8fe0b4;
  --shadow: 0 1px 2px rgb(20 30 25 / 6%), 0 6px 20px rgb(20 30 25 / 8%);
  --focus: #0b57d0;
  --radius: 12px;
  --radius-small: 8px;
  --topbar-h: 101px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #131715;
    --surface: #1c2220;
    --surface-2: #252d2a;
    --text: #e7ece9;
    --muted: #a3ada8;
    --line: #2f3835;
    --line-strong: #7b8782;
    --accent: #5cc48e;
    --accent-strong: #7ed6a6;
    --on-accent: #0c1a12;
    --accent-soft: #1e3429;
    --danger: #ff8a80;
    --danger-soft: #3b1f1d;
    --warn-bg: #3a3012;
    --warn-text: #ffe08a;
    --warn-line: #6e5a1a;
    --toast-bg: #e7ece9;
    --toast-text: #17201c;
    --toast-action: #165c39;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 45%);
    --focus: #9cc2ff;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #131715;
  --surface: #1c2220;
  --surface-2: #252d2a;
  --text: #e7ece9;
  --muted: #a3ada8;
  --line: #2f3835;
  --line-strong: #7b8782;
  --accent: #5cc48e;
  --accent-strong: #7ed6a6;
  --on-accent: #0c1a12;
  --accent-soft: #1e3429;
  --danger: #ff8a80;
  --danger-soft: #3b1f1d;
  --warn-bg: #3a3012;
  --warn-text: #ffe08a;
  --warn-line: #6e5a1a;
  --toast-bg: #e7ece9;
  --toast-text: #17201c;
  --toast-action: #165c39;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 45%);
  --focus: #9cc2ff;
  color-scheme: dark;
}

/* Teams high contrast: black, white, and yellow for what can be operated. */
:root[data-theme="contrast"] {
  --bg: #000000;
  --surface: #000000;
  --surface-2: #000000;
  --text: #ffffff;
  --muted: #ffffff;
  --line: #ffffff;
  --line-strong: #ffffff;
  --accent: #ffff01;
  --accent-strong: #ffff01;
  --on-accent: #000000;
  --accent-soft: #000000;
  --danger: #ff6e6e;
  --danger-soft: #000000;
  --warn-bg: #000000;
  --warn-text: #ffff01;
  --warn-line: #ffff01;
  --toast-bg: #ffffff;
  --toast-text: #000000;
  --toast-action: #000000;
  --shadow: 0 0 0 2px #ffffff;
  --focus: #1aebff;
  color-scheme: dark;
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  overflow-wrap: anywhere;
}

h1,
h2,
h3,
p,
ul,
ol,
dl,
dd {
  margin: 0;
  padding: 0;
}

ul,
ol {
  list-style: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.5;
}

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

svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-more circle {
  fill: currentColor;
  stroke: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius-small);
  font-weight: 600;
}

.skip-link:focus {
  top: 8px;
}

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  background: none;
  font-weight: 600;
  white-space: nowrap;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.btn-quiet {
  color: var(--accent-strong);
  border-color: var(--line);
  background: var(--surface);
  padding: 0 12px;
}

.btn-quiet:hover:not(:disabled) {
  background: var(--accent-soft);
}

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

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

.btn-block {
  width: 100%;
  margin-top: 12px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: none;
  color: var(--muted);
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.icon-danger:hover:not(:disabled) {
  color: var(--danger);
  background: var(--danger-soft);
}

.input {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.hint {
  font-size: 13px;
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  max-width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.chip svg {
  width: 16px;
  height: 16px;
  color: var(--accent-strong);
}

.chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-sub {
  color: var(--muted);
  font-weight: 400;
}

button.chip:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.chip-empty {
  color: var(--muted);
  font-weight: 400;
  border-style: dashed;
}

.chip-empty svg {
  color: var(--muted);
}

.chip-static {
  min-height: 32px;
  border-color: transparent;
  background: var(--accent-soft);
}

.tag {
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 23px;
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.segment {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1 0 auto;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 20px;
  background: none;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.segment[aria-checked="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.segment:hover:not([aria-checked="true"]) {
  color: var(--text);
  background: var(--surface);
}

.segment-count {
  min-width: 22px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

.segment[aria-checked="true"] .segment-count {
  background: var(--on-accent);
  color: var(--accent-strong);
}

:root[data-theme="contrast"] .segment[aria-checked="true"] .segment-count {
  color: #ffffff;
}

.segmented-small .segment {
  flex: 0 0 auto;
  padding: 0 12px;
  font-size: 13px;
}

/* -------------------------------------------------------------------- gate */

.gate {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}

.gate-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  max-width: 420px;
  text-align: center;
}

.gate-title {
  font-size: 20px;
}

.gate-text {
  color: var(--muted);
}

.spinner {
  display: none;
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.gate-loading .spinner {
  display: block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------------------------------------------ layout */

.app {
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-row,
.views,
main {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 54px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-mark {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.sync-status {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--danger);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.spinning svg {
  animation: spin 0.6s linear;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  max-width: 200px;
  padding: 0 12px 0 5px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
}

.user-chip:hover {
  background: var(--surface-2);
}

.user-initials {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  border: 1px solid transparent;
}

:root[data-theme="contrast"] .user-initials {
  border-color: var(--line);
}

.user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.views {
  display: flex;
  gap: 4px;
  height: 46px;
}

.view-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 0;
  background: none;
  color: var(--muted);
  font-weight: 600;
}

.view-tab::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
}

.view-tab:hover {
  color: var(--text);
}

.view-tab[aria-current="page"] {
  color: var(--accent-strong);
}

.view-tab[aria-current="page"]::after {
  background: var(--accent);
}

.tab-count {
  min-width: 22px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

main {
  padding-top: 16px;
  padding-bottom: 48px;
}

main:focus {
  outline: none;
}

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.view-title {
  font-size: 20px;
  letter-spacing: -0.01em;
}

#view-settings > .view-title {
  margin-bottom: 12px;
}

/* --------------------------------------------------------------- list view */

.storebar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -16px -16px 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.storebar-label {
  flex: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.storebar .segmented {
  flex: 1;
  min-width: 0;
}

.banner {
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid var(--warn-line);
  border-radius: var(--radius-small);
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 14px;
}

.add-form {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.add-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.add-name {
  flex: 1;
  border-color: transparent;
  background: var(--surface-2);
  font-size: 16px;
}

.add-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.suggestions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.suggestions-title {
  flex: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.suggestion-chips {
  display: flex;
  gap: 6px;
  min-width: 0;
  padding: 3px;
  overflow-x: auto;
  scrollbar-width: none;
}

.suggestion-chips::-webkit-scrollbar,
.segmented::-webkit-scrollbar {
  display: none;
}

.suggestion-chips li {
  flex: none;
}

.list-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-wrap svg {
  position: absolute;
  left: 11px;
  top: 10px;
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  padding-left: 38px;
  border-color: var(--line);
}

.list-summary {
  min-height: 20px;
  margin: 8px 2px;
  color: var(--muted);
  font-size: 13px;
}

.groups {
  display: grid;
  gap: 12px;
}

.group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.group-empty {
  display: none;
}

.is-dragging .group-empty {
  display: block;
  border-style: dashed;
}

.group.drop-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
  background: var(--accent-soft);
}

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 8px;
}

.group-title {
  flex: 1;
  min-width: 0;
  font-size: inherit;
}

.group-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  font-weight: 700;
  text-align: left;
}

.group-toggle .icon-chevron {
  width: 16px;
  height: 16px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.group-toggle[aria-expanded="true"] .icon-chevron {
  transform: rotate(90deg);
}

.group-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-count {
  min-width: 22px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  border: 1px solid transparent;
}

:root[data-theme="contrast"] .group-count,
:root[data-theme="contrast"] .segment-count,
:root[data-theme="contrast"] .tag {
  border: 1px solid var(--line);
}

.group-done {
  background: none;
  border-style: dashed;
}

.rows {
  display: block;
}

.row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: 2px 6px 2px 4px;
  border-top: 1px solid var(--line);
}

#history-list {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

#history-list > .row:first-child {
  border-top: 0;
}

.row-static {
  gap: 10px;
  padding: 8px 10px 8px 14px;
}

.row-placeholder {
  padding: 10px 14px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13px;
}

.row-label {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 4px 4px 4px 8px;
  border-radius: var(--radius-small);
  cursor: pointer;
}

.check-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.check-box {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border: 2px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: transparent;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.check-box svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.6;
}

.row-label:hover .check-box {
  border-color: var(--accent);
}

.check-input:checked + .check-box {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.check-input:focus-visible + .check-box {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.row-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.row-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
}

.row-name {
  font-size: 16px;
  font-weight: 600;
}

.qty {
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 600;
}

.row-meta {
  color: var(--muted);
  font-size: 13px;
}

.row-done .row-name {
  color: var(--muted);
  font-weight: 400;
  text-decoration: line-through;
}

.row-done .qty {
  color: var(--muted);
}

.row[draggable="true"] {
  -webkit-user-drag: element;
}

.row-dragging {
  opacity: 0.45;
}

.store-chip {
  flex: 0 1 auto;
  min-width: 0;
}

.scan-status {
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.empty {
  padding: 28px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
}

li.empty {
  border: 0;
}

.empty-title {
  font-size: 16px;
  font-weight: 700;
}

.empty-text {
  margin-top: 4px;
  color: var(--muted);
}

.skeleton {
  min-height: 52px;
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

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

/* ----------------------------------------------------------------- metrics */

.metrics-body {
  display: grid;
  gap: 12px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.tile-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.tile-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.tile-sub {
  color: var(--muted);
  font-size: 12px;
}

.card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.card-title {
  font-size: 15px;
}

.card-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.card-title + :not(.card-sub),
.card-sub + * {
  margin-top: 12px;
}

.card-empty,
.card-text {
  color: var(--muted);
  font-size: 14px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.bars {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 38%) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.bar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  display: block;
  height: 10px;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
}

.bar-value {
  min-width: 24px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
}

.chart {
  display: flex;
  gap: 8px;
  /* Room for the value label above a full-height bar. */
  padding-top: 20px;
}

.chart-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 150px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.cols {
  display: flex;
  align-items: stretch;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.col {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  border-radius: 4px;
}

.col-plot {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 150px;
  border-bottom: 1px solid var(--line-strong);
  background: linear-gradient(var(--line), var(--line)) top / 100% 1px no-repeat;
}

.col-bar {
  display: block;
  flex: none;
  width: min(72%, 28px);
  min-height: 0;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
  opacity: 0.72;
}

.col-current .col-bar,
.col:hover .col-bar,
.col:focus-visible .col-bar {
  opacity: 1;
}

.col-value {
  /* Out of the flow, on top of the bar (dashboard.js sets `bottom`). */
  position: absolute;
  left: 0;
  right: 0;
  visibility: hidden;
  text-align: center;
  line-height: 16px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.col-value-on,
.col:hover .col-value,
.col:focus-visible .col-value {
  visibility: visible;
}

.col-label {
  overflow: hidden;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
}

.col:nth-last-child(even) .col-label {
  visibility: hidden;
}

.chart-tip {
  position: fixed;
  z-index: 60;
  max-width: 240px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 13px;
  pointer-events: none;
}

/* ---------------------------------------------------------------- settings */

.settings-body {
  display: grid;
  gap: 12px;
}

.manage-list {
  display: grid;
  gap: 6px;
}

.manage-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.manage-name {
  flex: 1;
  border-color: var(--line);
}

.manage-count {
  min-width: 28px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.manage-add {
  display: flex;
  gap: 8px;
  max-width: 460px;
}

.manage-list + .manage-add {
  margin-top: 12px;
}

.facts {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 6px 16px;
  font-size: 14px;
}

.facts dt {
  color: var(--muted);
}

/* -------------------------------------------------------- menus and dialogs */

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.menu-backdrop-dim {
  background: rgb(0 0 0 / 40%);
}

.menu {
  position: fixed;
  z-index: 41;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 16px));
  padding: 6px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.menu:focus {
  outline: none;
}

.menu-sheet {
  left: 0;
  right: 0;
  bottom: 0;
  max-width: none;
  max-height: 75vh;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  animation: sheet-up 0.16s ease-out;
}

@keyframes sheet-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 12px 0 8px;
  border: 0;
  border-radius: var(--radius-small);
  background: none;
  text-align: left;
}

.menu-sheet .menu-item {
  min-height: 46px;
  font-size: 16px;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--accent-soft);
}

.menu-item[aria-checked="true"] {
  font-weight: 700;
}

.menu-mark {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--accent-strong);
}

.menu-mark svg {
  width: 18px;
  height: 18px;
}

.menu-danger,
.menu-danger .menu-mark {
  color: var(--danger);
}

.menu-heading {
  padding: 8px 10px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.menu-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--line);
}

.dialog {
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 45%);
}

.dialog-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-title {
  font-size: 18px;
}

.dialog-body {
  display: grid;
  gap: 12px;
}

.dialog-error {
  padding: 8px 12px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-small);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.spacer {
  flex: 1;
}

/* ------------------------------------------------------------------ toasts */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 50;
  display: grid;
  gap: 8px;
  width: min(460px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 16px;
  border-radius: var(--radius);
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}

@keyframes toast-in {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}

.toast-error {
  border-left: 5px solid var(--danger);
}

.toast-text {
  flex: 1;
  min-width: 0;
  padding: 6px 0;
  font-size: 14px;
}

.toast-action {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-small);
  background: none;
  color: var(--toast-action);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.toast .toast-close {
  color: var(--toast-text);
}

.toast .toast-close:hover {
  background: rgb(128 128 128 / 30%);
  color: var(--toast-text);
}

/* --------------------------------------------------- Teams configuration page */

.config-page {
  display: grid;
  gap: 14px;
  max-width: 520px;
  padding: 24px 20px;
}

.config-status {
  color: var(--muted);
}

.config-form {
  display: grid;
  gap: 12px;
}

a {
  color: var(--accent-strong);
}

/* ------------------------------------------------------------- narrow tabs */

@media (max-width: 640px) {
  :root {
    --topbar-h: 50px;
  }

  .topbar-row {
    height: 50px;
    padding-left: 12px;
    padding-right: 8px;
  }

  main {
    padding: 12px 12px calc(84px + env(safe-area-inset-bottom));
  }

  .storebar {
    margin: -12px -12px 10px;
    padding: 8px 12px;
  }

  .storebar-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  /* The view switcher becomes a bottom bar: thumbs reach it in a store. */
  .views {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: auto;
    max-width: none;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    gap: 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
  }

  .view-tab {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 52px;
    padding: 0 4px;
    border-radius: var(--radius-small);
    font-size: 12px;
  }

  .view-tab::after {
    top: 0;
    bottom: auto;
    left: 28%;
    right: 28%;
    border-radius: 0 0 3px 3px;
  }

  .tab-count {
    position: absolute;
    top: 4px;
    left: calc(50% + 6px);
    min-width: 18px;
    padding: 0 5px;
    font-size: 11px;
    line-height: 18px;
  }

  .toasts {
    bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .user-chip {
    min-width: 40px;
    padding: 0 5px;
    justify-content: center;
  }

  .user-name {
    display: none;
  }

  #scan-btn {
    padding: 0 10px;
    font-size: 13px;
  }

  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .add-details {
    grid-template-columns: 1fr 1fr;
  }

  .add-details .field:first-child {
    grid-column: 1 / -1;
  }

  .suggestions {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  .store-chip {
    min-width: 40px;
    padding: 0 10px;
    justify-content: center;
  }

  .store-chip .chip-text {
    max-width: 84px;
  }

  .store-chip.chip-empty .chip-text {
    display: none;
  }

  .row-meta {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }

  .view-head {
    align-items: flex-start;
    flex-direction: column;
  }

  /* Narrow columns: label every third week, centred under its bar. */
  .col-label {
    align-self: center;
    overflow: visible;
    font-size: 11px;
  }

  .cols .col .col-label {
    visibility: hidden;
  }

  .cols .col:nth-last-child(3n + 1) .col-label {
    visibility: visible;
  }

  .manage-add {
    max-width: none;
  }
}

@media (max-width: 380px) {

  .field-pair {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .segment[aria-checked="true"],
  .check-input:checked + .check-box,
  .view-tab[aria-current="page"] {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }

  .bar-fill,
  .col-bar {
    forced-color-adjust: none;
    background: Highlight;
  }
}
