/* Top-layer helpers: interest hints, task previews and toasts. */
@layer components {
  [interestfor] { interest-delay: .35s .15s; --interest-delay-start: .35s; --interest-delay-end: .15s; }

  .hint-pop {
    position: fixed;
    inset: auto;
    /* A named anchor stops the interestfor polyfill from tethering the hint; hints.js places it. */
    position-anchor: --hint-placed-by-script;
    max-inline-size: min(18rem, 100vw - 1rem);
    margin: 0;
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-s);
    background: var(--color-text);
    color: var(--color-bg);
    box-shadow: var(--shadow-raised);
    font-size: .8125rem;
    line-height: 1.35;
    opacity: 0;
    transition: opacity var(--duration), display var(--duration) allow-discrete, overlay var(--duration) allow-discrete;

    &:popover-open {
      opacity: 1;
      @starting-style { opacity: 0; }
    }
  }

  #theme-hint { white-space: nowrap; }

  /* Task preview on hover over a card title. */
  .hint-pop.task-preview {
    display: none;
    inline-size: min(20rem, 100vw - 1rem);
    max-inline-size: none;
    padding: var(--space-3);
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: var(--radius-m);
    font-size: .875rem;
    cursor: default;
    user-select: text;

    /* Not grid: WebKit stretches a grid popover to the viewport height. */
    &:popover-open { display: flex; flex-direction: column; gap: var(--space-2); }
    & p { margin: 0; }
  }

  .task-preview-title { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
  .task-preview-desc {
    display: -webkit-box;
    overflow: hidden;
    color: var(--color-text-muted);
    white-space: pre-line;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 6;
    line-clamp: 6;
  }
  .task-preview-facts {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-1) var(--space-3);
    margin: 0;
    padding-block-start: var(--space-2);
    border-block-start: 1px solid var(--color-line);
    font-size: .8125rem;

    & dt { color: var(--color-text-muted); }
    & dd { margin: 0; overflow-wrap: anywhere; }
  }

  /* Previews only for precise pointers: on touch a long press drags the card. */
  @media (any-hover: none) { .task-preview { display: none !important; } }
  body.kanban-dragging .hint-pop { display: none !important; }

  /* Toasts */
  .toast {
    position: fixed;
    inset: auto var(--space-4) var(--space-4) auto;
    display: none;
    align-items: center;
    gap: var(--space-2);
    max-inline-size: min(26rem, 100vw - 2rem);
    margin: 0;
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
    border: 1px solid color-mix(in oklab, currentColor 35%, transparent);
    border-radius: var(--radius-l);
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-raised);
    opacity: 0;
    translate: 0 .75rem;
    transition: opacity .2s, translate .2s, display .2s allow-discrete, overlay .2s allow-discrete;

    &:popover-open {
      display: flex;
      opacity: 1;
      translate: 0 0;
      @starting-style { opacity: 0; translate: 0 .75rem; }
    }

    &.ok .toast-icon { background: var(--color-ok-soft); color: var(--color-ok); }
    &.err { border-color: color-mix(in oklab, var(--color-danger) 45%, var(--color-line)); }
    &.err .toast-icon { background: var(--color-danger-soft); color: var(--color-danger); }

    @media (prefers-reduced-motion: reduce) { translate: none; @starting-style { translate: none; } }
    @media (width < 30rem) { inset-inline: var(--space-3); max-inline-size: none; }
  }

  .toast-icon {
    display: inline-grid;
    flex: none;
    place-items: center;
    inline-size: 1.5rem;
    block-size: 1.5rem;
    border-radius: 50%;
    font-size: .8125rem;
    font-weight: 700;
  }

  .toast-text { flex: 1; min-inline-size: 0; font-size: .9375rem; }

  button.toast-close {
    flex: none;
    inline-size: 2rem;
    min-block-size: 2rem;
    padding: 0;
    background: transparent;
    color: var(--color-text-muted);
    font-weight: 400;

    &:hover:not(:disabled) { background: var(--color-surface-subtle); color: var(--color-text); }
  }
}
