/* ============================================================
   Weight Tracker — full-screen pages
   ============================================================ */

/* ---- Shared screen base ---- */
/* These classes are applied directly to <main> */
main.weight-entry-screen,
main.weight-index-screen {
  min-height: 100dvh;
  background: #000;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 0;
  padding-bottom: calc(env(safe-area-inset-bottom) + 80px);
  /* Override reset.css align-items: center/flex-start with higher specificity */
  align-items: stretch !important;
  justify-content: flex-start;
}

/* ============================================================
   NEW ENTRY SCREEN
   ============================================================ */

/* Reset global header styles inside weight screens */
.weight-entry-screen header,
.weight-index-screen header {
  position: static;
  padding: 0;
}

/* Header */
.weight-entry-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  flex-shrink: 0;
}

.weight-entry-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: #fff;
  flex-shrink: 0;
}

.weight-entry-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
}

.weight-entry-form {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ---- Drum-roll picker ---- */
.weight-picker-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.weight-picker-list {
  height: 168px; /* 3 items × 56px */
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  width: 200px;
  position: relative;
  z-index: 1;
}

.weight-picker-list::-webkit-scrollbar {
  display: none;
}

.weight-picker-item {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--gray-600);
  scroll-snap-align: start;
  cursor: pointer;
  transition: color 0.15s ease, font-size 0.15s ease;
  font-family: "Geist Mono", monospace;
  letter-spacing: -0.02em;
}

.weight-picker-item.selected {
  color: #fff;
  font-size: 1.75rem;
  font-weight: 700;
}

.weight-picker-padding {
  pointer-events: none;
}

/* Gradient masks — top and bottom fade */
.weight-picker-mask {
  position: absolute;
  left: 0;
  right: 0;
  height: 56px;
  pointer-events: none;
  z-index: 2;
}

.weight-picker-mask-top {
  top: 0;
  background: linear-gradient(to bottom, #000 0%, transparent 100%);
}

.weight-picker-mask-bottom {
  bottom: 0;
  background: linear-gradient(to top, #000 0%, transparent 100%);
}

/* Selection indicator lines above/below center */
.weight-picker-selector {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 180px;
  top: 50%;
  margin-top: -28px;
  height: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  z-index: 3;
}

.weight-picker-selector-line {
  height: 1px;
  background: var(--gray-700);
  width: 100%;
}

/* Unit label beside the selected row */
.weight-picker-unit {
  position: absolute;
  right: calc(50% - 110px);
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--gray-500);
  font-family: "Geist Mono", monospace;
  pointer-events: none;
  z-index: 3;
}

/* ---- Footer actions ---- */
.weight-entry-footer {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.weight-add-btn {
  flex: 1;
  height: 56px;
  background: var(--blue-500);
  color: #fff;
  border: none;
  border-radius: 28px;
  font-size: 1rem;
  font-weight: 600;
  font-family: "Geist Mono", monospace;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.weight-add-btn:hover {
  background: var(--blue-600);
}

.weight-add-btn:active {
  opacity: 0.85;
}

.weight-calendar-btn {
  width: 56px;
  height: 56px;
  background: var(--gray-900);
  border: 1px solid var(--gray-800);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

.weight-calendar-btn:hover {
  background: var(--gray-800);
  color: #fff;
}

/* ============================================================
   CALENDAR MODAL
   ============================================================ */

.weight-calendar-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.weight-calendar-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.weight-calendar-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.weight-calendar-sheet {
  position: relative;
  z-index: 1;
  background: #000;
  padding: var(--space-6);
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
  transform: translateY(30px);
  transition: transform 0.3s ease;
}

.weight-calendar-modal.open .weight-calendar-sheet {
  transform: translateY(0);
}

/* Selected date heading inside calendar */
.cal-selected-date {
  margin-bottom: var(--space-4);
}

.cal-year {
  font-size: 0.875rem;
  color: var(--gray-500);
  margin: 0 0 var(--space-1);
  font-family: "Geist Mono", monospace;
}

.cal-dayname {
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
  font-family: "Geist Mono", monospace;
}

/* Calendar panel (white card) */
.cal-panel {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.cal-prev {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: #333;
  cursor: pointer;
  padding: 0;
}

.cal-month-year {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #111;
  font-family: "Geist Mono", monospace;
  flex: 1;
  text-align: center;
}

/* Grid: 7 columns */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0;
}

.cal-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: #666;
  text-align: center;
  padding: var(--space-2) 0;
  font-family: "Geist Mono", monospace;
}

.cal-day {
  font-size: 0.875rem;
  font-weight: 500;
  color: #111;
  text-align: center;
  padding: 10px 0;
  border-radius: 50%;
  cursor: pointer;
  font-family: "Geist Mono", monospace;
  transition: background 0.15s ease;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-day:not(.cal-future):not(.cal-empty):hover {
  background: #eee;
}

.cal-day.cal-future {
  color: #bbb;
  cursor: default;
}

.cal-day.cal-empty {
  pointer-events: none;
}

.cal-day.cal-today {
  color: var(--blue-500);
  font-weight: 700;
}

.cal-day.cal-selected {
  background: #111;
  color: #fff;
  font-weight: 700;
}

.cal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-6);
  margin-top: var(--space-4);
}

.cal-btn-cancel,
.cal-btn-ok {
  background: none;
  border: none;
  font-size: 0.875rem;
  font-weight: 700;
  font-family: "Geist Mono", monospace;
  color: var(--blue-500);
  cursor: pointer;
  padding: var(--space-2) 0;
  min-height: 44px;
  letter-spacing: 0.05em;
}

/* ============================================================
   INDEX / HISTORY SCREEN
   ============================================================ */

.weight-index-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-4);
  flex-shrink: 0;
}

.weight-index-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: #fff;
}

.weight-index-actions {
  display: flex;
  gap: var(--space-4);
}

/* button_to wraps in a <form> — reset the global form flex layout */
.weight-index-actions form {
  display: contents;
}

.weight-index-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--gray-300);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
}

.weight-index-action-btn:hover {
  color: #fff;
}

/* Time frame row */
.weight-timeframe {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-3) var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--gray-800);
}

.weight-timeframe-label {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #fff;
  font-family: "Geist Mono", monospace;
}

.weight-timeframe-select {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--blue-500);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: "Geist Mono", monospace;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  min-height: 44px;
}

/* Chart */
.weight-chart-wrap {
  padding: var(--space-2) 0;
  background: #000;
}

.weight-chart-svg {
  width: 100%;
  height: 160px;
  display: block;
}

/* Current weight big display */
.weight-current-display {
  padding: var(--space-8) var(--space-6) var(--space-4);
  text-align: center;
}

.weight-current-value {
  font-size: 3rem;
  font-weight: 700;
  color: #fff;
  margin: 0 0 var(--space-2);
  font-family: "Geist Mono", monospace;
  letter-spacing: -0.03em;
}

.weight-current-change {
  font-size: 0.9375rem;
  font-weight: 500;
  margin: 0;
  font-family: "Geist Mono", monospace;
}

.weight-current-change.positive {
  color: var(--blue-500);
}

.weight-current-change.negative {
  color: #f87171;
}

/* ---- Utility ---- */
.hidden {
  display: none !important;
}

/* Entry list rows */
.weight-entry-list {
  padding: var(--space-2) var(--space-4) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.weight-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: var(--gray-900);
  border: 1px solid var(--gray-800);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  min-height: 60px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.weight-list-row:hover {
  border-color: var(--gray-700);
}

.weight-list-row.selected {
  border-color: var(--blue-500);
  background: #0070f310;
}

.weight-list-date {
  font-size: 0.9375rem;
  font-weight: 500;
  color: #fff;
  font-family: "Geist Mono", monospace;
}

.weight-list-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.weight-list-value {
  font-size: 0.875rem;
  color: var(--gray-400);
  font-family: "Geist Mono", monospace;
}

.weight-list-checkbox {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-600);
  flex-shrink: 0;
}

/* Toggle between empty and checked SVG based on row selection */
.weight-list-row .checkbox-checked {
  display: none;
}

.weight-list-row.selected .checkbox-empty {
  display: none;
}

.weight-list-row.selected .checkbox-checked {
  display: block;
}

/* FAB */
.weight-fab {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom));
  right: var(--space-5);
  width: 48px;
  height: 48px;
  background: var(--blue-500);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 112, 243, 0.4);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  z-index: 50;
}

.weight-fab:hover {
  background: var(--blue-600);
  box-shadow: 0 6px 24px rgba(0, 112, 243, 0.5);
  transform: translateY(-1px);
}

.weight-fab:active {
  transform: scale(0.96);
}

/* Empty state */
.weight-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  padding: var(--space-16) var(--space-6);
  color: var(--gray-500);
  font-size: 0.9375rem;
  text-align: center;
}

/* ============================================================
   "TIME FRAME" LABEL — clickable toggle
   ============================================================ */

.weight-timeframe-label {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #fff;
  font-family: "Geist Mono", monospace;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: color 0.2s ease;
}

/* Indicator dot that appears when table view is active */
.weight-timeframe-label::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue-500);
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.weight-timeframe-label--table {
  color: var(--blue-500);
}

.weight-timeframe-label--table::after {
  opacity: 1;
  transform: scale(1);
}

/* ============================================================
   CHART / TABLE / LIST REGIONS — animated transitions
   ============================================================ */

/* Chart region: visible by default, slides/fades out in table mode */
.weight-chart-region {
  transition: opacity 0.3s ease, transform 0.3s ease, max-height 0.35s ease;
  max-height: 400px;
  opacity: 1;
  transform: translateY(0);
  overflow: hidden;
}

/* Table region: hidden by default, slides/fades in in table mode */
.weight-table-region {
  transition: opacity 0.3s ease, transform 0.3s ease, max-height 0.35s ease;
  max-height: 0;
  opacity: 0;
  transform: translateY(-12px);
  overflow: hidden;
  pointer-events: none;
}

/* List region: visible by default, hidden in table mode */
.weight-list-region {
  transition: opacity 0.25s ease;
  opacity: 1;
}

/* Table view active ----------------------------------------- */
[data-view="table"] .weight-chart-region {
  max-height: 0;
  opacity: 0;
  transform: translateY(-8px);
}

[data-view="table"] .weight-table-region {
  max-height: 2000px;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

[data-view="table"] .weight-list-region {
  opacity: 0;
  pointer-events: none;
}

/* ============================================================
   WEEKLY TABLE VIEW
   4 columns: # | Period | Avg | Diff
   Tapping a row expands an inline day-detail row below it.
   Animation: CSS grid-template-rows 0fr → 1fr (no stutter).
   ============================================================ */

.weight-table-wrap {
  padding: var(--space-3) var(--space-4) var(--space-4);
}

/* Card container — rounded, bordered, clips overflow for corner radius */
.weight-table-card {
  border: 1px solid var(--gray-800);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--gray-900);
}

.weight-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Geist Mono", monospace;
  font-size: 0.75rem;
  table-layout: fixed;
}

/* Header */
.weight-table thead tr {
  border-bottom: 1px solid var(--gray-800);
  background: var(--gray-900);
}

.weight-table th {
  padding: var(--space-3) var(--space-4);
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray-600);
  white-space: nowrap;
}

/* Column widths */
.weight-table th.wt-col-week,
.weight-table td.wt-col-week   { width: 40px; text-align: center; }

.weight-table th.wt-col-period,
.weight-table td.wt-col-period { text-align: left; }

.weight-table th.wt-col-avg,
.weight-table td.wt-col-avg    { width: 72px; text-align: right; }

.weight-table th.wt-col-diff,
.weight-table td.wt-col-diff   { width: 64px; text-align: right;
                                  padding-right: var(--space-4); }

/* ---- Summary rows ---- */
.wt-summary-row {
  border-bottom: 1px solid var(--gray-800);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease;
}

.wt-summary-row:last-of-type,
.wt-summary-row--open {
  border-bottom-color: transparent;
}

.wt-summary-row:hover {
  background: var(--gray-800);
}

/* Chevron on the # cell */
.wt-summary-row td.wt-col-week {
  position: relative;
}

.wt-summary-row td.wt-col-week::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-top: 4.5px solid var(--gray-600);
  vertical-align: middle;
  margin-left: 3px;
  transition: transform 0.22s ease;
}

.wt-summary-row--open td.wt-col-week::after {
  transform: rotate(180deg);
}

/* Body cells */
.weight-table td {
  padding: var(--space-3) var(--space-4);
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.weight-table td.wt-col-week {
  color: var(--gray-600);
  font-size: 0.625rem;
  font-weight: 500;
}

.weight-table td.wt-col-period {
  color: var(--gray-400);
  font-size: 0.6875rem;
}

/* Avg — most prominent */
.weight-table td.wt-col-avg {
  color: #fff;
  font-weight: 700;
  font-size: 0.8125rem;
}

.weight-table td.wt-col-avg.wt-empty {
  color: var(--gray-700);
  font-weight: 400;
}

/* Diff */
.weight-table td.wt-col-diff { font-weight: 700; }

.weight-table td.wt-diff-up      { color: var(--blue-500); }
.weight-table td.wt-diff-down    { color: #f87171; }
.weight-table td.wt-diff-neutral { color: var(--gray-500); }
.weight-table td.wt-col-diff.wt-empty { color: var(--gray-700); font-weight: 400; }

/* ---- Detail rows — grid-template-rows animation ---- */
/*
   Structure:
     <tr.wt-detail-row>
       <td.wt-detail-cell>
         <div.wt-detail-grid>      ← display:grid; animates grid-template-rows
           <div.wt-detail-inner>   ← overflow:hidden; clips during animation
             day pills…
           </div>
         </div>
       </td>
     </tr>
*/

.wt-detail-row {
  border-bottom: 1px solid var(--gray-800);
}

/* Remove bottom border when collapsed (detail row has no visible content) */
.wt-detail-row:not(.wt-detail-row--open) {
  border-bottom-color: transparent;
}

.wt-detail-cell {
  padding: 0;
}

/* Grid container: 0fr = fully collapsed, 1fr = fully expanded */
.wt-detail-grid {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.26s ease;
}

.wt-detail-row--open .wt-detail-grid {
  grid-template-rows: 1fr;
}

/* Inner: must have overflow:hidden for the 0fr clip to work.
   Do NOT add padding here — it breaks the collapse clip. */
.wt-detail-inner {
  overflow: hidden;
}

/* Days wrapper: carries the padding and flex layout */
.wt-detail-days {
  display: flex;
  padding: var(--space-3) var(--space-3) var(--space-4);
}

/* Individual day pills */
.wt-day-pill {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.wt-day-name {
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray-600);
}

.wt-day-value {
  font-size: 0.75rem;
  font-weight: 600;
}

.wt-day-pill--has-value .wt-day-value { color: #fff; }
.wt-day-pill--empty     .wt-day-value { color: var(--gray-700); }

/* ============================================================
   PERIOD PICKER SHEET
   ============================================================ */

.period-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.period-sheet.open {
  opacity: 1;
  pointer-events: auto;
}

.period-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.period-sheet-panel {
  position: relative;
  z-index: 1;
  background: var(--gray-900);
  border-top: 1px solid var(--gray-800);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-5) var(--space-4);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  transform: translateY(16px);
  transition: transform 0.25s ease;
}

.period-sheet.open .period-sheet-panel {
  transform: translateY(0);
}

.period-sheet-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-3);
  padding: 0 var(--space-2);
}

.period-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-4) var(--space-4);
  min-height: 52px;
  font-size: 1rem;
  font-weight: 500;
  font-family: "Geist Mono", monospace;
  color: var(--gray-200);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: background 0.1s ease, color 0.1s ease;
}

.period-option:hover {
  background: var(--gray-800);
  color: #fff;
}

.period-option--active {
  color: var(--blue-500);
  font-weight: 600;
}

.period-option--active::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue-500);
  flex-shrink: 0;
}
