/* ai.css — the AI capture sheet (apps/pwa/js/ai_capture.js).
 *
 * Every class is prefixed `ai-` so this stylesheet can never collide with a tab.
 * Colour comes only from the base.css tokens: black / grey / white with the one
 * red accent, which stays reserved for the primary action (.btn-primary, from
 * base) and for the over-budget style of warnings. No new hues.
 */

.ai-body {
  display: grid;
  gap: 14px;
}

.ai-step,
.ai-review,
.ai-unavailable,
.ai-picker-wrap {
  display: grid;
  gap: 12px;
}

.ai-lede {
  font: 400 var(--fs-3)/1.5 var(--font);
  color: var(--ink-2);
}

.ai-field {
  display: grid;
  gap: 6px;
}

.ai-label {
  font: 500 var(--fs-2)/1.4 var(--font);
  color: var(--ink-2);
}

.ai-text {
  min-height: 96px;
  resize: vertical;
  line-height: 1.45;
}

.ai-actions {
  display: grid;
  gap: 10px;
  margin-top: 2px;
}

.ai-actions-split {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
}

/* The actions keep base.css's .btn look; they only need to survive a 390px
 * sheet without wrapping "Estimate from photo" onto a second line. */
.ai-go,
.ai-save,
.ai-back,
.ai-manual {
  min-width: 0;
  padding-inline: 12px;
  white-space: nowrap;
}

.ai-hint-input {
  font-size: var(--fs-4);
}

/* ------------------------------------------------------------- loading -- */

.ai-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 96px;
  padding: 18px 2px;
  color: var(--ink-2);
  font: 500 var(--fs-4)/1.4 var(--font);
}

.ai-spinner {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  animation: ai-spin .8s linear infinite;
}

.ai-loading-text { color: var(--ink-2); }

@keyframes ai-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .ai-spinner { border-top-color: var(--line); }
}

/* --------------------------------------------------------- unavailable -- */

.ai-unavailable-title {
  font: 600 var(--fs-5)/1.35 var(--font);
  color: var(--ink);
}

.ai-reason {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font: 400 var(--fs-3)/1.5 var(--font);
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.ai-hint {
  font: 400 var(--fs-2)/1.5 var(--font);
  color: var(--ink-3);
}

/* The server's own how_to_enable, one line per step. Monospaced because every
 * line is a command to be typed exactly, and scrollable because a key export
 * is longer than any phone is wide. */
.ai-enable {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.ai-steps {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ai-error {
  border-left: 3px solid var(--red);
  padding: 2px 0 2px 10px;
  font: 500 var(--fs-3)/1.5 var(--font);
  color: var(--ink);
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------- the live camera - */

.ai-camera {
  display: grid;
  gap: 8px;
}

.ai-stage {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  line-height: 0;
}

.ai-stage[hidden] { display: none; }

.ai-video {
  display: block;
  width: 100%;
  max-height: 46dvh;
  object-fit: cover;
}

.ai-cam-controls { display: grid; gap: 8px; }

/* Two controls while the camera is live: the shutter takes the width it needs,
 * stopping sits beside it rather than under the thumb. */
.ai-cam-controls:has(.ai-cam-stop) {
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
}

.ai-cam-status {
  font: 400 var(--fs-2)/1.45 var(--font);
  color: var(--ink-2);
  min-height: 1.45em;
  overflow-wrap: anywhere;
}

/* -------------------------------------------------------------- photo --- */

.ai-picker {
  position: relative;
  display: grid;
  gap: 2px;
  justify-items: center;
  align-content: center;
  min-height: 88px;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  text-align: center;
}

.ai-picker:hover { border-color: var(--ink-3); }
/* Build Spec 4 C3: a focus ring is the person's accent, not red. --red keeps
   its single job here too — destructive, and over a limit. */
.ai-picker:focus-within { outline: 2px solid var(--accent-ink); outline-offset: 2px; }

.ai-picker-label { font: 600 var(--fs-4)/1.3 var(--font); color: var(--ink); }
.ai-picker-sub { font: 400 var(--fs-2)/1.4 var(--font); color: var(--ink-3); }

/* Visually hidden, still focusable and still the real control. */
.ai-file {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.ai-preview {
  display: grid;
  gap: 6px;
  margin: 0;
}

.ai-preview-img {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.ai-preview-name {
  font: 400 var(--fs-2)/1.4 var(--font);
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

/* Buttons keep base.css's .btn look; these only stop the labels wrapping. */
.ai-cam-start,
.ai-cam-shot,
.ai-cam-stop,
.ai-to-portion {
  min-width: 0;
  padding-inline: 12px;
  white-space: nowrap;
}

/* ------------------------------------------------------ portion guide --- */

.ai-portion { gap: 14px; }

.ai-hands {
  display: grid;
  gap: 10px;
}

.ai-hand {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* A counted row steps forward; an empty one stays quiet. Greyscale only —
 * red is for the primary action, not for "you put rice on the plate". */
.ai-hand-on { border-color: var(--ink-3); }

.ai-hand-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* The size cue: the four shapes carry the relative volume of the portions. */
.ai-hand-glyph {
  flex: none;
  width: 32px;
  height: 32px;
  fill: var(--ink-3);
}

.ai-hand-on .ai-hand-glyph { fill: var(--ink-2); }

.ai-hand-name {
  flex: 1 1 auto;
  min-width: 0;
  font: 600 var(--fs-5)/1.25 var(--font);
  color: var(--ink);
}

.ai-hand-stands { font: 400 var(--fs-2)/1.35 var(--font); color: var(--ink-3); }

.ai-hand-step {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-hand-kind {
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  background: var(--surface);
  color: var(--ink);
}

.ai-hand-btn {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: 500 var(--fs-6)/1 var(--font);
  cursor: pointer;
}

.ai-hand-btn:hover { border-color: var(--ink-3); }

/* Same control, two directions — named apart so the markup reads and so a
 * future asymmetry has somewhere to live. */
.ai-hand-minus,
.ai-hand-plus { letter-spacing: 0; }

.ai-hand-count {
  width: 56px;
  min-width: 0;
  padding: 10px 2px;
  text-align: center;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  -moz-appearance: textfield;
  appearance: textfield;
}

.ai-hand-count::-webkit-outer-spin-button,
.ai-hand-count::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

.ai-hand-macros {
  font: 400 var(--fs-1)/1.35 var(--font);
  color: var(--ink-3);
}

.ai-hand-on .ai-hand-macros { color: var(--ink-2); }

/* ------------------------------------------------------------- review --- */

.ai-review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

/* base.css's `.pill`, to the declaration — ai_capture.js builds these two spans
 * by hand instead of calling ui.pill(). Keep them identical; delete this rule
 * once the sheet uses ui.pill. */
.ai-badge,
.ai-confidence {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font: 600 var(--fs-2)/1.3 var(--font);
  background: var(--surface-2);
  color: var(--ink-2);
  white-space: nowrap;
}

.ai-confidence { color: var(--ink-3); }

.ai-note {
  font: 400 var(--fs-3)/1.5 var(--font);
  color: var(--ink-2);
}

.ai-empty {
  font: 400 var(--fs-4)/1.5 var(--font);
  color: var(--ink-3);
  padding: 6px 0;
}

.ai-items {
  display: grid;
  gap: 10px;
}

.ai-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.ai-item-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
}

.ai-name,
.ai-macro { background: var(--surface); }

/* Where a number came from, when it did not come from the estimate: a saved
 * food beat the model, and the row says so rather than quietly changing. */
.ai-from {
  font: 500 var(--fs-1)/1.35 var(--font);
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

.ai-remove {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-3);
  font: 500 var(--fs-5)/1 var(--font);
  cursor: pointer;
}

/* Greyscale even here: red stays reserved for the primary action and for
 * things that are actually wrong (.ai-error). */
.ai-remove:hover { color: var(--ink); background: var(--surface); }

.ai-macros {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 6px;
}

.ai-macro-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.ai-macro-label {
  font: 500 var(--fs-1)/1.3 var(--font);
  color: var(--ink-3);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-macro {
  padding: 10px 4px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  -moz-appearance: textfield;
  appearance: textfield;
}

.ai-macro::-webkit-outer-spin-button,
.ai-macro::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

.ai-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.ai-total {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.ai-total-v { font: 700 var(--fs-6)/1.2 var(--font); color: var(--ink); }
.ai-total-k { font: 500 var(--fs-1)/1.2 var(--font); color: var(--ink-3); }
.ai-total-kcal .ai-total-v { font-size: var(--fs-7); }

.ai-slot {
  display: grid;
  gap: 6px;
}

/* ---------------------------------------------------------- responsive -- */

@container (max-width: 376px) {
  .ai-macros { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ai-actions-split { grid-template-columns: minmax(0, 1fr); }
  .ai-totals { gap: 10px; }
  .ai-back,
  .ai-save,
  .ai-go { font-size: var(--fs-4); }
}

/* ================================================= l'interrogatoire (A′) ==
 *
 * Build Spec 4 Workstream A′. The screen where an estimate is a RANGE and two
 * chosen questions are the instrument that narrows it. Everything here obeys
 * the same rule as the rest of the file: greyscale, the person's accent for the
 * one live affordance in view, and red kept back for the single thing that is
 * actually wrong.
 */

.ai-interro { gap: 14px; }

/* The description is the instrument, so it gets the height a dictated sentence
 * needs — three lines before it scrolls, not one. */
.ai-desc { min-height: 84px; }

.ai-venue { width: 100%; }

/* ---- the camera, demoted to a disclosure ---- */

/* §E8: the photo finds the items, the words find the portions. So the camera is
 * one tap below the description rather than the thing that opens first. */
.ai-more {
  display: grid;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.ai-more-btn {
  justify-self: start;
  width: auto;
  min-width: 0;
  padding: 10px 12px;
  font-size: var(--fs-3);
}

.ai-more-body { display: grid; gap: 12px; }

/* ---- the library chips (§E7) ---- */

.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-chips:empty { display: none; }

.ai-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  max-width: 100%;
}

.ai-chip:hover { border-color: var(--accent-mark); }

.ai-chip-name {
  font: 500 var(--fs-3)/1.2 var(--font);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chip-macros {
  font-size: var(--fs-1);
  color: var(--ink-3);
  flex: none;
}

/* ---- the band ---- */

/* The headline is the RANGE, not a number — the whole point of the workstream
 * is that the honest answer has a width. */
.ai-band {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.ai-band-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.ai-band-k {
  font: 500 var(--fs-1)/1.2 var(--font);
  color: var(--ink-3);
}

.ai-band-v {
  font-size: var(--fs-6);
  font-weight: 600;
  color: var(--ink);
}

/* Which rung of the ladder answered, when it was not the model. */
.ai-path {
  font-size: var(--fs-1);
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

/* ---- the questions ---- */

.ai-qs { display: grid; gap: 12px; }

.ai-q {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.ai-q-text {
  font: 600 var(--fs-4)/1.35 var(--font);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.ai-q-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* A chip is the answer, so it is a real thumb target — 44px, like everything
 * else that gets tapped. */
.ai-q-chip {
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font: 500 var(--fs-4)/1.2 var(--font);
  cursor: pointer;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.ai-q-chip:hover { border-color: var(--ink-3); }

.ai-q-chip-on {
  border-color: var(--accent-mark);
  background: var(--accent-wash);
  color: var(--ink);
}

.ai-q-said {
  font: 400 var(--fs-2)/1.4 var(--font);
  color: var(--ink-3);
}

/* The budget, stated. Two rounds and four questions is a ratified cap, not a
 * quota to be quietly exceeded. */
.ai-cap {
  font: 400 var(--fs-1)/1.4 var(--font);
  color: var(--ink-3);
  letter-spacing: .02em;
}

/* ---- the estimate, item by item ---- */

.ai-est-item {
  display: grid;
  gap: 3px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.ai-est-name {
  font: 500 var(--fs-5)/1.3 var(--font);
  overflow-wrap: anywhere;
}

.ai-est-desc {
  font: 400 var(--fs-2)/1.4 var(--font);
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

.ai-est-band {
  font-size: var(--fs-3);
  color: var(--ink-2);
}

.ai-fix {
  justify-self: start;
  width: auto;
  min-width: 0;
  padding: 10px 12px;
  font-size: var(--fs-3);
}

/* What will actually reach the ledger, and at which percentile. The number is
 * loud because it is the only one on this screen that is not a range. */
.ai-point {
  display: grid;
  gap: 2px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.ai-point-v {
  font-size: var(--fs-7);
  font-weight: 700;
  color: var(--ink);
}

.ai-point-k {
  order: -1;
  font: 500 var(--fs-1)/1.2 var(--font);
  color: var(--ink-3);
}

.ai-point-why {
  font: 400 var(--fs-2)/1.45 var(--font);
  color: var(--ink-3);
}

/* ---- what it could not see, and what it assumed instead ---- */

.ai-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ai-flag {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font: 500 var(--fs-2)/1.3 var(--font);
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.ai-assume { display: grid; gap: 6px; }

.ai-assume-title {
  font: 600 var(--fs-2)/1.3 var(--font);
  color: var(--ink-2);
}

.ai-assume-line {
  font: 400 var(--fs-2)/1.5 var(--font);
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

/* A statement that the instrument stopped short. Not an error — an admission,
 * which is why it is bordered rather than red. */
.ai-warn {
  font: 400 var(--fs-3)/1.5 var(--font);
  color: var(--ink-2);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

/* ---- save to library (§E7, the flywheel) ---- */

.ai-lib {
  display: grid;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.ai-lib-btn {
  justify-self: start;
  width: auto;
  min-width: 0;
  padding: 10px 14px;
  font-size: var(--fs-3);
}

.ai-lib-name { width: 100%; }

/* ---- the unavailable panel's own two lists ---- */

.ai-next {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
}

.ai-next-line {
  font: 400 var(--fs-2)/1.5 var(--font);
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

/* A near match is a real route, not a consolation: tapping it resolves the meal
 * from the library rung with no model at all. So it looks like a button. */
.ai-near { display: grid; gap: 6px; }

.ai-near-row {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ai-near-row:hover { border-color: var(--accent-mark); }

.ai-near-name {
  font: 500 var(--fs-4)/1.3 var(--font);
  overflow-wrap: anywhere;
}

.ai-near-macros { font-size: var(--fs-2); color: var(--ink-2); }

.ai-near-why {
  font: 400 var(--fs-1)/1.4 var(--font);
  color: var(--ink-3);
  overflow-wrap: anywhere;
}

@container (max-width: 376px) {
  .ai-band-v { font-size: var(--fs-5); }
  .ai-point-v { font-size: var(--fs-6); }
  .ai-q-chip { font-size: var(--fs-3); padding: 10px 12px; }
}
