/* Task Vending Machine - styles. Colors are defined once here.
   Screen sizes: the layout is one column that fits any width from a small phone up.
   Two adjustments are made near the end of this file ("screen sizes"): a wider column on
   wide screens (tablets, PC), and slimmer bars on short screens (a phone held sideways). */
:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --surface-2: #efe9e0;
  --text: #1f1b16;
  --muted: #6b6258;
  --border: #ddd4c7;
  --accent: #d9480f;
  --accent-hover: #c13f0b;
  --accent-text: #ffffff;
  --accent-soft: #fde5d7;
  --good: #2b8a3e;
  --danger: #c92a2a;
  --danger-soft: #fde2e2;
  --warn: #b35900;
  --warn-soft: #fff0d6;
  --radius: 14px;
  --tabbar-h: 64px;
  --col: 640px; /* the widest the column of content gets */
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --surface: #221e18;
    --surface-2: #2d2820;
    --text: #f3ede4;
    --muted: #a99f92;
    --border: #3d362c;
    --accent: #ff7a3d;
    --accent-hover: #ff8f5c;
    --accent-text: #1a0f08;
    --accent-soft: #4a2412;
    --good: #69db7c;
    --danger: #ff8787;
    --danger-soft: #4a1d1d;
    --warn: #ffc078;
    --warn-soft: #43300f;
  }
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- the app's frame ----------
   The page as a whole never scrolls. A frame is pinned to the four edges of the screen and
   holds three parts, top to bottom: the title bar, the middle (<main>), and the tab bar.
   Only the middle scrolls, so the two bars cannot drift out of place, whatever the screen
   size or which way up the device is held. ("html.app" = the app itself; the login page
   has no frame and is an ordinary scrolling page.) */
html.app, html.app body { overflow: hidden; overscroll-behavior: none; }
html.app body {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column;
}
/* On-screen keyboard open: the frame shrinks to the part of the screen above the keyboard
   (--vv-top and --vv-height are measured by initKeyboardRoom in app.js). */
html.app.kb-open body { top: var(--vv-top, 0px); bottom: auto; height: var(--vv-height, 100%); }
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; }
code { font-size: 0.92em; background: var(--surface-2); padding: 0 4px; border-radius: 4px; }

/* "safe-area-inset-..." = the strip at each edge of an iPhone/iPad screen taken up by the
   notch, the rounded corners or the home bar. Content is kept out of those strips. */
.topbar {
  position: relative; z-index: 5; flex: none;
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  touch-action: none; /* dragging on the bar does nothing (it can't pull the page about) */
}
.topbar h1 { font-size: 1.3rem; text-align: center; }
html.kb-tight .topbar { display: none; } /* keyboard open on a very short screen: every line counts */

main { max-width: var(--col); margin: 0 auto; padding: 16px; }
/* The middle of the frame: the only part that scrolls. It is as wide as the screen (so the
   scroll bar sits at the edge) and the content inside it is a centred column. */
html.app main {
  flex: 1 1 auto; min-height: 0; max-width: none; margin: 0;
  overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;          /* scrolling stops here; it never tugs the whole page */
  scrollbar-gutter: stable both-edges;   /* PC: content doesn't shift when the scroll bar comes and goes */
  padding: 16px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
  scroll-padding: 12px 0 16px;           /* a little air around anything scrolled into view */
}
html.app main > .screen { max-width: var(--col); margin-left: auto; margin-right: auto; }
html.modal-open main { overflow: hidden; } /* a pop-up is open: see initModalScrollLock in app.js */
@media (pointer: coarse) {
  /* Touch screens: the middle can always move by a hair, so a finger dragging on it gets
     the usual springy scroll instead of trying to drag the whole page. */
  html.app main > .screen { min-height: calc(100% + 1px); }
}
.screen > * + * { margin-top: 18px; }

/* ---------- form controls ---------- */
.field { display: block; }
.label { display: block; font-weight: 600; font-size: 0.95rem; margin-bottom: 8px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  font: inherit; font-size: 17px; /* 16px+ stops iPhone zooming in on tap */
  color: var(--text); background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 12px;
  padding: 12px 14px; min-height: 50px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .pill:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px;
  border-color: var(--accent);
}
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%23888' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
/* iPhone gives date and time boxes a built-in minimum width and its own look, which pushed
   them past the edge of the Scheduling box. Make them behave like the other boxes. */
input[type="date"], input[type="time"] {
  appearance: none; -webkit-appearance: none;
  display: block; min-width: 0; text-align: left;
}
input::-webkit-date-and-time-value { text-align: left; margin: 0; min-height: 1.45em; }
input::-webkit-datetime-edit-fields-wrapper { padding: 0; } /* PC: same height as the other boxes */
.date-box { position: relative; }
.date-placeholder {
  position: absolute; left: 15.5px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.date-box:not(.is-empty) .date-placeholder, .date-box:focus-within .date-placeholder { display: none; }
.date-box.is-empty input:not(:focus) { color: transparent; } /* hides the PC's "yyyy-mm-dd" under "No date" */
.time-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }

/* A two-way switch: Serve's All / Today, the Inbox tab's Inbox / Done. */
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px;
  background: var(--surface-2); border-radius: 14px;
}
.segmented .pill { min-height: 44px; min-width: 0; background: transparent; border-color: transparent; border-radius: 11px; }
.segmented .pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pills-3 { display: grid; grid-template-columns: repeat(3, 1fr); }
.pill {
  min-height: 48px; padding: 0 16px;
  font: inherit; font-weight: 600; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px;
  cursor: pointer; touch-action: manipulation;
}
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 0 18px;
  font: inherit; font-weight: 650; text-decoration: none; color: var(--text);
  background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 12px;
  cursor: pointer; touch-action: manipulation;
}
.btn:disabled { opacity: 0.55; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
@media (hover: hover) {
  .btn-primary:hover { background: var(--accent-hover); }
  .pill:hover, .btn:not(.btn-primary):hover { border-color: var(--muted); }
}
.btn-danger { color: var(--danger); background: transparent; }
.btn-quiet { background: transparent; }
.btn-outline { background: transparent; border: 2px solid var(--accent); color: var(--accent); }
.any-task .hint { margin-top: 6px; font-size: 0.85rem; text-align: center; }
.serve-shortcuts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.serve-shortcuts .btn { min-width: 0; padding: 0 8px; }
.btn-block { width: 100%; }
.btn-big { min-height: 60px; font-size: 1.15rem; }
.btn-small { min-height: 44px; padding: 0 14px; font-size: 0.95rem; }

.hint { color: var(--muted); font-size: 0.93rem; margin: 0; }
.form-error { color: var(--danger); font-weight: 600; margin: 0; }

/* ---------- serve screen ---------- */
.serve-result { scroll-margin-top: 4px; }
.serve-result > * + * { margin-top: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.task-card { padding: 20px; border-width: 2px; }
.task-card.is-urgent { border-color: var(--danger); }
.task-card.is-relatively-urgent { border-color: var(--warn); }
.fallback-note {
  display: inline-block; margin-bottom: 10px; padding: 4px 10px; border-radius: 8px;
  background: var(--accent-soft); color: var(--text); font-size: 0.88rem; font-weight: 600;
}
.serve-label {
  display: inline-block; margin-bottom: 10px; padding: 3px 10px; border-radius: 999px;
  border: 1.5px solid var(--accent); color: var(--accent); font-size: 0.8rem; font-weight: 700;
}
.task-position { color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }
.task-title { font-size: 1.65rem; line-height: 1.2; overflow-wrap: anywhere; }
.task-notes { white-space: pre-wrap; margin: 14px 0 0; overflow-wrap: anywhere; }
.serve-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.empty-fit {
  text-align: center; padding: 32px 16px; font-size: 1.2rem; font-weight: 600;
  color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 0.85rem; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.chip-urgent { background: var(--danger-soft); color: var(--danger); }
.chip-relatively-urgent { background: var(--warn-soft); color: var(--warn); }

/* ---------- scheduling (collapsible) ---------- */
.sched {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
}
.sched summary {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  min-height: 52px; padding: 10px 16px; cursor: pointer; list-style: none;
}
.sched summary::-webkit-details-marker { display: none; }
.sched summary::before {
  content: ""; width: 8px; height: 8px; flex: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s;
}
.sched[open] summary::before { transform: rotate(45deg); }
.sched-title { font-weight: 650; }
.sched-summary { color: var(--muted); font-size: 0.93rem; margin-left: auto; }
.sched-body { padding: 4px 16px 16px; }
.sched-body > * + * { margin-top: 16px; }
.sched-body .hint { margin-top: 6px; font-size: 0.85rem; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.link-button {
  min-height: 36px; padding: 0 4px; margin-bottom: 4px;
  font: inherit; font-size: 0.93rem; font-weight: 650; color: var(--accent);
  background: none; border: none; cursor: pointer;
}
.inline-row { display: flex; align-items: center; gap: 8px; }
.inline-row input { flex: 1; min-width: 0; padding-left: 10px; padding-right: 6px; }
.inline-row .to { color: var(--muted); }
.pills-7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.pills-7 .pill { padding: 0; font-size: 0.88rem; min-width: 0; }

.chip-schedule { background: transparent; border: 1.5px solid var(--border); }
.chip-missing { background: var(--warn-soft); color: var(--warn); }
.not-now {
  display: inline-block; margin-bottom: 8px; padding: 3px 10px; border-radius: 8px;
  background: var(--warn-soft); color: var(--warn); font-size: 0.85rem; font-weight: 650;
}
.card.is-unavailable { border-style: dashed; }
.card.is-unavailable .list-title { color: var(--muted); }

/* ---------- today (day lists) ---------- */
.day-picker > * + * { margin-top: 8px; }
.day-nav { display: grid; grid-template-columns: 52px 1fr 52px; gap: 8px; }
.day-arrow { padding: 0; font-size: 1.6rem; line-height: 1; }
.day-quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.day-quick .pill { min-height: 44px; min-width: 0; }
.day-label {
  display: inline-block; margin-top: 8px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); font-size: 0.78rem; font-weight: 600;
}
.row-actions.row-actions-move { gap: 8px; }
.row-actions-minor.row-actions-move .btn { padding: 0 4px; min-width: 0; font-size: 0.8rem; }
.move-day > * + * { margin-top: 10px; }
.move-day-quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.today-empty > * + * { margin-top: 14px; }

/* ---------- capture ---------- */
.capture-box { min-height: 150px; font-size: 1.15rem; }
/* The Today switch at the top of Capture: plain when off, highlighted when on. */
.today-toggle[aria-pressed="true"] {
  background: var(--accent-soft); border: 2px solid var(--accent); color: var(--accent);
}

/* ---------- lists ---------- */
/* Section header rows ("Tasks · 6" + a button): one line, both centred, and always the
   same gap before what comes next. (Lists have margin: 0, which used to remove that gap.) */
.section-head {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 8px 12px; min-height: 44px;
}
.section-head > h2 { flex: 1 1 auto; min-width: 0; }
.section-head > .btn { flex: none; }
main .section-head + * { margin-top: 12px; }
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.list-title { font-weight: 650; font-size: 1.05rem; overflow-wrap: anywhere; }
.list .task-notes { margin-top: 8px; font-size: 0.95rem; color: var(--muted); }
.list-meta { color: var(--muted); font-size: 0.85rem; margin-top: 6px; }
.task-dates { color: var(--muted); font-size: 0.78rem; margin-top: 8px; line-height: 1.35; }
.task-progress { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.progress-link { display: block; margin-top: 6px; font-size: 0.85rem; }
.progress-list { list-style: none; margin: 0; display: grid; gap: 12px; }
ul.progress-list:not(.sched-body) { padding: 0; }
.progress-entry { padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.progress-entry:last-child { padding-bottom: 0; border-bottom: 0; }
.progress-when { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.progress-note { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.progress-note.is-empty { color: var(--muted); font-style: italic; }
.progress-actions { display: flex; gap: 18px; margin-top: 6px; }
.link-button.danger { color: var(--danger); }
.optional { font-weight: 400; }
.draft-missing { margin-top: 8px; font-size: 0.85rem; font-weight: 600; color: var(--warn); }
.row-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.row-actions .btn { flex: 1; min-height: 46px; }
.row-actions-minor { margin-top: 8px; gap: 24px; }
.row-actions-minor .btn { min-height: 40px; font-size: 0.9rem; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

/* All Tasks and Today: drag to reorder (see initTaskReorder in app.js) */
.tasks-hint { font-size: 0.85rem; }
.tasks-hint + .list { margin-top: 12px; }
.card-head { display: flex; align-items: flex-start; gap: 8px; }
.card-head .list-title { flex: 1; min-width: 0; }
.drag-handle {
  flex: none; width: 44px; height: 44px; margin: -10px -10px -8px 0;
  display: grid; place-items: center; border-radius: 10px;
  font-size: 1.6rem; line-height: 1; color: var(--muted);
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.reorder-list > li { -webkit-touch-callout: none; }
@media (pointer: coarse) {
  /* On a touch screen a long press lifts the card, so it mustn't select text instead. */
  .reorder-list > li { user-select: none; -webkit-user-select: none; }
}
.reorder-list > li.make-room { transition: transform .18s ease; }
.reorder-list > li.is-dragging {
  position: relative; z-index: 3; cursor: grabbing;
  border-color: var(--accent); box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
}
html.dragging, html.dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

.import-card > * + * { margin-top: 12px; }
.import-card p { margin: 0; }
.format {
  margin: 0; padding: 10px 12px; font-size: 0.85rem; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--surface-2); border-radius: 8px;
}
.format-help { margin: 0; padding-left: 20px; font-size: 0.93rem; }
.format-help li + li { margin-top: 4px; }
.import-ok { color: var(--good); font-weight: 600; margin: 0; }
.import-errors { margin: 8px 0 0; padding-left: 20px; color: var(--danger); font-size: 0.93rem; }
.import-errors li + li { margin-top: 6px; }
.import-errors q { color: var(--text); }

/* ---------- bottom tab bar ---------- */
/* Hidden while the on-screen keyboard is up or on its way: see initKeyboardWatch in app.js */
html.kb-coming .tabbar, html.kb-open .tabbar { display: none; }
.tabbar {
  position: relative; z-index: 10; flex: none;
  display: grid; grid-template-columns: repeat(6, 1fr);
  /* The bar spans the screen; its six buttons stay within the column of content. */
  padding: 0 max(env(safe-area-inset-right), calc((100% - var(--col)) / 2))
           env(safe-area-inset-bottom) max(env(safe-area-inset-left), calc((100% - var(--col)) / 2));
  background: var(--surface);
  border-top: 1px solid var(--border);
  touch-action: none; /* taps only: dragging on the bar does nothing */
}
.tabbar a {
  position: relative;
  height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 0.7rem; font-weight: 600;
}
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: var(--accent-text);
  font-size: 0.72rem; line-height: 20px; text-align: center;
}

/* ---------- groceries ---------- */
.store-bar { display: flex; align-items: center; gap: 8px; }
.store-select { flex: 1 1 auto; width: auto; min-width: 0; min-height: 52px; font-weight: 650; }
.store-bar > .btn { flex: none; min-height: 52px; }

.quick-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.quick-add textarea { resize: none; min-height: 52px; font-size: 1.05rem; line-height: 1.35; }
.quick-add .btn { min-height: 52px; min-width: 76px; }
.keep-box { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; font-size: 0.9rem; color: var(--muted); cursor: pointer; }
.keep-box input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
#gi-form .keep-box { color: inherit; font-size: 1rem; }
#gi-form .keep-box + .hint { margin-top: 2px; }
.qa-more summary, .groc-section summary {
  cursor: pointer; min-height: 44px; display: flex; align-items: center;
  font-weight: 650; color: var(--muted);
}
.qa-more summary::-webkit-details-marker, .groc-section summary::-webkit-details-marker { display: none; }
.qa-more summary::before, .groc-section summary::before {
  content: ""; width: 8px; height: 8px; margin: 0 12px 0 4px; flex: none;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s;
}
.qa-more[open] summary::before, .groc-section[open] summary::before { transform: rotate(45deg); }
.qa-more > * + * { margin-top: 12px; }
#groc-main > * + * { margin-top: 12px; }
#groc-main > .keep-box { margin-top: 6px; }
.qa-more[open] { padding-bottom: 8px; }
#groc-main > .groc-head { margin-top: 20px; }
#groc-active > .gcat:first-child { margin-top: 0; }
.qa-more summary { font-size: 0.93rem; }

.suggest, .glist { list-style: none; margin: 0; padding: 0; }
.suggest {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.suggest li + li { border-top: 1px solid var(--border); }
.suggest-item {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  min-height: 52px; padding: 8px 14px; font: inherit; color: var(--text); background: none; border: 0; cursor: pointer;
}
.suggest-plus {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 1.1rem;
}

.dup-panel {
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--warn-soft); color: var(--text); border: 1.5px solid var(--warn);
}
.dup-panel p { margin: 0; }
.dup-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.gcat {
  margin: 18px 0 6px; font-size: 0.82rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}
.glist { display: grid; gap: 6px; }
.gitem {
  display: flex; align-items: stretch;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  transition: box-shadow .3s, border-color .3s;
}
.gitem-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; text-align: left;
  min-height: 56px; padding: 8px 12px; font: inherit; color: var(--text);
  background: none; border: 0; cursor: pointer; touch-action: manipulation;
}
.gcheck {
  flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted);
}
.gitem.is-bought .gcheck { background: var(--good); border-color: var(--good); position: relative; }
.gitem.is-bought .gcheck::after {
  content: ""; position: absolute; left: 7px; top: 3px; width: 7px; height: 12px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}
.gitem.is-bought .gitem-name { text-decoration: line-through; color: var(--muted); }
.gitem-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gitem-name { font-weight: 600; font-size: 1.05rem; overflow-wrap: anywhere; }
.gqty {
  margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: 0.85rem; font-weight: 650;
  background: var(--surface-2); color: var(--text);
}
.gnotes { font-size: 0.88rem; color: var(--muted); overflow-wrap: anywhere; }
.galso { font-size: 0.8rem; font-weight: 600; color: var(--accent); }
.gitem-edit {
  flex: none; min-width: 64px; padding: 0 12px; font: inherit; font-size: 0.9rem; font-weight: 600;
  color: var(--muted); background: none; border: 0; border-left: 1px solid var(--border); cursor: pointer;
}
.gitem.flash { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); }
.groc-section > * + * { margin-top: 10px; }
.groc-section .btn { width: 100%; }
#groc-active .glist + .gcat { margin-top: 22px; }

dialog.sheet { padding: 20px; }
.sheet-body > * + * { margin-top: 14px; }
.sheet-message { margin: 0; }
.sheet-buttons { display: grid; gap: 8px; }
.orphan-list { margin: 6px 0 0; padding-left: 20px; }
.store-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.store-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.store-row-name { font-weight: 650; }
.store-row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.store-row-actions .btn { min-width: 44px; padding: 0 12px; }
.store-manager > * + * { margin-top: 14px; }

/* ---------- login page & log out link ---------- */
main.login {
  max-width: 420px; text-align: center;
  padding: calc(env(safe-area-inset-top) + 48px) 16px calc(env(safe-area-inset-bottom) + 32px);
}
main.login > * + * { margin-top: 18px; }
.login-icon { border-radius: 20px; }
.login h1 { font-size: 1.5rem; }
.login-card { text-align: left; }
.login-card > * + * { margin-top: 16px; }
.login-message {
  margin: 18px 0 0; padding: 12px 14px; border-radius: 12px;
  background: var(--danger-soft); color: var(--danger); font-weight: 600;
}
.logout-link {
  position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: 12px;
  font-size: 0.85rem; font-weight: 600; color: var(--muted); text-decoration: none;
  padding: 4px 0;
}

/* ---------- dialogs & toast ---------- */
dialog {
  width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 40px);
  padding: 20px; border: none; border-radius: 18px;
  background: var(--bg); color: var(--text); overflow: auto;
  overscroll-behavior: contain; /* scrolling stops at the pop-up's top and bottom */
}
/* Keyboard open: fit the pop-up into the part of the screen above it. */
html.kb-open dialog[open] {
  top: calc(var(--vv-top, 0px) + 10px); bottom: auto; margin-top: 0;
  max-height: calc(var(--vv-height, 100dvh) - 20px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog form > * + * { margin-top: 16px; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast {
  position: absolute; left: 50%; z-index: 20; /* placed within the app's frame */
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600; text-align: center;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
html.kb-open .toast { bottom: 14px; } /* keyboard open: just above the keyboard */

/* The screen readout: tap any one tab five times quickly (see initScreenReadout in app.js). */
.diag {
  position: absolute; z-index: 30; left: 8px; right: 8px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  max-width: 520px; margin: 0 auto; padding: 10px 12px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.88); color: #fff;
  font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer;
}
html.kb-open .diag { bottom: 8px; }

/* ---------- screen sizes ---------- */
/* Wide screens (tablets, a PC window): a wider column. */
@media (min-width: 700px) {
  :root { --col: 720px; }
}
/* Short screens (a phone held sideways): slimmer bars, so more of the list fits. */
@media (max-height: 500px) {
  :root { --tabbar-h: 46px; }
  .topbar { padding-top: calc(env(safe-area-inset-top) + 6px); padding-bottom: 6px; }
  .topbar h1 { font-size: 1.05rem; }
  .logout-link { bottom: 4px; }
  html.app main { padding-top: 12px; padding-bottom: 16px; }
  .tabbar a { flex-direction: row; gap: 6px; font-size: 0.75rem; }  /* picture beside the word */
  .tabbar svg { width: 22px; height: 22px; }
  .badge { position: static; margin-left: -1px; }
  dialog { max-height: calc(100dvh - 16px); }
}
