/* =========================================================
   PilotMetrics - Story cards (scripts/share.js)
   The share sheet, the share buttons on cards and the
   Dashboard's milestone celebration.
   ========================================================= */

body.story-open { overflow: hidden; }

.story-overlay { z-index: 120; }

.modal.story-modal { max-width: 760px; padding: 20px 22px; }

.story-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.story-eyebrow { font-size: 12px; font-weight: 800; color: var(--cyan); }
.story-head h3 { margin: 2px 0 0; font-size: 20px; }
.story-close { background: transparent; border: 1px solid var(--line); color: var(--muted); padding: 2px 9px; min-height: 0; }
.story-close:hover { background: var(--line); box-shadow: none; }

/* The app is dark-only: native scrollbars and the record picker follow suit */
.story-overlay { color-scheme: dark; }
.modal.story-modal { scrollbar-width: thin; scrollbar-color: var(--line-light) transparent; }
.modal.story-modal::-webkit-scrollbar { width: 8px; }
.modal.story-modal::-webkit-scrollbar-thumb { background: var(--line-light); border-radius: 4px; }
.modal.story-modal::-webkit-scrollbar-track { background: transparent; }

/* One tile per kind of card, wrapping (no sideways scrolling); records share one tile */
.story-label { font-size: 12px; font-weight: 800; color: var(--muted); margin-bottom: 6px; }
.story-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-bottom: 16px; }
.story-option {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 1px;
  min-height: 0; padding: 8px 10px; border-radius: 10px; text-align: left;
  background: var(--inset); color: #e2e8f0; border: 1px solid var(--line);
}
.story-option:hover { background: #17233a; border-color: var(--line-light); box-shadow: none; }
.story-option.active { background: var(--cyan-light); border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan) inset; }
.story-option-icon { font-size: 18px; line-height: 1.2; margin-bottom: 2px; }
.story-option b { font-size: 12px; font-weight: 700; line-height: 1.3; }
.story-option small { font-size: 12px; color: var(--muted); line-height: 1.3; }
.story-option.active small { color: #a5f3fc; }
.story-option.loading { justify-content: center; align-items: center; font-size: 12px; font-style: italic; color: var(--muted); border-style: dashed; }

/* Which record (the cards that share a tile) */
.story-variant { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 700; color: var(--muted); }
.story-variant[hidden] { display: none; }
.story-variant select { width: 100%; font-size: 12px; }

.story-body { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: start; }

.story-preview { display: flex; align-items: center; gap: 6px; }
.story-frame {
  position: relative; width: 270px; aspect-ratio: 9 / 16; border-radius: 16px; overflow: hidden;
  background: var(--bg); border: 1px solid var(--line-light); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.story-frame img { display: block; width: 100%; height: 100%; object-fit: cover; transition: opacity 0.15s ease; }
.story-frame img:not([src]) { visibility: hidden; }
.story-loading {
  position: absolute; inset: 0; display: none; place-items: center; font-size: 12px; font-weight: 700; color: var(--muted);
}
.story-frame.busy img { opacity: 0.35; }
.story-frame.busy .story-loading { display: grid; }

.story-nav {
  flex: none; width: 30px; height: 30px; min-height: 0; padding: 0; border-radius: 50%; font-size: 18px; line-height: 1;
  background: var(--line); color: var(--text-soft); border: 1px solid var(--line-light);
}
.story-nav:hover { background: var(--line-light); box-shadow: none; }
.story-nav:disabled { opacity: 0.3; cursor: default; }

.story-side { display: flex; flex-direction: column; gap: 8px; }
.story-caption { margin: 0 0 4px; font-size: 13px; line-height: 1.5; color: #e2e8f0; }
.story-caption:empty { display: none; }
.story-tip { margin: 4px 0 0; font-size: 12px; line-height: 1.55; color: var(--muted); }
.story-status { margin: 0; font-size: 12px; font-weight: 600; color: var(--green-text); min-height: 1em; }

/* Instagram's own gradient, so the button is recognisable at a glance */
button.story-ig {
  min-height: 44px; font-size: 13px; font-weight: 800;
  background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
}
button.story-ig:hover { filter: brightness(1.08); }

@media (max-width: 640px) {
  .modal.story-modal { padding: 16px; }
  /* base.css makes every modal button full width on phones; these stay compact */
  .modal.story-modal .story-close,
  .modal.story-modal .story-nav { width: auto !important; }
  .story-options { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
  .story-option { padding: 6px 7px; }
  .story-option-icon { font-size: 16px; }
  .story-option b { font-size: 12px; }
  .story-option small { font-size: 12px; }
  .modal.story-modal .story-nav { width: 30px !important; }
  .story-body { grid-template-columns: 1fr; gap: 14px; }
  .story-preview { justify-content: center; }
  /* Small enough that the share button stays in view */
  .story-frame { width: min(48vw, 190px); }
}

/* "Share" buttons on cards (hidden on shared profiles, where the training isn't the visitor's) */
.story-btn { gap: 6px; }
body.is-read-only .story-btn { display: none !important; }
.record-banner-share { margin-left: auto; flex: none; }
.story-rank { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* The Dashboard's milestone celebration (Today card) */
.story-celebrate {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 12px; padding: 12px 14px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.16), rgba(148, 163, 184, 0.12));
  border: 1px solid rgba(234, 179, 8, 0.45);
}
.story-celebrate-icon { font-size: 26px; line-height: 1; }
.story-celebrate-text { flex: 1 1 220px; font-size: 12px; line-height: 1.5; color: #e2e8f0; }
.story-celebrate-text b { display: block; font-size: 13px; color: #fff; }
.story-celebrate-actions { display: flex; gap: 6px; align-items: center; }

/* Setup wizard's last step: tell your friends */
.setup-share {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; padding: 12px 14px; border-radius: 10px;
  background: var(--inset); border: 1px solid var(--line);
}
.setup-share > span { flex: 1 1 240px; font-size: 12px; line-height: 1.5; color: var(--muted); }
.setup-share > span b { color: #fff; }
