/* Shared component chrome for every webapp on the platform.
 *
 * Served at /static/platform-assets/css/components.css. Link it AFTER
 * tokens.css (it reads those tokens) and BEFORE the app's own <style>, so an
 * app can still override with equal specificity.
 *
 * A rule earns a place here only when every app that has it already agrees, and
 * it is inert in the apps that do not. A selector the apps still disagree on
 * stays with them until someone decides the canonical version. Extract, don't
 * invent.
 *
 * Before adding one, check it cannot lose: this sheet loads BEFORE the app's
 * <style>, so a rule hoisted here must already come first among its
 * equal-specificity peers. That failure does not show up in a diff.
 */

*{
  box-sizing: border-box;
}

/* Utility */
.hidden {
  display: none !important;
}

/* ── Focus ────────────────────────────────────────────────────────────────
 * :focus-visible, not :focus — the ring answers the keyboard, not every mouse
 * click.
 *
 * outline (not box-shadow) on purpose: it does not clobber an element's own
 * shadow and it does not affect layout. The offset puts the ring outside the
 * element, on the ground behind it — so anything sitting ON the accent has to
 * restate the colour, or the ring disappears into its own background. That is
 * what --on-accent is for; see #updateBanner button below.
 */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────
 * One component, modifiers on separate axes: intent (.primary/.danger),
 * size (.lg), shape (.icon), layout (.block). They compose — a prominent
 * full-width CTA is `class="btn primary block lg"`.
 *
 * Do not fold layout into intent: a class that means primary AND full-width
 * leaves no way to write a primary button that is not full-width.
 *
 * App-only modifiers stay in the app: .btn.ghost, .btn.sm, .nav-btn.
 */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .75rem;
  font-family: inherit;
  font-size: .82rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn:hover {
  background: var(--surface-3);
}

/* Both spellings: :disabled misses a disabled <a>, [disabled] misses a button
 * disabled by an ancestor <fieldset>. */
.btn:disabled,
.btn[disabled] {
  opacity: .45;
  cursor: default;
}

/* Intent — primary */
.btn.primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--on-accent-strong);
  font-weight: 600;
}

/* The ground lightens to --accent, so the text MUST flip to --on-accent with
 * it: keeping the resting colour here is 2.72, which fails WCAG AA. */
.btn.primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* Intent — danger. Outline at rest; hover tints its own ground rather than
 * filling, which is the gentler step up from an outline. */
.btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn.danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* Shape — square-ish, for a button that is only an icon */
.btn.icon {
  padding: .45rem;
}

/* Size — a prominent call to action */
.btn.lg {
  padding: .55rem .8rem;
  font-size: .88rem;
}

/* Layout — fills its container */
.btn.block {
  width: 100%;
  justify-content: center;
}

/* Empty states */
.empty svg {
  display: block;
  margin: 0 auto .75rem;
  opacity: .35;
}

/* ── Modal ────────────────────────────────────────────────────────────────
 * Structure:
 *   .modal-backdrop > .modal > [.modal-x]
 *                              .head > h2 + p.desc
 *                              .content
 *                              .foot
 *
 * The modal is a flex column and .content is the only scroller, so a long body
 * never pushes the buttons off-screen.
 *
 * Two properties stay in the app on purpose:
 *   .modal-backdrop { z-index }  stacking is a per-app fact — a shared value
 *                                would put a modal behind someone's drawer.
 *   .modal { max-width }         driven by what that modal actually holds.
 */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  padding: 1rem;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--scrim) 55%, transparent);
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  position: relative; /* anchor for .modal-x */
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 420px; /* override per app when the content needs more */
  max-height: calc(100dvh - 2rem);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.modal .head {
  padding: 1rem 1.1rem .25rem;
}

/* Room for the close button — only in the modals that have one. */
.modal:has(.modal-x) .head {
  padding-right: 2.5rem;
}

.modal h2 {
  font-size: 1.05rem;
  margin: 0 0 .25rem;
}

.modal .desc {
  margin: 0 0 .75rem;
  color: var(--text-dim);
  font-size: .82rem;
}

.modal .content {
  flex: 1;
  padding: .5rem 1.1rem;
  overflow-y: auto;
}

.modal .content p {
  margin: .35rem 0;
}

.modal .foot {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  padding: .85rem 1.1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.modal .foot.start {
  justify-content: flex-start;
}

.modal-x {
  position: absolute;
  top: .4rem;
  right: .5rem;
  z-index: 1;
  padding: .15rem .45rem;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-x:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ── Toast ────────────────────────────────────────────────────────────────
 * Bottom-centre. Where it sits is one decision spread over four declarations —
 * left, right, and the transform in both rules — so change them together.
 *
 * pointer-events: none is not cosmetic. Without it the toast swallows clicks in
 * the strip it occupies, which on a phone is exactly where the buttons are.
 *
 * z-index stays in the app: stacking is a per-app fact, as with .modal-backdrop.
 */
#toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  max-width: 90vw;
  padding: .65rem 1rem;
  font-size: .85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Tabs */
.tab.sel {
  color: var(--text);
  border-bottom-color: var(--accent-ink);
}

/* ── Live/connection dot ──────────────────────────────────────────────────
 * Three states, two classes: the dot is grey by default, so "disconnected" is
 * the absence of a modifier, not an .off class.
 *
 *   <span class="live-dot"><i class="d"></i> En vivo</span>   grey  — idle
 *   .on   → green + glow
 *   .err  → red
 */
.live-dot {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .75rem;
  color: var(--text-dim);
}

.live-dot .d {
  width: .55rem;
  height: .55rem;
  border-radius: 50%;
  background: var(--text-muted);
}

/* The glow is what makes it read as lit rather than merely green. */
.live-dot.on .d {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.live-dot.err .d {
  background: var(--danger);
}

/* ── Update banner ────────────────────────────────────────────────────────
 * The strip offering a reload when a new version is out. Its ground is
 * var(--accent), so everything on it is coloured from --on-accent, never a
 * literal.
 *
 *   <div id="updateBanner" class="hidden" role="alert">
 *     <span class="grow">Nueva versión disponible.</span>
 *     <button id="updateReloadBtn">Recargar</button>
 *     <button id="updateDismissBtn" class="dismiss" title="…">×</button>
 *   </div>
 *
 * role="alert" is part of the component, not decoration: without it a screen
 * reader never announces that an update is waiting.
 *
 * The button carries margin-left:auto so it hugs the right edge whether or not
 * the text is wrapped in .grow.
 */
#updateBanner {
  display: flex;
  align-items: center;
  gap: .75rem;
  /* flex:0 0 auto matters only where the banner's parent is a flex column (it
     stops the strip being squeezed); inert everywhere else. */
  flex: 0 0 auto;
  padding: .55rem 1rem;
  font-size: .88rem;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
}

#updateBanner.hidden {
  display: none;
}

#updateBanner .grow {
  flex: 1;
}

#updateBanner button {
  margin-left: auto;
  padding: .35rem .8rem;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
  /* --on-accent, not --bg: this button's job is to read against the accent it
     sits on. The two happen to be equal in the default skin and are NOT in a
     light one, which is exactly when the distinction pays. */
  background: var(--on-accent);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* :not(.dismiss) matters — the dismiss IS a <button>, so the filled button's
   hover would brighten it too and fight the tint below. */
#updateBanner button:not(.dismiss):hover {
  filter: brightness(1.15);
}

/* These buttons sit ON the accent, so the default ring — the accent itself —
   would be invisible against it. --on-accent is the colour defined to read
   against that ground. */
#updateBanner button:focus-visible {
  outline-color: var(--on-accent);
}

/* Dismiss ("remind me later") — a bare glyph, so it must not take the filled
   treatment above. */
#updateBanner .dismiss {
  margin-left: 0;
  padding: .35rem .5rem;
  background: transparent;
  color: var(--on-accent);
}

#updateBanner .dismiss:hover {
  background: color-mix(in srgb, var(--on-accent) 12%, transparent);
}
