/* CPQ controls: buttons, fields and choices. Tokens only. Sizes and rules are in DESIGN-NOTES.md; every one is live in lab.html. */

/* ---------- Buttons ----------
   One primary per screen (it lives in the Omnibar). Labels are one or two words. 48 px high; 44 px for .small. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--hba-space-2);
  min-height: 48px; min-width: 64px; padding: 0 var(--hba-space-4); border-radius: var(--hba-radius-control);
  border: var(--hba-border-thin) solid transparent; background: none; color: var(--hba-text-primary);
  font-weight: var(--hba-font-weight-bold); text-decoration: none; white-space: nowrap;
  transition: transform var(--hba-duration-fast);
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--hba-action-primary); color: var(--hba-action-on-primary); }
.btn.primary:active { background: var(--hba-action-primary-pressed); }
.btn.secondary { background: var(--hba-surface-page); color: var(--hba-action-secondary-text); border-color: var(--hba-action-secondary-border); }
.btn.secondary:active, .btn.text:active { background: var(--hba-action-secondary-pressed-surface); }
.btn.text { color: var(--hba-action-link); padding: 0 var(--hba-space-3); }
.btn.danger { background: var(--hba-action-danger); color: var(--hba-action-on-danger); }
.btn.danger:active { background: var(--hba-action-danger-pressed); }
.btn.small { min-height: var(--hba-size-touch); }
.btn.wide { width: 100%; }
/* Not ready: still tappable, and it answers with why. Never a dead grey button with no reason */
.btn[aria-disabled="true"] { background: var(--hba-control-disabled-surface); color: var(--hba-control-disabled-text); border-color: transparent; }
/* Busy: smooth living pulse (anti-spinner standard) and a second tap does nothing */
.btn[aria-busy="true"] { pointer-events: none; }
.btn .spin, .spin {
  width: 10px; height: 10px; flex: none; border-radius: 50%;
  background: currentColor; border: 0;
  animation: hba-busy-pulse 920ms var(--spring-effects, ease-in-out) infinite;
}
@keyframes hba-busy-pulse {
  0%, 100% { transform: scale(0.65); opacity: 0.4; }
  50% { transform: scale(1.1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .btn .spin, .spin { animation: none; opacity: 0.65; } }
/* Icon-only button: a 44 px tap area, and it always has an aria-label */
.icon-btn { width: var(--hba-size-touch); height: var(--hba-size-touch); flex: none; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--hba-text-primary); }
.icon-btn:active { background: var(--hba-action-secondary-pressed-surface); }

/* ---------- Field: label above, control, then a message row that is always there so nothing jumps ---------- */
.field { display: grid; gap: var(--hba-space-1); }
.field > label, .field > .label { font-weight: var(--hba-font-weight-bold); }
.field .opt { font-weight: var(--hba-font-weight-regular); color: var(--hba-text-muted); font-size: var(--hba-type-size-small); }
.field .hint { font-size: var(--hba-type-size-small); color: var(--hba-text-muted); }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 0 var(--hba-space-3); border-radius: var(--hba-radius-control);
  border: var(--hba-border-thin) solid var(--hba-line-control); background: var(--hba-surface-page); color: var(--hba-text-primary);
  font-family: inherit; font-size: var(--hba-type-size-input);   /* 16 px: smaller makes iPhones zoom the page */
}
.textarea { padding: var(--hba-space-3); min-height: 96px; line-height: var(--hba-type-leading-body); resize: vertical; }
.select { appearance: none; -webkit-appearance: none; padding-inline-end: var(--hba-space-7);
  background-image: linear-gradient(45deg, transparent 50%, var(--hba-text-muted) 50%), linear-gradient(135deg, var(--hba-text-muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) 21px, calc(100% - 16px) 21px; background-size: 6px 6px; background-repeat: no-repeat; }
[dir="rtl"] .select { background-position: 16px 21px, 22px 21px; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline-offset: 0; border-color: var(--hba-action-primary); }
.field .msg { min-height: 20px; display: flex; align-items: center; gap: var(--hba-space-1); font-size: var(--hba-type-size-small); line-height: 1.4; color: var(--hba-text-muted); }
.field.bad .input, .field.bad .select, .field.bad .textarea { border-color: var(--hba-status-danger); border-width: var(--hba-border-thick); }
.field.bad .msg { color: var(--hba-status-danger); font-weight: var(--hba-font-weight-bold); }
.field.good .msg { color: var(--hba-status-success); }
/* Search field: icon inside, 48 px */
.search { position: relative; }
.search .input { padding-inline-start: 44px; border-radius: 24px; }
.search > svg { position: absolute; inset-inline-start: var(--hba-space-3); top: 14px; color: var(--hba-text-muted); pointer-events: none; }

/* ---------- Choices: the whole row is the tap area, 48 px ---------- */
.choice { display: flex; align-items: center; gap: var(--hba-space-3); min-height: 48px; padding: var(--hba-space-1) 0; }
.choice input { appearance: none; -webkit-appearance: none; flex: none; width: 24px; height: 24px; margin: 0; display: grid; place-items: center;
  border: var(--hba-border-thick) solid var(--hba-line-control); background: var(--hba-surface-page); }
.choice input[type="checkbox"] { border-radius: var(--hba-radius-control); }
.choice input[type="radio"] { border-radius: 50%; }
.choice input:checked { border-color: var(--hba-action-primary); background: var(--hba-action-primary); }
.choice input[type="checkbox"]:checked::after { content: ""; width: 12px; height: 6px; margin-top: -3px; border: solid var(--hba-action-on-primary); border-width: 0 0 3px 3px; transform: rotate(-45deg); }
.choice input[type="radio"]:checked::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--hba-action-on-primary); }
.choice small { display: block; font-size: var(--hba-type-size-small); color: var(--hba-text-muted); }
/* Switch: takes effect at once, no Save. If it needs Save, use a checkbox */
.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--hba-space-3); min-height: 48px; }
.switch input { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 52px; height: 32px; margin: 0; border-radius: 16px;
  background: var(--hba-surface-alt); border: var(--hba-border-thick) solid var(--hba-line-control); transition: background var(--hba-duration-fast); }
.switch input::after { content: ""; position: absolute; top: 4px; inset-inline-start: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--hba-line-control); transition: transform var(--hba-duration-fast); }
.switch input:checked { background: var(--hba-action-primary); border-color: var(--hba-action-primary); }
.switch input:checked::after { transform: translateX(20px); background: var(--hba-action-on-primary); }
[dir="rtl"] .switch input:checked::after { transform: translateX(-20px); }

/* ---------- Chips: filters that can be on or off. 44 px tap area, 36 px look ---------- */
.chips { display: flex; flex-wrap: wrap; gap: var(--hba-space-1) var(--hba-space-2); }
.chip { min-height: var(--hba-size-touch); display: inline-flex; align-items: center; padding: 0; border: 0; background: none; }
.chip span { display: inline-flex; align-items: center; gap: var(--hba-space-1); height: 36px; padding: 0 var(--hba-space-3); border-radius: 18px;
  border: var(--hba-border-thin) solid var(--hba-line-control); background: var(--hba-surface-page); font-size: var(--hba-type-size-small); white-space: nowrap; }
.chip[aria-pressed="true"] span { background: var(--hba-surface-selected); border: var(--hba-border-thick) solid var(--hba-action-primary); font-weight: var(--hba-font-weight-bold); }

/* ---------- Counts, dots and deadlines. Always words or a number with the colour ---------- */
.count-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 var(--hba-space-1); border-radius: 10px;
  background: var(--hba-text-primary); color: var(--hba-surface-page); font-size: var(--hba-type-size-small); line-height: 1; font-weight: var(--hba-font-weight-bold); }
.count-badge.alert { background: var(--hba-status-danger); }
.due { display: inline-flex; align-items: center; gap: var(--hba-space-1); font-size: var(--hba-type-size-small); line-height: 1.3; white-space: nowrap; color: var(--hba-text-muted); }
.due.soon { color: var(--hba-status-warning); font-weight: var(--hba-font-weight-bold); }
.due.over { color: var(--hba-status-danger); font-weight: var(--hba-font-weight-bold); }
.due.done { color: var(--hba-status-success); }

/* ---------- Progress ---------- */
.bar { height: 8px; border-radius: 4px; background: var(--hba-surface-alt); border: var(--hba-border-thin) solid var(--hba-line-decorative); overflow: hidden; }
/* The fill is full width and scaled from the start edge (--v is 0 to 1), so growing it moves no layout */
.bar > i { display: block; width: 100%; height: 100%; border-radius: 4px; background: var(--hba-action-primary); transform: scaleX(var(--v, 0)); transform-origin: left; transition: transform var(--hba-duration-base); }
[dir="rtl"] .bar > i { transform-origin: right; }
.bar.busy > i { width: 40%; transform: none; animation: hba-slide 1.4s ease-in-out infinite; }
@keyframes hba-slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) { .bar.busy > i { animation: none; width: 100%; opacity: 0.5; } }
/* Steps through a flow: words first, the bar is extra */
.steps { display: grid; gap: var(--hba-space-1); font-size: var(--hba-type-size-small); color: var(--hba-text-muted); }

/* ---------- Slide to issue: for the one action that should never happen by a stray tap ---------- */
.slide { position: relative; height: 56px; border-radius: 28px; background: var(--hba-surface-alt); border: var(--hba-border-thin) solid var(--hba-line-control); touch-action: pan-y; user-select: none; -webkit-user-select: none; overflow: hidden; }
.slide .way { position: absolute; inset: 0; display: grid; place-items: center; padding-inline-start: 56px; font-weight: var(--hba-font-weight-bold); color: var(--hba-text-muted); }
.slide .knob { position: absolute; top: 3px; left: 3px; width: 48px; height: 48px; border: 0; border-radius: 50%; display: grid; place-items: center; background: var(--hba-action-primary); color: var(--hba-action-on-primary); }
.slide.done { background: var(--hba-status-success-soft); border-color: var(--hba-status-success); }
.slide.done .way { color: var(--hba-status-success); padding-inline-start: 0; }
.slide.done .knob { display: none; }
