/* ============================================================================
   BPSO Blog — token-bucket/app.css
   Self-contained styles for the Token Bucket simulator embedded in the post.
   Scoped under .bpso-bucket so it never leaks into the article. Uses the blog's
   BPSO Lab 2026 design tokens (with local fallbacks if loaded standalone).
   ========================================================================== */

.bpso-bucket {
  /* local fallbacks mirror blog.css :root so the widget is robust on its own */
  --b-brand-blue: var(--brand-blue, #2563eb);
  --b-brand-light: var(--brand-light, #60a5fa);
  --b-brand-dark: var(--brand-dark, #1e40af);
  --b-brand-glow: var(--brand-glow, rgba(37, 99, 235, .35));
  --b-bg: var(--bg-dark, #0f172a);
  --b-surface: var(--bg-card, #1e293b);
  --b-surface-2: #243349;
  --b-text: var(--text-main, #f8fafc);
  --b-muted: var(--text-muted, #94a3b8);
  --b-border: var(--border, rgba(255, 255, 255, .08));

  --b-ok: #22c55e;      /* approved request */
  --b-block: #ef4444;   /* rejected request */
  --b-token: #38bdf8;   /* a token / fill color */

  font-family: var(--font-body, 'Inter', system-ui, sans-serif);
  color: var(--b-text);
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(.8rem, 2.5vw, 1.4rem);
  align-items: stretch;
  width: 100%;
}

/* Light theme: keep the simulation panel dark (colors pop) but make the
   controls + readouts readable. */
[data-theme="light"] .bpso-bucket {
  --b-surface: #ffffff;
  --b-surface-2: #eef2f7;
  --b-text: #0f172a;
  --b-muted: #475569;
  --b-border: rgba(15, 23, 42, .12);
}

.bpso-bucket *,
.bpso-bucket *::before,
.bpso-bucket *::after { box-sizing: border-box; }

/* ---------------------------------------------------------- Stage (canvas) */
.bpso-bucket__stage {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.bpso-bucket__canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .03), transparent 30%),
    var(--b-bg);
  border: 1px solid var(--b-border);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25), 0 10px 30px -12px rgba(0, 0, 0, .6);
  touch-action: manipulation;
}
/* The canvas keeps the dark playfield even in light theme so the bucket pops. */
[data-theme="light"] .bpso-bucket__canvas {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .03), transparent 30%),
    #0f172a;
  border-color: rgba(15, 23, 42, .18);
}

/* Big "fire a request" button sits right under the canvas so the action and
   the visual feedback are always together (key on mobile). */
.bpso-bucket__fire {
  appearance: none;
  margin-top: .7rem;
  width: 100%;
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 600;
  font-size: 1.02rem;
  color: #fff;
  background: var(--b-brand-blue);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 10px 26px -10px var(--b-brand-glow);
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
}
.bpso-bucket__fire:hover { background: var(--b-brand-dark); transform: translateY(-2px); }
.bpso-bucket__fire:active { transform: translateY(0) scale(.99); }
.bpso-bucket__fire i { font-size: 1.2rem; }

/* ---------------------------------------------------------- Side panel */
.bpso-bucket__side {
  display: flex;
  flex-direction: column;
  gap: clamp(.7rem, 2vw, 1rem);
  min-width: 0;
}

.bpso-bucket__panel {
  background: var(--b-surface);
  border: 1px solid var(--b-border);
  border-radius: 12px;
  padding: .85rem .95rem;
}
.bpso-bucket__panel-label {
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 700;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--b-muted);
  margin: 0 0 .6rem;
}

/* ----- Stats grid (approved / rejected / cost saved) ----- */
.bpso-bucket__stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .6rem;
}
.bpso-bucket__stat {
  background: var(--b-surface);
  border: 1px solid var(--b-border);
  border-radius: 12px;
  padding: .7rem .55rem;
  text-align: center;
  min-width: 0;
}
.bpso-bucket__stat-num {
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 800;
  font-size: clamp(1.2rem, 4.5vw, 1.6rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--b-text);
  overflow-wrap: anywhere;
}
.bpso-bucket__stat--ok .bpso-bucket__stat-num { color: var(--b-ok); }
.bpso-bucket__stat--block .bpso-bucket__stat-num { color: var(--b-block); }
.bpso-bucket__stat--saved .bpso-bucket__stat-num { color: var(--b-brand-light); }
[data-theme="light"] .bpso-bucket__stat--saved .bpso-bucket__stat-num { color: var(--b-brand-blue); }
.bpso-bucket__stat-label {
  display: block;
  margin-top: .35rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--b-muted);
  line-height: 1.3;
}
.bpso-bucket__stat-num.is-pop { animation: bpso-bucket-pop .35s ease; }
@keyframes bpso-bucket-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

/* ----- Sliders ----- */
.bpso-bucket__control { margin-bottom: 1rem; }
.bpso-bucket__control:last-child { margin-bottom: 0; }
.bpso-bucket__control-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .6rem;
  margin-bottom: .4rem;
}
.bpso-bucket__control-name {
  font-size: .85rem;
  font-weight: 600;
  color: var(--b-text);
}
.bpso-bucket__control-val {
  font-family: var(--font-head, 'Poppins', sans-serif);
  font-weight: 800;
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
  color: var(--b-brand-light);
}
[data-theme="light"] .bpso-bucket__control-val { color: var(--b-brand-blue); }

.bpso-bucket__slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--b-surface-2);
  border: 1px solid var(--b-border);
  outline-offset: 4px;
  cursor: pointer;
}
[data-theme="light"] .bpso-bucket__slider { background: #e2e8f0; }
.bpso-bucket__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--b-brand-blue);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px -1px var(--b-brand-glow);
  cursor: pointer;
  transition: transform .12s ease;
}
.bpso-bucket__slider::-webkit-slider-thumb:hover { transform: scale(1.12); }
.bpso-bucket__slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--b-brand-blue);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px -1px var(--b-brand-glow);
  cursor: pointer;
}

/* ----- Action buttons (loop toggle / reset) ----- */
.bpso-bucket__actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.bpso-bucket__btn {
  appearance: none;
  /* Size to content (with a sane minimum) instead of forcing equal thirds, so a
     long label like "Modo agente em loop" fits cleanly without clipping. */
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 46px;
  padding: 0 .85rem;
  font-family: var(--font-body, 'Inter', sans-serif);
  font-weight: 600;
  font-size: .88rem;
  line-height: 1.2;
  color: var(--b-text);
  background: var(--b-surface);
  border: 1px solid var(--b-border);
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s, border-color .15s, background .15s, transform .1s;
}
/* The loop toggle carries the longest label — let it take the room it needs and
   shrink gracefully before the short Reset button does. */
.bpso-bucket__btn--loop { flex: 1 1 auto; }
.bpso-bucket__btn i { font-size: 1.05rem; flex: 0 0 auto; }
/* Labels may wrap to two lines on very tight widths rather than overflow. */
.bpso-bucket__btn > span { min-width: 0; overflow-wrap: break-word; }
.bpso-bucket__btn:hover { border-color: color-mix(in srgb, var(--b-brand-blue) 60%, var(--b-border)); color: var(--b-text); }
.bpso-bucket__btn:active { transform: translateY(1px); }

/* The loop toggle is the dramatic one: red when armed. */
.bpso-bucket__btn--loop[aria-pressed="true"] {
  background: var(--b-block);
  border-color: var(--b-block);
  color: #fff;
  animation: bpso-bucket-throb 1.1s ease-in-out infinite;
}
@keyframes bpso-bucket-throb {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .0); }
  50% { box-shadow: 0 0 0 5px rgba(239, 68, 68, .22); }
}
.bpso-bucket__btn--loop .label-on { display: none; }
.bpso-bucket__btn--loop[aria-pressed="true"] .label-on { display: inline; }
.bpso-bucket__btn--loop[aria-pressed="true"] .label-off { display: none; }

.bpso-bucket__hint {
  margin: .2rem 0 0;
  font-size: .76rem;
  line-height: 1.5;
  color: var(--b-muted);
}

/* ---------------------------------------------------------- Responsive */
@media (max-width: 640px) {
  .bpso-bucket {
    grid-template-columns: 1fr;
  }
  /* Stage (canvas + fire button) first, controls right under it so content
     and controls are visible together on mobile. */
  .bpso-bucket__stage { order: 0; }
  .bpso-bucket__side { order: 1; }
  /* Cap canvas height by viewport so the fire button + stats stay in view. */
  .bpso-bucket__canvas { max-height: 46vh; width: auto; max-width: 100%; margin: 0 auto; }
}

@media (max-width: 360px) {
  .bpso-bucket__stat-label { font-size: .62rem; }
  /* Stack the action buttons full-width on the tightest screens. */
  .bpso-bucket__btn,
  .bpso-bucket__btn--loop { flex: 1 1 100%; }
}

/* Respect reduced motion: drop flourish animations, keep the simulation. */
@media (prefers-reduced-motion: reduce) {
  .bpso-bucket__stat-num.is-pop,
  .bpso-bucket__btn--loop[aria-pressed="true"] { animation: none; }
  .bpso-bucket__fire,
  .bpso-bucket__btn,
  .bpso-bucket__slider::-webkit-slider-thumb { transition: none; }
}
