/*
 * The client portal v2 (docs/platform/YARSA-PORTAL-DESIGN.md §11, E6; WP2).
 *
 * The portal is a theme on the staff UI system, not a second kit: this sheet only adds what a staff page does not
 * have — the portal's top bar and phone bar, the "Now" hero, the course (the progress bar), the tour's banner, the
 * auth frame (sign-in, welcome, privacy) and the dark mode's two-token corrections. Every other part of a page is
 * `ui.css`'s (`ui-card`, `ui-btn`, `ui-list`, `ui-tabs`, `ui-more`, the toast), drawn from the same `--ui-*` tokens
 * (core/src/ui/v2/portal.ts `portalV2Css` sets them from the firm's brand).
 *
 * Hand-written, no build step (published as `ui-portal` by scripts/assemble.mjs). Layers: the same order as `ui.css`
 * and the Tailwind sheets, so any two of them load together in either order; `ui-portal` is linked last, so its
 * corrections of the system's rules win at equal specificity.
 */
@layer theme, base, kit, components, utilities;

@layer base {
  .ui-portal {
    background: var(--ui-ground);
  }
  .ui-portal :where(a) {
    color: inherit;
    text-decoration: none;
  }
  .ui-skip {
    position: absolute;
    left: 12px;
    top: -60px;
    z-index: 60;
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--ui-ink);
    color: #fff;
    font-weight: 600;
  }
  .ui-skip:focus {
    top: 12px;
  }
  .ui-portal :focus-visible {
    outline: 2px solid var(--ui-brand);
    outline-offset: 3px;
  }
}

@layer components {
  /* ---------- The frame ---------- */
  .ui-portal-frame {
    display: flex;
    min-height: 100dvh;
    flex-direction: column;
    background: var(--ui-ground);
  }
  .ui-portal-top {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    min-height: 60px;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-line);
  }
  .ui-portal-mark {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
    color: var(--ui-ink);
  }
  .ui-portal-mark-text {
    display: flex;
    min-width: 0;
    flex-direction: column;
  }
  .ui-portal-mark-name {
    overflow: hidden;
    max-width: 46vw;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .ui-portal-mark-sub {
    overflow: hidden;
    display: none;
    max-width: 22rem;
    font-size: 13px;
    color: var(--ui-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .ui-portal-mark-plain {
    font-family: var(--ui-font-title);
    font-size: 17px;
    font-weight: 600;
    color: var(--ui-ink);
  }
  .ui-portal-tabs {
    display: none;
    min-width: 0;
    flex: 1;
    margin-left: 8px;
  }
  .ui-portal-tabs .ui-tabs {
    margin: 0;
    padding: 0;
  }
  .ui-portal-tabs .ui-tabs ul {
    border-bottom: 0;
  }
  .ui-portal-switch,
  .ui-portal-account {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    border: 1px solid var(--ui-line);
    border-radius: var(--ui-radius-pill);
    font-size: 15px;
    font-weight: 600;
    color: var(--ui-ink);
    white-space: nowrap;
  }
  .ui-portal-switch {
    display: none;
    margin-left: auto;
  }
  .ui-portal-account {
    margin-left: auto;
    padding: 0 12px 0 8px;
  }
  .ui-portal-switch svg,
  .ui-portal-account svg {
    width: 18px;
    height: 18px;
    color: var(--ui-muted);
  }
  .ui-portal-offline {
    margin: 0;
    padding: 10px 16px;
    background: var(--ui-ink);
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    text-align: center;
  }
  .ui-portal-main {
    flex: 1;
    padding-bottom: calc(5rem + env(safe-area-inset-bottom));
  }
  .ui-portal-foot {
    padding: 20px 16px 24px;
    background: var(--ui-surface);
    border-top: 1px solid var(--ui-line);
    font-size: 15px;
    color: var(--ui-muted);
  }
  .ui-portal-foot-in {
    display: flex;
    max-width: 72rem;
    margin: 0 auto;
    flex-direction: column;
    gap: 8px;
  }
  .ui-portal-foot-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
  }
  .ui-portal-bar a {
    font-size: 11px;
  }
  .ui-portal-fab {
    position: fixed;
    right: 16px;
    bottom: calc(5rem + env(safe-area-inset-bottom));
    z-index: 35;
    display: inline-flex;
    width: 56px;
    height: 56px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--ui-brand);
    color: #fff;
    box-shadow: 0 2px 4px rgb(20 33 58 / 0.18), 0 14px 30px -12px rgb(20 33 58 / 0.55);
  }
  .ui-portal-fab svg {
    width: 24px;
    height: 24px;
  }
  .ui-portal-fab span:not(.ui-sr) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  /* ---------- The auth frame (sign-in, welcome, privacy, an invitation) ---------- */
  .ui-portal-auth {
    display: flex;
    min-height: 100dvh;
    flex-direction: column;
  }
  .ui-portal-auth-top {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-line);
  }
  .ui-portal-auth-main {
    flex: 1;
    padding: 24px 16px 40px;
  }
  .ui-portal-auth-main > * {
    max-width: 44rem;
    margin: 0 auto;
  }
  .ui-portal-auth .ui-portal-foot {
    background: transparent;
    text-align: center;
  }
  .ui-portal-auth .ui-portal-foot-in {
    align-items: center;
  }

  /* ---------- The "Now" hero ---------- */
  .ui-now {
    padding: 20px;
  }
  .ui-now-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }
  .ui-now-eyebrow {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ui-muted);
  }
  .ui-now-title {
    margin: 10px 0 0;
    font-family: var(--ui-font-title);
    font-size: 25px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.01em;
    color: var(--ui-ink);
  }
  .ui-now-text {
    margin: 8px 0 0;
    font-size: 17px;
    line-height: 1.55;
    color: var(--ui-body);
  }
  .ui-now-action {
    margin: 18px 0 0;
  }
  .ui-now-action .ui-btn {
    width: 100%;
  }

  /* ---------- The course (the progress bar) ---------- */
  .ui-course {
    margin: 24px 0 4px;
  }
  .ui-course-now {
    margin: 0 0 14px;
    font-size: 15px;
    color: var(--ui-body);
  }
  .ui-course-now b {
    color: var(--ui-ink);
  }
  .ui-course-list {
    display: flex;
    gap: 6px;
    margin: 0;
    padding: 0;
    overflow-x: auto;
    list-style: none;
    scrollbar-width: none;
  }
  .ui-course-list::-webkit-scrollbar {
    display: none;
  }
  .ui-course-step {
    position: relative;
    display: flex;
    min-width: 78px;
    flex: 1 0 78px;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
    text-align: center;
  }
  .ui-course-step::before {
    content: "";
    position: absolute;
    top: 18px;
    right: 50%;
    width: 100%;
    height: 2px;
    background: var(--ui-line-strong);
  }
  .ui-course-step:first-child::before {
    display: none;
  }
  .ui-course-step--done::before,
  .ui-course-step--now::before {
    background: var(--ui-brand);
  }
  .ui-course-mark {
    position: relative;
    z-index: 1;
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 2px solid var(--ui-line-strong);
    border-radius: 999px;
    background: var(--ui-surface);
    font-size: 15px;
    font-weight: 700;
    color: var(--ui-muted);
  }
  .ui-course-step--done .ui-course-mark {
    border-color: var(--ui-brand);
    background: var(--ui-brand);
    color: #fff;
  }
  .ui-course-step--now .ui-course-mark {
    border-color: var(--ui-brand);
    color: var(--ui-brand);
    box-shadow: 0 0 0 4px var(--ui-brand-soft);
  }
  .ui-course-label {
    font-size: 15px;
    line-height: 1.25;
    color: var(--ui-muted);
    overflow-wrap: break-word;
  }
  .ui-course-step--done .ui-course-label {
    color: var(--ui-body);
  }
  .ui-course-step--now .ui-course-label {
    font-weight: 700;
    color: var(--ui-ink);
  }

  /* ---------- The tour's banner (WP5) ---------- */
  .ui-tour {
    background: var(--ui-ink);
    color: #fff;
  }
  .ui-tour-in {
    display: flex;
    max-width: 72rem;
    margin: 0 auto;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 10px 16px;
    font-size: 15px;
    line-height: 1.4;
  }
  .ui-tour-badge {
    padding: 2px 10px;
    border: 1px solid rgb(255 255 255 / 0.4);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .ui-tour p {
    min-width: 12rem;
    flex: 1;
    margin: 0;
  }
  .ui-tour-exit {
    padding: 6px 14px;
    border-radius: 999px;
    background: #fff;
    font-size: 14px;
    font-weight: 700;
    color: var(--ui-ink) !important;
    white-space: nowrap;
  }

  /* ---------- The portal's reading column ---------- */
  .ui-card-title {
    margin: 0;
    font-family: var(--ui-font-title);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.25;
    color: var(--ui-ink);
  }
  .ui-card-text {
    margin: 8px 0 0;
    font-size: 16px;
    line-height: 1.55;
    color: var(--ui-body);
  }
  .ui-card-link {
    margin: 14px 0 0;
  }
  .ui-figure {
    margin: 6px 0 0;
    font-family: var(--ui-font-title);
    font-size: 2.5rem;
    font-weight: 600;
    line-height: 1.05;
    color: var(--ui-ink);
  }
  .ui-bullets {
    margin: 8px 0 0;
    padding-left: 1.15rem;
    font-size: 16px;
    line-height: 1.55;
    color: var(--ui-body);
  }
  .ui-bullets li + li {
    margin-top: 4px;
  }
  .ui-portal .ui-page {
    min-height: 0;
    padding: 20px 16px 40px;
    background: transparent;
  }
  /* The system's two columns let a long line (the course's seven steps) be as wide as it likes; on the portal the
     column is the page's width and the course scrolls inside itself, so the page never scrolls sideways. */
  .ui-portal .ui-grid2 > * {
    min-width: 0;
  }
  /* A page another module still draws with the platform kit (app.css, in `kit`: the checklist, the history, the case
     chooser) is not in one of the system's page columns: give it the same reading column the v2 pages have. */
  .ui-portal-main > :not(.ui-page) {
    margin-inline: max(16px, calc((100% - 60rem) / 2));
  }
  .ui-portal-main > :first-child:not(.ui-page) {
    padding-top: 20px;
  }
  .ui-portal .ui-title {
    font-size: 1.75rem;
  }
  .ui-portal .ui-section-title {
    font-family: var(--ui-font-title);
  }
  /* The links that read as links in the portal's dark mode (the system draws them in the firm's colour). */
  .ui-portal .ui-link,
  .ui-portal .ui-back {
    color: var(--ui-brand-text, var(--ui-brand));
  }
  .ui-portal .ui-tabs a[aria-current="page"]::after {
    background: var(--ui-brand);
  }
  .ui-portal .ui-tabbar a[aria-current="page"] {
    color: var(--ui-brand-text, var(--ui-brand));
  }
  .ui-portal .ui-course-step--now .ui-course-mark {
    color: var(--ui-brand-text, var(--ui-brand));
  }

  @media (min-width: 40rem) {
    .ui-portal .ui-page {
      padding: 32px 24px 48px;
    }
    .ui-portal-main > :not(.ui-page) {
      margin-inline: max(24px, calc((100% - 60rem) / 2));
    }
    .ui-portal-main > :first-child:not(.ui-page) {
      padding-top: 32px;
    }
    .ui-portal .ui-title {
      font-size: 2rem;
    }
    /* Seven steps fit one line: the steps share what there is instead of each keeping a phone's width. */
    .ui-course-step {
      min-width: 0;
      flex: 1 1 0;
      padding: 0 2px;
    }
    .ui-now {
      padding: 26px;
    }
    .ui-now-title {
      font-size: 30px;
    }
    .ui-now-action .ui-btn {
      width: auto;
    }
    .ui-portal-mark-sub {
      display: block;
    }
  }
  @media (min-width: 64rem) {
    .ui-portal-tabs {
      display: block;
    }
    .ui-portal-switch {
      display: inline-flex;
    }
    .ui-portal-main {
      padding-bottom: 2rem;
    }
    .ui-portal-foot {
      padding: 24px 32px;
    }
    .ui-portal-fab {
      bottom: 24px;
    }
  }
}

/*
 * The portal's faces, outside the layers: legacy's globals set a face on `body` for its own pages (Archivo, or the
 * theme's), and the portal is not one of them. Inter sets the text, Lora the titles, as the system's tokens say.
 */
.ui-portal {
  font-family: var(--ui-font);
}
