/* ── Reset & base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Prevent CSS display rules from overriding the hidden attribute */
[hidden] { display: none !important; }

/* Prevent horizontal overflow on all key containers */
html, body, #app, .view, .container, .entry-list, .card {
  max-width: 100% !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
}

html, body {
  height: 100%;
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-family-base);
  background: var(--color-surface-base);
  color: var(--color-text-primary);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* prevent iOS rubber-band on body */
  position: fixed;
  width: 100%;
  overflow: hidden;
}

/* ── App container ── */
#app {
  position: fixed;
  inset: 0;
  bottom: calc(var(--nav-height) + var(--safe-bottom));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: var(--safe-top);
}

/* ── Views ── */
.view {
  display: none;
  padding: 0 var(--space-4) var(--space-6);
  min-height: 100%;
}
.view.active {
  display: block;
}

/* ── View header ── */
.view-header {
  padding: var(--space-5) 0 var(--space-4);
  border-bottom: 1px solid var(--color-border-default);
  margin-bottom: var(--space-6);
}
.view-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.view-subtitle {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

/* ── Log picker (two big buttons) ── */
.log-picker {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.log-type-btn {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  padding: var(--space-6) var(--space-5);
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-surface-default);
  color: var(--color-text-primary);
  font-family: var(--font-family-base);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: opacity 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  min-height: 88px;
}
.log-type-btn:active {
  opacity: 0.75;
  transform: scale(0.98);
}
.log-type-btn--workout {
  border-left: 4px solid var(--color-brand-primary);
}
.log-type-btn--supplement {
  border-left: 4px solid var(--color-supplement);
}
.log-type-btn__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.log-type-btn--workout .log-type-btn__icon {
  background: color-mix(in srgb, var(--color-brand-primary) 15%, transparent);
  color: var(--color-brand-primary);
}
.log-type-btn--supplement .log-type-btn__icon {
  background: color-mix(in srgb, var(--color-supplement) 15%, transparent);
  color: var(--color-supplement);
}
.log-type-btn__chevron {
  color: var(--color-text-secondary);
  flex-shrink: 0;
}
.log-type-btn__label {
  flex: 1;
}

/* ── Forms ── */
.form-wrap {
  animation: fadeIn 0.15s ease;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

form {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Button — base ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-family-base);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.1s, transform 0.1s;
}

/* ── Button — size: large ── */
.btn--lg {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: var(--space-4) var(--space-6);
  font-size: 16px;
  font-weight: 400;
  min-height: 49px;
  margin-top: var(--space-2);
  text-align: center;
}

/* ── Button — ghost variant ── */
.btn.btn--ghost {
  background: none;
  border: none;
  color: var(--color-brand-primary);
  font-family: var(--font-family-base);
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  margin-bottom: var(--space-4);
  min-height: 44px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.form-heading {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: var(--space-6);
}

.form-field {
  margin-bottom: var(--space-5);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.form-field__label {
  display: block;
  font-size: 18px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}
.form-field__optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.input-field {
  display: block;
  width: 100%;
  box-sizing: border-box !important;
  padding: var(--space-4) var(--space-6);
  background: var(--color-surface-default);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-xs);
  color: var(--color-text-primary);
  font-family: var(--font-family-base);
  font-size: 20px !important;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  min-height: 56px;
  transition: border-color 0.15s;
}
.input-field:focus {
  border-color: var(--color-brand-primary);
}
.input-field::placeholder {
  color: var(--color-text-secondary);
}

/* number input: hide spinners */
.input-field[type="number"]::-webkit-inner-spin-button,
.input-field[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

/* ── Select Field / Select Control / Select Menu ── */
.select-field {
  position: relative;
}

.select-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-3) 14px;
  background: var(--color-surface-default);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-xs);
  color: var(--color-text-primary);
  font-family: var(--font-family-base);
  font-size: 20px;
  text-align: left;
  cursor: pointer;
  min-height: 48px;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.select-control:focus {
  outline: none;
  border-color: var(--color-brand-primary);
}
.select-field[aria-expanded="true"] .select-control {
  border-color: var(--color-brand-primary);
  border-bottom-left-radius: var(--radius-none);
  border-bottom-right-radius: var(--radius-none);
}

.select-control__value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.select-control__value--placeholder {
  color: var(--color-text-secondary);
}

.select-control__chevron {
  color: var(--color-text-secondary);
  flex-shrink: 0;
  margin-left: var(--space-2);
  transition: transform 0.15s;
  display: flex;
  align-items: center;
}
.select-field[aria-expanded="true"] .select-control__chevron {
  transform: rotate(180deg);
}

.select-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-surface-default);
  border: 1px solid var(--color-brand-primary);
  border-top: none;
  border-bottom-left-radius: var(--radius-xs);
  border-bottom-right-radius: var(--radius-xs);
  list-style: none;
  z-index: 50;
  overflow: hidden;
}

.select-menu__option {
  padding: 14px 16px;
  font-size: 16px;
  font-family: var(--font-family-base);
  color: var(--color-text-primary);
  cursor: pointer;
  min-height: 48px;
  display: flex;
  align-items: center;
  border-top: 1px solid var(--color-border-default);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.select-menu__option:first-child {
  border-top: none;
}
.select-menu__option:hover,
.select-menu__option:active {
  background: var(--color-surface-raised);
}
.select-menu__option[aria-selected="true"] {
  color: var(--color-brand-primary);
  font-weight: 600;
}

.form-field__error {
  color: var(--color-error);
  font-size: 14px;
  margin-top: 6px;
  margin-bottom: 0;
}

/* ── Button — filled variant ── */
.btn.btn--filled {
  color: var(--color-text-on-brand);
}
.btn.btn--filled:active {
  opacity: 0.8;
  transform: scale(0.98);
}
.btn.btn--filled.btn--brand    { background: var(--color-brand-primary); }
.btn.btn--filled.btn--supplement { background: var(--color-supplement); }

/* ── Preset chips ── */
.preset-chips-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  max-width: 100%;
  overflow: hidden;
}

.preset-chips-scroll {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-2);
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: var(--space-1);
  flex: 1;
  min-width: 0;
  /* hide scrollbar but keep scrollability */
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.preset-chips-scroll::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  margin: 2px 2px;
  padding: 5px 10px;
  height: 26px;
  border: none;
  border-radius: var(--radius-full);
  font-family: var(--font-family-base);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, opacity 0.1s;
}
.chip:active {
  opacity: 0.85;
}

/* Color modifiers */
.chip--supplement { color: var(--color-supplement); }
.chip--workout    { color: var(--color-brand-primary); }

/* Subtle variant: soft translucent background keyed to the color modifier */
.chip--subtle.chip--supplement { background: color-mix(in srgb, var(--color-supplement) 20%, transparent); }
.chip--subtle.chip--workout    { background: color-mix(in srgb, var(--color-brand-primary) 20%, transparent); }
.chip--subtle.chip--supplement:active { background: color-mix(in srgb, var(--color-supplement) 25%, transparent); }
.chip--subtle.chip--workout:active    { background: color-mix(in srgb, var(--color-brand-primary) 25%, transparent); }

.preset-manage-link {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-family: var(--font-family-base);
  font-size: 13px;
  cursor: pointer;
  padding: var(--space-1) 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.presets-empty {
  color: var(--color-text-secondary);
  font-size: 15px;
  padding: var(--space-6) 0;
  text-align: center;
}

/* ── Save confirmation ── */
.save-confirmation {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-surface-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  animation: fadeIn 0.2s ease;
}
.save-confirmation__icon {
  font-size: 28px;
  color: var(--color-success);
}
.save-confirmation__text {
  font-size: 18px;
  font-weight: 600;
}

/* ── Today view ── */
.today-empty {
  text-align: center;
  color: var(--color-text-secondary);
  padding: var(--space-12) 0;
  line-height: 2;
}
.today-empty strong {
  color: var(--color-text-primary);
}

.entry-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.card {
  background: var(--color-surface-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  border-left: 4px solid transparent;
  position: relative;
}
.card--workout    { border-left-color: var(--color-brand-primary); }
.card--supplement { border-left-color: var(--color-supplement); }

.card__body {
  flex: 1;
  min-width: 0;
}
.card__title {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card__detail {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}
.card__time {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 6px;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  margin-top: 2px;
}
.badge--workout {
  background: color-mix(in srgb, var(--color-brand-primary) 20%, transparent);
  color: var(--color-brand-primary);
}
.badge--supplement {
  background: color-mix(in srgb, var(--color-supplement) 20%, transparent);
  color: var(--color-supplement);
}

.btn.btn--icon {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: var(--space-1);
  line-height: 1;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s, background 0.1s;
}
.btn.btn--icon:active {
  color: var(--color-error);
  background: color-mix(in srgb, var(--color-error) 15%, transparent);
}

/* ── History view ── */
.view-header--history {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.history-date-label {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.history-arrow {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 22px;
  cursor: pointer;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
  flex-shrink: 0;
}
.history-arrow:active {
  color: var(--color-text-primary);
}
.history-arrow--disabled,
.history-arrow:disabled {
  color: var(--color-border-default);
  cursor: default;
  pointer-events: none;
}

.history-section {
  margin-bottom: var(--space-6);
}

.history-section__label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.history-section .entry-list {
  gap: 6px;
}

.history-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--color-surface-default);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  border-left: 3px solid transparent;
  min-height: 44px;
}
.history-card--workout    { border-left-color: var(--color-brand-primary); }
.history-card--supplement { border-left-color: var(--color-supplement); }

.history-card__text {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-card__time {
  font-size: 12px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── Undo toast ── */
.undo-toast {
  position: fixed;
  left: var(--space-4);
  right: var(--space-4);
  bottom: calc(var(--nav-height) + var(--safe-bottom) + var(--space-3));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  z-index: 90;
  animation: fadeIn 0.2s ease;
}
.undo-toast__text {
  font-size: 15px;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.undo-toast__btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--color-brand-primary);
  font-family: var(--font-family-base);
  font-size: 15px;
  font-weight: 700;
  padding: 0 var(--space-3);
  min-height: 44px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--color-surface-default);
  border-top: 1px solid var(--color-border-default);
  display: flex;
  align-items: stretch;
  z-index: 100;
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-family: var(--font-family-base);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-2) 0;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
  min-height: 48px;
}
.nav-btn.active {
  color: var(--color-brand-primary);
}
.nav-btn__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
}
.nav-btn__label {
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
