/* ===========================
   modals.css
   Overlay-based UI: calendar, growth chart, settings modals,
   the toggle switch, and the shared time-picker modal.
   =========================== */

/* ---- Shared overlay ---- */
.calendar-overlay,
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  backdrop-filter: blur(2px);
}

.calendar-overlay.visible,
.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---- Shared modal shell ---- */
.calendar-modal,
.growth-modal,
.settings-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: calc(100% - 32px);
  max-width: 400px;
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  z-index: 101;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  padding: 20px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}

.calendar-modal.visible,
.growth-modal.visible,
.settings-modal.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

/* ---- Calendar Modal ---- */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.cal-nav-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink);
  transition: all 0.15s;
}

.cal-nav-btn:active {
  background: var(--c4);
}

.cal-month-year {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.month-summary {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.ms-item {
  flex: 1;
  background: var(--bg);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.ms-label {
  font-size: 9px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.ms-value {
  font-family: 'DM Serif Display', serif;
  font-size: 18px;
  letter-spacing: -0.5px;
  color: var(--ink);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day-label {
  text-align: center;
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-mid);
  padding: 6px 0;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.cal-day {
  aspect-ratio: 1;
  border: none;
  background: transparent;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
  position: relative;
  transition: all 0.15s;
}

.cal-day:hover:not(.empty):not(.disabled) {
  background: var(--bg);
}

.cal-day:active:not(.empty):not(.disabled) {
  background: var(--c4);
}

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

.cal-day.disabled {
  color: var(--ink-light);
  pointer-events: none;
}

.cal-day.today {
  background: var(--c4);
  font-weight: 600;
}

.cal-day.selected {
  background: var(--ink);
  color: var(--white);
  font-weight: 600;
}

.cal-day.has-data::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--sleep-ink);
}

.cal-day.selected.has-data::after {
  background: var(--white);
}

.cal-day.today.has-data::after {
  background: var(--pee-ink);
}

/* ---- Growth Chart Modal ---- */
.growth-modal {
  max-width: 460px;
}

.growth-header,
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.growth-title,
.settings-title {
  font-family: 'DM Serif Display', serif;
  font-size: 20px;
  letter-spacing: -0.3px;
  color: var(--ink);
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-mid);
  transition: all 0.15s;
}

.modal-close:active {
  background: var(--c5);
  color: var(--ink);
}

.growth-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  padding: 0 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 0.3px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-weight .legend-dot { background: var(--weight-ink); }
.legend-height .legend-dot { background: var(--height-ink); }

.growth-chart-wrap {
  position: relative;
  width: 100%;
  background: var(--bg);
  border-radius: var(--radius-btn);
  padding: 14px 8px 8px;
  min-height: 220px;
}

#growthCanvas {
  display: block;
  width: 100%;
  height: 240px;
}

.growth-empty {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--ink-light);
  font-size: 13px;
  padding: 20px;
  text-align: center;
}

.growth-empty.visible {
  display: flex;
}

.growth-empty svg {
  opacity: 0.4;
}

.growth-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.gs-card {
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 12px;
}

.gs-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.gs-value {
  font-family: 'DM Serif Display', serif;
  font-size: 18px;
  letter-spacing: -0.3px;
  color: var(--ink);
}

.gs-delta {
  font-size: 11px;
  color: var(--vitamin-ink);
  font-weight: 500;
  margin-left: 6px;
}

/* ---- Settings Modal ---- */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: 12px;
}

.settings-row-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.settings-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-mid);
  flex-shrink: 0;
}

.settings-text {
  flex: 1;
  min-width: 0;
}

.settings-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.1px;
}

.settings-desc {
  font-size: 11px;
  color: var(--ink-mid);
  margin-top: 2px;
}

.settings-action {
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  background: var(--white);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 10px;
  padding: 6px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s;
  flex-shrink: 0;
}

.settings-action:active {
  background: var(--c4);
}

.settings-footer {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(0,0,0,.06);
}

.settings-danger {
  width: 100%;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  color: var(--ink-mid);
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  text-align: center;
  border-radius: 8px;
  transition: all 0.15s;
}

.settings-danger:active {
  background: var(--bg);
  color: var(--ink);
}

/* ---- Toggle Switch ---- */
.toggle {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--ink-light);
  border-radius: 24px;
  transition: 0.25s;
}

.toggle-track::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: 0.25s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-track {
  background: var(--sleep-ink);
}

.toggle input:checked + .toggle-track::before {
  transform: translateX(18px);
}

/* ---- Time Picker Modal (shared utility) ---- */
.tp-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  backdrop-filter: blur(2px);
}

.tp-picker {
  background: var(--white);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  max-width: 320px;
  width: calc(100% - 32px);
}

.tp-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--ink);
}

.tp-row {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.tp-field {
  flex: 1;
}

.tp-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mid);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 6px;
}

.tp-select,
.tp-input {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
}

.tp-input { cursor: text; }

.tp-actions {
  display: flex;
  gap: 10px;
}

.tp-btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.08);
}

.tp-btn-cancel {
  background: var(--white);
  color: var(--ink);
}

.tp-btn-save {
  background: var(--ink);
  color: var(--white);
  border-color: var(--ink);
}

.tp-btn:active {
  transform: scale(0.97);
}
