:where(button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, white);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .thread-subnav { padding-inline: 12px; }
  .thread-header { align-items: flex-start; padding: 10px 14px; }
  .thread-header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .thread-overview { padding: 18px 14px; }
  .thread-overview-toolbar { align-items: stretch; flex-direction: column; }
  .thread-overview-toolbar label { min-width: 0; }
  .thread-overview-card { align-items: flex-start; flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .thread-subnav { gap: 4px; padding: 6px 8px; }
  .thread-target { min-height: 44px; padding: 8px 11px; }
  .thread-header { display: grid; gap: 9px; }
  .thread-header > div:first-child { flex-wrap: wrap; }
  .thread-header-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .thread-header-actions button { min-height: 44px; min-width: 0; }
  .thread-overview { padding: 14px 10px calc(80px + env(safe-area-inset-bottom)); }
  .thread-overview-header { align-items: flex-start; }
  .thread-overview-header .primary-action { min-height: 44px; }
  .thread-overview-filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .thread-overview-filters button { min-height: 44px; flex: 0 0 auto; }
  .thread-overview-card { display: grid; }
  .thread-overview-main { min-height: 44px; }
  .thread-close-run-actions { display: grid; }
}

.mobile-sidebar-button,
.mobile-sidebar-backdrop,
.mobile-chat-back,
.mobile-global-navigation,
.mobile-more-overlay,
.workspace-mobile-heading {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1023px) {
  body.mobile-sidebar-open {
    overflow: hidden;
  }

  .app-shell {
    display: block;
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .mobile-sidebar-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
    gap: 8px;
    flex: 0 0 auto;
  }

  .mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 990;
    display: block;
    border: 0;
    border-radius: 0;
    background: rgb(0 0 0 / 58%);
    opacity: 0;
    pointer-events: none;
  }

  .mobile-sidebar-backdrop[hidden] {
    display: none;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    width: min(88vw, 340px);
    height: 100dvh;
    min-height: 100dvh;
    overflow: auto;
    transform: translateX(-102%);
    box-shadow: 12px 0 36px rgb(0 0 0 / 28%);
  }

  body.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.mobile-sidebar-open .mobile-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .chat-workspace {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
  }

  .topbar {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
  }

  .room-title {
    min-width: 0;
    flex: 1 1 auto;
  }

  .room-title h2 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions {
    width: auto;
    max-width: none;
    flex: 0 0 auto;
    flex-flow: row nowrap;
    overflow: visible;
  }

  .topbar-actions > button {
    min-width: 44px;
    min-height: 44px;
    flex: 0 0 auto;
  }

  .topbar-actions > .feedback-action,
  .topbar-actions > .pinned-messages-action {
    display: none;
  }

  .message-list {
    overscroll-behavior: contain;
  }

  .operating-context-strip,
  .campaign-workspace-strip {
    grid-template-columns: minmax(0, 1fr);
    margin-right: 12px;
    margin-left: 12px;
  }

  .operating-context-actions,
  .campaign-workspace-actions {
    width: 100%;
    align-items: stretch;
  }

  .operating-context-actions > button,
  .campaign-workspace-actions > button,
  .campaign-workspace-phase-status {
    flex: 1 1 0;
  }

  .campaign-workspace-phase-status strong {
    width: 100%;
    min-width: 0;
  }

  .composer {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  #attachment-button,
  #send-button,
  .composer button,
  .mobile-sidebar-button {
    min-width: 44px;
    min-height: 44px;
  }

  .detail-panel,
  .channel-context-panel,
  .operational-surface,
  .dialog[open] {
    inset: 0;
    z-index: 1200;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
  }

  .operational-surface {
    padding: 0;
  }

  .operational-surface-shell {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
  }
}

@media (max-width: 767px) {
  .app-shell {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  .chat-workspace {
    height: 100%;
    min-height: 0;
  }

  .sidebar {
    inset: 0 0 calc(64px + env(safe-area-inset-bottom)) 0;
    z-index: 800;
    width: 100vw;
    max-width: none;
    height: auto;
    min-height: 0;
    padding-bottom: 12px;
    transform: none;
    box-shadow: none;
  }

  body.mobile-workspace-chat .sidebar {
    display: none;
  }

  body.mobile-workspace-list .sidebar {
    display: flex;
  }

  body.mobile-workspace-list .chat-workspace {
    display: none;
  }

  body.mobile-workspace-chat .chat-workspace {
    display: flex;
    width: 100%;
    min-width: 0;
    max-width: 100vw;
    flex-direction: column;
    overflow: hidden;
  }

  .mobile-sidebar-backdrop,
  body.mobile-sidebar-open .mobile-sidebar-backdrop {
    display: none;
  }

  .workspace-mobile-heading {
    display: block;
    margin: 0;
    padding: 14px 18px 8px;
    color: #fff;
    font-size: 18px;
    line-height: 1.2;
  }

  .mobile-sidebar-button {
    display: none;
  }

  .mobile-chat-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    flex: 0 0 44px;
  }

  body.mobile-sidebar-open .mobile-chat-back {
    display: none;
  }

  .topbar {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 64px;
    flex-direction: row;
    align-items: center;
    padding: 8px 10px;
  }

  .topbar-actions {
    display: flex;
    width: auto;
    gap: 2px;
  }

  .topbar-actions > :not(#operating-context-open):not(#mobile-header-more) {
    display: none;
  }

  .topbar-actions > #operating-context-open,
  .topbar-actions > #mobile-header-more {
    display: inline-grid;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .room-title .eyebrow {
    font-size: 10px;
  }

  .room-title h2 {
    font-size: 17px;
  }

  .message-list {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 16px 12px;
  }

  .composer {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 10px 12px;
  }

  .composer-actions {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    flex-direction: row;
    align-items: center;
  }

  .composer-buttons {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .composer-buttons {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .runtime-composer,
  .context-composer {
    width: 1px;
    min-width: 1px;
    max-width: 1px;
    flex: 0 0 1px;
  }

  .runtime-action {
    width: auto;
    max-width: none;
  }

  .chat-run-status-row,
  .chat-run-status-row.failed {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .chat-run-status-row.failed .run-failure-label {
    display: none;
  }

  .chat-run-status-row.failed .run-status-copy {
    grid-column: 2;
  }

  .runtime-popover {
    right: 0;
    left: auto;
    width: min(100%, 420px);
  }

  .mobile-global-navigation {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 900;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 2px;
    min-height: calc(64px + env(safe-area-inset-bottom));
    padding: 6px 8px max(6px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    box-shadow: 0 -8px 24px rgb(15 23 42 / 10%);
  }

  .mobile-global-navigation button {
    min-width: 44px;
    min-height: 44px;
    padding: 6px 4px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
  }

  .mobile-global-navigation button[aria-current="page"] {
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
    color: var(--ink);
  }

  .login-form-stack input,
  .login-form-stack button,
  .google-auth-button,
  .channel-button,
  .campaign-workstream-button,
  .campaign-workstream-row-action,
  .campaign-archive-toggle,
  .campaign-workstream-action-menu button {
    min-height: 44px;
  }

  .campaign-workstream-row {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .campaign-workstream-row-action {
    width: 44px;
    min-width: 44px;
  }

  .operating-context-strip,
  .campaign-workspace-strip {
    min-width: 0;
    max-width: calc(100% - 16px);
    margin-right: 8px;
    margin-left: 8px;
  }

  .operating-context-actions,
  .campaign-workspace-actions {
    flex-wrap: wrap;
  }

  .notification-toast-region {
    right: 10px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
  }

  .reaction-toolbar {
    position: static;
    top: auto;
    right: auto;
    display: none;
    justify-content: flex-end;
    margin-top: 8px;
    opacity: 1;
    pointer-events: auto;
  }

  .message:focus .reaction-toolbar,
  .message:focus-within .reaction-toolbar,
  .reaction-toolbar:focus-within {
    display: flex;
  }

  .reaction-quickbar {
    max-width: 100%;
    overflow-x: auto;
  }

  .reaction-add-button,
  .reaction-quickbar-button,
  .reaction-action-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    flex: 0 0 44px;
  }

  .global-search-overlay {
    z-index: 1300;
    padding: 8px;
  }

  .global-search-panel {
    width: 100%;
    max-height: calc(100dvh - 16px);
  }

  .detail-panel .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .channel-group-heading,
  .sidebar-small-action,
  .icon-button,
  .detail-panel .tab,
  .global-search-form button,
  .notification-center-actions button,
  .notification-row button,
  .run-center-actions button,
  #new-channel-button,
  #agent-run-center-refresh,
  #notification-center-refresh-button,
  #notification-center-read-all-button {
    min-width: 44px;
    min-height: 44px;
  }

  .mobile-more-overlay {
    position: fixed;
    inset: 0;
    z-index: 1350;
    display: grid;
    align-items: end;
    padding: 16px 12px calc(76px + env(safe-area-inset-bottom));
    background: rgb(0 0 0 / 58%);
  }

  .mobile-more-overlay[hidden] {
    display: none;
  }

  .mobile-more-sheet {
    width: 100%;
    max-height: min(680px, calc(100dvh - 96px));
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 20px 60px rgb(15 23 42 / 32%);
  }

  .mobile-more-header {
    display: flex;
    min-height: 56px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px 8px 16px;
    border-bottom: 1px solid var(--line);
  }

  .mobile-more-header h3 {
    margin: 0;
  }

  .mobile-more-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
  }

  .mobile-more-actions button {
    min-width: 44px;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface-2);
    color: var(--ink);
    font-weight: 850;
  }
}
