/* =========================================================
   Apply Studio visual identity.

   Small, code-native graphics shared by the authenticated app and
   the public sign-in page. These line-based, data-adjacent marks sit
   alongside the original editorial artwork on the sign-in page and
   stay within the cockpit palette.
   ========================================================= */

.brand-mark {
  width: 27px;
  height: 27px;
  flex: 0 0 27px;
  overflow: visible;
}

.brand-mark__field {
  fill: var(--surface-2);
  stroke: var(--border);
  stroke-width: 1;
}

.brand-mark__route {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark__node {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 1.5;
}

.brand-mark__node--terminal { fill: var(--accent); }

.cockpit-brand a { gap: 10px; }
.header .cockpit-brand {
  display: flex;
  align-items: center;
  min-height: 38px;
  color: var(--text-dim);
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -.015em;
}

.header nav a.active,
.header nav a[aria-current="page"] {
  color: var(--text);
  position: relative;
}

.mobile-nav-toggle { display: none; }

@media (min-width: 768px) {
  .header nav a.active::after,
  .header nav a[aria-current="page"]::after {
    content: "";
    position: absolute;
    left: 2px;
    right: 2px;
    bottom: -7px;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
  }
}

@media (max-width: 767px) {
  .brand-mark { width: 25px; height: 25px; flex-basis: 25px; }
  .header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 12px;
    padding: 10px 0;
  }
  .header .cockpit-brand { grid-column: 1; min-height: 44px; }
  .cockpit-brand a { min-height: 44px; }
  .mobile-nav-toggle {
    grid-column: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 78px;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-btn);
    background: var(--surface);
    color: var(--text-dim);
    font-family: var(--display);
    font-size: .76rem;
    font-weight: 600;
    cursor: pointer;
  }
  .mobile-nav-toggle svg { width: 17px; height: 17px; }
  .mobile-nav-toggle path {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
  }
  .header nav,
  .header #site-nav {
    grid-column: 1 / -1;
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
    padding: 8px;
    max-height: calc(100dvh - 82px - env(safe-area-inset-top, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-card);
    box-shadow: var(--shadow-md);
  }
  .header.is-nav-open #site-nav { display: grid; }
  .header nav a,
  .header #site-nav a {
    min-height: 46px;
    padding: 10px 12px;
    border-radius: var(--r-btn);
    font-size: .82rem;
    scroll-snap-align: none;
  }
  .header nav a.active,
  .header nav a[aria-current="page"] {
    background: var(--accent-dim);
    color: var(--text);
    border-radius: var(--r-btn);
  }
  .header #palette-open,
  .header #theme-toggle,
  .header nav a[href="/auth/logout"] {
    position: static;
    right: auto;
    width: auto;
    min-width: 0;
    min-height: 46px;
    height: 46px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-btn);
    z-index: auto;
  }
  .header #palette-open { grid-column: 1; }
  .header #theme-toggle { grid-column: 2; }
  .header nav a[href="/auth/logout"] {
    grid-column: 1 / -1;
    width: auto;
    padding: 10px 12px;
    font-size: .76rem;
  }
  .header #palette-open::before { display: none; }
  .palette-trigger__hint { display: inline; }

  /* The guide lives in the menu on phones. This preserves access without a
     fixed control covering rows, forms, the inbox FAB, or the detail actions. */
  body > .guide-trigger { display: none; }
  .header #site-nav .guide-trigger {
    position: static;
    grid-column: 1 / -1;
    display: inline-flex;
    width: auto;
    min-width: 0;
    height: 46px;
    min-height: 46px;
    padding: 0 12px;
    justify-content: center;
    border-radius: var(--r-btn);
    background: var(--surface-2);
    box-shadow: none;
    z-index: auto;
  }
  .header #site-nav .guide-trigger-label { display: inline; }

  /* Phone-wide rhythm and safe-area handling. This sheet loads last on every
     authenticated page, so these rules also protect older dense page styles. */
  body.cockpit .container {
    padding-left: max(14px, env(safe-area-inset-left, 0px));
    padding-right: max(14px, env(safe-area-inset-right, 0px));
  }
  body.cockpit button,
  body.cockpit a,
  body.cockpit summary { touch-action: manipulation; }
  body.cockpit input,
  body.cockpit select,
  body.cockpit textarea { font-size: max(16px, 1em); }
  body.cockpit a,
  body.cockpit dd,
  body.cockpit td,
  body.cockpit pre { overflow-wrap: anywhere; }
  .resp-scroll,
  .mach-scroll,
  .ibx-accounts,
  .ibx-folder-seg {
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }
  .scroll-affordance.has-overflow-right:not(.has-overflow-left) {
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
  }
  .scroll-affordance.has-overflow-left:not(.has-overflow-right) {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 28px, #000 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 28px, #000 100%);
  }
  .scroll-affordance.has-overflow-left.has-overflow-right {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 28px, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 28px, #000 calc(100% - 28px), transparent 100%);
  }

  /* Touch targets: enlarge the actionable wrapper, not the checkbox or icon
     inside it. Presentational chips and status dots stay compact. */
  .needs-evidence-link,
  .needs-more > summary,
  .jx-search,
  .jx-seg-btn,
  .jx-source-item,
  .jx-toggle-row,
  .jx-show-more,
  .jx-chip-filter,
  .jx-detail-actions a,
  .jx-more-btn,
  .state-hero-item,
  .seg-btn,
  .apps-search,
  .apps-select,
  .apps-toggle-chip,
  .apps-clear,
  .apps-more,
  .row-evidence,
  .row-chevron,
  .outcome-btn,
  .apply-back,
  #add-question,
  .ibx-search-input,
  .ibx-search-clear,
  .ibx-chip-app,
  .ibx-act,
  .ibx-attach-chip,
  .ibx-reply-btn,
  .ibx-compose-x,
  .ibx-compose-send,
  .ibx-ccbcc-toggle {
    min-height: 44px;
  }
  .jx-rail-title[for] {
    display: flex;
    align-items: center;
    min-height: 44px;
    margin-bottom: 0;
  }
  .jx-source-item,
  .jx-toggle-row { padding-block: 7px; }
  .jx-source-item .jx-source-label { text-transform: none; }
  .jx-show-more { display: flex; align-items: center; }
  .jx-chip-filter,
  .state-hero-item,
  .row-evidence,
  .apply-back,
  .ibx-chip-app,
  .ibx-attach-chip { display: inline-flex; align-items: center; }
  .jx-chip--applied {
    display: inline-flex;
    align-items: center;
    min-width: 44px;
    min-height: 44px;
  }
  .state-hero-seg { pointer-events: none; }
  .apps-select {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    min-height: 44px;
  }
  .row-chevron { width: 44px; height: 44px; }
  .app-row-main { grid-template-columns: minmax(0, 1fr) 24px 104px; }
  .col-actions { gap: 4px; }
  .apply-back { padding-right: 12px; margin-bottom: 6px; }
  .ibx-refresh { min-width: 44px; }
  .ibx-search-clear { width: 44px; height: 44px; right: 0; }
  .ibx-chip-app { min-width: 44px; padding-inline: 8px; }
  .detail-grid a { display: inline-flex; align-items: center; min-height: 44px; }

  /* Profile data reads as label then value on phones. Long URLs and document
     names wrap within the panel instead of collapsing the value column. */
  .data-grid { grid-template-columns: minmax(0, 1fr); gap: 3px; }
  .data-grid dt { align-self: auto; margin-top: 10px; }
  .data-grid dt:first-child { margin-top: 0; }
  .data-grid dd { min-width: 0; overflow-wrap: anywhere; word-break: normal; }
  .data-grid dd a,
  .row-sub a,
  .doc-list a {
    display: inline-flex;
    align-items: center;
    min-width: 44px;
    min-height: 44px;
  }
  .doc-list li { align-items: flex-start; flex-wrap: wrap; }
  .doc-list a { min-width: 0; overflow-wrap: anywhere; }
  .doc-meta { white-space: normal; }

  /* The legacy bottom nav is retired, so the fixed detail controls belong at
     the physical bottom edge. One compact row leaves the active form visible. */
  .apply-actionbar {
    bottom: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 66px 106px;
    gap: 6px;
    padding:
      8px
      max(12px, env(safe-area-inset-right, 0px))
      max(8px, env(safe-area-inset-bottom, 0px))
      max(12px, env(safe-area-inset-left, 0px));
    flex-wrap: nowrap;
  }
  .apply-actionbar .action-primary,
  .apply-actionbar .action-save,
  .apply-actionbar .more-actions { min-width: 0; }
  .apply-actionbar .action-primary {
    width: auto;
    min-height: 48px;
    padding: 8px;
    font-size: .86rem;
    white-space: nowrap;
  }
  .apply-actionbar .action-save,
  .apply-actionbar .more-actions-trigger {
    min-height: 48px;
    padding: 8px;
    font-size: .8rem;
  }
  .apply-actionbar .more-actions-trigger { white-space: normal; line-height: 1.1; }

  .ibx-fab {
    right: max(18px, env(safe-area-inset-right, 0px));
  }
  .ibx-refresh,
  .ibx-acct-chip,
  .ibx-folder-seg .seg-btn { min-height: 44px; }
  .toast {
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 380px) {
  .header .cockpit-brand { font-size: .96rem; }
  .mobile-nav-toggle { min-width: 72px; padding-inline: 10px; }
  .apply-actionbar { grid-template-columns: minmax(0, 1fr) 60px 96px; }
  .apply-actionbar .action-primary,
  .apply-actionbar .action-save,
  .apply-actionbar .more-actions-trigger { font-size: .78rem; }
}
