/*
The interactive pieces every page may hold, on the platform's own elements (web/base.html loads this after site.css):
the modal dialog, the popover menus and dropdowns, the request error and the flash banners' region, the skip link,
the icon buttons' tip, and what the form tags add to a field (apps/web/templatetags/form_tags.py). All in `site`.
*/
@layer site {
  /* ---- the modal dialog: a <dialog> is the box itself, opened with showModal() or command="show-modal" ---- */

  /* the box: daisyUI's modal box, without its full-screen wrapper (light dismiss is closedby="any", platform.js) */
  .site-dialog {
    width: min(32rem, 100% - 2rem);
    max-height: calc(100dvh - 2rem);
    margin: auto;
    overflow-y: auto;
    padding: 1.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-box);
    background: var(--color-base-100);
    color: var(--color-base-content);
    box-shadow: var(--shadow-lg);
    & h2 { font-size: var(--text-lg); }
    & p { margin-top: 0.5rem; font-size: 0.9375rem; }
    /* the page behind does not scroll with a gesture made over the dialog or its backdrop */
    &:modal { overscroll-behavior: contain; }
    &::backdrop { overflow: hidden; overscroll-behavior: contain; background: var(--scrim); }
  }
  .site-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
  }
  /* a request that failed while the dialog was open says so in here (site.js) */
  .site-dialog [data-request-error]:not(:empty) { margin-top: 1rem; }

  /* In and out: a fade, and a slight growth for those who allow motion; the backdrop fades with it. `overlay` keeps the
     closing dialog in the top layer until it has faded (where a browser has it; elsewhere it closes at once). */
  .site-dialog {
    opacity: 0;
    transition: opacity 0.2s ease-out, scale 0.2s ease-out, display 0.2s, overlay 0.2s;
    transition-behavior: allow-discrete; /* apart, so the shorthand neither resets it nor fails where unknown */
    &[open] {
      opacity: 1;
      @starting-style { opacity: 0; }
    }
    &::backdrop {
      opacity: 0;
      transition: opacity 0.2s ease-out, display 0.2s, overlay 0.2s;
      transition-behavior: allow-discrete;
    }
    &[open]::backdrop {
      opacity: 1;
      @starting-style { opacity: 0; }
    }
    @media (prefers-reduced-motion: no-preference) {
      scale: 0.96;
      &[open] {
        scale: 1;
        @starting-style { scale: 0.96; }
      }
    }
  }

  /* ---- popovers under their trigger: the menus and the filters (daisyUI's .dropdown[popover]) ---- */

  /* placed by anchor positioning under the toggle that opens it (popovertarget is its anchor), flipping above it when
     there is no room below; platform.js places it where the browser has no anchor positioning, and no backdrop dims
     the page meanwhile, as daisyUI's fallback would. :where() keeps it a class's weight, so an area's own panel (in a
     file loaded later) sets its gap. */
  .dropdown:where([popover]) {
    margin-block-start: 0.25rem;
    position-try-fallbacks: flip-block;
    &::backdrop { background: none; }
  }

  /* a menu (focusgroup="menu" inside the popover), and the account's links: its commands and links in a column, icon
     first */
  .site-menu {
    padding: 0.375rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-box);
    background: var(--color-base-100);
    color: color-mix(in oklab, var(--color-base-content) 90%, transparent);
    box-shadow: var(--shadow-lg);
    & [focusgroup] { display: flex; flex-direction: column; }
    & :is(a, button) {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.375rem 0.75rem;
      border-radius: var(--radius-field);
      text-align: start;
      font-size: var(--text-md);
      cursor: pointer;
      &:is(:hover, :focus-visible) { background: var(--hover); }
      &:focus-visible { outline-offset: -2px; }
    }
    & svg { flex: none; width: 1rem; height: 1rem; }
  }

  /* ---- the skip link: out of sight until a keyboard reaches it ---- */

  .site-skip {
    position: absolute;
    inset-block-start: 0.5rem;
    inset-inline-start: 0.5rem;
    z-index: 100;
    &:not(:focus) {
      width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
    }
  }
  /* each page's <main> takes the focus from it, with no ring of its own */
  main[tabindex='-1']:focus { outline: none; }

  /* ---- an icon button's tip (data-tip): on hover, and on keyboard focus too, unlike a title; beside the button, to
     its inline start, where a pane's edge cannot clip it ---- */

  .site-tip {
    position: relative;
    &::after {
      content: attr(data-tip);
      position: absolute;
      inset-block-start: 50%;
      inset-inline-end: calc(100% + 0.375rem);
      translate: 0 -50%;
      z-index: 30;
      padding: 0.25rem 0.5rem;
      border-radius: var(--radius-field);
      background: var(--color-neutral);
      color: var(--neutral-bright);
      font-size: var(--text-xs);
      font-weight: 500;
      line-height: 1.3333;
      white-space: nowrap;
      opacity: 0;
      pointer-events: none;
    }
    &:is(:hover, :focus-visible)::after { opacity: 1; }
    @media (prefers-reduced-motion: no-preference) { &::after { transition: opacity 0.15s 0.3s; } }
  }

  /* ---- what the form tags add ---- */

  /* a form's own errors, which take the focus after a failed POST when no field holds one */
  .form-errors:focus { outline: none; }
  /* "(neobavezno)" after an optional field's label */
  .form-optional { font-weight: 400; }
  /* a password with its eye at the end of the field */
  .field-password {
    position: relative;
    & .input { width: 100%; padding-inline-end: 2.75rem; }
  }
  .field-reveal {
    position: absolute;
    inset-block: 0;
    inset-inline-end: 0.25rem;
    display: grid;
    place-items: center;
    width: 2.25rem;
    margin-block: auto;
    height: 2.25rem;
    border-radius: var(--radius-field);
    color: var(--muted);
    cursor: pointer;
    &:hover { color: var(--color-base-content); }
    &[aria-pressed='true'] { color: var(--color-primary); }
    & svg { width: 1.125rem; height: 1.125rem; fill: none; stroke: currentColor; stroke-width: 2; }
  }

  /* ---- targets and rings ---- */

  /* a button on a dark section rings in the section's own bright colour: the brand blue is 2.3:1 on it */
  .bg-neutral .btn:focus-visible { outline-color: var(--neutral-bright); }
  /* on a touch screen the smallest targets grow to 44px, the size a finger needs */
  @media (pointer: coarse) {
    :is(.dismiss, .chat-row-action, .matter-source-remove, .chat-rail-add, .chat-pane-close) {
      min-width: 2.75rem;
      min-height: 2.75rem;
    }
  }
}
