/* Nomios web UI: the administrator's read-only view of a person (U31, ADR 0046): the banner, the
   people picker and the controls that are not there while viewing. Its own layer, last. Design
   system: docs/design/DESIGN_SYSTEM.md. */

@layer viewing {
  /* The banner is part of the page flow (it reserves its own height), sticks to the top, and
     says it twice: words and the one violet of the page. Its height is fixed per width, so the
     sidebar, which sticks below it, never overlaps. */
  .shell.is-viewing {
    --banner-h: 3.25rem;
  }

  html:has(.is-viewing) {
    scroll-padding-top: calc(var(--shell-gap) * 2 + var(--banner-h, 3.25rem));
  }

  .viewing-banner {
    grid-column: 1 / -1;
    position: sticky;
    top: var(--shell-gap);
    z-index: calc(var(--z-sticky) + 1);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    box-sizing: border-box;
    height: var(--banner-h);
    padding: 0 var(--space-3) 0 var(--space-5);
    color: var(--viewing-text);
    background: var(--viewing-bg);
    border: 2px solid var(--viewing-edge);
    border-radius: var(--radius-lg);
  }

  .viewing-banner:focus-visible {
    outline: 3px solid var(--viewing-text);
    outline-offset: 2px;
  }

  .viewing-text {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-weight: 650;
    line-height: 1.25;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .viewing-banner form {
    flex: none;
    margin: 0;
  }

  .viewing-end {
    color: var(--viewing-button-text);
    background: var(--viewing-button-bg);
    border-color: transparent;
    font-weight: 650;
  }

  .viewing-end:hover {
    background: var(--viewing-text);
  }

  .shell.is-viewing .sidebar {
    top: calc(var(--shell-gap) * 2 + var(--banner-h));
    height: calc(100dvh - var(--shell-gap) * 3 - var(--banner-h));
  }

  .is-viewing .page {
    outline: 2px solid var(--viewing-edge);
    outline-offset: -2px;
  }

  /* Nothing that changes data is shown while viewing: the server refuses it anyway, so a button
     would only lead to a refusal. The sign-out and language forms are in the sidebar, not here. */
  .is-viewing main :is([hx-post], [hx-put], [hx-patch], [hx-delete]),
  .is-viewing main details.purge-inline,
  .is-viewing .task-actions,
  .is-viewing .column-add,
  .is-viewing .fab,
  .is-viewing :is([data-save-button], [data-delete-button], [data-purge-open]),
  .is-viewing .modal-fields :is([data-add], [data-remove], .dictate, .claude-buttons) {
    display: none;
  }

  /* The task window of the viewed person: the fields stay readable (a disabled field is dimmed
     everywhere else, here it is the content). */
  .modal-fields {
    min-width: 0;
    margin: 0;
    border: 0;
  }

  .modal-fields :is(input:not([type="radio"], [type="checkbox"], [type="file"]), textarea, select):disabled {
    color: var(--color-text);
    opacity: 1;
  }

  @media (max-width: 48rem) {
    .shell.is-viewing {
      --banner-h: 3.75rem;
    }

    .viewing-banner {
      top: var(--space-3);
      gap: var(--space-3);
      padding-inline-start: var(--space-4);
    }

    .shell.is-viewing .sidebar {
      height: auto;
    }

    .viewing-end {
      max-width: 7.5rem;
      padding-inline: var(--space-3);
      line-height: 1.2;
      text-align: center;
    }
  }

  /* The picker: a small glass dialog, the page blurs behind it (like every window). */
  .picker-dialog {
    width: min(30rem, calc(100% - var(--space-6)));
    max-height: calc(100dvh - var(--space-8));
    padding: 0;
    color: var(--color-text);
    background: var(--glass-overlay-bg);
    -webkit-backdrop-filter: blur(var(--glass-overlay-blur)) saturate(var(--glass-saturate));
    backdrop-filter: blur(var(--glass-overlay-blur)) saturate(var(--glass-saturate));
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-glass);
    overflow: auto;
  }

  .picker-dialog::backdrop {
    background: var(--scrim);
    -webkit-backdrop-filter: blur(var(--glass-overlay-blur)) saturate(var(--glass-saturate));
    backdrop-filter: blur(var(--glass-overlay-blur)) saturate(var(--glass-saturate));
  }

  .picker-dialog > form {
    margin: 0;
    padding: 0 var(--space-5) var(--space-5);
    display: flex;
    justify-content: flex-end;
  }

  .picker {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-5);
  }

  .picker h2,
  .picker p {
    margin: 0;
  }

  .picker-search {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: var(--space-2);
  }

  .picker-search .field {
    flex: 1 1 12rem;
    min-width: 0;
  }

  .picker-list {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
    max-height: 50dvh;
    overflow-y: auto;
  }

  .picker-list li[hidden] {
    display: none;
  }

  .picker-list form {
    margin: 0;
  }

  .picker-person {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    justify-content: flex-start;
    text-align: left;
  }

  .picker-name {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .viewing-note {
    margin: 0;
    overflow-wrap: anywhere; /* a name is text from outside: it may have no place to break */
  }

  .user-view {
    flex: none;
  }

  @media (max-width: 48rem) {
    .user-view {
      display: none; /* on a phone the picker is reached from the Settings page */
    }
  }
}
