/* ══ STATS MODAL ══ */

#stats-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(7, 9, 15, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  justify-content: center;
  align-items: flex-end; /* mobile: sheet from bottom */
  padding: 0;
  overscroll-behavior: contain;
}

#stats-modal.open {
  display: flex;
}

.stats-modal-card {
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  border-radius: 28px 28px 0 0;
  padding: 0;
  scrollbar-width: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* safe area for notched phones */
  padding-bottom: env(safe-area-inset-bottom);
}

.stats-modal-card::-webkit-scrollbar {
  display: none;
}

/* ── Header ── */
.stats-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(16px, 4vw, 22px) clamp(16px, 5vw, 24px) 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  background: inherit;
  z-index: 10;
}

.stats-modal-title {
  font-family: 'Outfit', sans-serif;
  font-size: clamp(1rem, 3.5vw, 1.1rem);
  font-weight: 400;
  color: rgba(255, 255, 255, 0.85);
  letter-spacing: 1px;
}

.stats-modal-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.35);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stats-modal-close:hover,
.stats-modal-close:focus-visible {
  color: rgba(255, 255, 255, 0.8);
  outline: none;
}

/* ── Week nav ── */
.stats-week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px clamp(16px, 5vw, 24px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  gap: 8px;
}

.week-range-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 1px;
  flex: 1;
  text-align: center;
}

.week-nav-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 36px;
}

.week-nav-btn:hover,
.week-nav-btn:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.8);
  outline: none;
}

/* ── Bar chart ── */
.stats-bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 100px;
  padding: 16px clamp(16px, 5vw, 24px) 8px;
}

.bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}

.bar-val {
  font-size: 9px;
  color: rgba(255, 255, 255, 0.3);
  white-space: nowrap;
}

.bar-fill {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: rgba(99, 102, 241, 0.35);
  min-height: 2px;
  transition: height 0.4s ease;
}

.bar-fill.today {
  background: #3b82f6;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

.bar-day {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.35);
}

/* ── Summary grid ── */
.stats-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1px;
  background: rgba(255, 255, 255, 0.06);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.summary-cell {
  background: rgba(255, 255, 255, 0.02);
  padding: clamp(10px, 3vw, 14px) clamp(10px, 4vw, 16px);
}

.summary-cell-label {
  font-size: 0.58rem;
  color: rgba(255, 255, 255, 0.35);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 5px;
}

.summary-cell-val {
  font-family: 'Outfit', sans-serif;
  font-size: clamp(0.85rem, 3vw, 1rem);
  font-weight: 400;
}

.summary-cell-val.blue  { color: #60a5fa; }
.summary-cell-val.green { color: #34d399; }
.summary-cell-val.pink  { color: #f472b6; }

/* ── Log list ── */
.stats-log-list {
  padding: 8px clamp(16px, 5vw, 24px) clamp(20px, 5vw, 24px);
}

.log-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  gap: 12px;
}

.log-row:last-child {
  border-bottom: none;
}

.log-date {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.55);
  flex-shrink: 0;
}

.log-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.log-meta-item {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.35);
  white-space: nowrap;
}

.log-meta-item span {
  color: rgba(255, 255, 255, 0.75);
  font-weight: 500;
}

.stats-empty {
  text-align: center;
  padding: 30px 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.25);
  letter-spacing: 1px;
}

/* ── Desktop: centered modal ── */
@media (min-width: 480px) {
  #stats-modal {
    align-items: center;
    padding: 20px;
  }

  .stats-modal-card {
    border-radius: 28px;
    padding-bottom: 0;
  }
}