/* Buttons, forms, and other reusable components. */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
  background: var(--color-accent);
  color: var(--color-accent-fg);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--font-size-md);
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; }
.btn[disabled], .btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-danger { color: var(--color-danger); }
.btn-archive { color: var(--color-danger); }

/* Reset default fieldset/legend chrome — we wrap groups in <fieldset> for
 * a11y, but never want the browser's default border / inset legend.
 */
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; }

/* Form fields */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--font-size-sm);
  color: var(--color-text);
}
.field > span {
  font-weight: 500;
  color: var(--color-text);
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: var(--space-3);
  font-size: var(--font-size-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 3px solid var(--color-focus);
  outline-offset: 1px;
  border-color: var(--color-accent);
}

.field input[readonly] { background: var(--color-bg); color: var(--color-muted); }

.inline {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-right: var(--space-3);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

/* Errors / messages */
.error {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
}

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

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

/* Bottom nav */
.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-2);
  padding-bottom: max(var(--space-2), env(safe-area-inset-bottom));
  gap: var(--space-1);
  justify-content: space-around;
  z-index: 10;
}
.nav-link {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  padding: var(--space-3) var(--space-1);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  color: var(--color-muted);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 360px) {
  .nav-link { font-size: var(--font-size-xs); }
}
.nav-link:hover { text-decoration: none; }
.nav-link.is-active { color: var(--color-accent); font-weight: 600; }

/* Reserve room for fixed bottom nav so content isn't hidden. We bump the
   container's padding-bottom (rather than body's) because `body` is a
   flex column with min-height:100vh — body padding doesn't grow document
   height when content is short, but the container's does. */
.container { padding-bottom: 96px; }
main.auth-shell { padding-bottom: var(--space-4); }
/* Help scrollIntoView keep clickable items above the fixed bottom nav. */
.btn, .field input, .field select, .field textarea {
  scroll-margin-bottom: 96px;
}

/* Toast */
.toast-root {
  position: fixed;
  top: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: var(--font-size-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.toast-success { background: var(--color-accent-soft); border-color: var(--color-accent); color: var(--color-text); }
.toast-error   { background: var(--color-danger-soft); border-color: var(--color-danger); color: var(--color-danger); }
.toast-leaving { opacity: 0; transition: opacity 0.25s ease; }

.saved-indicator {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-accent);
  color: var(--color-accent-fg);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-sm);
  z-index: 40;
}

/* Tabs */
.tabs {
  display: flex;
  gap: var(--space-2);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
}
.tab {
  padding: var(--space-3) var(--space-3);
  min-height: 44px;
  background: var(--color-bg);
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--color-muted);
  cursor: pointer;
  font-size: var(--font-size-md);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--color-text); }
.tab.is-active {
  color: var(--color-text);
  background: var(--color-surface);
  border-bottom-color: var(--color-accent);
  font-weight: 600;
}

/* Mobile food-new tabs split 50/50; on wider screens they hug content. */
.tabs-pair { gap: 0; }
.tabs-pair .tab {
  flex: 1 1 0;
  text-align: center;
}
@media (min-width: 720px) {
  .tabs-pair { gap: var(--space-2); }
  .tabs-pair .tab { flex: 0 0 auto; }
}

/* In-page section nav (anchor pills under a page H1). */
.section-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.section-nav .tab {
  text-decoration: none;
  border-bottom: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-4);
}
.section-nav .tab:hover { text-decoration: none; }

/* Chips */
.chips {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  cursor: pointer;
}
.chip.is-active { background: var(--color-accent); color: var(--color-accent-fg); border-color: var(--color-accent); }

/* Tags (non-interactive category badges on rows) */
.tag {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 500;
  border: 1px solid transparent;
  line-height: 1.4;
}
.tag-prepped { background: var(--color-accent-soft); color: var(--color-text); }
.tag-fresh { background: var(--color-tag-fresh-bg); color: var(--color-text); }

/* Auth pages */
.auth-shell {
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-6);
}
.brand-mark {
  display: block;
  font-size: 14px;
  color: var(--color-muted);
  text-decoration: none;
  margin-bottom: var(--space-3);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.brand-mark:hover { text-decoration: none; color: var(--color-text); }

/* Foods list */
.foods-list { list-style: none; padding: 0; margin: 0; }
.food-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.food-row-archived { opacity: 0.55; }
.food-row-main { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.food-row-name { font-weight: 600; display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.food-row-meta { font-size: var(--font-size-sm); display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.food-row-actions { display: flex; gap: var(--space-2); }
@media (max-width: 480px) {
  .food-row { grid-template-columns: 1fr; }
  .food-row-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

/* Targets editor */
.targets-editor { border: 0; padding: 0; }
.target-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}
.target-row-input {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.target-row-input input { width: 100px; }
.target-row-unit { color: var(--color-muted); font-size: var(--font-size-sm); }
@media (min-width: 520px) {
  .targets-editor {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
  }
  .targets-editor legend { grid-column: 1 / -1; }
}

.toolbar { margin-bottom: var(--space-4); }

/* Segmented button group (units / BMR mode toggles on profile).
 * Two `.seg` <button> chips inside a `.seg-group` div. The active one
 * carries `aria-pressed="true"`; CSS reads aria-pressed to style. */
.seg-group {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--color-surface);
  padding: 0;
  align-self: flex-start;
}
.seg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  min-height: 44px;
  font-size: var(--font-size-sm);
  background: transparent;
  color: var(--color-muted);
  border: 0;
  margin: 0;
  cursor: pointer;
  border-radius: 0;
  font-weight: 500;
}
.seg + .seg { border-left: 1px solid var(--color-border); }
.seg[aria-pressed="true"] {
  background: var(--color-accent);
  color: var(--color-accent-fg);
}
.seg:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

/* Legacy segmented control (radio-based) — retained for compatibility. */
.segmented {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  padding: 0;
  background: var(--color-surface);
  position: relative;
}
.segmented .segmented-option {
  /* Visually hidden but still focusable + clickable. Labels overlay the
   * radios visually; clicks on the radio itself still work for
   * Playwright's `.check()`. */
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  opacity: 0;
  margin: 0;
  width: 1px;
  height: 1px;
  pointer-events: auto;
}
.segmented label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  min-height: 44px;
  font-size: var(--font-size-sm);
  color: var(--color-muted);
  cursor: pointer;
  background: transparent;
  border: none;
  margin: 0;
  border-radius: 0;
}
.segmented .segmented-option:checked + label {
  background: var(--color-accent);
  color: var(--color-accent-fg);
}
.segmented .segmented-option:focus-visible + label {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}
