/*
 * The panel: one <dialog> that slides in from the right on desktop and rises as a bottom sheet on phones.
 * The account menu opens in it, and so does a row (a team member, later a guest) through the "panel" Turbo Frame.
 */
@layer components {
  .panel {
    --fill: var(--color-ink-8);
    --fill-hover: var(--color-ink-12);

    position: fixed;
    inset: 0 0 0 auto;
    width: min(var(--panel-width), 100%);
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-start-start-radius: var(--radius-xl);
    border-end-start-radius: var(--radius-xl);
    background: var(--color-surface);
    color: var(--color-ink);
    box-shadow: var(--shadow-panel);
    overflow: hidden;
    translate: 0 0;
    transition: translate var(--duration) var(--ease), display var(--duration) allow-discrete, overlay var(--duration) allow-discrete;

    &:not([open]) { translate: 100% 0; }
    @starting-style { &[open] { translate: 100% 0; } }

    &::backdrop { background: transparent; }
  }

  /* The modal: a task over the dimmed page, three quarters of the screen wide on desktop and as tall as its form; all of it on phones. */
  .modal {
    width: min(75vw, 64rem);
    max-width: 100%;
    max-height: 85dvh;
    padding: 0;
    border: 0;
    border-radius: var(--radius-xl);
    background: var(--color-canvas);
    color: var(--color-ink);
    box-shadow: var(--shadow-float);
    opacity: 1;
    scale: 1;
    transition: opacity var(--duration) var(--ease), scale var(--duration) var(--ease), display var(--duration) allow-discrete, overlay var(--duration) allow-discrete;

    &:not([open]) { opacity: 0; scale: 0.97; }
    @starting-style { &[open] { opacity: 0; scale: 0.97; } }

    &::backdrop { background: var(--color-scrim); }

    overflow: hidden;

    /* The contents scroll; the close button is placed on the modal, outside the scroll, so it stays put. */
    > turbo-frame { display: block; max-height: 85dvh; overflow-y: auto; overscroll-behavior: contain; }
    .focus__close { z-index: 1; }
    .page { padding-bottom: var(--space-10); }

    @media (max-width: 767px) {
      width: 100%;
      height: 100dvh;
      max-height: 100dvh;
      border-radius: 0;

      > turbo-frame { height: 100%; max-height: none; }
    }
  }

  .panel__body {
    display: grid;
    gap: var(--space-6);
    align-content: start;
    height: 100%;
    padding: var(--space-6);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  /* A record shown as cards, such as a guest's badge, sits on the canvas like a page, below the close button. */
  .panel__body:has(> .badge) { background: var(--color-canvas); }

  /* In the panel the badge runs edge to edge, its pastel top under the close button and the handle. */
  .panel .panel__body > .badge { margin: calc(-1 * var(--space-6)) calc(-1 * var(--space-6)) 0; border-radius: 0; }
  .panel .panel__body > .badge .badge__top { padding: var(--space-12) var(--space-16) var(--space-2) var(--space-6); }

  .panel__close { position: absolute; top: var(--space-4); right: var(--space-4); }
  .panel__head { display: flex; gap: var(--space-4); align-items: center; padding-right: var(--space-12); }
  .panel__title { font-size: var(--text-3xl); letter-spacing: var(--tracking-display); line-height: var(--leading-tight); }
  .panel__handle { display: none; }

  @media (max-width: 767px) {
    .panel {
      inset: auto 0 0 0;
      width: 100%;
      height: auto;
      max-height: 92dvh;
      border-radius: var(--radius-xl) var(--radius-xl) 0 0;

      &:not([open]) { translate: 0 100%; }
      @starting-style { &[open] { translate: 0 100%; } }

      &::backdrop { background: var(--color-scrim); }
    }

    .panel__body { height: auto; max-height: 92dvh; padding-top: var(--space-4); }
    .panel .panel__body > .badge { margin-top: calc(-1 * var(--space-4)); }
    .panel .panel__body:has(> .badge) .panel__handle { position: absolute; top: var(--space-3); left: 0; right: 0; }
    .panel__handle { display: block; width: 2.5rem; height: 5px; margin: 0 auto; border-radius: 3px; background: var(--color-ink-12); }

    /* The account panel is the phones' menu: the whole screen, its sections first. */
    .panel--menu { inset: 0; height: 100dvh; max-height: none; border-radius: 0; .panel__body { height: 100%; max-height: none; } .panel__handle { display: none; } }
  }

  /* Rows of choices inside the panel: Team, Billing, Settings, workspaces */
  .menu { display: grid; gap: var(--space-2); }
  .menu__label { font-size: var(--text-sm); font-weight: var(--weight-bold); }

  .menu__item {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: var(--control-height);
    padding: 0 var(--space-4);
    border: 0;
    border-radius: var(--radius-md);
    background: var(--fill);
    color: inherit;
    font-weight: var(--weight-bold);
    text-align: left;
    text-decoration: none;
    cursor: pointer;

    &:hover { background: var(--fill-hover); }
    &[aria-current] { background: var(--color-mint); }
  }

  .menu__value { font-weight: var(--weight-medium); }
  @media (min-width: 768px) {
    .panel__nav { display: none; }
    /* A panel that is only a panel on phones, such as the guest list's search and filter: on desktop its contents sit in the page. */
    .panel--inline:not([open]), .panel--inline > .panel__body { display: contents; }
    .panel--inline .panel__close { display: none; }
  }
  @media (max-width: 767px) { .panel--inline .search-bar { grid-template-columns: 1fr; } }

  /* The one floating bar: it appears when rows are selected and leaves when they are not. */
  .selection-bar {
    --fill: var(--color-surface);
    --fill-hover: color-mix(in srgb, var(--color-surface) 85%, transparent);

    position: fixed;
    bottom: var(--space-6);
    left: 50%;
    z-index: 10;
    display: flex;
    gap: var(--space-4);
    align-items: center;
    max-width: calc(100% - 2 * var(--gutter));
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-5);
    border-radius: var(--radius-lg);
    background: var(--color-button);
    color: var(--color-on-button);
    box-shadow: var(--shadow-float);
    font-weight: var(--weight-bold);
    translate: -50% 0;
    transition: translate var(--duration) var(--ease), opacity var(--duration) var(--ease), display var(--duration) allow-discrete;

    &[hidden] { display: none; opacity: 0; translate: -50% var(--space-4); }
    @starting-style { &:not([hidden]) { opacity: 0; translate: -50% var(--space-4); } }

    .button--secondary { color: var(--color-ink); }
  }

  /* The dialog before something that can't be undone: what will happen, then the action and the way out. */
  .dialog {
    width: min(28rem, calc(100% - 2 * var(--space-4)));
    padding: var(--space-6);
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-ink);

    &::backdrop { background: var(--color-scrim); }
  }

  .dialog__title { font-size: var(--text-xl); font-weight: var(--weight-bold); letter-spacing: var(--tracking-title); }
}
