/* ============================================================
   A Better Plan — Custom Styles & Animations
   ============================================================ */

/* ---- General ---- */
body {
  background-color: #f8f9fa;
  min-height: 100vh;
}

.navbar-brand {
  letter-spacing: 0.5px;
}

/* ============================================================
   KEYFRAMES
   ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRow {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes rowFadeOut {
  to {
    opacity: 0;
    transform: translateX(10px) scaleY(0.6);
    max-height: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
  }
}

/* Rating button selection: bouncy pop */
@keyframes ratingPop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.22); }
  65%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}

/* Log dots: scale in with overshoot */
@keyframes dotPop {
  0%   { transform: scale(0); opacity: 0; }
  55%  { transform: scale(1.4); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Counter badge pop */
@keyframes badgeBounce {
  0%, 100% { transform: scale(1); }
  40%      { transform: scale(1.4); }
  70%      { transform: scale(0.9); }
}

/* Save button success ripple */
@keyframes successRipple {
  0%   { box-shadow: 0 0 0 0 rgba(25, 135, 84, 0.55); }
  70%  { box-shadow: 0 0 0 12px rgba(25, 135, 84, 0); }
  100% { box-shadow: 0 0 0 0 rgba(25, 135, 84, 0); }
}

/* Positive things list item entrance (stats) */
@keyframes ptItemEnter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Reveal button toggle pop */
@keyframes revealPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.2); }
  70%  { transform: scale(0.9); }
  100% { transform: scale(1); }
}

/* ============================================================
   PAGE ENTRANCE
   ============================================================ */

/* Whole container fades in smoothly on every page load */
.container {
  animation: fadeIn 0.35s ease both;
}

/* Flash / alert messages slide down from above */
.alert {
  border-radius: 8px;
  animation: slideDown 0.3s ease both;
}

/* ============================================================
   SOCIAL CARDS — STAGGERED ENTRANCE
   ============================================================ */

.row.g-4 > .col {
  animation: fadeSlideUp 0.4s ease both;
}

.row.g-4 > .col:nth-child(1)  { animation-delay: 0.05s; }
.row.g-4 > .col:nth-child(2)  { animation-delay: 0.10s; }
.row.g-4 > .col:nth-child(3)  { animation-delay: 0.15s; }
.row.g-4 > .col:nth-child(4)  { animation-delay: 0.20s; }
.row.g-4 > .col:nth-child(5)  { animation-delay: 0.25s; }
.row.g-4 > .col:nth-child(6)  { animation-delay: 0.30s; }
.row.g-4 > .col:nth-child(7)  { animation-delay: 0.35s; }
.row.g-4 > .col:nth-child(8)  { animation-delay: 0.38s; }
.row.g-4 > .col:nth-child(9)  { animation-delay: 0.41s; }
.row.g-4 > .col:nth-child(n+10) { animation-delay: 0.44s; }

/* ============================================================
   LOG PAGE — RATING CARDS ENTRANCE
   ============================================================ */

#logForm > .rating-card {
  animation: fadeSlideUp 0.35s ease both;
}
#logForm > .rating-card:nth-child(1) { animation-delay: 0.07s; }
#logForm > .rating-card:nth-child(2) { animation-delay: 0.14s; }
#logForm > .rating-card:nth-child(3) { animation-delay: 0.21s; }
#logForm > .rating-card:nth-child(4) { animation-delay: 0.28s; }
#logForm > .rating-card:nth-child(5) { animation-delay: 0.35s; }

/* Positive-things card appears after rating cards */
#logForm > .card:not(.rating-card) {
  animation: fadeSlideUp 0.35s ease both;
  animation-delay: 0.42s;
}

/* ============================================================
   RATING BUTTON GROUP — MICRO-INTERACTIONS
   ============================================================ */

.rating-group-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.rating-label-low,
.rating-label-high {
  font-size: 0.8rem;
  color: #6c757d;
  white-space: nowrap;
}

.rating-group .btn {
  min-width: 2.6rem;
  font-weight: 600;
  transition: transform 0.12s ease, background-color 0.15s, border-color 0.15s, color 0.15s;
}

/* Hover lift on individual rating buttons */
.rating-group .btn:hover {
  transform: translateY(-2px) scale(1.06);
}

/* Satisfying pop when a rating is selected */
.btn-check:checked + .btn {
  animation: ratingPop 0.28s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* ============================================================
   RATING CARDS — HOVER LIFT
   ============================================================ */

.rating-card {
  border-left: 4px solid #0d6efd;
  transition: box-shadow 0.22s ease, transform 0.22s ease;
}

.rating-card:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.10) !important;
  transform: translateY(-2px);
}

/* ============================================================
   POSITIVE THINGS INPUT (LOG PAGE)
   ============================================================ */

.positive-thing-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  /* Entrance animation fires when element is inserted into DOM */
  animation: slideInRow 0.22s ease both;
  overflow: hidden;
}

/* Remove animation: class added by JS before actual removal */
.positive-thing-row.pt-row-out {
  animation: rowFadeOut 0.2s ease forwards;
}

.positive-thing-row input {
  flex: 1;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.positive-thing-row input:focus {
  transform: scale(1.01);
}

.positive-thing-row .btn-remove {
  flex-shrink: 0;
  padding: 0.25rem 0.6rem;
  color: #dc3545;
  background: none;
  border: 1px solid #dc3545;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1.5;
  transition: background-color 0.15s, color 0.15s;
}

.positive-thing-row .btn-remove:hover {
  background: #dc3545;
  color: #fff;
}

/* Counter badge pop when number increases */
#ptCounter.badge-pop {
  animation: badgeBounce 0.3s ease;
}

/* Save button success state */
#saveBtn.btn-saved {
  animation: successRipple 0.6s ease;
}

/* ============================================================
   CHART
   ============================================================ */

.chart-container {
  position: relative;
  height: 320px;
}

/* Period nav buttons */
#periodPrev,
#periodNext {
  transition: transform 0.15s ease, background-color 0.15s;
}

#periodPrev:not(:disabled):hover { transform: translateX(-3px); }
#periodNext:not(:disabled):hover { transform: translateX(3px); }

/* ============================================================
   POSITIVE THINGS LIST (STATS PAGE)
   ============================================================ */

.pt-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #e9ecef;
  gap: 12px;
  /* Entrance animation is triggered by adding .pt-item-enter in JS */
}

.pt-item.pt-item-enter {
  animation: ptItemEnter 0.25s ease both;
}

.pt-item:last-child {
  border-bottom: none;
}

.pt-item-content {
  flex: 1;
}

.pt-item-date {
  font-size: 0.78rem;
  color: #6c757d;
  margin-bottom: 2px;
}

.pt-item-text {
  font-size: 0.95rem;
}

.btn-reveal {
  flex-shrink: 0;
  font-size: 0.8rem;
  padding: 4px 10px;
  white-space: nowrap;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-reveal:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

/* Pop when reveal state toggles */
.btn-reveal.reveal-pop {
  animation: revealPop 0.25s ease;
}

/* ============================================================
   SOCIAL PAGE
   ============================================================ */

.user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #0d6efd;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  object-fit: cover;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.user-avatar:hover,
.user-avatar-img:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.user-avatar-img {
  background: none;
}

.user-avatar-lg {
  width: 72px;
  height: 72px;
  font-size: 2rem;
}

/* 7-day log dots — staggered pop-in triggered via IntersectionObserver */
.log-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0;
  transform: scale(0);
  transition: transform 0.15s ease;
}

/* Animation fires when JS adds .log-dots-animate to the parent container */
.log-dots-animate .log-dot {
  animation: dotPop 0.28s ease both;
}

.log-dot:hover {
  transform: scale(1.5);
}

.log-dot:nth-child(1) { animation-delay: 0.05s; }
.log-dot:nth-child(2) { animation-delay: 0.10s; }
.log-dot:nth-child(3) { animation-delay: 0.15s; }
.log-dot:nth-child(4) { animation-delay: 0.20s; }
.log-dot:nth-child(5) { animation-delay: 0.25s; }
.log-dot:nth-child(6) { animation-delay: 0.30s; }
.log-dot:nth-child(7) { animation-delay: 0.35s; }

.log-dot-yes  { background-color: #198754; }
.log-dot-no   { background-color: #dee2e6; }

/* ============================================================
   NAVBAR
   ============================================================ */

/* Explicit stacking context so dropdown always paints above page content */
.navbar {
  position: relative;
  z-index: 1030;
}

.nav-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.6);
  transition: transform 0.18s ease, border-color 0.18s;
}

.nav-avatar:hover { transform: scale(1.12); border-color: #fff; }

.nav-avatar-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  border: 2px solid rgba(255,255,255,0.6);
  flex-shrink: 0;
  transition: transform 0.18s ease;
}

.nav-avatar-initial:hover { transform: scale(1.12); }

/* Nav links: smooth underline slide-in (exclude dropdown-toggle — Bootstrap owns its ::after) */
.navbar .nav-link:not(.dropdown-toggle) {
  position: relative;
}

.navbar .nav-link:not(.dropdown-toggle)::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 0.5rem;
  right: 0.5rem;
  height: 2px;
  background: rgba(255,255,255,0.8);
  transform: scaleX(0);
  transition: transform 0.2s ease;
  border-radius: 2px;
  pointer-events: none;
}

.navbar .nav-link:not(.dropdown-toggle):hover::after,
.navbar .nav-link:not(.dropdown-toggle).active::after {
  transform: scaleX(1);
}

/* ============================================================
   CARDS — GENERAL HOVER LIFT
   ============================================================ */

.card {
  border-radius: 10px;
  transition: box-shadow 0.22s ease, transform 0.22s ease;
}

.card.shadow-sm:hover {
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.13) !important;
}

/* ============================================================
   POSITIVE THING ITEMS (SOCIAL CARDS)
   ============================================================ */

.positive-thing-item {
  padding: 4px 0;
  font-size: 0.9rem;
  color: #495057;
  border-bottom: 1px solid #f0f0f0;
  transition: color 0.15s, padding-left 0.15s;
}

.positive-thing-item:hover {
  padding-left: 4px;
}

.positive-thing-item:last-child {
  border-bottom: none;
}

.positive-thing-item::before {
  content: "✦ ";
  color: #ffc107;
  font-size: 0.7rem;
}

/* ============================================================
   ADMIN PAGE
   ============================================================ */

.table td, .table th {
  vertical-align: middle;
}

/* ============================================================
   FORM INPUTS
   ============================================================ */

.form-control {
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
}

.form-control:focus {
  border-color: #86b7fe;
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
  transform: scale(1.005);
}

/* ============================================================
   BUTTONS — GENERAL
   ============================================================ */

.btn {
  transition: transform 0.12s ease, box-shadow 0.12s ease,
              background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}

.btn:not(:disabled):active {
  transform: translateY(0) scale(0.97);
  box-shadow: none;
}

/* ============================================================
   PROFILE AVATAR LARGE
   ============================================================ */

.user-avatar-lg {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.user-avatar-lg:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

/* ============================================================
   REDUCED MOTION — accessibility
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   RESPONSIVE TWEAKS
   ============================================================ */

@media (max-width: 576px) {
  .rating-group .btn {
    min-width: 2.1rem;
    padding: 0.3rem 0.4rem;
    font-size: 0.9rem;
  }

  .chart-container {
    height: 240px;
  }
}
