/* History Profile: base, responsive and interaction states. */
.profile-form {
  margin: 25px 0;
}

.history-row {
  background: var(--card);
  padding: 20px;
  border-radius: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 12px 0;
  text-align: left;
  width: 100%;
}

.history-bar {
  height: 5px;
  background: var(--track);
  border-radius: 5px;
  margin-top: 10px;
  width: 140px;
  overflow: hidden;
}

.history-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.storage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 25px;
}

.storage-actions label.secondary {
  font-size: 16px;
}

@media (max-width: 700px) {
  #profileForm .field-grid > div:has(> label[for="race"]),
  #profileForm .field-grid > div:has(> label[for="date"]) {
    grid-column: 1/-1;
  }
}

#profileForm .field-grid > div:has(> label[for="name"]) {
  grid-column: 1/-1;
}

.about-carbs {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  max-width: 860px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.about-carbs p + p {
  margin-top: 12px;
}

.about-carbs a {
  text-underline-offset: 3px;
  font-size: 12px;
}

.history-race-heading {
  margin-bottom: 25px;
}

.profile-plan-help {
  margin-top: 18px;
}

.analytics-preferences {
  margin-top: 28px;
  margin-bottom: 28px;
}

.analytics-preferences h2 {
  font-size: 1.2rem;
}

.analytics-preferences p {
  margin-top: 12px;
}

.analytics-actions {
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.analytics-actions button {
  flex: 1;
  min-width: 130px;
}

#analyticsDialog .card {
  margin: 0;
  background: transparent;
  padding: 0;
}

#analyticsDialog p {
  margin-top: 14px;
}

.load-recap {
  margin-top: 18px;
}

.load-recap-total {
  display: grid;
  gap: 5px;
  margin: 18px 0;
}

.load-recap-total strong {
  font-size: 24px;
  color: var(--accent);
}

.load-recap-foods {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0;
  margin: 12px 0 16px;
  list-style: none;
}

.load-recap-foods li {
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--page);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.load-recap-feedback {
  border-top: 1px solid var(--line);
  margin-top: 20px;
  padding-top: 18px;
}

.load-recap-feedback p {
  margin: 8px 0 14px;
}

.load-recap-feedback a {
  display: inline-flex;
  text-decoration: none;
  text-align: center;
}

.history-day {
  margin-bottom: 22px;
}

.history-day > .small {
  margin-top: 6px;
}

.history-chart {
  width: min(100%,220px);
}

.history-meal-foods {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-meal-foods li {
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.history-meal-foods li:last-child {
  border-bottom: 0;
}

.history-meal-foods li > div {
  min-width: 0;
  overflow-wrap: anywhere;
}

.history-meal-foods li > div > span {
  display: block;
}

.history-meal-foods strong {
  white-space: nowrap;
  font-size: 14px;
}

.history-day-link {
  margin-top: 18px;
}

.history-score {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0 12px;
}

.history-score > strong {
  font-size: 38px;
  line-height: 1.1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

.history-score > strong > span {
  font-size: 20px;
  letter-spacing: 0;
  margin-left: 2px;
}

.history-score > span {
  font-size: 14px;
}

.history-meal-bar {
  display: flex;
  overflow: hidden;
  height: 10px;
  border-radius: 6px;
  background: var(--line);
  gap: 2px;
}

.history-meal-bar > span {
  height: 100%;
  flex-shrink: 1;
}

.history-score-meals {
  gap: 0;
  margin-top: 14px;
}

.history-score-meals .daily-meal-card {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.history-score-meals summary {
  padding: 12px 0;
  gap: 10px;
}

.history-score-meals .meal-card-name {
  font-size: 15px;
}

.history-score-meals .meal-card-name > span {
  margin-left: 8px;
  font-size: 12px;
}

.history-score-meals .meal-color-dot {
  width: 9px;
  height: 9px;
}

.history-score-meals .meal-card-example {
  margin: 0 0 0 19px;
  padding: 0 0 10px;
  border-top: 0;
}

.history-score-meals summary > strong {
  font-size: 15px;
}

@media(max-width:380px) {
  .history-score-meals .meal-card-name > span {
    display: block;
    margin-left: 0;
  }
}

.new-race-cta {
  margin-top: 18px;
}

#newRaceDialog {
  width: min(620px,calc(100% - 32px));
  max-height: 90dvh;
  overflow: auto;
}

#newRaceForm {
  margin-top: 20px;
}

.archived-race-summary {
  margin-bottom: 22px;
}

.archived-race-summary > p {
  margin-top: 8px;
}

#historyRace + .history-race-heading {
  margin-top: 24px;
}

.profile-next-race {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  margin-top: 4px;
}

.profile-next-race > p {
  margin-top: 8px;
}

.load-recap-feedback a.secondary {
  color: var(--text);
}

.history-score-meals .meal-card-name > span {
  display: block;
  margin: 3px 0 0;
}

.history-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.history-day-header > div:first-child {
  min-width: 0;
}

.history-day-header p {
  margin-top: 6px;
}

.history-progress-ring.ring {
  width: 76px;
  height: 76px;
  min-width: 76px;
  flex: 0 0 76px;
  margin-left: auto;
}

.history-progress-ring .ring-label strong {
  font-size: 18px;
}

@media(max-width:380px) {
  .history-day-header {
    gap: 10px;
  }

  .history-progress-ring.ring {
    width: 64px;
    height: 64px;
    min-width: 64px;
    flex-basis: 64px;
  }

  .history-progress-ring .ring-label strong {
    font-size: 16px;
  }
}

.history-progress-ring svg circle {
  stroke-width: 14px;
}

.history-progress-ring .ring-completion {
  width: 22px;
  height: 22px;
  border-width: 2px;
  top: -4px;
}

.history-progress-ring .ring-completion svg {
  width: 13px;
  height: 13px;
}

.recap-days,.recap-favourites {
  list-style: none;
  padding: 0;
  margin: 24px 0;
  display: grid;
  gap: 18px;
}

.recap-days .row {
  gap: 12px;
  font-size: 14px;
}

.recap-bar {
  height: 10px;
  border-radius: 8px;
  background: var(--ring-track);
  overflow: hidden;
  margin-top: 8px;
}

.recap-bar>span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.recap-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.recap-split strong,.recap-split span {
  display: block;
}

.recap-split strong {
  font-size: 24px;
}

.recap-split span {
  font-size: 14px;
  color: var(--muted);
}

.recap-favourites li {
  flex-wrap: wrap;
  justify-content: space-between;
}

.recap-note {
  margin-top: 28px;
}

.recap-note label {
  font-weight: 700;
}

.recap-note textarea {
  width: 100%;
  margin: 12px 0 6px;
  resize: vertical;
  box-sizing: border-box;
}

.recap-note p {
  margin-top: 8px;
}

.recap-note textarea {
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.recap-note textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.new-race-note {
  padding: 18px;
  margin: 20px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.new-race-note h3 {
  font-size: 17px;
}

.new-race-note p {
  margin-top: 8px;
}

.new-race-note-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.recap-day-link {
  display: block;
  width: 100%;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.recap-day-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 5px;
}

.recap-day-link .recap-bar {
  display: flex;
}

.recap-day-link .recap-bar>span {
  border-radius: 0;
  flex-shrink: 0;
  box-shadow: inset -1px 0 var(--card);
}

.recap-meal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 22px;
}

.recap-meal-legend>span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.recap-meal-legend i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.load-recap .recap-plan-link {
  margin-top: 18px;
}

.recap-day-label {
  text-decoration: none;
}

.recap-day-hint {
  margin-top: 24px;
}

.recap-days {
  gap: 10px;
}

.recap-day-link {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  box-sizing: border-box;
}

.recap-day-link .row {
  flex-wrap: wrap;
}

.recap-day-link .row>span:last-child {
  font-variant-numeric: tabular-nums;
}

.recap-day-link>.small {
  display: block;
  margin-top: 8px;
}

.recap-favourites li {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  align-items: start;
  gap: 8px 16px;
}

.recap-favourites li>span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.recap-favourites li>span:last-child {
  text-align: right;
  white-space: nowrap;
}

.recap-split strong small {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.history-day {
  scroll-margin-top: 24px;
}

.history-day:focus {
  outline: none;
}

.history-day:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.profile-legal .legal-links {
  margin-top: 20px;
}

.profile-legal p {
  margin-top: 12px;
}

.profile-legal a {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.profile-legal {
  margin-top: 24px;
}

.profile-legal .legal-links>a {
  font-size: 14px;
  color: var(--danger);
  text-align: center;
}

.profile-legal .analytics-preferences {
  width: 100%;
  margin: 0;
  text-align: center;
}

.profile-legal .analytics-preferences>.card {
  text-align: left;
}

.profile-legal #changeAnalytics {
  color: var(--danger);
  font-size: 14px;
}

.profile-legal .legal-links>a,.profile-legal .analytics-preferences {
  text-align: left;
}

.profile-legal #changeAnalytics {
  padding-left: 0;
  padding-right: 0;
  text-align: left;
}

.recap-day-link .recap-target-percent {
  display: block;
  margin-top: 5px;
}

.profile-legal #analyticsPreferences>.card {
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  margin: 0;
}

.archived-shopping {
  margin: 28px 0;
  padding: 22px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.archived-shopping summary {
  font-weight: 600;
  cursor: pointer;
}

.archived-shopping ul {
  margin: 18px 0 0;
  padding-left: 24px;
  line-height: 1.8;
}

.archived-shopping + .load-recap-feedback {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.history-meal-foods li {
  padding-right: 23px;
}

.history-meal-foods li>div {
  flex: 1;
}

.history-meal-foods .diary-kind-icon {
  flex: none;
  margin-top: 2px;
}

.history-meal-foods .diary-kind-icon svg {
  width: 16px;
  height: 16px;
}

.profile-options .setup-options {
  padding: 0;
  border: 0;
}

.profile-options .setup-option {
  font-size: 14px;
}

.profile-legal .legal-links {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  gap: 12px 24px;
}

.profile-legal .legal-links a {
  width: auto;
}

.profile-options>h2 {
  margin-bottom: 24px;
}

.profile-ai-usage {
  margin-top: 24px;
  margin-bottom: 24px;
}

.profile-ai-usage .ai-usage-count {
  margin: 16px 0 8px;
}

.profile-ai-usage p+p {
  margin-top: 8px;
}

#profileAiUsageTitle {
  display: flex;
  align-items: center;
  gap: 10px;
}

#profileAiUsageTitle svg {
  flex-shrink: 0;
  color: var(--accent);
}

.profile-ai-usage .ai-usage-empty {
  margin-bottom: 8px;
}

.history-entry-edit {
  min-height: 28px;
  font-size: 14px;
}

.history-meal-foods li > .history-entry-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.history-entry-actions .history-entry-edit {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.history-entry-meta {
  display: flex;
  align-items: center;
  gap: 14px;
}

.history-entry-meta .history-entry-edit {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
}

.history-meal-foods li {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) max-content;
  column-gap: 12px;
  row-gap: 4px;
}

.history-meal-foods li > .diary-kind-icon {
  grid-column: 1;
  grid-row: 1;
}

.history-meal-foods li > div:not(.history-entry-actions),
.history-meal-foods .history-entry-meta,
.history-meal-foods li > .history-entry-actions {
  display: contents;
}

.history-meal-foods li > div > span {
  grid-column: 2;
  grid-row: 1;
}

.history-meal-foods .history-entry-meta > span {
  grid-column: 2;
  grid-row: 2;
  align-self: center;
}

.history-meal-foods .history-entry-actions > strong {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
}

.history-meal-foods .history-entry-actions > .history-entry-edit {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
  min-height: 28px;
}
