/**
 * Personal Bests — themed for Ippo light UI
 *
 * Shell: fixed right-edge badges panel.
 * - Desktop: floating ribbons always visible (no tab).
 * - Mobile: thin vertical orange "Badges" tab; drawer slides out from the right.
 */

.pb-ribbons-wrap {
  position: fixed;
  right: 0;
  top: 96px;
  z-index: 95;
  pointer-events: none;
  max-width: 280px;
}

.pb-ribbons-tab {
  display: none; /* mobile only */
  pointer-events: auto;
  box-sizing: border-box;
  width: 26px;
  min-height: 96px;
  padding: 0.65rem 0.2rem;
  margin: 0;
  border: none;
  border-radius: 10px 0 0 10px;
  background: linear-gradient(180deg, #fb923c 0%, #ea580c 100%);
  color: #fff;
  box-shadow: -3px 4px 12px rgba(234, 88, 12, 0.35);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.pb-ribbons-tab-text {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1;
  user-select: none;
}
.pb-ribbons-tab.is-open {
  background: linear-gradient(180deg, #f97316 0%, #c2410c 100%);
  box-shadow: -2px 2px 8px rgba(194, 65, 12, 0.4);
}
.pb-ribbons-tab:active {
  transform: translateX(1px);
}

.pb-ribbons-drawer {
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 260px;
  padding-right: 16px;
}
.pb-ribbons-drawer-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.15rem 0.1rem 0.25rem;
  font-size: 0.9rem;
  color: #1c1917;
}
.pb-ribbons-close {
  border: none;
  background: #f5f5f4;
  color: #44403c;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  flex-shrink: 0;
  pointer-events: auto;
  touch-action: manipulation;
}
.pb-ribbons-close:active {
  background: #e7e5e4;
}

#pbRibbonsContainer,
.pb-ribbons-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 260px;
  pointer-events: none;
}

/* Re-enable clicks on ribbons AND reaction controls */
#pbRibbonsContainer .pb-ribbon,
#pbRibbonsContainer .pb-ribbon-wrap,
#pbRibbonsContainer .pb-react-bar,
#pbRibbonsContainer .pb-react-btn,
#pbRibbonsContainer .pb-react-toggle,
#pbRibbonsContainer .pb-ribbon-empty,
.pb-view-all-link {
  pointer-events: auto;
}

.pb-view-all-link {
  font-size: 0.8rem;
  font-weight: 700;
  color: #c2410c;
  text-decoration: none;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  text-align: center;
  display: inline-block;
  align-self: stretch;
}
.pb-view-all-link:hover { background: #ffedd5; }

/* Desktop: always show drawer contents, hide tab */
@media (min-width: 901px) {
  .pb-ribbons-wrap {
    right: 16px;
    top: 96px;
  }
  .pb-ribbons-tab { display: none !important; }
  .pb-ribbons-drawer {
    position: static;
    pointer-events: none;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    width: auto;
    max-width: 260px;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: visible;
  }
  .pb-ribbons-drawer-head { display: none !important; }
}

/* Mobile: vertical tab peeks on right; drawer slides out */
@media (max-width: 900px) {
  .pb-ribbons-wrap {
    /* Align near mascot / "Ippo 🔥" header band */
    top: 72px;
    right: 0;
    bottom: auto;
    width: auto;
    max-width: none;
    height: auto;
    max-height: calc(100vh - 130px);
  }

  .pb-ribbons-tab {
    display: inline-flex;
    position: relative;
    z-index: 2;
  }

  .pb-ribbons-drawer {
    position: absolute;
    top: 0;
    right: 100%; /* sits just left of the tab */
    width: min(78vw, 248px);
    max-height: calc(100vh - 140px);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.55rem 0.6rem 0.7rem;
    margin: 0;
    background: rgba(255, 255, 255, 0.98);
    border: 1.5px solid #fed7aa;
    border-right: none;
    border-radius: 14px 0 0 14px;
    box-shadow: -10px 8px 28px rgba(28, 25, 23, 0.16);
    /* Hidden off to the right (under tab / off-screen) */
    transform: translateX(calc(100% + 26px));
    opacity: 0;
    visibility: hidden;
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.18s ease,
                visibility 0.24s;
    pointer-events: none;
    gap: 8px;
  }

  .pb-ribbons-wrap.is-open .pb-ribbons-drawer {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .pb-ribbons-drawer-head {
    display: flex;
  }

  #pbRibbonsContainer,
  .pb-ribbons-container {
    max-width: 100%;
    width: 100%;
  }

  .pb-ribbon {
    min-height: 42px;
    padding: 8px 10px;
    font-size: 12px;
    width: 100%;
  }
  .pb-ribbon-value { font-size: 14px; }

  /* Home landing nudge: bounce tab left so users notice it */
  @keyframes pb-badges-nudge {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-12px); }
    45% { transform: translateX(0); }
    65% { transform: translateX(-8px); }
    85% { transform: translateX(0); }
  }
  .pb-ribbons-wrap.nudge:not(.is-open) {
    animation: pb-badges-nudge 1.05s ease 0.45s 1;
  }
}

.pb-ribbon {
  background: linear-gradient(135deg, #fb923c 0%, #ea580c 55%, #f97316 100%);
  color: white;
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(234, 88, 12, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  border: none;
  min-height: 48px;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.pb-ribbon:hover {
  transform: translateX(-4px);
  box-shadow: 0 12px 28px rgba(234, 88, 12, 0.32);
}

.pb-ribbon:active {
  transform: translateX(-2px) scale(0.99);
}

.pb-ribbon-emoji {
  font-size: 20px;
  min-width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pb-ribbon-content {
  flex: 1;
  min-width: 0;
}

.pb-ribbon-label {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.95;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.pb-ribbon-value {
  font-size: 16px;
  font-weight: 800;
  margin-top: 2px;
  display: block;
}

.pb-ribbon-date {
  font-size: 11px;
  opacity: 0.85;
  margin-top: 2px;
  display: block;
}

/* Modal PB pieces when shown */
.pb-primary-metric,
.pb-metrics-section,
.pb-description-section {
  color: #1c1917;
}

.pb-primary-value {
  font-weight: 800;
  color: #ea580c;
}

.pb-metric-choices button,
.pb-metric-choice {
  min-height: 48px;
  border-radius: 12px;
  border: 1.5px solid #e7e0d6;
  background: #fff7ef;
  color: #1c1917;
  font-weight: 700;
  touch-action: manipulation;
}

.pb-empty-state,
.pb-loading-state {
  text-align: center;
  padding: 2rem 1rem;
  color: #57534e;
}

.pb-loading-state .spinner {
  margin: 0 auto 1rem;
  width: 40px;
  height: 40px;
  border: 4px solid #e7e0d6;
  border-top-color: #f97316;
  border-radius: 50%;
  animation: pbspin 0.8s linear infinite;
}

@keyframes pbspin {
  to { transform: rotate(360deg); }
}

@media (max-width: 1200px) {
  .pb-ribbon {
    padding: 10px 12px;
  }
}

.pb-ribbon.has-upgrade {
  box-shadow: 0 0 0 2px #fbbf24, 0 10px 24px rgba(234, 88, 12, 0.25);
}
.pb-upgrade-dot {
  font-weight: 900;
  background: #fbbf24;
  color: #78350f;
  border-radius: 999px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.pb-ribbon-empty {
  background: #fff7ed;
  color: #9a3412;
  border: 1.5px dashed #fb923c;
  box-shadow: none;
  text-decoration: none;
}
.pb-ribbon-empty .pb-ribbon-label { color: #c2410c; }

/* Library */
.pb-library-page { max-width: 900px; margin: 0 auto; padding-bottom: 5rem; }
.pb-library-header h1 { font-size: 1.6rem; margin: 0 0 0.4rem; color: #1c1917; }
.pb-library-lead { color: #57534e; margin: 0 0 1.5rem; line-height: 1.45; }
.pb-section { margin-bottom: 2rem; }
.pb-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.pb-section-head h2 { margin: 0; font-size: 1.15rem; color: #1c1917; }
.pb-section-meta { color: #a8a29e; font-weight: 700; font-size: 0.9rem; }

.pb-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.pb-card {
  text-align: left;
  border: none;
  border-radius: 16px;
  padding: 1rem;
  background: linear-gradient(145deg, #fff7ed, #ffedd5);
  border: 1.5px solid #fed7aa;
  cursor: pointer;
  display: flex;
  gap: 0.75rem;
  transition: transform 0.12s ease;
}
.pb-card:hover { transform: translateY(-2px); }
.pb-card.has-upgrade { border-color: #f59e0b; box-shadow: 0 0 0 2px #fde68a; }
.pb-card-empty {
  background: #fafaf9;
  border-style: dashed;
  border-color: #d6d3d1;
  cursor: default;
  color: #78716c;
}
.pb-card-emoji { font-size: 1.8rem; }
.pb-card-label { font-weight: 800; color: #9a3412; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }
.pb-card-activity { font-size: 0.85rem; color: #57534e; }
.pb-card-value { font-size: 1.25rem; font-weight: 800; color: #1c1917; margin-top: 0.2rem; }
.pb-card-date { font-size: 0.75rem; color: #a8a29e; }
.pb-card-upgrade { margin-top: 0.35rem; font-size: 0.8rem; font-weight: 700; color: #b45309; }

.pb-list { display: flex; flex-direction: column; gap: 0.5rem; }
.pb-list-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #fff;
  border: 1px solid #e7e0d6;
  border-radius: 12px;
  padding: 0.4rem 0.5rem 0.4rem 0.25rem;
}
.pb-list-row.has-upgrade { border-color: #fbbf24; }
.pb-list-main {
  flex: 1;
  display: flex;
  gap: 0.65rem;
  align-items: center;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  min-width: 0;
}
.pb-list-emoji { font-size: 1.4rem; }
.pb-list-info { display: flex; flex-direction: column; min-width: 0; gap: 0.1rem; }
.pb-list-info .muted, .muted { color: #a8a29e; font-size: 0.8rem; }
.pb-list-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.pb-group-title { margin: 1rem 0 0.4rem; font-size: 1rem; color: #44403c; }
.pb-empty-hint { color: #78716c; font-size: 0.95rem; }
.pb-filters { margin-bottom: 0.75rem; }
.pb-filter { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; font-weight: 600; color: #57534e; max-width: 240px; }
.pb-filter select {
  border: 1.5px solid #e7e0d6;
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  background: #fff;
  color: #1c1917;
}

/* Upgrade banner in modal */
.pb-upgrade-banner {
  margin: 1rem 0;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  background: linear-gradient(135deg, #fef3c7, #ffedd5);
  border: 1.5px solid #fbbf24;
}
.pb-upgrade-title { font-weight: 800; color: #92400e; margin-bottom: 0.35rem; }
.pb-upgrade-values { font-size: 1.1rem; font-weight: 700; color: #1c1917; }
.pb-upgrade-date { display: block; font-size: 0.8rem; color: #78716c; font-weight: 500; }
.pb-upgrade-actions { display: flex; gap: 0.5rem; margin-top: 0.65rem; flex-wrap: wrap; }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; border-radius: 8px; }

/* Metric choices */
.pb-metric-choice {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
}
.pb-metric-choice-label { font-weight: 700; }
.pb-metric-choice-value { color: #57534e; font-size: 0.9rem; }

.pb-swap-choices { display: flex; flex-direction: column; gap: 0.5rem; }
.pb-swap-choice {
  text-align: left;
  border: 1.5px solid #e7e0d6;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  background: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.pb-swap-choice:hover { border-color: #fb923c; background: #fff7ed; }
.pb-swap-cta { color: #ea580c; font-weight: 700; font-size: 0.85rem; margin-top: 0.25rem; }

.pb-toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: #1c1917;
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  max-width: 90vw;
}
.pb-toast.error { background: #b91c1c; }

.pb-primary-metric {
  text-align: center;
  padding: 1rem 0;
}
.pb-primary-value { font-size: 2rem; }
.pb-primary-unit { font-size: 1rem; margin-left: 0.25rem; color: #78716c; }
.pb-all-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}
.pb-metric-item {
  background: #fafaf9;
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  border: 1px solid #e7e0d6;
}
.pb-metric-label { font-size: 0.75rem; color: #78716c; display: block; }
.pb-metric-number { font-weight: 800; color: #1c1917; }

@media (max-width: 768px) {
  .pb-list-row { flex-direction: column; align-items: stretch; }
  .pb-list-actions { justify-content: flex-end; padding: 0 0.35rem 0.35rem; }
}

/* Section expand / collapse */
.pb-section-expand {
  display: flex;
  justify-content: center;
  margin-top: 0.65rem;
}
.pb-expand-btn {
  border: 1.5px solid #fed7aa;
  background: #fff7ed;
  color: #c2410c;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 44px;
}
.pb-expand-btn:hover {
  background: #ffedd5;
  border-color: #fb923c;
}
