/* ===========================================================================
   "Best Time to Post on Reddit" tool
   /tools/best-time-to-post-on-reddit/  — loaded via $extraCss on top of site.css
   Uses the shared design tokens from site.css (:root). Heatmap cell colours
   are set inline by JS (white -> --hot green ramp).
   ===========================================================================*/

.bttr { background: #fff; padding-top: 48px; }
.bttr .container { max-width: 900px; }

/* ---- Step 1 form -------------------------------------------------------- */
.bttr-form-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 26px 24px;
  box-shadow: 0 20px 45px -30px rgba(15, 23, 42, .35);
}
.bttr-form__row {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .bttr-form__row { grid-template-columns: 1fr 1fr; }
}

/* r/ prefix on the subreddit input */
.bttr-prefixed {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
  overflow: hidden;
}
.bttr-prefixed:focus-within {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
  background: #fff;
}
.bttr-prefixed span {
  display: flex;
  align-items: center;
  padding: 0 0 0 14px;
  font-weight: 600;
  color: var(--text-muted);
}
.bttr-prefixed input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 12px 14px 12px 1px;
  font-family: var(--font-body);
  font-size: .96rem;
}
.bttr-field select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-page);
  font-family: var(--font-body);
  font-size: .96rem;
  color: var(--navy);
}
.bttr-field select:focus { outline: 2px solid var(--orange); outline-offset: 1px; background: #fff; }
.bttr-field label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.bttr-field .bttr-hint { display: block; min-height: 1.1em; font-size: .78rem; color: #B91C1C; margin-top: 4px; }
.bttr-prefixed.bttr-invalid { border-color: #FCA5A5; background: #FEF2F2; }

.bttr-form__actions {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.bttr-form__actions .btn { flex-shrink: 0; }
.bttr-quota { font-size: .82rem; color: var(--text-muted); }

/* ---- Loading --------------------------------------------------------------- */
.bttr-loading {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  padding: 48px 0;
  color: var(--text-muted);
}
.bttr-loading.is-on { display: flex; }
.bttr-spinner {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--orange);
  animation: bttr-spin .8s linear infinite;
}
@keyframes bttr-spin { to { transform: rotate(360deg); } }

/* ---- Alert -------------------------------------------------------------- */
.bttr-alert {
  display: none;
  gap: 12px;
  align-items: flex-start;
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  font-size: .92rem;
  margin-top: 20px;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: #991B1B;
}
.bttr-alert.is-on { display: flex; }
.bttr-alert.is-warn { background: #FFFBEB; border-color: #FDE68A; color: #92400E; }
.bttr-alert svg { flex-shrink: 0; margin-top: 1px; }

/* ---- Result ----------------------------------------------------------------- */
.bttr-result { display: none; }
.bttr-result.is-on { display: block; }

.bttr-result__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 26px;
}
.bttr-result__title h2 { font-size: clamp(1.35rem, 3vw, 1.8rem); margin-bottom: 4px; }
.bttr-result__title h2 a { color: inherit; text-decoration: none; }
.bttr-result__title h2 a:hover { text-decoration: underline; }
.bttr-result__title p { margin: 0; color: var(--text-muted); font-size: .9rem; }
.bttr-result__meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.bttr-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #EFF4FF;
  color: var(--navy);
  font-size: .8rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
}
.bttr-badge svg { width: 13px; height: 13px; }

.bttr-cards {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 26px;
}
@media (min-width: 720px) { .bttr-cards { grid-template-columns: repeat(4, 1fr); } }
.bttr-card {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  text-align: center;
}
.bttr-card__num {
  font-family: var(--font-head);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.1;
}
.bttr-card__num small { font-size: .95rem; font-weight: 600; color: var(--text-muted); }
.bttr-card__label {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-top: 6px;
}

.bttr-sentence {
  background: #F0FDF4;
  border: 1px solid #BBF7D0;
  color: #166534;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-weight: 600;
  font-size: .98rem;
  margin-bottom: 24px;
}

.bttr-section-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.bttr-slots { display: grid; gap: 10px; margin-bottom: 4px; }
.bttr-slot {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.bttr-slot__rank {
  width: 26px; height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.bttr-slot__when { font-weight: 600; font-size: .95rem; }
.bttr-slot__stats { margin-left: auto; text-align: right; font-size: .82rem; color: var(--text-muted); }
.bttr-slot__stats b { color: var(--navy); }

/* ---- Bar charts (engagement by day / by hour) -------------------------- */
.bttr-charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px 40px;
  margin: 0 0 30px;
  padding: 28px 0 30px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
@media (min-width: 720px) {
  .bttr-charts { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
  /* vertical divider between the two bar charts */
  .bttr-bars--hour { border-left: 1px solid var(--border); padding-left: 24px; }
}
@media (max-width: 719px) {
  /* horizontal divider when they stack */
  .bttr-bars--hour { border-top: 1px solid var(--border); padding-top: 24px; }
}
.bttr-bars { margin: 0; min-width: 0; }
.bttr-bars figcaption { margin-bottom: 12px; }
.bttr-bars__plot {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;          /* overflow-x:auto alone makes y compute to auto */
  -webkit-overflow-scrolling: touch;
  padding: 4px 2px 0;
}
.bttr-bar {
  flex: 1 1 0;
  min-width: 16px;
  max-width: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  outline: none;
  cursor: default;
}
.bttr-bars--day .bttr-bar { max-width: 46px; }
.bttr-bars--hour .bttr-bars__plot { gap: 2px; }
.bttr-bars--hour .bttr-bar { min-width: 9px; max-width: 40px; }
.bttr-bars--hour .bttr-bar__track { width: 82%; }
.bttr-bar__track {
  width: 68%;
  min-width: 8px;
  height: 108px;
  display: flex;
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
}
.bttr-bar__fill {
  width: 100%;
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  transition: filter .12s ease;
}
.bttr-bars--day  .bttr-bar__fill { background: #4F46E5; }
.bttr-bars--hour .bttr-bar__fill { background: #0D9488; }
.bttr-bar.is-empty .bttr-bar__fill { background: transparent; }
.bttr-bar.is-empty .bttr-bar__track { position: relative; }
.bttr-bar.is-empty .bttr-bar__track::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: var(--cold);
  opacity: .55;
}
.bttr-bar.is-empty .bttr-bar__label { opacity: .5; }
.bttr-bar__label {
  margin-top: 6px;
  font-size: .62rem;
  /* fixed height so bars with a label and bars with an empty label are the
     same total height — otherwise flex-end alignment staggers the baselines
     (every 3rd hour bar would sit higher than its neighbours). */
  height: 12px;
  line-height: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: visible;
}
.bttr-bar:hover .bttr-bar__fill,
.bttr-bar:focus .bttr-bar__fill { filter: brightness(1.12); }
.bttr-bar:focus .bttr-bar__track { box-shadow: 0 0 0 2px var(--navy); border-radius: 3px; }

/* ---- Heatmap ------------------------------------------------------------- */
.bttr-heat-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 10px; }
.bttr-heat-wrap {
  overflow-x: auto;
  overflow-y: hidden;          /* overflow-x:auto alone makes y compute to auto */
  -webkit-overflow-scrolling: touch;
  margin: 8px 0 6px;
  padding: 3px 0 5px;
}
.bttr-heat {
  border-collapse: separate;
  border-spacing: 3px;
  margin: 0 auto;
}
.bttr-heat th {
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0;
  text-align: center;
}
.bttr-heat thead th { height: 18px; min-width: 22px; }
.bttr-heat tbody th { text-align: right; padding-right: 6px; width: 34px; }
.bttr-heat td {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: #F1F5F9;
  cursor: default;
  outline: none;
}
.bttr-heat td[data-posts="0"] { background: #F1F5F9; }
.bttr-heat td:focus,
.bttr-heat td:hover { box-shadow: 0 0 0 2px var(--navy); position: relative; }
@media (min-width: 720px) {
  .bttr-heat td, .bttr-heat thead th { width: 30px; min-width: 30px; }
  .bttr-heat td { height: 26px; }
}

.bttr-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .75rem;
  color: var(--text-muted);
}
.bttr-legend__scale {
  display: flex;
  gap: 2px;
}
.bttr-legend__scale i {
  width: 16px; height: 12px;
  border-radius: 2px;
  display: block;
}
.bttr-heat-note { font-size: .8rem; color: var(--text-muted); margin-top: 8px; }

.bttr-tip {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  background: var(--navy);
  color: #fff;
  font-size: .78rem;
  line-height: 1.45;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 10px 30px -8px rgba(15, 23, 42, .5);
  max-width: 220px;
  opacity: 0;
  transition: opacity .1s ease;
}
.bttr-tip.is-on { opacity: 1; }
.bttr-tip b { color: #fff; }
.bttr-tip span { color: #CBD5E1; }

/* ---- CTA --------------------------------------------------------------------- */
.bttr-cta {
  margin-top: 34px;
  background: var(--navy);
  color: #fff;
  border-radius: 20px;
  padding: 30px 26px;
  text-align: center;
}
.bttr-cta h3 { color: #fff; font-size: 1.25rem; margin-bottom: 8px; }
.bttr-cta p { color: #CBD5E1; font-size: .96rem; margin: 0 auto 18px; max-width: 460px; }

/* ---- Article ------------------------------------------------------------- */
.bttr-article { background: var(--bg-page); }
.bttr-article .container { max-width: 760px; }
.bttr-article h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
.bttr-article h3 { font-size: 1.15rem; margin-top: 1.8em; }
.bttr-article p,
.bttr-article li { color: var(--text-muted); font-size: 1.02rem; }
.bttr-article ul { list-style: disc; padding-left: 22px; margin-bottom: 1em; }
.bttr-article li { margin-bottom: .5em; }
.bttr-figure {
  margin: 28px 0 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 14px;
}
.bttr-figure__title {
  font-size: .92rem;
  font-weight: 700;
  color: var(--navy);
  margin: 0 0 8px;
}
.bttr-figure svg { display: block; width: 100%; height: auto; overflow: visible; }
.bttr-figure figcaption {
  font-size: .82rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-top: 12px;
}

.bttr-article .bttr-article__cta {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--orange);
  border-radius: var(--radius-sm);
  padding: 20px 22px;
  margin-top: 2em;
}
.bttr-article .bttr-article__cta p { margin: 0 0 14px; color: var(--navy); font-weight: 500; }
.bttr-article .bttr-article__cta p:last-child { margin: 0; }
