/* New Weight Entry */
.additional-form {
  margin-bottom: 16px;
}

.weight-entry {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(320px, 1.2fr);
  align-items: end;
  gap: 16px;
  padding: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
}

.weight-entry__errors {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  background: #fef2f2;
  font-size: 0.9rem;
  font-weight: 700;
}

.weight-entry__period,
.weight-entry__field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.weight-entry__label {
  color: #4b5563;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.weight-entry__fields {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.weight-entry__value-control {
  display: flex;
  align-items: center;
  min-height: 46px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #f8fafc;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.weight-entry__value-control:focus-within {
  border-color: #2563eb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.weight-entry__input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: none;
  color: #111827;
  background: transparent;
  font-family: monospace;
  font-size: 1rem;
  font-weight: 700;
}

.weight-entry__input--value {
  padding: 12px 8px 12px 13px;
  text-align: right;
}

.weight-entry__unit {
  flex: 0 0 auto;
  padding-right: 13px;
  color: #6b7280;
  font-size: 0.95rem;
  font-weight: 700;
}

.weight-entry__input--value::-webkit-outer-spin-button,
.weight-entry__input--value::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.weight-entry__input--value[type="number"] {
  -moz-appearance: textfield;
}

.weight-entry__submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: #2563eb;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
  transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
}

.weight-entry__submit:hover {
  background: #1d4ed8;
  box-shadow: 0 10px 24px rgba(29, 78, 216, 0.24);
}

.weight-entry__submit:active {
  transform: translateY(1px);
}

/* Chart Section */
.chart-section {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(239, 246, 255, 0.96) 0%, rgba(255, 255, 255, 0) 120px),
    #fff;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.08);
  padding: 18px;
  overflow: visible;
}

.weight-chart {
  display: grid;
  gap: 16px;
}

.weight-chart__header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.weight-chart__eyebrow {
  display: block;
  margin-bottom: 4px;
  color: #2563eb;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.weight-chart__title {
  margin: 0;
  color: #111827;
  font-size: 1.3rem;
  line-height: 1.2;
}

.weight-chart__summary {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  min-width: 0;
}

.weight-chart__stat {
  display: grid;
  gap: 3px;
  min-width: 88px;
  padding-left: 18px;
  border-left: 1px solid #dbe3ea;
}

.weight-chart__stat--button {
  appearance: none;
  padding-top: 0;
  padding-right: 0;
  padding-bottom: 0;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.weight-chart__stat-content {
  display: grid;
  gap: 3px;
}

.weight-chart__stat-content[hidden] {
  display: none;
}

.weight-chart__stat--button:hover .weight-chart__stat-label {
  color: #2563eb;
}

.weight-chart__stat--button:focus-visible {
  border-radius: 6px;
  outline: 2px solid #93c5fd;
  outline-offset: 4px;
}

.weight-chart__stat-label {
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.weight-chart__stat strong {
  color: #111827;
  font-size: 1rem;
  line-height: 1.2;
  white-space: nowrap;
}

.weight-chart__stat .weight-chart__change--down {
  color: #15803d;
}

.weight-chart__stat .weight-chart__change--up {
  color: #b91c1c;
}

.weight-chart__stat .weight-chart__change--flat {
  color: #475569;
}

.weight-chart__canvas {
  min-height: 360px;
}

.period-picker {
  position: relative;
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid #e5e7eb;
}

.weight-entry .period-picker {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

.period-select {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  max-width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  color: #111827;
  background: #f8fafc;
  font-family: monospace;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.period-select:hover,
.period-select[aria-expanded="true"] {
  border-color: #2563eb;
  background: #fff;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.12);
}

.period-select__calendar-icon {
  position: relative;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 4px;
  color: #2563eb;
  flex: 0 0 auto;
}

.period-select__calendar-icon::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  border-top: 2px solid currentColor;
}

.period-select__content {
  display: grid;
  gap: 2px;
  min-width: 0;
  text-align: left;
}

.period-select__value {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

.period-select__range {
  color: #6b7280;
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.period-picker__popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 210px minmax(520px, 1fr);
  gap: 16px;
  width: min(900px, calc(100vw - 48px));
  padding: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.16);
}

.period-picker__popover[hidden] {
  display: none;
}

.period-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 16px;
  border-right: 1px solid #e5e7eb;
}

.period-option-form {
  margin: 0;
}

.period-picker__form {
  display: none;
}

.period-option {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  color: #111827;
  background: transparent;
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: left;
  text-decoration: none;
}

.period-option:hover {
  color: #1d4ed8;
  background: #eff6ff;
}

.period-option.is-active {
  color: #1d4ed8;
  background: #dbeafe;
}

.period-calendar {
  min-width: 0;
}

.period-calendar__toolbar {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.period-calendar__selection {
  color: #111827;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}

.period-calendar__nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  color: #2563eb;
  background: #f8fafc;
  font-family: monospace;
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
}

.period-calendar__nav:hover {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.period-calendar__months {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.period-calendar__month h4 {
  margin: 0 0 14px;
  color: #111827;
  font-size: 1.15rem;
  text-align: center;
}

.period-calendar__weekdays,
.period-calendar__grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(34px, 1fr));
  gap: 4px;
}

.period-calendar__weekdays {
  margin-bottom: 8px;
  color: #6b7280;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.period-calendar__day {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  min-width: 0;
  border: none;
  border-radius: 999px;
  color: #111827;
  background: transparent;
  font-family: monospace;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.period-calendar__day:hover {
  color: #1d4ed8;
  background: #eff6ff;
}

.period-calendar__day.is-empty {
  cursor: default;
}

.period-calendar__day.is-today {
  box-shadow: inset 0 0 0 2px #93c5fd;
}

.period-calendar__day.is-in-range {
  background: #bfdbfe;
}

.period-calendar__day.is-range-start,
.period-calendar__day.is-range-end {
  color: #fff;
  background: #2563eb;
}

/* Responsive Design */
@media (max-width: 768px) {
  .weight-entry {
    grid-template-columns: 1fr;
  }

  .chart-section {
    padding: 10px;
  }

  .weight-chart {
    gap: 12px;
  }

  .weight-chart__header {
    flex-direction: column;
    align-items: stretch;
  }

  .weight-chart__summary {
    justify-content: space-between;
    gap: 12px;
  }

  .weight-chart__stat {
    flex: 1 1 0;
    min-width: 0;
    padding-left: 12px;
  }

  .weight-chart__stat:first-child {
    padding-left: 0;
    border-left: 0;
  }

  .weight-chart__canvas {
    min-height: 330px;
  }

  .weight-chart__canvas > div {
    height: 330px !important;
  }

  .weight-entry__fields {
    justify-content: stretch;
  }

  .weight-entry__field {
    flex: 1 1 auto;
  }

  .form-section {
    grid-template-columns: 1fr;
  }

  .navigation {
    flex-wrap: wrap;
  }

  .back-link,
  .edit-link {
    flex: 1 1 auto;
    margin-bottom: 10px;
    text-align: center;
  }

  .period-select,
  .period-picker__popover {
    width: 100%;
  }

  .period-picker__popover {
    position: static;
    grid-template-columns: 1fr;
    margin-top: 8px;
  }

  .period-options {
    padding-right: 0;
    padding-bottom: 12px;
    border-right: none;
    border-bottom: 1px solid #e5e7eb;
  }

  .period-calendar__months {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .weight-entry__fields {
    flex-direction: column;
    align-items: stretch;
  }

  .weight-entry__submit {
    width: 100%;
  }
}
