/* style.css */

/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f8f8f8;
  --text: #1c1c1e;
  --text-secondary: #6c6c70;
  --text-tertiary: #aeaeb2;
  --border: #e5e5ea;
  --accent: #1a1a2e;
  --accent-fg: #ffffff;

  --green: #34c759;
  --green-bg: #e8f9ed;
  --green-text: #1a7a31;
  --amber: #ff9500;
  --amber-bg: #fff6e0;
  --amber-text: #7a4800;
  --red: #ff3b30;
  --red-bg: #ffebea;
  --red-text: #7a0f00;
  --blue-bg: #e5f1ff;
  --blue-text: #0a52a0;
  --purple-bg: #ede8ff;
  --purple-text: #4c1d95;
  --teal-bg: #e0f5f5;
  --teal-text: #0e6b6b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --tab-bar-height: 56px;
  --header-height: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { cursor: pointer; font: inherit; border: none; background: none; }
input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ── App shell ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Views ──────────────────────────────────────────────────────────────────── */
.view {
  display: none;
  flex-direction: column;
  flex: 1;
  padding-bottom: calc(var(--tab-bar-height) + var(--safe-bottom));
}
.view.active { display: flex; }

/* ── App header ─────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-height);
  background: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}
.app-header h1 { font-size: 17px; font-weight: 600; flex: 1; }
.header-title { font-size: 17px; font-weight: 600; flex: 1; }

/* ── Tab bar (mobile) ───────────────────────────────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: calc(var(--tab-bar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-tertiary);
  padding: 8px 0;
  transition: color 0.15s;
}
.tab-btn.active { color: var(--accent); font-weight: 600; }

/* ── Scrollable main content ────────────────────────────────────────────────── */
.view-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}
.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-icon-settings { font-size: 18px; color: var(--text-secondary); }
.btn-icon-settings:active { opacity: 0.7; }
.btn-back {
  color: var(--accent);
  font-size: 22px;
  padding: 4px 8px 4px 0;
  display: flex;
  align-items: center;
}
.btn-text {
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  padding: 4px;
}
.btn-danger { color: var(--red); }

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  width: 100%;
}
.btn-secondary:active { opacity: 0.7; }

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 64px 24px;
  font-size: 15px;
}
.empty-state p { margin-top: 8px; font-size: 13px; color: var(--text-tertiary); }

/* ── Event card (events list) ───────────────────────────────────────────────── */
.event-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.event-card:active { opacity: 0.75; }
.event-card-row { display: flex; align-items: center; gap: 8px; }
.event-card-name { font-weight: 600; font-size: 16px; flex: 1; }
.event-card-meta { font-size: 13px; color: var(--text-secondary); }

.past-events-section { margin-top: 8px; }
.past-events-summary {
  display: flex;
  align-items: center;
  padding: 10px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.past-events-summary::-webkit-details-marker { display: none; }
.past-events-summary::before {
  content: '›';
  display: inline-block;
  margin-right: 6px;
  font-size: 16px;
  transition: transform 0.15s;
}
.past-events-section[open] > .past-events-summary::before { transform: rotate(90deg); }
.past-events-list { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }

/* ── Fuel running total ─────────────────────────────────────────────────────── */
.fuel-totals-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
  user-select: none;
  background: var(--surface);
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}
.fuel-totals-summary::-webkit-details-marker { display: none; }
.fuel-totals-summary::before {
  content: '›';
  display: inline-block;
  margin-right: 4px;
  font-size: 16px;
  line-height: 1;
  transition: transform 0.15s;
  color: var(--text-tertiary);
}
.fuel-totals-section[open] > .fuel-totals-summary { border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.fuel-totals-section[open] > .fuel-totals-summary::before { transform: rotate(90deg); }
.fuel-label-text { flex: 1; }
.fuel-count-chip {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1px 7px;
  white-space: nowrap;
}
.fuel-totals-list {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 2px 0 6px;
}
.fuel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  gap: 8px;
}
.fuel-row-name { font-size: 13px; color: var(--text); flex: 1; }
.fuel-row-type { font-size: 11px; color: var(--text-tertiary); }
.fuel-row-qty {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 48px;
  text-align: right;
}
.type-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--blue-bg);
  color: var(--blue-text);
}

/* ── Event detail meta row ──────────────────────────────────────────────────── */
.event-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 0;
}
.event-meta-date { font-size: 13px; color: var(--text-secondary); }

/* ── Metric summary cards ───────────────────────────────────────────────────── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 16px;
  background: var(--accent);
  flex-shrink: 0;
}
.summary-cards--two {
  grid-template-columns: repeat(2, 1fr);
}
.metric-card {
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  color: #fff;
}
.metric-value { font-size: 20px; font-weight: 700; line-height: 1.1; }
.metric-label { font-size: 10px; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.3px; margin-top: 2px; }
.metric-rate { font-size: 11px; opacity: 0.85; margin-top: 4px; }

/* ── Segment section ────────────────────────────────────────────────────────── */
.segment-section {
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.segment-header {
  background: var(--surface-2);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.segment-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.segment-name {
  font-weight: 600;
  font-size: 15px;
}
.segment-duration {
  font-size: 13px;
  color: var(--text-secondary);
}
.segment-targets-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.target-pill {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  border-radius: 20px;
  padding: 3px 9px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.target-pill:active { background: var(--border); }
.editable {
  border-bottom: 1px dashed var(--text-tertiary);
  cursor: pointer;
  min-width: 20px;
  display: inline-block;
}
.inline-edit {
  border: none;
  border-bottom: 2px solid var(--accent);
  background: transparent;
  font: inherit;
  outline: none;
  min-width: 40px;
  max-width: 120px;
}

/* ── Progress bars ──────────────────────────────────────────────────────────── */
.progress-group {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}
.progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.progress-label { font-size: 12px; color: var(--text-secondary); width: 52px; flex-shrink: 0; }
.progress-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  width: calc(var(--pct, 0) * 1%);
  max-width: 100%;
  transition: width 0.25s ease;
  background: var(--text-tertiary);
}
.progress-row.status-on-target .progress-fill { background: var(--green); }
.progress-row.status-warning-under .progress-fill,
.progress-row.status-warning-over .progress-fill { background: var(--amber); }
.progress-row.status-under .progress-fill,
.progress-row.status-over .progress-fill { background: var(--red); }
.progress-value { font-size: 12px; color: var(--text-secondary); min-width: 58px; width: auto; text-align: right; flex-shrink: 0; white-space: nowrap; }

/* ── Item rows ──────────────────────────────────────────────────────────────── */
.item-list { padding: 0 0 4px; }
.item-row {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.item-row:last-child { border-bottom: none; }
.item-info { flex: 1; min-width: 0; }
.item-name { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Quantity stepper ───────────────────────────────────────────────────────── */
.stepper {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.stepper-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.stepper-btn:active { background: var(--border); }
.stepper-qty {
  font-size: 17px;
  font-weight: 600;
  min-width: 28px;
  text-align: center;
}

/* ── Fractional quantity ────────────────────────────────────────────────────── */
.qty-frac-trigger,
.qty-actual-frac-trigger {
  border-bottom: 1.5px dashed var(--text-tertiary);
  cursor: pointer;
  padding-bottom: 1px;
}
.qty-frac-trigger.open,
.qty-actual-frac-trigger.open { color: var(--accent); border-bottom-color: var(--accent); }

.qty-frac-dropdown {
  position: fixed;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  z-index: 200;
  min-width: 80px;
  overflow: hidden;
}
.qty-frac-option {
  display: block;
  width: 100%;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.qty-frac-option:last-child { border-bottom: none; }
.qty-frac-option.selected { color: var(--accent); font-weight: 700; }
.qty-frac-option:active { background: var(--bg); }

.qty-frac-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  padding: 8px 16px 4px;
  text-align: right;
}

/* ── Add item button ────────────────────────────────────────────────────────── */
.btn-add-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  color: var(--accent);
  font-weight: 500;
  font-size: 14px;
  border-top: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
}
.btn-add-item:active { background: var(--bg); }

/* ── Food log actuals block (carb load detail view) ─────────────────────────── */
.food-log-actuals {
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
}
.food-log-actuals-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.food-log-actuals-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
}

/* ── Totals footer ──────────────────────────────────────────────────────────── */
.totals-footer {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ── Bottom sheet ───────────────────────────────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  padding-top: 10dvh;
  justify-content: center;
}
.sheet-overlay.hidden { display: none; }
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}
.sheet-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sheet-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sheet-tab-btn {
  flex: 1;
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  text-align: center;
}
.sheet-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.sheet-tab-content { display: none; flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px; }
.sheet-tab-content.active { display: flex; flex-direction: column; }

/* ── Search input ───────────────────────────────────────────────────────────── */
.search-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}
.search-input:focus { border-color: var(--accent); }

/* ── Search wrap (input + clear button) ─────────────────────────────────────── */
.search-wrap {
  position: relative;
  margin-bottom: 12px;
}
.search-wrap .search-input {
  padding-right: 36px;
  margin-bottom: 0;
  width: 100%;
}
.fl-sheet-search-wrap {
  position: relative;
  margin: 0 16px 8px;
  width: calc(100% - 32px);
  flex-shrink: 0;
}
.fl-sheet-search-wrap .fl-sheet-search {
  margin: 0;
  width: 100%;
  padding-right: 34px;
}
.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: var(--text-tertiary);
  color: var(--bg);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  font-size: 10px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}
.search-clear.visible { display: flex; }
.search-wrap input[type="search"]::-webkit-search-cancel-button,
.fl-sheet-search-wrap input[type="search"]::-webkit-search-cancel-button { display: none; }

/* ── Section label ──────────────────────────────────────────────────────────── */
.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
  padding: 0 2px;
}

/* ── Product rows (library and sheet) ──────────────────────────────────────── */
.product-row {
  display: flex;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.product-row:last-child { border-bottom: none; }
.product-row:active { opacity: 0.6; }
.product-row-info { flex: 1; min-width: 0; }
.product-row-name { font-weight: 500; font-size: 15px; }
.product-row-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.product-type-chip {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-secondary);
  flex-shrink: 0;
}
.lib-brand-pill {
  font-size: 11px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-secondary);
  margin-left: 4px;
  vertical-align: middle;
}
.lib-fuel-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  margin-left: auto;
  vertical-align: middle;
  float: right;
}

/* Ad-hoc tab parsed result */
.adhoc-parsed-result {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.adhoc-parsed-name { font-weight: 500; font-size: 15px; }
.adhoc-parsed-meta { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.form-input {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  outline: none;
  width: 100%;
  touch-action: manipulation;
  text-align: left;
}
.form-input:focus { border-color: var(--accent); }
/* iOS Safari date input: prevent the browser chrome from centering the value */
input[type="date"].form-input {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 8px;
  min-height: 48px;
  line-height: normal;
}
.form-row {
  display: flex;
  gap: 10px;
}
.form-row .form-group { flex: 1; min-width: 0; }

/* Stack form rows on narrow phones so date/select inputs have enough width */
@media (max-width: 480px) {
  .form-row { flex-direction: column; }
}
.form-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.form-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}
.form-section-header h3 { font-size: 15px; font-weight: 600; }

/* ── Toggle ─────────────────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}
.toggle-label { font-size: 15px; }
.toggle-input { width: 44px; height: 26px; appearance: none; background: var(--border); border-radius: 13px; cursor: pointer; position: relative; transition: background 0.2s; }
.toggle-input:checked { background: var(--green); }
.toggle-input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.toggle-input:checked::after { transform: translateX(18px); }

/* ── Library grouped list ───────────────────────────────────────────────────── */
.product-group { margin-bottom: 8px; }
.product-group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: capitalize;
  padding: 12px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

/* ── Segment totals line ────────────────────────────────────────────────────── */
.segment-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 16px 8px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.segment-totals span::after { content: ' ·'; }
.segment-totals span:last-child::after { content: ''; }

/* ── Misc polish ────────────────────────────────────────────────────────────── */
.segment-header { cursor: default; }
.target-pill:hover { background: var(--border); }
.editable:hover { border-bottom-color: var(--accent); }

/* Smooth view transitions */
.view { animation: none; }
.view.active { animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Top nav (base — hidden on mobile) ──────────────────────────────────────── */
.top-nav { display: none; }
.top-nav-link { display: none; }
.top-nav-cta { display: none; }
.btn-new-product-desktop { display: none; }
#btn-settings-nav { display: none; }

/* ── Desktop layout (≥ 768px) ───────────────────────────────────────────────── */
@media (min-width: 768px) {
  /* Show top nav, hide mobile tab bar */
  .top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    height: 58px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
    flex-shrink: 0;
  }

  .top-nav-brand {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.2px;
    flex-shrink: 0;
  }

  .top-nav-links {
    display: flex;
    align-items: center;
    gap: 2px;
  }

  #btn-settings-nav {
    background: transparent;
    margin-left: 8px;
  }

  .top-nav-link {
    display: inline-flex;
    align-items: center;
    padding: 7px 14px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
    /* reset mobile tab-btn styles */
    flex-direction: row;
    gap: 0;
    white-space: nowrap;
  }

  .top-nav-link:hover {
    color: var(--text);
    background: var(--bg);
  }

  .top-nav-link.active {
    color: var(--accent);
    font-weight: 600;
    background: var(--bg);
  }

  .top-nav-cta {
    display: inline-flex;
    align-items: center;
    padding: 7px 16px;
    font-size: 14px;
    font-weight: 600;
    background: var(--accent);
    color: var(--accent-fg);
    border-radius: var(--radius-sm);
    margin-left: 10px;
    transition: opacity 0.15s;
  }

  .top-nav-cta:hover { opacity: 0.82; }

  /* Hide mobile bottom tab bar */
  .tab-bar { display: none !important; }

  /* Remove tab-bar bottom clearance */
  .view { padding-bottom: 0; }

  /* Hide per-view headers on list views — top nav handles navigation */
  #view-events .app-header,
  #view-library .app-header,
  #view-food-log .app-header { display: none; }

  /* Show top-nav gear, hide in-header gear icons (redundant on desktop) */
  #btn-settings-nav { display: flex; }
  .btn-icon-settings { display: none; }

  /* Center content with comfortable reading width */
  .view-body {
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    padding: 28px 40px;
    width: 100%;
    box-sizing: border-box;
  }

  #detail-summary {
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 40px;
    padding-right: 40px;
    width: 100%;
    box-sizing: border-box;
  }

  /* Library desktop add-product button */
  .btn-new-product-desktop {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    background: var(--accent);
    color: var(--accent-fg);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    transition: opacity 0.15s;
  }
  .btn-new-product-desktop:hover { opacity: 0.82; }
}

/* Focus ring for accessibility */
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.7);
  z-index: 200;
}
.loading-overlay.hidden { display: none; }

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Inline container spinner (used inside view bodies while data loads) */
.container-spinner {
  display: flex;
  justify-content: center;
  padding: 48px 0;
}
.container-spinner::after {
  content: '';
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 80px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 300;
  opacity: 1;
  transition: opacity 0.3s ease;
}
.toast.hidden { display: none; }
.toast.fade-out { opacity: 0; }

@media (min-width: 768px) {
  .toast { bottom: 32px; }
}

/* ── Post-event actuals ──────────────────────────────────────────────────── */
.actual-section {
  border-top: 2px solid var(--accent);
  background: var(--surface);
  margin-top: 0;
}

.actual-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 6px;
}

.actual-pill {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 2px 7px;
  border-radius: 20px;
}

.actual-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.actual-duration-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 16px 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.actual-duration-value {
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px dashed var(--border);
}

.actual-section .item-row.is-oneoff {
  background: var(--amber-bg);
}

.actual-section .item-row.is-oneoff .item-name::after {
  content: ' · one-off';
  font-size: 11px;
  font-weight: 400;
  color: var(--amber-text);
}

/* ── Post-event notes ────────────────────────────────────────────────────── */
.post-event-notes-section {
  background: var(--surface);
  margin-top: 8px;
  padding: 14px 16px 20px;
}

.post-event-notes-section label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.post-event-notes-textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  resize: vertical;
  line-height: 1.5;
}

.post-event-notes-textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Summary cards: planned→actual layout ────────────────────────────────── */
.metric-card.has-actuals .metric-value {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  text-decoration: line-through;
  font-weight: 400;
  margin-bottom: 0;
}

.metric-card.has-actuals .metric-actual {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.metric-card.has-actuals .metric-rate {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  text-decoration: line-through;
}

.metric-card.has-actuals .metric-actual-rate {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.75);
}

.metric-card.has-actuals .metric-goal-rate {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 2px;
}

/* Actual segment progress bars */
.actual-progress {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 4px;
}

.start-actuals-section {
  padding: 16px;
  text-align: center;
}
.clear-actuals-section {
  padding: 8px 16px 20px;
  text-align: center;
}
.btn-clear-actuals {
  background: none;
  border: none;
  color: var(--red);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.75;
}
.btn-clear-actuals:active { opacity: 1; }

/* ── Landing + Setup shared ──────────────────────────────────────────────── */
.view-centered {
  justify-content: center;
  align-items: center;
  padding: 32px 24px;
  padding-bottom: 32px; /* override tab-bar padding — these views have no tab bar */
}

/* ── Landing page ────────────────────────────────────────────────────────── */
.landing-content {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  text-align: center;
}

.landing-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.landing-tagline {
  font-size: 16px;
  color: var(--text-secondary);
}

.landing-features {
  text-align: left;
  list-style: disc;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ── Claim indicator ─────────────────────────────────────────────────────── */
.claim-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--amber-bg);
  color: var(--amber-text);
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.claim-indicator.hidden { display: none; }
.claim-indicator-text {
  flex: 1;
}
.claim-indicator-dismiss {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
}

/* ── Claim screen ────────────────────────────────────────────────────────── */
.claim-subtext,
.recovery-subtext {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.claim-phrase {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-align: center;
  padding: 20px 8px;
  color: var(--text);
  line-height: 1.4;
}

.claim-phrase-actions {
  display: flex;
  gap: 8px;
}
.claim-phrase-actions .btn-secondary {
  padding: 8px 12px;
  font-size: 13px;
}

/* ── Recovery screen ─────────────────────────────────────────────────────── */
.recovery-error {
  font-size: 13px;
  color: var(--error, #d93025);
  margin-top: 8px;
  padding: 4px 0;
}

/* ── Multi-day date range ─────────────────────────────────────────────────── */
.date-range-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-range-wrap .form-input {
  flex: 1;
  min-width: 0;
}

.date-range-sep {
  flex-shrink: 0;
  color: var(--text-secondary);
  font-size: 14px;
  display: none;
}

.ef-end-date-hidden {
  display: none;
}

/* When end date is visible, show the separator */
.date-range-wrap:has(#ef-end-date:not(.ef-end-date-hidden)) .date-range-sep {
  display: block;
}

/* ── Execution Plan Panel ─────────────────────────────────────────────────── */
.exec-plan-panel {
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.exec-plan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px;
}

.exec-plan-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.exec-plan-toggle {
  background: none;
  border: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  text-align: left;
  white-space: nowrap;
}
.exec-plan-chevron {
  font-size: 12px;
  margin-right: 4px;
  display: inline-block;
  transition: transform 0.15s ease;
}
.exec-plan-toggle[aria-expanded="true"] .exec-plan-chevron {
  transform: rotate(90deg);
}

.exec-plan-interval-label {
  font-size: 12px;
  color: var(--text-tertiary);
}

.exec-plan-interval {
  font-size: 12px;
  color: var(--text-tertiary);
}

.exec-plan-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.exec-plan-generate-btn,
.exec-plan-regen-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}


.exec-plan-delete-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--red-bg);
  background: var(--surface);
  color: var(--red-text);
  cursor: pointer;
  margin-left: 8px;
}

.exec-plan-stale-warning {
  font-size: 12px;
  color: var(--warning, #b45309);
  background: var(--warning-bg, #fef3c7);
  padding: 6px 16px;
  border-radius: 6px;
  margin: 0 16px 8px;
}

.exec-plan-body { padding-bottom: 8px; }
.exec-plan-body.hidden { display: none; }

.exec-slots-list { padding: 0 16px; }

.exec-slot-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}
.exec-slot-row:last-child { border-bottom: none; }
.exec-slot-row:active { background: var(--border); }

.exec-slot-empty .exec-slot-items { color: var(--text-tertiary); }

.exec-slot-time {
  min-width: 36px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  font-size: 12px;
}

.exec-slot-items { flex: 1; }

.exec-slot-carbs {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.exec-plan-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}
.exec-plan-footer-warn {
  color: var(--warning, #c67b00);
}
.exec-plan-footer-target {
  color: var(--text-tertiary);
}

/* ── Slot editor sheet ────────────────────────────────────────────────────── */
.slot-editor-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px;
}

.slot-editor-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.slot-assignment-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.slot-assignment-row:last-child { border-bottom: none; }

.slot-assignment-label { flex: 1; }

.slot-assignment-actions {
  display: flex;
  gap: 8px;
}

.slot-assignment-actions button {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}

.slot-empty-label {
  padding: 16px 0;
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
}

/* ── Slot picker sheet ────────────────────────────────────────────────────── */
.slot-picker-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.slot-picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
}
.slot-picker-row:last-child { border-bottom: none; }
.slot-picker-row:active { background: var(--border); }

.slot-picker-time {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  min-width: 40px;
}

.slot-picker-summary {
  flex: 1;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-left: 8px;
}

/* ── Food Log ─────────────────────────────────────────────────────────────── */

:root {
  --m-cal:     #1a1a2e;
  --m-protein: #0a52a0;
  --m-carbs:   #b45309;
  --m-fat:     #6d28d9;
  --m-fiber:   #1a7a31;
  --m-sodium:  #0e6674;
  --m-sat-fat: #e8a838;
}

/* Date navigation */
.fl-back-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.fl-date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.fl-date-nav-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-secondary);
  padding: 4px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.fl-date-nav-btn:hover { background: var(--surface-2); }
.fl-date-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  gap: 2px;
}
.fl-today-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.fl-date-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}
.fl-date-caret { font-size: 13px; color: var(--text-tertiary); }
.fl-today-jump {
  font-size: 11px;
  color: var(--text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

/* Progress section */
.fl-progress {
  padding: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.fl-cal-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 8px;
}
.fl-cal-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--m-cal);
  font-variant-numeric: tabular-nums;
}
.fl-cal-target {
  font-size: 14px;
  color: var(--text-secondary);
}
.fl-cal-bar-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  margin-bottom: 12px;
  overflow: hidden;
}
.fl-cal-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--m-cal);
  transition: width 0.3s;
}
.fl-macro-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}
.fl-macro-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.fl-macro-label {
  font-size: 13px;
  color: var(--text-secondary);
  width: 90px;
  flex-shrink: 0;
  white-space: nowrap;
}
.fl-macro-bar-track {
  flex: 1;
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}
.fl-macro-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}
.fl-macro-value {
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  text-align: right;
}

/* Timeline */
.fl-timeline {
  padding: 16px 0;
}
.fl-timeline-entry {
  display: flex;
  gap: 0;
  padding: 0 0 16px 0;
}
.fl-time-col {
  width: 56px;
  flex-shrink: 0;
  padding-top: 2px;
  padding-right: 16px;
  text-align: right;
  position: relative;
}
.fl-time-col::before {
  content: '';
  position: absolute;
  right: -4px;
  top: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  z-index: 1;
}
.fl-time-col::after {
  content: '';
  position: absolute;
  right: -1px;
  top: 14px;
  bottom: -16px;
  width: 2px;
  background: var(--border);
}
.fl-timeline-entry:last-child .fl-time-col::after { display: none; }
.fl-time-text {
  font-size: 12px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}
.fl-entry-body {
  flex: 1;
  padding: 0 16px;
  cursor: pointer;
}
.fl-entry-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}
.fl-entry-meta {
  font-size: 13px;
  color: var(--text-secondary);
}
.fl-category-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 6px;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.fl-empty-timeline {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* Floating + button */
.fl-fab {
  position: fixed;
  bottom: calc(var(--tab-bar-height) + 16px);
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

/* Entry form */
.fl-freeform-area {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  box-sizing: border-box;
}
.fl-freeform-area:focus { outline: none; border-color: var(--accent); }
.fl-parse-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.fl-parse-btn:disabled { opacity: 0.6; cursor: default; }

/* Estimated macros block */
.fl-estimated {
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 12px 16px;
  margin-top: 16px;
}
.fl-estimated-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}
.fl-macro-edit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.fl-macro-edit-row:last-child { border-bottom: none; }
.fl-macro-edit-label { font-size: 14px; color: var(--text-secondary); }
.fl-macro-edit-value-wrap {
  display: flex;
  align-items: baseline;
  gap: 3px;
  border-bottom: 1.5px solid var(--border);
  padding-bottom: 1px;
}
.fl-macro-edit-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  border: none;
  background: none;
  text-align: right;
  width: 64px;
  padding: 0;
  font-family: inherit;
}
.fl-macro-edit-value:focus { outline: none; }
.fl-macro-edit-value-wrap:focus-within { border-bottom-color: var(--accent); }
.fl-macro-edit-unit { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; }
.fl-unit-input {
  width: 54px;
  font-size: inherit;
  color: var(--text-2);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  outline: none;
  padding: 0 2px;
  text-align: left;
}
.fl-unit-input:focus {
  border-bottom-color: var(--accent);
}
.fl-entry-serving {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 400;
  margin-left: 6px;
}
.fl-ai-notes {
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
  margin-top: 8px;
}

/* Category chips */
.fl-category-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 12px 0;
}
.fl-chip {
  padding: 5px 12px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
}
.fl-chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

/* Save-to-library checkbox row */
.fl-save-library-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}

/* Targets form */
.fl-target-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.fl-target-row:last-of-type { border-bottom: none; }
.fl-targets-label { font-size: 14px; color: var(--text); }
.fl-targets-slider {
  height: 44px;
  cursor: pointer;
}
.fl-targets-input {
  width: 100px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.fl-targets-input:focus { outline: none; border-color: var(--accent); }
.fl-targets-input::-webkit-inner-spin-button,
.fl-targets-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.fl-targets-input { -moz-appearance: textfield; }

/* Library sub-tab toggle */
.fl-lib-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 0;
}
.fl-lib-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.fl-lib-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Food log: Build mode ───────────────────────────────────────────────────── */
.fl-mode-tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 3px;
  margin: 10px 0 0;
  gap: 2px;
}
.fl-mode-tab {
  flex: 1;
  padding: 7px 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fl-mode-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ── Build mode: component list ─────────────────────────────────────────────── */
.fl-component-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
}
.fl-component-row {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.fl-component-color {
  width: 3px;
  height: 28px;
  border-radius: 2px;
  flex-shrink: 0;
}
.fl-component-info { flex: 1; min-width: 0; }
.fl-component-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fl-component-sub { font-size: 11px; color: var(--text-tertiary); margin-top: 1px; }
.fl-component-amount-wrap { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.fl-component-amount {
  width: 56px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  text-align: right;
  color: var(--text);
}
.fl-component-unit { font-size: 11px; color: var(--text-tertiary); }
.fl-component-remove {
  font-size: 18px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  padding: 0 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fl-add-from-lib-btn {
  margin: 6px 0 0;
  background: var(--surface-2);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── Build mode: estimated totals ───────────────────────────────────────────── */
.fl-estimated-block {
  margin: 8px 0 0;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px;
}
.fl-estimated-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}
.fl-estimated-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.fl-estimated-name-label { font-size: 12px; color: var(--text-secondary); flex-shrink: 0; width: 40px; }
.fl-estimated-name-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
}
.fl-estimated-macros {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 4px;
}
.fl-estimated-macro { text-align: center; }
.fl-estimated-macro-val {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.fl-estimated-macro-label {
  font-size: 9px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 1px;
}
.fl-estimated-caveat {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 6px;
}

/* ── Picker sheet ───────────────────────────────────────────────────────────── */
.fl-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 50;
  display: flex;
  align-items: flex-end;
}
.fl-sheet {
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 75%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.fl-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
.fl-sheet-header {
  padding: 10px 16px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.fl-sheet-title { font-size: 15px; font-weight: 600; flex: 1; }
.fl-sheet-count { font-size: 12px; color: var(--text-tertiary); }
.fl-sheet-search {
  margin: 0 16px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  width: calc(100% - 32px);
  flex-shrink: 0;
}
.fl-sheet-list {
  overflow-y: auto;
  flex: 1;
  padding: 0 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.fl-sheet-list::-webkit-scrollbar { display: none; }
.fl-picker-row {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fl-picker-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fl-picker-check.checked { background: var(--accent); border-color: var(--accent); }
.fl-picker-check.checked::after {
  content: '✓';
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-fg);
}
.fl-picker-info { flex: 1; min-width: 0; }
.fl-picker-name { font-size: 13px; font-weight: 500; }
.fl-picker-brand { font-size: 11px; color: var(--text-secondary); }
.fl-picker-macros { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.fl-sheet-confirm-btn {
  margin: 4px 16px 12px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  flex-shrink: 0;
  cursor: pointer;
}
.fl-sheet-confirm-btn:disabled,
.fl-sheet-confirm-btn[disabled] { opacity: 0.4; pointer-events: none; }

/* ── Timeline: component pills ──────────────────────────────────────────────── */
.fl-entry-components {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.fl-component-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 11px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.fl-component-pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.fl-entry-expand {
  font-size: 11px;
  color: var(--accent);
  margin-top: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── Batch meals ─────────────────────────────────────────────────────────────── */

/* Amber pill on timeline entries */
.fl-batch-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--amber-bg);
  color: var(--amber-text);
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}

/* Re-log button on active batches */
.fl-relog-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--blue-text);
  background: var(--blue-bg);
  border-radius: 6px;
  padding: 4px 9px;
  margin-top: 6px;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Active batches section on food log home */
.fl-active-batches {
  margin: 0 16px 4px;
}
.fl-active-batches-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  padding-left: 2px;
}
.fl-active-batch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 6px;
}
.fl-active-batch-info { flex: 1; min-width: 0; }
.fl-active-batch-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fl-active-batch-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.fl-active-batch-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.fl-batch-discard {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text-tertiary);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* Servings row inside entry form macros block */
.fl-servings-row {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  background: var(--amber-bg);
}
.fl-servings-label {
  font-size: 14px;
  color: var(--amber-text);
  flex: 1;
  font-weight: 500;
}
.fl-servings-input {
  width: 44px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--amber-text);
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--amber-text);
  outline: none;
  padding: 0 2px;
}
.fl-servings-unit {
  font-size: 13px;
  color: var(--amber-text);
  opacity: 0.7;
}

/* Per-serving preview inside entry form macros block */
.fl-per-serving-preview {
  background: var(--green-bg);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.fl-per-serving-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green-text);
  white-space: nowrap;
}
.fl-per-serving-nums {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
}
.fl-ps-macro {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.fl-ps-macro-lbl {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Serving picker sheet */
.fl-mult-chips {
  display: flex;
  gap: 6px;
}
.fl-mult-chip {
  flex: 1;
  padding: 9px 0;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.fl-mult-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.fl-mult-custom {
  flex: 1;
  padding: 9px 6px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  outline: none;
  min-width: 0;
}
.fl-serving-preview {
  display: flex;
  justify-content: space-between;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.fl-ps-box { text-align: center; }
.fl-ps-val {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.fl-ps-lbl { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
